qgis / QGIS

QGIS is a free, open source, cross platform (lin/win/mac) geographical information system (GIS)
https://qgis.org
GNU General Public License v2.0
10.66k stars 3.02k forks source link

[DXF Export] attributes are not exported #34156

Open basilrabi opened 4 years ago

basilrabi commented 4 years ago

Describe the bug

Layer attributes are not exported in dxf (even if they are valid dxf attributes). In the attached project file, the layer has 2 fields:

  1. Layer and
  2. Text

but neither are exported in dxf. Also, when Exporting Labels as MTEXT elements in exporting project as dxf, no labels seem to be exported.

How to Reproduce

TLDR

Method 1
  1. Right-click the layer in Layers Panel
  2. Export > Save Feature As >
  3. Choose Format: AutoCAD DXF then Enter any file name
  4. Save
Method 2
  1. Click Project > Import/Export > Export Project to DXF
  2. Enter file name in Save As
  3. Check Export Labels as MTEXT elements
  4. Click OK

QGIS and OS versions

QGIS version 3.11.0-Master QGIS code revision c9fa1ab73ce
Compiled against Qt 5.13.2 Running against Qt 5.13.2
Compiled against GDAL/OGR 2.3.2 Running against GDAL/OGR 2.3.2
Compiled against GEOS 3.7.1-CAPI-1.11.1 Running against GEOS 3.7.1-CAPI-1.11.1 27a5e771
Compiled against SQLite 3.30.0 Running against SQLite 3.30.0
PostgreSQL Client Version 11.6 SpatiaLite Version 4.3.0a
QWT Version 6.1.3 QScintilla2 Version 2.11.2
Compiled against PROJ 5.2.0 Running against PROJ Rel. 5.2.0, September 15th, 2018
OS Version Fedora 31 (Workstation Edition)
Active python plugins MetaSearch; db_manager; processing

Additional context

I tried importing the layer to postgis then exporting it to dxf using ogr2ogr. The attribute "Layer" is exported but the attribute "Text" is still empty. The command I used: ogr2ogr -f "DXF" export.dxf PG:"host=localhost dbname=r user=tmcgis" -sql "SELECT * FROM mylayer"

Pedro-Murteira commented 2 years ago

This issue is still valid on QGIS 3.16.15 and 3.22.2.

agusamirudin25 commented 2 years ago

same still bug on windows

asdro-f commented 2 years ago

Someone found a Workaround?

I tried to use GDALs convertformat for exporting a shp to dxf.

If i export it direct to the disc it does not include attributes. If i use the Tool and save to temporary Layer the attributes are within the attributetable. But of course it isnt a dxf. If i try to export this temporary Layer with right-click -> Again no attributes exported.

basilrabi commented 2 years ago

This seems to be a limitation of the DXF format wherein limited fields are available (e.g. layer name, color, etc). I created my own processing plugin using ezdxf to export layers using some field as dxf layer name.

lorenzogrv commented 1 year ago

While QGis May have a bug here, please note the following:

GDAL's DXF Vector format only supports "Text" for point geometries having defined style. From docs:

Point features with LABEL styling are written as MTEXT entities based on the styling information.

Point features without LABEL styling are written as POINT entities.

Here, "LABEL styling" must complain with:

And should be specified using "OGR_STYLE" column

That said, code used from CLI - instead of the proposed by @basilrabi - should be:

ogr2ogr \
  -f DXF output_file.dxf \
  PG:"service=example_service" \
  -sql "SELECT 'LABEL(t:''' || text_field || ''')' AS ogr_style, text_field AS \"Text\", geom FROM some.table"

You can check your results using

ogrinfo -so output_file.dxf entities