Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __update__(self, feature):
"""
Called by the protocol on object update.
Arguments:
* ``feature`` The GeoJSON feature as received from the client.
"""
for p in class_mapper(self.__class__).iterate_properties:
if not isinstance(p, ColumnProperty):
continue
col = p.columns[0]
if isinstance(col.type, Geometry):
geom = feature.geometry
if geom and not isinstance(geom, geojson.geometry.Default):
srid = col.type.srid
shape = asShape(geom)
setattr(self, p.key, from_shape(shape, srid=srid))
self._shape = shape
elif not col.primary_key:
if p.key in feature.properties:
setattr(self, p.key, feature.properties[p.key])
if self.__add_properties__:
for k in self.__add_properties__:
setattr(self, k, feature.properties.get(k))
def parse_feature(feature):
if isinstance(feature.geometry, (geojson.geometry.Polygon,
geojson.geometry.MultiPolygon)):
feature.geometry = shapely.geometry.asShape(feature.geometry)
return feature
else:
return None
ret = dict(obj)
ret['features'] = features
return self._cleanup(ret)
if isinstance(obj, (geojson.Point)):
ret = dict(obj)
if len(coordinates) == 3:
ret["hasZ"] = True
ret['x'], ret['y'], ret['z'] = coordinates
else:
ret['x'], ret['y'] = coordinates
ret['type'] = 'esriGeometryPoint'
return self._cleanup(ret)
if isinstance(obj, geojson.geometry.LineString):
ret = dict(obj)
path = coordinates
ret['paths'] = [[xy for xy in path]]
ret['type'] = 'esriGeometryPolyline'
ret = self._hasZ(xy, ret)
return self._cleanup(ret)
if isinstance(obj, (geojson.MultiPoint)):
ret = dict(obj)
points = [xy for xy in coordinates]
ret['points'] = points
ret['type'] = 'esriGeometryMultipoint'
ret = self._hasZ(xy, ret)
def _adapt_feature_geometry(feature: geojson.Feature) -> geojson.Feature:
"""
Adapts the feature geometry to be used as a shapely geometry
:param feature: geojson.feature to be adapted
:return: feature with geometry adapted
"""
if isinstance(feature.geometry, (geojson.geometry.Polygon,
geojson.geometry.MultiPolygon)):
# adapt the geometry for use as a shapely geometry http://toblerity.org/shapely/manual.html#shapely.geometry.asShape
feature.geometry = shapely.geometry.asShape(feature.geometry)
return feature
else:
return None
ref = d['spatialReference']
if 'wkid' in ref:
wkid = ref['wkid']
crs = Named(properties=dict(name="urn:ogc:def:crs:EPSG:%d" % wkid))
if 'x' in d:
coords = [d['x'], d['y']]
return geojson.geometry.Point(coords, crs=crs)
if 'xmin' in d:
minx, miny, maxx, maxy = [d.get(k) for k in ['xmin', 'ymin', 'xmax', 'ymax']]
coords = [[[minx, miny], [maxx, miny], [maxx, maxy], [minx, maxy], [minx, miny]]]
return geojson.geometry.Polygon(coords, crs=crs)
if 'paths' in d:
coords = d['paths'][0]
return geojson.geometry.LineString(coords, crs=crs)
if 'rings' in d:
coords = d['rings']
return geojson.geometry.Polygon(coords, crs=crs)
return d
def _adapt_feature_geometry(feature: geojson.Feature) -> geojson.Feature:
"""
Adapts the feature geometry to be used as a shapely geometry
:param feature: geojson.feature to be adapted
:return: feature with geometry adapted
"""
if isinstance(feature.geometry, (geojson.geometry.Polygon,
geojson.geometry.MultiPolygon)):
# adapt the geometry for use as a shapely geometry http://toblerity.org/shapely/manual.html#shapely.geometry.asShape
feature.geometry = shapely.geometry.asShape(feature.geometry)
return feature
else:
return None
def _adapt_feature_geometry(feature: geojson.Feature) -> geojson.Feature:
"""
Adapts the feature geometry to be used as a shapely geometry
:param feature: geojson.feature to be adapted
:return: feature with geometry adapted
"""
if isinstance(
feature.geometry, (geojson.geometry.Polygon, geojson.geometry.MultiPolygon)
):
# adapt the geometry for use as a shapely geometry
# http://toblerity.org/shapely/manual.html#shapely.geometry.asShape
feature.geometry = shapely.geometry.asShape(feature.geometry)
return feature
else:
return None
ret['type'] = 'esriGeometryMultipoint'
ret = self._hasZ(xy, ret)
return self._cleanup(ret)
if isinstance(obj, geojson.MultiLineString):
ret = dict(obj)
paths = coordinates
ret['paths'] = [[xy for xy in p] for p in paths]
ret['type'] = 'esriGeometryPolyline'
ret = self._hasZ(xy, ret)
return self._cleanup(ret)
if isinstance(obj, (geojson.Polygon, geojson.geometry.Polygon)) or geom_type == 'Polygon':
ret = dict(obj)
rings = coordinates
ret['rings'] = [[xy for xy in ring] for ring in rings]
ret['type'] = 'esriGeometryPolygon'
ret = self._hasZ(xy, ret)
return self._cleanup(ret)
if isinstance(obj, geojson.MultiPolygon):
ret = dict(obj)
rings = reduce(add, coordinates)
ret['rings'] = [[xy for xy in ring] for ring in rings]
ret['type'] = 'esriGeometryPolygon'
ret = self._hasZ(xy, ret)
def parse_feature(feature):
if isinstance(feature.geometry, (geojson.geometry.Polygon,
geojson.geometry.MultiPolygon)):
feature.geometry = shapely.geometry.asShape(feature.geometry)
return feature
else:
return None