AW: Re: AW: RE: [postgis-users] Geometrycollection to Multipolygon

Burgholzer,Robert rwburgholzer at deq.virginia.gov
Thu Apr 24 06:20:17 PDT 2008


Horst,
I have what seems to be an ugly solution to your difficulty, but I think it works.  I do a manipulation on the asText entities, stripping out the "POLYGON" label, and merging them together to form a MULTIPOLYGON.  While this is ugly, it could form the basis of a simple function to achieve this, perhaps by iterating through an array collection.  This example shows the creation of a MULTI with 3 component polygons:

select geomFromText('MULTIPOLYGON(' || a.poly || ',' || b.poly || ',' ||  
   c.poly ')',4326) as newgeom 
from (select trim (leading 'POLYGON' from asText(geometryN(the_geom,1))) as
   poly from proj_seggroups where gid = 5
   ) as a,
   (select trim (leading 'POLYGON' from asText(geometryN(the_geom,2))) as 
   poly from proj_seggroups where gid = 5
   ) as b,
   (select trim (leading 'POLYGON' from asText(geometryN(the_geom,3))) as 
   poly from proj_seggroups where gid = 5
   ) as c


The interesting part is, that I have checked this with a multi that has 5 polys in it, and when converted asText, they are identical, however, using the postgis Equals function declares them to be non-equal.  Not sure exactly, but here is the query that I used to do this:

select Equals(foo.newgeom, bar.the_geom) from (
   select geomFromText('MULTIPOLYGON(' || a.poly || ',' || b.poly || ',' || c.poly || ',' || d.poly || ',' || e.poly || ')',4326) as newgeom 
   from (select trim (leading 'POLYGON' from asText(geometryN(the_geom,1))) as poly from proj_seggroups where gid = 5)
    as a,
      (select trim (leading 'POLYGON' from asText(geometryN(the_geom,2))) as poly from proj_seggroups where gid = 5)
    as b,
      (select trim (leading 'POLYGON' from asText(geometryN(the_geom,3))) as poly from proj_seggroups where gid = 5)
    as c,
      (select trim (leading 'POLYGON' from asText(geometryN(the_geom,4))) as poly from proj_seggroups where gid = 5)
    as d,
      (select trim (leading 'POLYGON' from asText(geometryN(the_geom,5))) as poly from proj_seggroups where gid = 5)
    as e
) as foo, (
   select the_geom from proj_seggroups where gid = 5
) as bar;

Good luck!


Robert W. Burgholzer
Surface Water Modeler
Office of Water Supply and Planning
Virginia Department of Environmental Quality
rwburgholzer at deq.virginia.gov
804-698-4405
Open Source Modeling Tools:
http://sourceforge.net/projects/npsource/

-----Original Message-----
From: postgis-users-bounces at postgis.refractions.net [mailto:postgis-users-bounces at postgis.refractions.net] On Behalf Of Stephen Woodbridge
Sent: Wednesday, April 23, 2008 12:54 PM
To: Düster Horst
Cc: postgis-users
Subject: Re: AW: Re: AW: RE: [postgis-users] Geometrycollection to Multipolygon

I would expect to get a collection out of st_collect(), I think it is 
strange (a bug?) that you get a multipolygon out of two polygons.

-Steve

