import gws.common.layer
import gws.gis.shape
import gws.gis.feature
import gws.gis.proj
import gws.common.db
import gws.tools.json2
import gws.types as t
[docs]class Config(gws.common.layer.VectorConfig):
"""GeoJson layer"""
path: t.FilePath #: geojson file
keyProp: str = 'id' #: property name for unique ids
[docs]class Object(gws.common.layer.Vector):
[docs] def get_features(self, bounds, limit=0):
shape = gws.gis.shape.from_bounds(bounds).transformed_to(self.own_crs)
fs = [f for f in self.features if f.shape.intersects(shape)]
if limit:
fs = fs[:limit]
return [self.connect_feature(f) for f in fs]
def _get_crs(js):
crs = js.get('crs')
if not crs:
return
if crs['type'] == 'name':
return crs['properties']['name']
if crs['type'] == 'epsg':
return 'EPSG:' + str(crs['properties']['code'])
raise ValueError(f'unsupported crs type {crs["type"]!r}')