Intersecting geometries
In PostGIS, there are two ways in which geometries can be intersected. The first way is checking whether two geometries intersect (at least one point of geometry A lies within the interior of geometry B). That's the ST_Intersects
function. It accepts two arguments of the geometry type, and returns a Boolean.
For example, these lines intersect:
SELECT ST_Intersects( ST_MakeLine(ST_MakePoint(20,50),ST_MakePoint(21,51)), ST_MakeLine(ST_MakePoint(20.5,50.5), ST_MakePoint(22,52)) );
But these lines don't:
st_intersects --------------- t SELECT ST_Intersects( ST_MakeLine(ST_MakePoint(20,50),ST_MakePoint(21,51)), ST_MakeLine(ST_MakePoint(21.5,51.5), ST_MakePoint(22,52)) ); st_intersects --------------- f
ST_Intersects
can also be used for table joining. The following query will return land features that had at least one earthquake:
SELECT ne_110m_land.* FROM data_import.ne_110m_land JOIN data_import.earthquakes_subset_with_geom ON ST_Intersects(ne_110m_land...