[QGIS-Developer] Loading DXF in QGIS?

Catania, Luke A ERDC-RDE-GRL-VA CIV Luke.A.Catania at erdc.dren.mil
Tue Oct 3 13:29:52 PDT 2023


Assume though the shown variable dwg I am really reading a dxf since readfile did not work on my DWG.  I converted it to DXF using ODA file converter.

I tried it with my dxf but it never went through the loop, so it did not find POLYLINES.  When I bring the dxf  in using QGIS’s Project/Import/Export/Import Layers from DWG/DXF, I see it shows several named layers, but I tried searching on the ones that showed up in the QGIS layer panel  of these and nothing was found.

[cid:image004.png at 01D9F616.D36F2410]

[cid:image005.png at 01D9F616.D36F2410]

From: QGIS-Developer <qgis-developer-bounces at lists.osgeo.org> On Behalf Of Stefan Giese (WhereGroup) via QGIS-Developer
Sent: Tuesday, October 3, 2023 2:59 AM
To: qgis-developer at lists.osgeo.org
Subject: Re: [QGIS-Developer] Loading DXF in QGIS?


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 der Blockedwww.foss-academy.comBlocked<Blockedhttp://www.foss-academy.comBlocked>

---------------------------------------------

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<mailto:stefan.giese at wheregroup.com>

Blockedwww.wheregroup.comBlocked<Blockedhttp://www.wheregroup.comBlocked>

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.

[cid:image001.png at 01D9F614.283AA0D0]

[cid:image002.png at 01D9F614.283AA0D0]

[cid:image003.png at 01D9F614.283AA0D0]

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<mailto:QGIS-Developer at lists.osgeo.org>

List info: Blockedhttps://lists.osgeo.org/mailman/listinfo/qgis-developerBlocked

Unsubscribe: Blockedhttps://lists.osgeo.org/mailman/listinfo/qgis-developerBlocked

--
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20231003/52a6c54f/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.png
Type: image/png
Size: 6904 bytes
Desc: image001.png
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20231003/52a6c54f/attachment-0005.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image002.png
Type: image/png
Size: 62713 bytes
Desc: image002.png
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20231003/52a6c54f/attachment-0006.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image003.png
Type: image/png
Size: 47885 bytes
Desc: image003.png
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20231003/52a6c54f/attachment-0007.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image004.png
Type: image/png
Size: 57429 bytes
Desc: image004.png
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20231003/52a6c54f/attachment-0008.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image005.png
Type: image/png
Size: 122154 bytes
Desc: image005.png
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20231003/52a6c54f/attachment-0009.png>


More information about the QGIS-Developer mailing list