[postgis-users] MULTILINESTRING to MULTIPOLYGON
Birgit Laggner
birgit.laggner at vti.bund.de
Wed Mar 30 01:53:22 PDT 2011
Hi Javier,
you could add the missing end point (and then try again with
ST_BuildArea() etc.). Here a more or less suiting example of the PostGIS
manual for ST_AddPoint():
UPDATE sometable
SET the_geom = ST_AddPoint(the_geom, ST_StartPoint(the_geom))
FROM sometable
WHERE ST_IsClosed(the_geom) = false;
With a MultiLineString, this might be a bit more complicated because you
have to find out first, is your multilinestring resulting in a polygon
or a multipolygon? If all linestrings form one polygon, you have to
select the start point of the first linestring as end point of the last
linestring. If the result is a multipolygon, you have to find out which
of the rings is not closed, first. As I see from your first e-mail, you
are expecting the geometry to become a multipolygon, so (assuming every
linestring is representing a polygon within the multipolygon, otherwise
it might be a solution to union the linestrings first) maybe the sql
code could look like this:
UPDATE sometable a
SET the_geom = sel.geom FROM
(SELECT b1.gid, ST_Collect(b1.geom) AS geom --put together all linestrings to one multilinestring again
FROM
(SELECT b.gid, ST_AddPoint(b.geom, ST_StartPoint(b.geom)) --add an end point on the position of the start point for each non-closed linestring
FROM
(SELECT gid, (st_dump(the_geom)).geom AS geom --separate the linestrings and select the not closed ones
FROM sometable
WHERE ST_IsClosed(the_geom)=false) b
WHERE ST_IsClosed(b.geom) = false
UNION ALL
SELECT b.gid, b.geom
FROM
(SELECT gid, (st_dump(the_geom)).geom AS geom --separate the linestrings and select the closed ones
FROM sometable
WHERE ST_IsClosed(the_geom)=false) b
WHERE ST_IsClosed(b.geom) = true) b1
GROUP BY b1.gid) sel
WHERE ST_IsClosed(a.the_geom)=false AND a.gid=sel.gid;
I did not test the code, but I hope you get the idea...
Regards,
Birgit.
On 28.03.2011 18:47, Javier Perez wrote:
> Hi,
>
> I tried |*ST_BuildArea*(|geometry A|)|; and
> |*ST_BdMPolyFromText*(|text WKT, integer srid|)|;
>
> but the output is empty. I think it's becouse this functions may need
> the MULTILINESTRING to be closed and it's not.
>
> Any suggestion?
>
> 2011/3/25 Javier Perez <javi.peisaco at gmail.com
> <mailto:javi.peisaco at gmail.com>>
>
> Hi Marc-Andre!
>
> I think this usefull.
>
> Thanks a lot!
>
> Regards
>
> 2011/3/25 Morin, Marc-André <Marc-Andre.Morin at dfo-mpo.gc.ca
> <mailto:Marc-Andre.Morin at dfo-mpo.gc.ca>>
>
> *Hi,*
> **
> *This is the recipe I found in the past to get it done:*
> **
> http://postgis.refractions.net/pipermail/postgis-users/2008-May/019901.html
> It worked well for me.
> Regards,
> Marc-André
> ------------------------------------------------------------------------
> *De :* postgis-users-bounces at postgis.refractions.net
> <mailto:postgis-users-bounces at postgis.refractions.net>
> [mailto:postgis-users-bounces at postgis.refractions.net
> <mailto:postgis-users-bounces at postgis.refractions.net>] *De la
> part de* Javier Perez
> *Envoyé :* March 25, 2011 7:35 AM
> *À :* postgis-users at postgis.refractions.net
> <mailto:postgis-users at postgis.refractions.net>
> *Objet :* [postgis-users] MULTILINESTRING to MULTIPOLYGON
>
> Hi!,
>
> In my app I get a MULTILINESTRING and want to insert it as
> MULTIPOLYGON. I think there's an easy way but I did't found,
> can anyone bring some light?
>
>
> Thanks in advance
>
>
> _______________________________________________
> postgis-users mailing list
>
> postgis-users at postgis.refractions.net
> <mailto: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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20110330/2f4eb09f/attachment.html>
More information about the postgis-users
mailing list