giovedì 7 agosto 2014

How retrieve polygons from a set of lines

The use-case is that the usual  BuildArea don't work because the linea are tto mixed and intersecating each other.

The solution is to noed them before the BuildArea.

So, as example:
this code:

The shapefile with the lines to transform in polygon is named "errbordo.shp"
----------------
.headers on
.timer on

.loadshp errbordo errbordo CP1252 3003 geometry pk_uid auto 2d 1

create table tabella_nodata as select * from errbordo;
select RecoverGeometryColumn('tabella_nodata','geometry',3003,'LINESTRING','XY');
select CreateSpatialIndex( 'tabella_nodata','geometry' );
select AddGeometryColumn( 'tabella_nodata','geometry_noded', 3003, 'MULTILINESTRING','XY' );
select AddGeometryColumn( 'tabella_nodata','geometry_poligono', 3003, 'MULTIPOLYGON','XY' );

update tabella_nodata set geometry_noded = ST_NODE(geometry);

update tabella_nodata set geometry_poligono = ST_Multi(ST_BuildArea(geometry_noded));

the field "geometry_poligono" has the polygon.
----------------

The End.


Nessun commento:

Posta un commento