Created
November 25, 2011 09:19
-
-
Save walkermatt/1393111 to your computer and use it in GitHub Desktop.
Disaggregate MultiLineStrings using ST_Dump PostGIS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT *, ST_GeometryType(geom) as geom_type, ST_AsEWKT(geom) as geom_wkt from complex; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE complex | |
( | |
id serial, | |
"name" text, | |
geom geometry | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)') | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Code for http://longwayaround.org.uk/notes/dissagregate_multilinestring_st_dump_postgis/