Finding out whether a point is inside a polygon
A point inside a polygon analysis query is a very common spatial operation. This query can identify objects located within an area such as a polygon. The area of interest in this example is a 100 m buffer polygon around bike paths and we would like to locate all schools that are inside this polygon.
Getting ready
In the previous section, we used the schools
table to create a buffer. This time around, we will use this table as our input points table. The bikeways
table that we imported in Chapter 3, Moving Spatial Data from One Format to Another, will be used as our input lines to generate a new 100 m buffer polygon. Be sure, however, that you have the two datasets in your local PostgreSQL database.
How to do it...
Now, let's dive into some more code to find schools located within 100 m of the bikeways in order to find points inside a polygon:
#!/usr/bin/env python # -*- coding: utf-8 -*- import json import psycopg2 from geojson import loads, Feature...