Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _raises_on_dump(self, unstrict):
with self.assertRaises(ValueError):
geojson.dumps(unstrict)
def test_crs_decode(self):
dumped = geojson.dumps(self.crs)
actual = geojson.loads(dumped)
self.assertEqual(actual, self.crs)
elif format == 'zip':
return ''
elif format == 'geojson':
return geojson.dumps(geojson.FeatureCollection([]))
elif format == 'json':
return cjson.encode({})
# If the scenario has an error,
if c.scenario.status == model.statusFailed:
c.traceback = c.scenario.output['traceback']
c.status = model.statusFailed
if format == 'html':
return render('/scenarios/show.mako')
elif format == 'zip':
return forward(FileApp(c.scenario.getFolder() + '.zip'))
elif format == 'geojson':
return geojson.dumps(geojson.FeatureCollection([]))
elif format == 'json':
return c.scenario.exportJSON()
# If the scenario has not been processed,
if c.scenario.isQueued():
c.status = model.statusPending
if format == 'html':
return render('/scenarios/show.mako')
elif format == 'zip':
return forward(FileApp(c.scenario.getFolder() + '.zip'))
elif format == 'geojson':
return geojson.dumps(geojson.FeatureCollection([]))
elif format == 'json':
return c.scenario.exportJSON()
# Prepare
c.status = model.statusDone
c.scenarioInput = c.scenario.input
# if self.use_geom:
# raise(NotImplementedError)
# headers = ['GID','WKT']
# else:
## if self.use_stat:
## adds = ['WKT']
## else:
## adds = ['WKT','TIME']
# headers = self.get_headers()
features = [attrs for attrs in self.get_iter(wkt=True)]
for feat in features:
feat['geometry'] = feat.pop('WKT')
if 'TIME' in feat:
feat['TIME'] = str(feat['TIME'])
fc = geojson.FeatureCollection(features)
return(geojson.dumps(fc))
def geojson(self):
return geojson.dumps(self._geom)
return render('/scenarios/show.mako')
elif format == 'zip':
return forward(FileApp(c.scenario.getFolder() + '.zip'))
elif format == 'geojson':
return geojson.dumps(geojson.FeatureCollection([]))
elif format == 'json':
return c.scenario.exportJSON()
# If the scenario has not been processed,
if c.scenario.isQueued():
c.status = model.statusPending
if format == 'html':
return render('/scenarios/show.mako')
elif format == 'zip':
return forward(FileApp(c.scenario.getFolder() + '.zip'))
elif format == 'geojson':
return geojson.dumps(geojson.FeatureCollection([]))
elif format == 'json':
return c.scenario.exportJSON()
# Prepare
c.status = model.statusDone
c.scenarioInput = c.scenario.input
c.scenarioOutput = c.scenario.output
transform_point = geometry_store.get_transform_point(geometry_store.proj4LL, geometry_store.proj4SM)
# If the user wants HTML,
if format == 'html':
# Render scenario
c.metricModel = metric.getModel(c.scenarioInput['metric model name'])
scenarioStatistics = c.scenarioOutput['statistics']
nodeStatistics = scenarioStatistics['node']
# Prepare map
centerX, centerY = transform_point(nodeStatistics['mean longitude'], nodeStatistics['mean latitude'])
box1X, box1Y = transform_point(nodeStatistics['minimum longitude'], nodeStatistics['maximum latitude'])
def as_geojson(elements):
features = []
for e in elements:
e['properties']['timestamp'] = str(e['properties']['timestamp'])
features.append(geojson.Feature(**e))
fc = geojson.FeatureCollection(features)
return(geojson.dumps(fc))
def set_project_aoi(self, draft_project_dto: DraftProjectDTO):
""" Sets the AOI for the supplied project """
aoi_geojson = geojson.loads(json.dumps(draft_project_dto.area_of_interest))
aoi_geometry = GridService.merge_to_multi_polygon(aoi_geojson, dissolve=True)
valid_geojson = geojson.dumps(aoi_geometry)
self.geometry = ST_SetSRID(ST_GeomFromGeoJSON(valid_geojson), 4326)
self.centroid = ST_Centroid(self.geometry)
def as_geojson(elements):
features = []
for e in elements:
e['properties']['timestamp'] = str(e['properties']['timestamp'])
features.append(geojson.Feature(**e))
fc = geojson.FeatureCollection(features)
return(geojson.dumps(fc))
def __init__(self, name, feature):
""" Construct mapping object from a GeoJson feature"""
self.name = name
geojson_str = geojson.dumps(feature['geometry'])
self.geometry = ST_SetSRID(ST_GeomFromGeoJSON(geojson_str), 4326)