[postgis-users] Convert lines to polygon

Michael Fuhr mike at fuhr.org
Wed Aug 16 06:44:00 PDT 2006


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)

-- 
Michael Fuhr



More information about the postgis-users mailing list