[GIS] SELECT geometry FROM spaces WHERE geometry ARE WITHIN OR OVERLAP polygons FROM OTHER table

postgispostgresql

I've got two tables, one containing LINESTRINGs and one containing POLYGONEs.

I would like to select all the LINESTRINGs that are containing within the outer boundary of all the POLYGONs combined.

I'm running PostgreSQL 9.3 and PostGIS 2.1.

Is that possible from within the WHERE statement?

Best Answer

Sure, using ST_Contains

SELECT lines.*
FROM lines, polygons
WHERE ST_Contains(polygons.geom, lines.geom)