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?
-
Do you have only polygons with one outer ring or perhaps also polygons with holes or multipolygons? In the latter case, what would be the result? – user30184 Feb 24 '17 at 07:54
-
anyone know how to do this with GeoPandas – Geospatial Engineer Mar 20 '17 at 16:22
2 Answers
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 :)
- 41
- 2
-
1your example does not work but if I add -dialect sqlite then yes it does work. Thanks so much – Geospatial Engineer Jan 23 '18 at 12:58
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).
- 8,182
- 1
- 17
- 33