[gdal-dev] Extract Linestrings from GeometryCollections with ogr2gor

Jukka Rahkonen jukka.rahkonen at maanmittauslaitos.fi
Mon Mar 16 14:34:22 PDT 2015


Stefan Ziegler <stefan.ziegler.de <at> gmail.com> writes:

 
> Hi
> I have some contour lines which I clip with ogr2ogr's -clipsrc options. As
a result and in very rare cases I get some GeometryCollections which cannot
be stored in a  shapefile. 
> So I'm clipping to a GeoPackage and tried to extract the LinesStrings from
the GeometryCollections with the following command:ogr2ogr -dialect
INDIRECT_SQLITE -sql 'SELECT ID, elev, (ST_Dump(geom)).geom as geom FROM
linestring WHERE geometrytype = \'LINESTRING'\' clipped_dumped.shp clipped.gpkg
> ST_Dump seems to be unknown (as SQlite does not support arrays I guess) so
is ST_CollectionExtract(geom,2). 
> Is there a way to extract LineStrings from GeometryCollections. Probably
already avoiding them when clipping the original geometry?
> best regards
> Stefan

Hi,

There is no need to guess what functions are supported by Spatialite SQL, it
is documented in
https://www.gaia-gis.it/gaia-sins/xmlBlob/spatialite-sql-latest.html.

You are right with the arrays but Spatialite does have some tools for
splitting collections into elementary geometries. With the standard
functions you could probably do something useful with NumGeometries and
GeometryN by finding out the total number or geometries and then selecting
them one by one.

There are also special tools which can by used with spatialite-cli and
spatialite-gui
https://groups.google.com/forum/#!topic/spatialite-users/04YoENWokuA. An
then there is this brand new creative:

https://www.gaia-gis.it/fossil/libspatialite/wiki?name=VirtualElementary

-Jukka Rahkonen-


More information about the gdal-dev mailing list