One of the most common problems is trying to determine whether a point is in the polygon. To solve this problem with PostGIS, you can use ST_Contains or ST_Intersects.
St_Contains takes two geometries and determines whether the first contains the second.
By using contains, no part of geometry b can be outside of geometry a. The following code solves a point in polygon (PIP) problem:
isin=Point(-106.558743,35.318618)cur.execute("SELECT ST_Contains(polygon.location,ST_GeomFromText('{}')) FROM poly polygon WHERE polygon.id=1".format(isin.wkt))cur.fetchall()
The previous code creates a point and then uses ST_Contains(polygon,point) ...