Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm still pretty new to this stuff, so bear with me. In PostGIS how could I find a polygon that would contain all the linestring records in a given table?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

If you know beforehand what your polygon is, you could do:

SELECT * from linetable WHERE ST_Intersects(linetable.the_geom,(SELECT the_geom from polytable where id='123'));

or

SELECT * FROM linetable WHERE ST_Intersects(linetable.the_geom, ST_GeomFromText('POLYGON((0 0,0 1,1 1,0 1,0 0))');

There are many ways to fetch the polygon you want, but the path is to try for ST_Intersects = true

OR do you need the polygon that encloses all linestrings?

If so, you can use ConvexHull:

http://postgis.refractions.net/docs/ST_ConvexHull.html

share|improve this answer
    
The latter. And actually, ST_Envelope is more up my problems alley. But your answer pointed me in the right direction. Thanks. –  Eric Palakovich Carr Jul 23 '10 at 17:10
    
No problem Eric. I wasn't sure if ConvexHull or Envelope would do the trick, but I'm glad that it worked. –  George Jul 23 '10 at 17:16
    
And actually, I was wrong about ST_Envelope. ST_Extent did the trick though. –  Eric Palakovich Carr Jul 23 '10 at 17:31
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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