[QGIS-Developer] Loading DXF in QGIS?

Stefan Giese (WhereGroup) stefan.giese at wheregroup.com
Mon Oct 2 23:59:19 PDT 2023


Hi,

with ezdxf you can do the job. The following snippet shows how it works:

/......
/

/#Reading the dxf and get the modelspace
     dwg = ezdxf.readfile(filepath)
     msp = dwg.modelspace()

     #loop through all Polylines of the DXF
     polylines = msp.query('POLYLINE')
     for polyline in polylines:/

/       # for example converts a dxf Polyline to a QgsGeometry (Polygon)
        points = []
        for i, location in enumerate(polyline.points()):
            points.append(QgsPointXY(location[0],location[1]))
       polygon = QgsGeometry.fromPolygonXY([points])/

/.....
/

hope this will be a starting point for you...

Mit freundlichen Grüßen
Stefan Giese
Projektleiter/Consultant
---------------------------------------------
Aufwind durch Wissen!
Web-Seminare und Online-Schulungen
bei derwww.foss-academy.com
---------------------------------------------
WhereGroup GmbH
Schwimmbadstr. 2
79100 Freiburg
Germany

Tel.: +49 (0)761 / 519 102 - 61
Fax: +49 (0)761 / 519 102 - 11

stefan.giese at wheregroup.com
www.wheregroup.com
Geschäftsführer:
Olaf Knopp, Peter Stamm
Amtsgericht Bonn, HRB 9885

Am 03.10.2023 um 00:47 schrieb Catania, Luke A ERDC-RDE-GRL-VA CIV via 
QGIS-Developer:
>
> I have a DXF in both AC1027 and AC1032 format.  Original file was a 
> DWG.  I converted to DXF using ODA File Converter.  I am trying to 
> load in QGIS and dragging and dropping or using the Data Source 
> Manager results in a layer with the name “entities appended to it and 
> nothing shows up.  When looking at the properties there is not much 
> there. The layer type is a dataset.  I am trying to display all the 
> lines of the dxf.
>
> Now I can use the Project/Import/Export/Import Layers from DWG/DXF to 
> import, but I am looking to do this programmatically in python and I 
> am using ezdxf to assist.
>
> Ideas?
>
>
> _______________________________________________
> QGIS-Developer mailing list
> QGIS-Developer at lists.osgeo.org
> List info:https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe:https://lists.osgeo.org/mailman/listinfo/qgis-developer

-- 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20231003/bf4ee5e4/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.png
Type: image/png
Size: 6904 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20231003/bf4ee5e4/attachment-0003.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image004.png
Type: image/png
Size: 62713 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20231003/bf4ee5e4/attachment-0004.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image003.png
Type: image/png
Size: 47885 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20231003/bf4ee5e4/attachment-0005.png>


More information about the QGIS-Developer mailing list