I try to convert my multipolygon layer to a multilinestring layer. In the postgis codumentation I found this example:

(...) -- If you have a table of MULTIPOLYGONs -- and want to return a MULTILINESTRING composed of the exterior rings of each polygon SELECT gid, ST_Collect(ST_ExteriorRing(the_geom)) AS erings FROM (SELECT gid, (ST_Dump(the_geom)).geom As the_geom FROM sometable) As foo GROUP BY gid;


My postgresql connection is called database, schema public, default primary key field gid, default geometry field geom, my multipolygon layer poly_layer.

How can I convert the layer poly_layer into a new multilinestring layer line_layer?

1 Answer 1


You probably want to use ST_Boundary. ST_ExteriorRing will just give your the outter ring of the polygon. http://postgis.net/docs/ST_Boundary.html

SELECT gid, ST_Boundary(geom)::geometry(MULTILINESTRING,4326) As geom
    INTO line_layer
    FROM poly_layer;

Change the 4326 to whatever your srid is.

  • Thanks, I started to collect some sql commands because I use more and more postgis while editing in qgis. Sometimes qgis tools don't work and it's good to know more "powerful" tools.
    – Piotrek
    Commented Sep 24, 2015 at 13:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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