Skip to Content
Mastering Geospatial Analysis with Python
book

Mastering Geospatial Analysis with Python

by Silas Toms, Paul Crickard, Eric van Rees
April 2018
Beginner to intermediate content levelBeginner to intermediate
440 pages
11h 36m
English
Packt Publishing
Content preview from Mastering Geospatial Analysis with Python

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning Geospatial Analysis with Python

Learning Geospatial Analysis with Python

Joel Lawhead

Publisher Resources

ISBN: 9781788293334Supplemental Content