Skip to content

Instantly share code, notes, and snippets.

@walkermatt
Created November 25, 2011 09:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save walkermatt/1393111 to your computer and use it in GitHub Desktop.
Save walkermatt/1393111 to your computer and use it in GitHub Desktop.
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
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment