I’m developing a project using PostGIS to hold spatial data where I have records that hold geometry point data and records that hold geometry area data. To solve my problem I’m looking for two queries that can take geographic shapes rather than geometric shapes as parameters.
For query A I need it to return all points that intersect with a given area.
For query B I need it to return all areas that intersect with a given point.
The query is pretty much the same which ever direction you go, it just depends on your select criteria, lets assume you have the following table:
using the following:
or
will display that table as is (The later will give a more English readable output)
now if you also have a similar table, but instead of polygons in the geometry, you have points, to do cross filters on them you can use simple joins.
EG:
this will return all points from the points table that fall inside the selected polygon representing the area your interested in.
note: I’m using ST_Within here, but there are may other geometry operators in PostGIS that can do many other types of checking that would make your intersects and or bounding measurements more accurate, for all of them the principle however is the same.
For your second Query, the GIS-SQL needed is going to be very similar, but instead of returning the points for a given poly, you need to reverse your criteria to return polys for a given point:
NOTE: we keep the parameters in ‘ST_Within in exactly the same order, because ST_Within processes using the following rule:
Since the point is still the smaller of the 2 entities then we still need to check for the same spatial ordering.