[postgis-users] Convert lines to polygon

Vera Schulze v.schulze at ccgis.de
Wed Aug 16 07:56:15 PDT 2006


Michael Fuhr schrieb:
> On Wed, Aug 16, 2006 at 12:19:04PM +0200, Vera Schulze wrote:
>> I have a problem with converting lines to a polygon.
>>
>> The geometry of the lines are in different datasets. I want to convert 
>> these lines to one polygon.
> 
> Have you tried using polygonize() with a join or union of the data
> sets?  Is the following close to what you're looking for?
> 
> test=> SELECT AsText(geom) FROM foo;
>        astext        
> ---------------------
>  LINESTRING(0 0,0 5)
>  LINESTRING(5 5,5 0)
> (2 rows)
> 
> test=> SELECT AsText(geom) FROM bar;
>        astext        
> ---------------------
>  LINESTRING(0 5,5 5)
>  LINESTRING(5 0,0 0)
> (2 rows)
> 
> test=> SELECT AsText(polygonize(geom))       
> test-> FROM (SELECT geom FROM foo UNION ALL SELECT geom FROM bar) AS s;
>                        astext                       
> ----------------------------------------------------
>  GEOMETRYCOLLECTION(POLYGON((0 0,0 5,5 5,5 0,0 0)))
> (1 row)
> 
> test=> SELECT AsText(GeometryN(polygonize(geom), 1))
> test-> FROM (SELECT geom FROM foo UNION ALL SELECT geom FROM bar) AS s;
>              astext             
> --------------------------------
>  POLYGON((0 0,0 5,5 5,5 0,0 0))
> (1 row)
> 
Sorry, I was wrong saying datasets. The geometry of the lines are stored 
in the same table but in different records and I'm looking for a way to 
join these lines into a polygon.

I tried what you suggested but the resultset is empty if the linestring 
doesn't contain end- and startpoint in one record.

Are there any other possibilities to solve my problem?

Thank you very much,
Vera



More information about the postgis-users mailing list