I am using postgres with postgis and I have a set of points which I would like to interpolate with a set of lines.
Now my problem is that the set of lines are of type multilinestring.
Is there a way to convert them to linestring?
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.Sign up to join this community
This answer shows a great way to convert multi-part to single-part.
Example for converting multilinestring to linestring with SRID 3857:
Check your table if there is any feature with more than 1 part:
SELECT COUNT(CASE WHEN ST_NumGeometries(geom) > 1 THEN 1 END) AS multi_geom, COUNT(geom) AS total_geom FROM my_table;
If you see "multi_geom" in the result of the above statement is 0, it's safe to proceed to the next step. Otherwise, when multi_geom is larger than 0, you have features in my_table that can not convert safely to single part, you'll have to resolve those problem by hand before proceeding.
ALTER TABLE my_table ALTER COLUMN geom TYPE geometry(linestring,3857) USING ST_GeometryN(geom, 1);
" ST_Dump comes in very handy for expanding a MULTI geometry into single geometries. Below is an example. That expands a set of MULTIPOLYGONs into single POLYGONs
SELECT somefield1, somefield2, (ST_Dump(the_geom)).geom As the_geom FROM sometable "