21 September 2012

postgis convert geometrycollection to linestring or point

SELECT ST_AsEWKT(the_geom)
FROM
(SELECT ST_Locate_Between_Measures(
ST_GeomFromEWKT('MULTILINESTRINGM((1 2 3, 3 4 2, 9 4 3),
(1 2 3, 5 4 5))'),1.5, 3) As the_geom) As foo;
st_asewkt
-----------------------------------------------------------------
GEOMETRYCOLLECTIONM(LINESTRING(1 2 3,3 4 2,9 4 3),POINT(1 2 3))
--Geometry collections are difficult animals so dump them
--to make them more digestable
SELECT ST_AsEWKT((ST_Dump(the_geom)).geom)
FROM
(SELECT ST_Locate_Between_Measures(
ST_GeomFromEWKT('MULTILINESTRINGM((1 2 3, 3 4 2, 9 4 3),
(1 2 3, 5 4 5))'),1.5, 3) As the_geom) As foo;
st_asewkt
--------------------------------
LINESTRINGM(1 2 3,3 4 2,9 4 3)
POINTM(1 2 3)

This is example script from postgis manual. 
after you dump geometrycollection, you can select linestring .



--
Xiaoyu Guan (Sam)
http://goo.gl/TpmBs