Convert Polygon to Polyline

Jun 10, 2016 at 11:11 PM
Edited Jun 10, 2016 at 11:14 PM
Hi

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?

Cheers

Phil.
Coordinator
Sep 27, 2016 at 2:20 PM
Sorry for the late response.

First you need to make sure you only have single part polygons using sf.ExplodeShapes: http://www.mapwindow.org/documentation/mapwingis4.9/group__shapefile__geoprocessing.html#ga5d7fa6b688d294b3a236537b07a72ea1

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 (http://www.mapwindow.org/documentation/mapwingis4.9/class_shape.html#ad4063312b170dcee5f6065b3dfcef0d9) around your polygon to get the outline and add all points except the last one to a new polyline shape.

Using Utils.ogr2ogr (http://www.mapwindow.org/documentation/mapwingis4.9/class_utils.html#a269f6ab098480f14202a530d7e278407) might also work with the -nlt (http://www.gdal.org/ogr2ogr.html) option.

Regards,

Paul