Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Disaggregate MultiLineStrings using ST_Dump PostGIS
SELECT *, ST_GeometryType(geom) as geom_type, ST_AsEWKT(geom) as geom_wkt from complex;
CREATE TABLE complex
(
id serial,
"name" text,
geom geometry
);
SELECT
COALESCE((simple.id || '.' || simple.path[1]::text)::float, simple.id) as id,
simple.name,
simple.simple_geom as geom,
ST_GeometryType(simple.simple_geom) as geom_type,
ST_AsEWKT(simple.simple_geom) as geom_wkt
FROM (
SELECT
dumped.*,
(dumped.geom_dump).geom as simple_geom,
(dumped.geom_dump).path as path
FROM (
SELECT *, ST_Dump(geom) AS geom_dump FROM complex
) as dumped
) AS simple;
INSERT INTO complex (name, geom)
VALUES (
'Bob',
ST_GeomFromEWKT('MULTILINESTRING((498376.89 651569.6,498372.28 651571.89),(498372.28 651571.89,498371.77 651576.05))')
);
INSERT INTO complex (name, geom)
VALUES (
'Harry',
ST_GeomFromEWKT('LINESTRING(598376.89 751569.6,398372.75 658771.03)')
);
@walkermatt

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.