I'm using sqlite with the Spatialite extension to query a geopackage file.
Consider the following test table where each row have geometry type either LineString or MultiLineString.
sqlite>load_extension('mod_spatialite');
sqlite>select EnableGpkgMode(); -- I'm testing on GeoPackage
sqlite>SELECT id,geom FROM mix AS ft;
1|LINESTRING(10 0,10 60)
2|MULTILINESTRING( (40 0,40 60), (50 0,50 60) )
I need a result where each MultiLineString is "exploded" into a number of LineStrings, like this:
1|1|LINESTRING(10 0,10 60)
2|2.1|LINESTRING( 40 0,40 60 )
2|2.2|LINESTRING( 50 0,50 60 )
If possible I would like both to keep the original id
and create a new newid
as shown above.
The following solution works in PostGIS, but I still have not found a solution for Spatialite.
postgis=> SELECT
id,
array_to_string(
id || (ST_Dump(geom)).path,
'.'
) AS newid,
ST_AsText((ST_Dump(geom)).geom) AS geom
FROM cubetown.MixLS_1
;
id | newid | geom
----+-------+------------------------
1 | 1 | LINESTRING(10 0,10 60)
2 | 2.1 | LINESTRING(40 0,40 60)
2 | 2.2 | LINESTRING(50 0,50 60)