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?

  • I've tried something like WHERE ST_Contains("geometry", (SELECT geometry FROM POLYGONs)), but that slows the query down very much.
    – Henrik
    Jan 21 '15 at 13:10

Sure, using ST_Contains

SELECT lines.*
FROM lines, polygons
WHERE ST_Contains(polygons.geom, lines.geom)
  • It worked with ST_Contains(polygons.geom, lines.geom). Thanx.
    – Henrik
    Jan 21 '15 at 13:13
  • Sorry, I got the order mixed up. Corrected now. Glad you got it working.
    – AndyHarney
    Jan 21 '15 at 13:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.