Polygonize noded lines

88 views
Skip to first unread message

Keith

unread,
Mar 14, 2010, 11:32:19 AM3/14/10
to SpatiaLite Users
Hello,

Does Spatialite have the ability to create polygons from noded
linestrings? I believe GEOS and JTS have a Polygonize function. This
is an example for JEQL. Postgis has Polygonize_garray().

(LINESTRING (0 0, 10 0)"),
("LINESTRING (10 0, 10 10)"),
("LINESTRING (0 0, 0 10)"),
("LINESTRING (0 10, 10 10)"),
("LINESTRING (10 10, 20 10)"),
("LINESTRING (20 10, 20 0)"),
("LINESTRING (10 0, 20 0)

Two polygons are created from the 2 pt lines listed above.

("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0 ))" ),
("POLYGON ((10 10, 20 10, 20 0, 10 0, 10 10))")

Keith

a.furieri

unread,
Mar 31, 2010, 1:01:57 PM3/31/10
to SpatiaLite Users
Hi Keith,

your post was stimulating enough: so I've introduced the
following new SQL functions in spatialite:

------
BdPolyFromText ( wkt_geom [, srid] )
ST_BdPolyFromText ( wkt_geom [, srid] )
BdMPolyFromText ( wkt_geom [, srid] )
ST_BdMPolyFromText ( wkt_geom [, srid] )
BdPolyFromWKB ( wkb_geom [, srid] )
ST_BdPolyFromWKB ( wkb_geom [, srid] )
BdMPolyFromWKB ( wkb_geom [, srid] )
ST_BdMPolyFromWKB ( wkb_geom [, srid] )

all these are OGC defined functions: according to
the OGC specs, geom has to be of the MULTILINESTRING
type anyway: passing a simple LINESTRING will then fail.

any individual LINESTRING has to represent a closed
figure, so to transform it into a valid RING

BdPolyFrom... will return a POLYGON: if geom requires
a MULTIPOLYGON, the this function will fail.

on the other side BdMPolyFrom... will return a MULTIPOLYGON
anyway, even if it contains only one polygon.


------
BuildArea ( geom )

you can pass a LINESTRING or a MULTILINESTRING at your will;
a POLYGON or a MULTIPOLYGON is then returned, depending
on how much individual polygon where actually contained
into the original geom.
the SRID is the same corresponding to the original geom


------

Polygonize (geom)

this will try to aggregate polygons from a collection of
arbitrary linestrings; example:

SELECT ST_AsText(Polygonize(ST_GeomFromText(
'MULTILINESTRING(
(100 100, 100 110), (110 100, 110 110),
(5 5, 5 6, 6 6), (100 100, 110 100),
(0 0, 0 10, 10 10, 10 0), (5 5, 6 5, 6 6),
(0 0, 10 0), (110 110, 100 110))')));

will return:

MULTIPOLYGON(
((10 0, 0 0, 0 10, 10 10, 10 0), (6 6, 5 6, 5 5, 6 5, 6 6)),
((100 110, 110 110, 110 100, 100 100, 100 110))
)


------
to be released ASAP in RC3.

bye
Sandro

Keith

unread,
Apr 8, 2010, 12:29:31 PM4/8/10
to SpatiaLite Users
Good news. I appreciate it.

Keith

Reply all
Reply to author
Forward
0 new messages