Spatial queries

To find the county and the congressional district, two PostGIS spatial analysis techniques are used—ST_Contains and ST_Intersects. The first query determines if the arena is contained within a county; if not, the result is null (or None in Python):

        county=session.query(County).filter(
County.geom.ST_Contains(arena.geom)).first()
if county != None:
district=session.query(District).filter(
District.geom.ST_Intersects(arena.geom)).first()

While ST_Contains could be used for both queries, I wanted to demonstrate that the GeoAlchemy2 ORM allows for access to all PostGIS functions when using Geometry columns. These searches combine the SQLAlchemy filter method with the GeoAlchemy2 ORM to make it possible to return query results based on a spatial analysis.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset