Bug report #4381

Saving a shape as DXF ("save as...") leads to corrupted files

Added by Giovanni Manghi about 13 years ago. Updated about 11 years ago.

Status:Closed
Priority:Normal
Assignee:-
Category:Vectors
Affected QGIS version:master Regression?:No
Operating System: Easy fix?:No
Pull Request or Patch supplied:No Resolution:invalid
Crashes QGIS or corrupts data:No Copied to github as #:14313

Description

During a training course I have been pointed that almost any vector saved as dxf in QGIS (using "save as..."), does not open in Autocad. I have tested myself with an Autodesk free viewer (Free DWG Viewer), and the message is like


Invalid database handle 0 on line 1548.
Invalid or incomplete DXF input -- drawing discarded.

The same seems to happen in other CAD software like LivreCAD (under Linux), but not if you open it back in QGIS.

Translating the vector to DXF with ogr2ogr leads to a file that opens fine in CAD software. Ex:

ogr2ogr -f "DXF" teste10.dxf TM_WORLD_BORDERS-0.3.shp

QGIS_Art_14_Lwpolyline_.dxf (16.5 KB) Thaddeus -, 2011-10-17 01:02 PM

QGIS_Art_12_Polyline_.dxf (30.8 KB) Thaddeus -, 2011-10-17 01:02 PM

QGIS_Art_12_Line_.dxf (45.1 KB) Thaddeus -, 2011-10-17 01:02 PM

shapefile_used_for_testing.7z - Shapefile used for testing (52.7 KB) zirneklitis -, 2012-10-02 06:02 AM

generated_DXF.7z - Generated DXF files (58.6 KB) zirneklitis -, 2012-10-02 06:03 AM

test_qgis_master_gdalogr_master.dxf.tar.bz2 (2.69 MB) Giovanni Manghi, 2013-02-25 09:12 AM

History

#1 Updated by Thaddeus - about 13 years ago

Yes, I get the same here: Handle is a string representing a hex value, always starting at hex 20 or so and incrementing, never recycled or repeated. Zero is a special number that, at least, the utility Audit uses it for special flag when running ....

Other comments:

QGIS is saving too many drawing sections (HEADER, CLASSES, TABLES, BLOCKS, ENTITIES, OBJECTS). ENTITIES would be the only one needed. If it were to ask the user to select a particular layer, then TABLES would be needed too.

Also, the HEADER variable $ACADVER indirectly enforces a "purchase newer CAD version" because, I guess, the application has to assume that all DXF features of the DWG AC1018 format could be found on the drawing, but QGIS is using just drawing entities (ENTITIES) with the LWPOLYLINE -- introduced on version 14: I'd use a header like this:

0
SECTION
2
HEADER
9
$ACADVER
1
AC1014
0
ENDSEC

or switch to POLYLINE and use $ACADVER=AC1001 (wikipedia.org/wiki/Autocad)

The attached examples can be opened in QGIS and saved back to DXF: comment-line header is 999.

QGIS cannot properly handle open polylines (DXF group 70): displays an invisible object on the canvas: it can be selected, but it is no highlighted: see 999.

#4 Updated by Thaddeus - about 13 years ago

erratum:
The attached examples can be opened in QGIS and saved back to SHP: comment-line header is 999.

#5 Updated by Giovanni Manghi about 13 years ago

From Mick F.

"In regards to Bug #4381 for the Quantum GIS Desktop, the issue is to due with the handle ID created for the first lwpolyline entity. For some reason the first entity has a handle of "0" and the next entity (second) has a handle of "20000", the third "20001" etc etc

It seems that the counter used to create the handles (which need to be unique) is not starting at the correct value (which should be 20000) before being incremented."

#6 Updated by Thaddeus - about 13 years ago

I get different (QGIS1.7.1) initial Handles (0 or 20000) when exporting, depending if the source file is VRT or SHP: it would appear as if there were two counters running on parallel with two independent counts ?.

Other non-graphic objects in the header are also using handles, so 20000 seems a reasonable initial value for graphic objects. The variable $HANDSEED in the header publishes the next available handle (last one used + 1).

#7 Updated by Giovanni Manghi almost 13 years ago

  • Target version set to Version 1.7.4

#8 Updated by Giovanni Manghi almost 13 years ago

  • Crashes QGIS or corrupts data set to No
  • Status changed from Open to Closed
  • Resolution set to worksforme
  • Affected QGIS version set to master

This seems fixed now in qgis-master

#9 Updated by zirneklitis - about 12 years ago

This bug should be reopened!

The wrong first handle is created with:
  • QGIS 1.8.0-Lisboa; Compiled against GDAL/OGR 2.0dev; Fedora 14 x64 (self-compiled)
  • QGIS 1.8.0-Lisboa; QGIS code revision 6416f38; Compiled against GDAL/OGR 1.9.1; OSGeo4W/ Windows XP
  • QGIS 1.9.0-Master; QGIS code revision 9d8b9fc; Compiled against GDAL/OGR 1.9.1; OSGeo4W/ Windows XP

Any of them creates wrong first handle:

LWPOLYLINE
  5
0

At the same time ogr2ogr creates the first handle as expected:

LWPOLYLINE
  5
20000

(ogrinfo --version
GDAL 1.9.1, released 2012/05/16)

#10 Updated by zirneklitis - about 12 years ago

#11 Updated by Giovanni Manghi about 12 years ago

  • Status changed from Closed to Reopened
  • Target version changed from Version 1.7.4 to Version 2.0.0
  • Resolution deleted (worksforme)

#12 Updated by Giovanni Manghi almost 12 years ago

Still true and apparently not an OGR issue.

It makes even crash DWG TrueView 2013.. :) priceless :)

#13 Updated by Giovanni Manghi almost 12 years ago

  • Priority changed from High to Normal

#14 Updated by Andreas Neumann over 11 years ago

Hi,

Did you recently test with current master? I believe it should be fixed now. You also need the most recent OGR though.

Andreas

#15 Updated by Giovanni Manghi over 11 years ago

I compiled on ubuntu GDAL master and then qgis master against it.

The I opened the (thematicmapping.org) world borders shapefile and saved it as dxf. The result works fine in QGIS.

Then I launched Windows, installed the latest version of Autodesk DWGTrueView and opened the DFX -> crash.

cheers!

#16 Updated by Giovanni Manghi over 11 years ago

Giovanni Manghi wrote:

I compiled on ubuntu GDAL master and then qgis master against it.

The I opened the (thematicmapping.org) world borders shapefile and saved it as dxf. The result works fine in QGIS.

Then I launched Windows, installed the latest version of Autodesk DWGTrueView and opened the DFX -> crash.

cheers!

attaching the DXF created with GDAL/OGR master.

#17 Updated by Giovanni Manghi over 11 years ago

  • Status changed from Reopened to Closed
  • Resolution set to invalid

Andreas Neumann wrote:

Hi,

Did you recently test with current master? I believe it should be fixed now. You also need the most recent OGR though.

Andreas

Tested again and now, after the latest updates in both ogr and qgis, the created DXF are correctly opened in CAD software.

#18 Updated by hagit Wiener about 11 years ago

I'm having the same problem.
Downloaded the latest version of Qgis earlier this month. What is the OGR?

#19 Updated by Giovanni Manghi about 11 years ago

hagit Wiener wrote:

I'm having the same problem.
Downloaded the latest version of Qgis earlier this month. What is the OGR?

what QGIS version? what OS? can attach sample data?

Also available in: Atom PDF