This project is read-only.

Convert Polygon to Polyline

Jun 11, 2016 at 12:11 AM
Edited Jun 11, 2016 at 12:14 AM

Does anyone know a quick way to do this? As I understand it there's very little difference so it should be trivial and there's probably a trick that I don't know! I've had a go with something really long-winded like this...
(polygonfile and polygonshape are polygons, polylinefile and lineshape are polylines)
for each polygonshape in polygonfile  
  for each point in polygonshape 
    copy point from polygonshape to lineshape
  insert lineshape into polylinefile
which looked like it was going somewhere - however it was extremely slow and ultimately the points copied but the shape wouldn't insert into the polyline file

Is there a better way to do this?


Sep 27, 2016 at 3:20 PM
Sorry for the late response.

First you need to make sure you only have single part polygons using sf.ExplodeShapes:

The difference between a polygon and a polyline is that the last and first points of a polygon are the same.

You need to figure out how to handle donut shaped polygons (polygon with a hole).
Probably the easiest part is to create a zero buffer ( around your polygon to get the outline and add all points except the last one to a new polyline shape.

Using Utils.ogr2ogr ( might also work with the -nlt ( option.