Using shapely
package for Python how to export the resulting shapely objects such as buffer
to a DXF
file?
Answer
Shapely doesn't directly support exporting to DXF - it supports export to Well Known Text (WKT), Well Known Binary (WKB), Numpy arrays and GeoJSON objects (interoperation from the Shapely manual). As such you need a package that can transform from one of these formats to DXF.
I'd suggest OGR as the way to go for my money. The easiest method would be to simply export your shapely geometries to a GeoJSON file through Python using shapely.geometry.mapping(obj)
, e.g.
from shapely.geometry import mapping
import json
open("buffer.geojson", "wb").write(json.dumps(mapping(buffer_obj)))
Then simply use the ogr2ogr utility to transform the GeoJSON to a DXF file, e.g.
ogr2ogr -f DXF buffer.dxf buffer.geojson
Then, if you're keen you can look up the GDAL/OGR Python bindings and do it within a single script. Hope this helps!
No comments:
Post a Comment