How to use the geoalchemy2.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 / gallery / View on Github external
def check_wkb(wkb, x, y):
    pt = shape.to_shape(wkb)
    assert round(pt.x, 5) == x
    assert round(pt.y, 5) == y
github hotosm / tasking-manager / osmtm / views / View on Github external
TaskState.state != TaskState.state_ready)
    history = DBSession.query(TaskState) \
                       .filter(filter) \
                       .order_by( \

    user_id = authenticated_userid(request)
    locked_task = None
    user = None
    if user_id:
        user = DBSession.query(User).get(user_id)
        locked_task = get_locked_task(, user)

    features = []
    for area in project.priority_areas:

    return dict(page_id='project', project=project,
github hotosm / tasking-manager / server / services / grid / View on Github external
horizontal_dividing_line = LineString([(minx, centroid.y), (maxx, centroid.y)])

        vertical_halves = SplitService._as_halves(
            split(geometry, vertical_dividing_line), centroid, "x"
        for half in vertical_halves:
            split_geometries += SplitService._as_halves(
                split(half, horizontal_dividing_line), centroid, "y"

        # convert split geometries into GeoJSON features expected by Task
        split_features = []
        for split_geometry in split_geometries:
            feature = geojson.Feature()
            # Tasks expect multipolygons. Convert and use the database to get as GeoJSON
            multipolygon_geometry = shape.from_shape(split_geometry, 4326)
            feature.geometry = geojson.loads(
  ["x"] = None
  ["y"] = None
  ["zoom"] = None
  ["isSquare"] = False
        return split_features
github hotosm / tasking-manager / server / services / View on Github external
trk, "name"
        ).text = f"Task for project {project_id}. Do not edit outside of this area!"

        # Construct trkseg elements
        if task_ids_str is not None:
            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()
            tasks = Task.get_all_tasks(project_id)
            if not tasks or len(tasks) == 0:
                raise NotFound()

        for task in tasks:
            task_geom = shape.to_shape(task.geometry)
            for poly in task_geom:
                trkseg = ET.SubElement(trk, "trkseg")
                for point in poly.exterior.coords:
                        attrib=dict(lon=str(point[0]), lat=str(point[1])),

                    # Append wpt elements to end of doc
                    wpt = ET.Element(
                        "wpt", attrib=dict(lon=str(point[0]), lat=str(point[1]))

        xml_gpx = ET.tostring(root, encoding="utf8")
github hotosm / tasking-manager / osmtm / scripts / View on Github external
# then, load the Alembic configuration and generate the
    # version table, "stamping" it with the most recent rev:
    from alembic.config import Config
    from alembic import command
    alembic_cfg = Config("alembic.ini")
    url = settings['sqlalchemy.url']
    alembic_cfg.set_section_option("alembic", "sqlalchemy.url", url)
    command.stamp(alembic_cfg, "head")

    with transaction.manager:
        geometry = '{"type":"Polygon","coordinates":[[[85.31038284301758,27.70731518595052],[85.31089782714842,27.698120147680104],[85.3242015838623,27.69842412827061],[85.323429107666,27.70731518595052],[85.31038284301758,27.70731518595052]]]}'  # noqa
        geometry = geojson.loads(geometry,
        geometry = shapely.geometry.asShape(geometry)
        geometry = shape.from_shape(geometry, 4326)

        area = Area(

        license1 = License() = 'NextView'
        license1.description = "This data is licensed for use by the US Government (USG) under the NextView (NV) license and copyrighted by Digital Globe or GeoEye. The NV license allows the USG to share the imagery and Literal Imagery Derived Products (LIDP) with entities outside the USG when that entity is working directly with the USG, for the USG, or in a manner that is directly beneficial to the USG. The party receiving the data can only use the imagery or LIDP for the original purpose or only as otherwise agreed to by the USG. The party receiving the data cannot share the imagery or LIDP with a third party without express permission from the USG. At no time should this imagery or LIDP be used for other than USG-related purposes and must not be used for commercial gain. The copyright information should be maintained at all times. Your acceptance of these license terms is implied by your use."  # noqa
        license1.plain_text = "In other words, you may only use NextView imagery linked from this site for digitizing OpenStreetMap data for humanitarian purposes."  # noqa

        license2 = License() = 'Astrium/UNOSAT'
        license2.description = "UNOSAT allow any INTERNET USER to use the IMAGE to develop DERIVATIVE WORKS provided that the INTERNET USER includes the DERIVATIVE WORKS he/she created in the OpenStreetMap database under CC-BY-SA licence ( and/or Open Database licence (ODbL:, with the credit of the corresponding PRODUCT conspicuously displayed and written in full, in order to allow any OpenStreetMap database user to have access to and to use the DERIVATIVE WORKS. Except for the foregoing, the END USER and/or the INTERNET USER shall not be entitled to sell, distribute, assign, dispose of, lease, sublicense or transfer, directly or indirectly, any DERIVATIVE WORKS to any third party."  # noqa
        license2.plain_text = "Astrium GEO-Information Services and UNOSAT are allowing access to this imagery for creating information in OpenStreetMap. Other uses are not allowed."  # noqa
github hotosm / tasking-manager / osmtm / View on Github external
def __init__(self, x, y, zoom, geometry=None, properties=None):
        self.x = x
        self.y = y
        self.zoom = zoom
        if properties is not None:
            self.extra_properties = unicode(_dumps(properties))
        if geometry is None:
            geometry = self.to_polygon()
            multipolygon = MultiPolygon([geometry])
            geometry = ST_Transform(shape.from_shape(multipolygon, 3857), 4326)

        self.geometry = geometry

github hotosm / tasking-manager / server / services / View on Github external
def _get_area_sqm(polygon: Polygon) -> float:
        """ get the area of the polygon in square metres """
        return db.engine.execute(
            ST_Area(ST_Transform(shape.from_shape(polygon, 4326), 3857))
github hotosm / tasking-manager / server / services / grid / View on Github external
max = MAXRESOLUTION * 256 / 2

        # calculate extents
        step = max / (2 ** (zoom - 1))
        xmin = x * step - max
        ymin = y * step - max
        xmax = (x + 1) * step - max
        ymax = (y + 1) * step - max

        # make a shapely multipolygon
        multipolygon = MultiPolygon(
            [Polygon([(xmin, ymin), (xmax, ymin), (xmax, ymax), (xmin, ymax)])]

        # use the database to transform the geometry from 3857 to 4326
        transformed_geometry = ST_Transform(shape.from_shape(multipolygon, 3857), 4326)

        # use DB to get the geometry as geojson
        return geojson.loads(
github hotosm / tasking-manager / osmtm / View on Github external
def auto_fill(self, zoom):
        self.zoom = zoom
        geom_3857 = DBSession.execute(ST_Transform(self.area.geometry, 3857)) \
        geom_3857 = shape.to_shape(geom_3857)

        tasks = []
        for i in get_tiles_in_geom(geom_3857, zoom):
            multi = MultiPolygon([i[2]])
            geometry = ST_Transform(shape.from_shape(multi, 3857), 4326)
            tasks.append(Task(i[0], i[1], zoom, geometry))
        self.tasks = tasks
github hotosm / tasking-manager / osmtm / views / View on Github external
def project_grid_simulate(request):
    ''' Returns collection of polygons representing the grid cells to be
        created. Helpful when creating a new project '''
    geometry = request.params['geometry']
    tile_size = int(request.params['tile_size'])

    features = parse_geojson(geometry)
    multipolygon = convert_to_multipolygon(features)

    geometry = shape.from_shape(multipolygon, 4326)

    geom_3857 = DBSession.execute(ST_Transform(geometry, 3857)).scalar()
    geom_3857 = shape.to_shape(geom_3857)
    zoom = get_zoom_for_tile_size(geom_3857, tile_size)

    found = get_tiles_in_geom(geom_3857, zoom)
    polygons = [i[2] for i in found]
    multi = MultiPolygon(polygons)

    geometry = DBSession.execute(
        ST_Transform(shape.from_shape(multi, 3857), 4326)).scalar()

    return FeatureCollection([Feature(geometry=shape.to_shape(geometry))])