4

I'm using a MapGuide system which provides some CURVEPOLYGON(s).

Using python shapely's loads() raises a WKTReadingError.

Tried to find a tool that can approximate curved shapes into a polygon (as a set of points) but no luck.

I suspect ogr2ogr to be able to do this (not sure if I'm stupid) but wasn't able to do so...

Has anyone been successful when dealing with such shapes?

5

You're on the right track. Curved geometries were brought into GDAL/OGR 2.x. You can approximate curved geometries as a linear geometry. Both OGR and Shapely can export as a GeoJSON-like dict (via mapping):

from osgeo import ogr
from shapely import wkb
from shapely.geometry import mapping

# Import as an OGR curved geometry
wkt_in = 'CURVEPOLYGON(CIRCULARSTRING(1 3, 3 5, 4 7, 7 3, 1 3))'
g1 = ogr.CreateGeometryFromWkt(wkt_in)

# Approximate as linear geometry, and export to GeoJSON
g1l = g1.GetLinearGeometry()
geojson_out = g1l.ExportToJson()

# Or transfer to shapely, then export as GeoJSON
g2 = wkb.loads(g1l.ExportToWkb())
geojson_dict = mapping(g2)

wkt_out

  • God bless you @Mike! Works perfectly. Except for the installation of the gdal package, but that's another story... ;) – Ikar Pohorský Sep 21 '17 at 8:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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