OSGeo / gdal

GDAL is an open source MIT licensed translator library for raster and vector geospatial data formats.
https://gdal.org
Other
4.9k stars 2.55k forks source link

DXF: add a creation option to set the maximum number of decimal places #10847

Open agiudiceandrea opened 1 month ago

agiudiceandrea commented 1 month ago

Feature description

The DXF drivers of GDAL/OGR 3.9.2 - 3.10 writes double precision floating point numbers with 15 significant figures:

https://github.com/OSGeo/gdal/blob/9ada0c882751f18c8156aa2fd51afd6f6540a46f/ogr/ogrsf_frmts/dxf/ogrdxfwriterds.cpp#L328-L333

https://github.com/OSGeo/gdal/blob/9ada0c882751f18c8156aa2fd51afd6f6540a46f/ogr/ogrsf_frmts/dxf/ogrdxfwriterlayer.cpp#L161-L166

AFAIK, AutoCAD normally writes coordinates in DXF with 16 significant figures and allows to set the maximum number of decimal places between 0 and 16. Refs:

Additional context

No response

agiudiceandrea commented 1 month ago

Side note: in the doc page at https://gdal.org/en/latest/drivers/vector/dxf.html, the link AutoCAD 2000 DXF Reference is broken. A copy is at https://web.archive.org/web/20170314200346/http://www.autodesk.com/techpubs/autocad/acad2000/dxf/.

rouault commented 1 month ago

Ideally https://gdal.org/en/latest/development/rfc/rfc99_geometry_coordinate_precision.html should be honored too

rouault commented 1 month ago

AutoCAD normally writes coordinates in DXF with 16 significant figures

The documentation you point is a bit confusing. There's a mix between mentions of 16 significant figures and 16 decimal places. The screenshot at https://forums.autodesk.com/t5/autocad-forum/rounding-coordinates-of-line/m-p/8827743/highlight/true#M981665 has a "Decimal places of accuracies" in a label. I'm not sure if there are indeed 2 distinct limitations for the number of sigificant figures and decimal places, or if there's a single one but inaccurate terminology in some of the pages.

CC @atlight

atlight commented 1 month ago

It would be more accurate to say that AutoCAD writes coordinates to DXF with up to 16 significant figures, but no more decimal places than specified in the "Decimal places of accuracy" field in the Saveas Options dialog. This option is really specifying the maximum number of decimal places to write.

For example, here are some coordinates written to a DXF file by AutoCAD with the default value of 16 decimal places:

2.342052207121668
0.3634708370966422
22647145632.09978
-5497270855.233004

Here are those same coordinates written to a DXF file when 3 decimal places were specified:

2.342
0.363
22647145632.1
-5497270855.233
atlight commented 1 month ago

AFAIK, AutoCAD normally writes coordinates in DXF with 16 significant figures and allows to set the maximum number of decimal places between 0 and 16.

...so @agiudiceandrea was right, in other words.

agiudiceandrea commented 1 month ago

I was also a little bit confused by the available docs when I wrote this feature request's title... So it is actually only needed to make available an option for the maximum number of decimal places and to ensure that the number is written with no more then the specified maximum number of decimal places and also up to and no more then 16 significant figures.