gdal icon indicating copy to clipboard operation
gdal copied to clipboard

GeoJSON: Decimal number inside extra member may get more decimals

Open jratike80 opened this issue 3 years ago • 1 comments

If GeoJSON contains an extra feature member like this (sorry if it is not a member, I do not master the JSON vocubulary): "kiinteistotunnuksenSijainti":{"type":"Point","coordinates":[461312.783,6685388.485]}} then the numbers seem to go through a decimal->double conversion and the result from ogrinfo and from ogr2ogr conversions is kiinteistotunnuksenSijainti (String(JSON)) = { "type": "Point", "coordinates": [ 461312.783, 6685388.4850000003 ] } By comparison a numeric attribute "testnumber":6685388.485 is not changed and ogrinfo shows it unaltered testnumber (Real) = 6685388.485.

How to reproduce: ogrinfo base_3067.json -al

base_3067.zip

jratike80 avatar Nov 29 '22 18:11 jratike80

JSON numbers are stored as IEEE754 64-bit real numbers on JSON parsing (as most parsers do). Regarding the output back to decimal representation, this is just dependent on the number of significant figures selected. OGR is on the safe side, using potentially more significant figures than strictly necessary, to avoid any loss of accuracy.

$ python -c "print('%.17g' % 6685388.485)"
6685388.4850000003

$ python -c "print(6685388.485 == 6685388.4850000003)"
True

We have logic at a number of places to try to find the "minimal" decimal representation. Probably not used for that particular use case. Minor issue from my point of view

rouault avatar Nov 29 '22 18:11 rouault