[postgis-users] Making one out of several connected polygons?

Nicolas Ribot nicky666 at gmail.com
Fri Feb 1 03:28:37 PST 2008


Try to  geomunion() your polygons.
It will create a multipolygon where touching polygons will be unioned.
then, use dump()  on the geomunion to extract each polygon.

Example:
the polygon table contains:

test=# select id, astext(geometry) from tpoly2;
 id |                               astext
----+--------------------------------------------------------------------
  1 | POLYGON((166 272,107 210,145 142,218 158,209 215,182 240,166 272))
  2 | POLYGON((242 118,218 158,145 142,167 104,242 118))
  3 | POLYGON((76 161,145 142,167 104,112 78,76 161))
    | POLYGON((284 174,283 112,320 124,295 129,302 156,284 174))
(4 rows)

The query to extract unioned polygon based on a common edge:

select astext(geom(dump(geom))), path(dump(geom))
from (select geomunion(t1.geometry)::geometry as geom
        from tpoly2 t1
        ) as foo;

Leads to this result:
                                            astext
                         | path
-------------------------------------------------------------------------------------------------+------
 POLYGON((284 174,302 156,295 129,320 124,283 112,284 174))
                          | {1}
 POLYGON((76 161,145 142,107 210,166 272,182 240,209 215,218 158,242
118,167 104,112 78,76 161)) | {2}
(2 rows)

(see polygon.png and result.png images done with openjump)

HTH

Nicolas
On 01/02/2008, Simon Schneider <Kallas at gmx.de> wrote:
> Hi,
>
> I've several polygons wich are all connected by at least one line and
> I'm looking for a way to make one big polygon which contains all the
> others. In other words the shape of the polygoncluster.
>
> I've been locking around for quite a while but I found no way to solve
> this within postgis.
>
>
> Cheers,
> Simon
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: result.png
Type: image/png
Size: 77794 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20080201/5bb2a8a0/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: polygons.png
Type: image/png
Size: 9993 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20080201/5bb2a8a0/attachment-0001.png>


More information about the postgis-users mailing list