How to use the geoalchemy2.shape.to_shape function in GeoAlchemy2

To help you get started, we’ve selected a few GeoAlchemy2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github geoalchemy / geoalchemy2 / tests / test_shape.py View on Github external
def test_to_shape_WKBElement():
    # POINT(1 2)
    e = WKBElement(b'\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00'
                   b'\x00\xf0?\x00\x00\x00\x00\x00\x00\x00@')
    s = to_shape(e)
    assert isinstance(s, Point)
    assert s.x == 1
    assert s.y == 2
github hotosm / tasking-manager / server / services / mapping_service.py View on Github external
# Note XML created with upload No to ensure it will be rejected by OSM if uploaded by mistake
        root = ET.Element('osm', attrib=dict(version='0.6', upload='never', creator='HOT Tasking Manager'))

        if task_ids_str:
            task_ids = map(int, task_ids_str.split(','))
            tasks = Task.get_tasks(project_id, task_ids)
            if not tasks or tasks.count() == 0:
                raise NotFound()
        else:
            tasks = Task.get_all_tasks(project_id)
            if not tasks or len(tasks) == 0:
                raise NotFound()

        fake_id = -1  # We use fake-ids to ensure XML will not be validated by OSM
        for task in tasks:
            task_geom = shape.to_shape(task.geometry)
            way = ET.SubElement(root, 'way', attrib=dict(id=str((task.id * -1)), action='modify', visible='true'))
            for poly in task_geom:
                for point in poly.exterior.coords:
                    ET.SubElement(root, 'node', attrib=dict(action='modify', visible='true', id=str(fake_id),
                                                            lon=str(point[0]), lat=str(point[1])))
                    ET.SubElement(way, 'nd', attrib=dict(ref=str(fake_id)))
                    fake_id -= 1

        xml_gpx = ET.tostring(root, encoding='utf8')
        return xml_gpx
github hotosm / tasking-manager / server / services / mapping_service.py View on Github external
attrib=dict(version="0.6", upload="never", creator="HOT Tasking Manager"),
        )

        if task_ids_str:
            task_ids = map(int, task_ids_str.split(","))
            tasks = Task.get_tasks(project_id, task_ids)
            if not tasks or len(tasks) == 0:
                raise NotFound()
        else:
            tasks = Task.get_all_tasks(project_id)
            if not tasks or len(tasks) == 0:
                raise NotFound()

        fake_id = -1  # We use fake-ids to ensure XML will not be validated by OSM
        for task in tasks:
            task_geom = shape.to_shape(task.geometry)
            way = ET.SubElement(
                root,
                "way",
                attrib=dict(id=str((task.id * -1)), action="modify", visible="true"),
            )
            for poly in task_geom:
                for point in poly.exterior.coords:
                    ET.SubElement(
                        root,
                        "node",
                        attrib=dict(
                            action="modify",
                            visible="true",
                            id=str(fake_id),
                            lon=str(point[0]),
                            lat=str(point[1]),
github waymarkedtrails / waymarked-trails-site / api / details.py View on Github external
ret = OrderedDict()
        ret['id'] = oid

        r = cherrypy.request.app.config['DB']['map'].tables.routes.data
        gen = sa.select([sa.func.generate_series(0, segments).label('i')]).alias()
        field = sa.func.ST_LineInterpolatePoint(r.c.geom, gen.c.i/float(segments))
        field = sa.func.ST_Collect(field)

        sel = sa.select([field]).where(r.c.id == oid)\
                .where(r.c.geom.ST_GeometryType() == 'ST_LineString')

        res = cherrypy.request.db.execute(sel).first()

        if res is not None and res[0] is not None:
            geom = to_shape(res[0])
            xcoord, ycoord = zip(*((p.x, p.y) for p in geom))
            geomlen = LineString(geom).length
            pos = [geomlen*i/float(segments) for i in range(segments)]
            compute_elevation(((xcoord, ycoord, pos), ), geom.bounds, ret)
            return ret

        # special treatment for multilinestrings
        sel = sa.select([r.c.geom,
                         sa.literal_column("""ST_Length2dSpheroid(ST_MakeLine(ARRAY[ST_Points(ST_Transform(geom,4326))]),
                             'SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY["EPSG",\"7030\"]]')"""),
                         r.c.geom.ST_NPoints()])\
                .where(r.c.id == oid)

        res = cherrypy.request.db.execute(sel).first()

        if res is not None and res[0] is not None:
github hotosm / tasking-manager / osmtm / models.py View on Github external
properties['short_description'] = self.short_description
        properties['instructions'] = self.instructions
        properties['per_task_instructions'] = self.per_task_instructions
        properties['status'] = self.status
        properties['created'] = self.created.strftime('%FT%TZ')
        if self.author:
            properties['author'] = self.author.username
        properties['last_update'] = self.last_update.strftime('%FT%TZ')
        properties['license'] = self.license_id
        properties['priority'] = self.priority
        properties['done'] = self.done
        properties['validated'] = self.validated
        properties['changeset_comment'] = self.changeset_comment

        return Feature(
            geometry=shape.to_shape(self.area.geometry),
            id=self.id,
            properties=properties
        )
github nextgis / nextgisweb / nextgisweb / webmap / api.py View on Github external
def annotation_to_dict(obj):
    result = OrderedDict()
    for k in ('id', 'description', 'style', 'geom'):
        v = getattr(obj, k)
        if k == 'geom':
            v = to_shape(v).wkt
        if v is not None:
            result[k] = v
    return result
github ibis-project / ibis / ibis / sql / alchemy.py View on Github external
def to_shapely(row, name):
        return shape.to_shape(row[name]) if row[name] is not None else None
github hotosm / tasking-manager / server / services / project_search_service.py View on Github external
def _make_4326_polygon_from_bbox(bbox: list, srid: int) -> Polygon:
        """ make a shapely Polygon in SRID 4326 from bbox and srid"""
        try:
            polygon = box(bbox[0], bbox[1], bbox[2], bbox[3])
            if not srid == 4326:
                geometry = shape.from_shape(polygon, srid)
                geom_4326 = db.engine.execute(ST_Transform(geometry, 4326)).scalar()
                polygon = shape.to_shape(geom_4326)
        except Exception as e:
            raise ProjectSearchServiceError(f"error making polygon: {e}")
        return polygon