I am trying to read from a local instance of the OpenStreetMap database all roads intersecting a boundary coming from another database.

I actually get a result with the following piece of code:

#postgis_engine is the SQLAlchemy postgis engine
#boundary_geom is the polygon representing the boundary
roads = geopandas.GeoDataFrame.from_postgis(text('SELECT name, way FROM planet_osm_line WHERE highway IS NOT NULL AND ST_Intersects(way, ST_GeomFromText(:b, 3857)) = true'),
            postgis_engine, 'way', {'init': 'epsg:3857'}, params={'b': boundary_geom.wkt})

As you can see I convert the boundary to its wkt representation and use it as a parameter for the SQL query.

I am wondering if, in a such way, I can break some text parameter length limitation of the underlying database access technology (i.e. SqlAlchemy).

Is there another way to pass a geometry parameter to the GeoDataFrame from_postgis method?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.