6

I need to make vector tiles but want the source to be like my data is.made up of polygons Can GDAL ogr2ogr convert from polygon to line?

Jordan Bess
  • 200
  • 1
  • 5

2 Answers2

4

An old question but... using ogr2ogr:

ogr2ogr output.shp input.shp -dialect sqlite -f "ESRI Shapefile" -sql "select ST_ExteriorRing(geometry) as geometry from input"

This works for single part polygons, no holes :)

SDavison
  • 41
  • 2
3

According to one of the GDAL/OGR authors, there is no direct way of doing this using GDAL utilities, and it must be done manually (ie, using either a GIS, or using scripts/code, eg, with GDAL/OGR API). See details and reasons in his full explanation here: https://lists.osgeo.org/pipermail/gdal-dev/2009-September/021967.html

To do this manually, you would have to extract the polygon geometry, then from this geometry, extract the external ring geometry (remember a polygon may have multiple rings for internal holes, etc). From this external ring geometry, you would then get a sequence of coordinates.

You would then have to construct a line geometry based on these coordinates, add it to a line feature, and then (optionally) add in all of the attributes from the original polygon (assuming the line feature class had the right attributes configured when it was created).

Son of a Beach
  • 8,182
  • 1
  • 17
  • 33