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
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