Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

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?

share|improve this question

marked as duplicate by Michael Miles-Stimson, PolyGeo Mar 11 at 4:15

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

st_linemerge() convert multilies to lines if possible (postgis 1.5 tested) – simplexio Feb 5 '13 at 11:43

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.

  • Convert:

    ALTER TABLE my_table
    ALTER COLUMN geom TYPE geometry(linestring,3857) USING ST_GeometryN(geom, 1);
share|improve this answer

" 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 "

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.