Düster Horst wrote:
> 
> Stephen
> 
>>and see if you get a multipolygon ot a collection as the result.
> 
> A collection is the result of course. The mix of two geometry types is 
> the one reason, but your idea leeds also to a collection because your 
> idea tries to collect two multigeometries. I believe it is not possible 
> to merge multipolygons into one multipolygon like 
> MULTIPOLYGON(MULTIPOLYGON1, MULTIPOLYGON2,...). This geometry has to be 
> a collection.
> 
> Horst
> 
> ------------------------------------------------
> 
> Dr. Horst Düster
> GIS-Koordinator, Stv. Amtschef
> 
> Kanton Solothurn
> Bau- und Justizdepartement
> Amt für Geoinformation
> SO!GIS Koordination
> Rötistrasse 4
> CH-4501 Solothurn
> 
> Telefon ++41(0)32 627 25 32
> Telefax ++41(0)32 627 22 14
> 
> mailto:horst.duester at bd.so.ch
> http://www.agi.so.ch
> 
> -----Ursprüngliche Nachricht-----
> Von: Stephen Woodbridge [mailto:woodbri at swoodbridge.com]
> Gesendet am: Mittwoch, 23. April 2008 17:59
> An: PostGIS Users Discussion
> Betreff: Re: AW: RE: [postgis-users] Geometrycollection to Multipolygon
> 
> I think you are getting the collection because you are mixing types.
> Try this (I haven't tried it):
> 
> st_collect(
> st_collect(st_multi(polygon1), st_multi(polygon2)),
> st_multi(polygon3))
> 
> and see if you get a multipolygon ot a collection as the result.
> 
> -Steve W
> 
> Düster Horst wrote:
>>
>>  Regina
>>
>>  Thank you for your response. Mmmm.. your trick doesn't solve my problem.
>>  Perhaps I should tell you why I do have a geometrycollection. My
>>  startingpoint is a sequence of single polygons. My aim is to merge them
>>  together to one multipolygon. I do this with st_collect. This works fine
>>  with two polygons:
>>
>>  st_collect(polygon1,polygon2) => multipolygon(1,2).
>>
>>  When I Process the third polygon with: st_collect(multipolygon(1,2),
>>  polygon3) => Geometrycollection(multipolygon(1,2),polygon3)
>>
>>  I do get the geomtrycollection and so on.
>>
>>  My main problem is to merge the three polygons into one multipolygon
>>  with 3 geometries.
>>
>>  When I solve this problem I can offer a procedure to clean invalid
>>  geometries.
>>
>>  Regards
>>  Horst
>>
>>
>>  ------------------------------------------------
>>
>>  Dr. Horst Düster
>>  GIS-Koordinator, Stv. Amtschef
>>
>>  Kanton Solothurn
>>  Bau- und Justizdepartement
>>  Amt für Geoinformation
>>  SO!GIS Koordination
>>  Rötistrasse 4
>>  CH-4501 Solothurn
>>
>>  Telefon ++41(0)32 627 25 32
>>  Telefax ++41(0)32 627 22 14
>>
>>  mailto:horst.duester at bd.so.ch
>>  http://www.agi.so.ch <http://www.agi.so.ch/>
>>
>>
>>
>>  -----Ursprüngliche Nachricht-----
>>  *Von:* Obe, Regina [mailto:robe.dnd at cityofboston.gov]
>>  *Gesendet am:* Mittwoch, 23. April 2008 14:24
>>  *An:* PostGIS Users Discussion
>>  *Betreff:* RE: [postgis-users] Geometrycollection to Multipolygon
>>
>>  This sometimes does the trick for me if they actually can be unioned
>>
>>  ST_Union(GEOMCOLL, ST_GeomFromText('GEOMETRYCOLLECTION(EMPTY)',
>>  yoursridhere) )
>>
>>  (your number 2 doesn't work because that is the aggregate form, not
>>  because ST_Union can't handle geometry collections I think)
>>
>>
>>  Hope that helps,
>>  Regina
>>  *From:* postgis-users-bounces at postgis.refractions.net
>>  [mailto:postgis-users-bounces at postgis.refractions.net] *On Behalf Of
>>  *Düster Horst
>>  *Sent:* Wednesday, April 23, 2008 2:25 AM
>>  *To:* postgis-users
>>  *Subject:* [postgis-users] Geometrycollection to Multipolygon
>>
>>  I do have a Geometrycollection which consists of a collection of
>>  Multipolygons and Polygons. My aim is to create one single
>>  Multipolygon from the mentioned Geometry collection.
>>
>>  Until now I tried the following steps without result:
>>
>>  1. ST_BUFFER(GEOMCOLL,0.0) => It works but all inner rings of my
>>  input geometry are lost.
>>  2. ST_UNION(GEOMCOLL) => doesn't work with Geometrycollections
>>
>>  Does anyone has a solution to solve my problem?
>>
>>  Best regards
>>  Horst
>>
>>  ------------------------------------------------
>>
>>  Dr. Horst Düster
>>  GIS-Koordinator, Stv. Amtschef
>>
>>  Kanton Solothurn
>>  Bau- und Justizdepartement
>>  Amt für Geoinformation
>>  SO!GIS Koordination
>>  Rötistrasse 4
>>  CH-4501 Solothurn
>>
>>  Telefon ++41(0)32 627 25 32
>>  Telefax ++41(0)32 627 22 14
>>
>>  mailto:horst.duester at bd.so.ch
>>  http://www.agi.so.ch
>>
>>
>>
>>  *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. *
>>
>>
>>
>>  * Help make the earth a greener place. If at all possible resist
>>  printing this email and join us in saving paper. *
>>
>>  * *
>>
>>
>>  ------------------------------------------------------------------------
>>
>>  _______________________________________________
>>  postgis-users mailing list
>>  postgis-users at postgis.refractions.net
>>  http://postgis.refractions.net/mailman/listinfo/postgis-users
> 
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users

_______________________________________________
postgis-users mailing list
postgis-users at postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users



More information about the postgis-users mailing list