[postgis-users] how to find smallest containing region

Obe, Regina robe.dnd at cityofboston.gov
Mon Jul 14 04:33:26 PDT 2008


Well if you make your linestrings actually polygons, that would be the
first step.

Then I think something like this might work (not it would be much more
efficient if you create a table with polygons instead having linestrings
and put an index on that.

If you really have line strings and not polygons - do this before the
below query
SELECT gid, ST_MakePolygon(the_geom) As the_geom INTO poly
FROM linestring;

CREATE INDEX idx_poly_gist
  ON poly
  USING gist
  (the_geom);
ALTER TABLE poly CLUSTER ON idx_poly_gist;

--then do this

SELECT DISTINCT ON(pt.gid)
	pt.gid, pt.the_geom as the_point, poly.gid as poly_gid,
poly.the_geom as encpolygon 
FROM points pt LEFT JOIN poly ON ST_Within(pt.the_geom, poly.the_geom)
ORDER BY
pt.gid, ST_Area(poly.the_geom);

Hope that helps,
Regina



-----Original Message-----
From: postgis-users-bounces at postgis.refractions.net
[mailto:postgis-users-bounces at postgis.refractions.net] On Behalf Of
Edward Q. Bridges
Sent: Sunday, July 13, 2008 8:22 AM
To: postgis-users at postgis.refractions.net
Subject: [postgis-users] how to find smallest containing region

Hello,

I have data stored as points and linearrings (i.e. closed polygons).  
Can someone suggest an efficient approach to finding the smallest 
enclosing region for a given point?

Thanks!
Ed

_______________________________________________
postgis-users mailing list
postgis-users at postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users
-----------------------------------------
The substance of this message, including any attachments, may be
confidential, legally privileged and/or exempt from disclosure
pursuant to Massachusetts law. It is intended
solely for the addressee. If you received this in error, please
contact the sender and delete the material from any computer.




More information about the postgis-users mailing list