shapely package for Python how to export the resulting shapely objects such as
buffer to a
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.
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!
with fiona.collection("file.shp", "r") as source: with fiona.collection( "file.dxf", "w", driver="DXF", schema=source.schema, ) as sink: # Do whatever you like to records results = some_function(source) sink.writerecords(results)
It coughs up a lot of warnings about mismatch between GIS simple feature and DXF data models but does write a file of entities.