Ejemplo n.º 1
0
 def insert(entity: Entity, data: dict[str, Any]) -> None:
     for shape in ['point', 'line', 'polygon']:
         if shape not in data or not data[shape]:
             continue  # pragma: no cover
         for item in json.loads(data[shape]):
             if not item['geometry']['coordinates'] \
                     or item['geometry']['coordinates'] == [[]]:
                 continue  # pragma: no cover
             if item['properties']['shapeType'] != 'centerpoint' \
                     and not Db.test_geom(json.dumps(item['geometry'])):
                 raise InvalidGeomException
             Db.insert(shape='linestring' if shape == 'line' else shape,
                       data={
                           'entity_id':
                           entity.id,
                           'name':
                           sanitize(item['properties']['name'], 'text'),
                           'description':
                           sanitize(item['properties']['description'],
                                    'text'),
                           'type':
                           item['properties']['shapeType'],
                           'geojson':
                           json.dumps(item['geometry'])
                       })
Ejemplo n.º 2
0
 def insert(entity: Entity, form: FlaskForm) -> None:
     for shape in ['point', 'line', 'polygon']:
         data = getattr(form, 'gis_' + shape + 's').data
         if not data:
             continue  # pragma: no cover
         for item in json.loads(data):
             if not item['geometry']['coordinates'] \
                     or item['geometry']['coordinates'] == [[]]:
                 continue  # pragma: no cover
             if item['properties']['shapeType'] != 'centerpoint':
                 Db.test_geom(json.dumps(item['geometry']))
             Db.insert(shape='linestring' if shape == 'line' else shape,
                       data={
                           'entity_id':
                           entity.id,
                           'name':
                           sanitize(item['properties']['name'], 'text'),
                           'description':
                           sanitize(item['properties']['description'],
                                    'text'),
                           'type':
                           item['properties']['shapeType'],
                           'geojson':
                           json.dumps(item['geometry'])
                       })