Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
src_path = kwargs.get('src_path')
if src_path is None:
raise IOError('src path not defined')
path = os.path.join(src_path, 'mbr.txt')
polys = []
with open(path) as f:
#skip first line which is a bunding polygon
f.readline()
for line in f:
feature_id, x1, y1, x2, y2 = line.split()
properties = {'feature_id': feature_id}
polys.append(Feature(geometry=Polygon([_bbox2poly(x1, y1, x2, y2)]), properties=properties, id=feature_id))
return FeatureCollection(polys)
catalog_entries = to_geodataframe(catalog_entries)
if fmt.lower() == 'mbr-csv':
# TODO merge this with the above,
# mbr format from datalibrary not exactly the same as
# mbr fromat in quest-demo-data
polys = []
for line in f:
catalog_id, y1, x1, y2, x2 = line.split(',')
catalog_id = catalog_id.split('.')[0]
properties = {}
polys.append(Feature(geometry=bbox2poly(x1, y1, x2, y2,
as_geojson=True),
properties=properties,
id=catalog_id))
catalog_entries = FeatureCollection(polys)
catalog_entries = to_geodataframe(catalog_entries)
if fmt.lower() == 'isep-json':
# uses exported json file from ISEP DataBase
# assuming ISEP if a geotypical service for now.
catalog_entries = pd.read_json(p)
catalog_entries.rename(columns={'_id': 'service_id'}, inplace=True)
catalog_entries['download_url'] = catalog_entries['files'].apply(
lambda x: os.path.join(x[0].get('file location'), x[0].get('file name')))
# remove leading slash from file path
catalog_entries['download_url'] = catalog_entries['download_url'].str.lstrip('/')
catalog_entries['parameters'] = 'met'
all_catalog_entries.append(catalog_entries)
# drop duplicates fails when some columns have nested list/tuples like
def validate_geojson(data):
"""
Validate geojson
"""
if not (isinstance(data, dict)):
return False
if not isinstance(data.get('features'), list):
return False
gj = geojson.FeatureCollection([geojson.Feature(f) for f in data['features']])
return gj.is_valid
Name of the geometries stored, for example `buses.geojson`
geometries: pd.Series
Index entries become name fields in GeoJSON properties.
directory: string
Directory where the file is stored. Default: `data/geometries`
Returns
-------
path: string
Returns the path where the file has been stored.
"""
path = os.path.join(directory, filename)
if os.path.splitext(filename)[1] == ".geojson":
features = FeatureCollection(
[
Feature(geometry=v, properties={"name": k})
for k, v in geometries.iteritems()
]
)
if os.path.exists(path):
with open(path) as infile:
existing_features = load(infile)["features"]
names = [f["properties"]["name"] for f in existing_features]
assert all(i not in names for i in geometries.index), (
"Cannot " "create duplicate entries in %s." % filename
)
sequence = dist_node[0] # sequence number
node = dist_node[1] # node id
cost = dist_node[2] # cost value
geojs = dist_node[3] # geometry
geojs_geom = loads(geojs) # create geojson geom
geojs_feat = Feature(geometry=geojs_geom,
properties={'sequence_num': sequence,
'node':node, 'evac_time_sec':cost,
'evac_code': evac_time})
# add each point to total including all points
combined_result.append(geojs_feat)
# add each point for individual evacuation time
route_results.append(geojs_geom)
# geojson module creates GeoJSON Feature Collection
geojs_fc = FeatureCollection(route_results)
# create list of points for each evac time
evac_time_pts = [asShape(route_segment) for route_segment in route_results]
# create MultiPoint from our list of points for evac time
point_collection = geometry.MultiPoint(list(evac_time_pts))
# create our convex hull polyon around evac time points
convex_hull_polygon = point_collection.convex_hull
# intersect convex hull with hallways polygon (ch = convex hull)
cvex_hull_intersect = e01_hallway_shply.intersection(convex_hull_polygon)
# export convex hull intersection to geojson
cvex_hull = cvex_hull_intersect.__geo_interface__
def read(self, request, filter=None, id=None):
""" Build a query based on the filter or the idenfier, send the query
to the database, and return a Feature or a FeatureCollection. """
ret = None
if id is not None:
o = self.Session().query(self.mapped_class).get(id)
if o is None:
return HTTPNotFound()
# FIXME: we return a Feature here, not a mapped object, do
# we really want that?
ret = self._filter_attrs(o.__geo_interface__, request)
else:
objs = self._query(request, filter)
ret = FeatureCollection(
[self._filter_attrs(o.__geo_interface__, request)
for o in objs if o is not None])
return ret
def createGeojson(twofishes, locations):
"""Create geojson for given locations and twofishes url"""
geoms = []
for i in locations:
wkt = TwoFishes.getWktFromTwoFishes(twofishes, i)
geom = TwoFishes.createGeometryFromWkt(wkt)
for g in geom:
geoms.append(geojson.Feature(geometry=g,
properties={'location': i}))
multiPoly = geojson.FeatureCollection(geoms)
return multiPoly
dtype = matching_triangles.dtype.descr
shape = matching_triangles.shape + (len(dtype),)
coordinates = (matching_triangles.view(dtype='
for kk in range(len(data)):
if data[kk] == None: continue
feature = geojson.Feature(id=ids.next(),
geometry=igrid[ii,jj],
properties=dict({VAR:float(data[kk]),
'timestamp':str(timevec[idxtime[kk]])}))
features.append(feature)
return(features)
features = []
for polygon in POLYINT:
features += dump(polygon)
print('dumping...')
fc = geojson.FeatureCollection(features)
with open('/tmp/out.geojson','w') as f:
f.write(geojson.dumps(fc))
args = ['ogr2ogr','-overwrite','-f','ESRI Shapefile', '/tmp/out.shp','/tmp/out.geojson','OGRGeoJSON']
subprocess.call(args)
if aoi_multi_polygon.contains(tile):
# tile is completely within aoi, use as is
intersecting_features.append(feature)
else:
intersection = aoi_multi_polygon.intersection(tile)
if intersection.is_empty or intersection.geom_type not in [
"Polygon",
"MultiPolygon",
]:
continue # this intersections which are not polygons or which are completely outside aoi
# tile is partially intersecting the aoi
clipped_feature = GridService._update_feature(
clip_to_aoi, feature, intersection
)
intersecting_features.append(clipped_feature)
return geojson.FeatureCollection(intersecting_features)