1

I'm trying to convert shapefiles into one DXF file using pyqgis, I started with one layer, the problem is that I can't open the DXF file after conversion. Screen capture when trying to open converted dxf

I've tried two approaches but still getting the same problem.
First approach: based on this answer

from PyQt4.QtCore import QFile
dxfExport = QgsDxfExport()
layers=[QgsDxfExport.DxfLayer(iface.activeLayer())]
settings = iface.mapCanvas().mapSettings()
dxfExport.setMapSettings( settings )
dxfExport.addLayers( layers )
dxfExport.setLayerTitleAsName(True)
dxfExport.setDestinationCrs(26191)
dxfExport.setForce2d( True )
dxfFile = QFile( 'C:\\Users\\Desktop\\test\\file.dxf' )
dxfExport.writeToFile( dxfFile, 'utf-8')

second approach : based on this answer

I converted my shapefile to geojson then used FWtools to convert the geojson file to dxf.

ogr2ogr -f DXF test.dxf test.geojson

Is it possible to access source code of 'project>DXF export' funcionality ?

1 Answer 1

1

Have you tried using ogr2ogr with the shapefile?

ogr2ogr -f DXF myfile.dxf my_shapefile.shp
5
  • Yes I did, the output can't be opened in AutoCAD Oct 25, 2018 at 8:22
  • Can you share your shapefile? If not try exporting the same shapefile using qgis and see if that will export properly to DXF.
    – GreyHippo
    Oct 25, 2018 at 13:31
  • I don't know why it didn't work using command prompt but excuting the command in the QGIS python console fixed the problem. The code I used is : import subprocess command = ["C:\\Program Files\\QGIS 2.18\\bin\\ogr2ogr.exe","-f", "DXF","C:\\Users\\Desktop\\output_dxf.dxf","C:\\Users\\Desktop\\b\\input_shp.shp"] subprocess.check_call(command) . But I steel can't convert many shapfiles to one DXF file Oct 25, 2018 at 13:43
  • You can first merge all shapefile into one (gis.stackexchange.com/questions/25061/…) then export to DXF
    – GreyHippo
    Oct 25, 2018 at 13:59
  • unfortunately they don't have the same geometry type Oct 25, 2018 at 14:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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