Opened 9 years ago
Last modified 9 years ago
#5882 closed defect
GeoJSON driver truncate numbers — at Version 2
Reported by: | emanueledigiacomo | Owned by: | warmerdam |
---|---|---|---|
Priority: | normal | Milestone: | 1.11.3 |
Component: | OGR_SF | Version: | 1.11.2 |
Severity: | normal | Keywords: | geojson |
Cc: |
Description (last modified by )
Some numeric values in GeoJSON file (e.g. 4.1e-8, 0.00000001) are truncated.
I think the problem is in the conversion from JSON double to JSON string (function json_object_double_to_json_string in ogr/ogrsf_frmts/geojson/libjson/json_object.c): the conversion is done with a %f
format (by default, 6 digits after the decimal number):
size = snprintf(buf, 128, "%f", jso->o.c_double);
See attached file "data.json", where the properties are
"properties" : { "value1" : 4.1e-9, "value2": 0.00000001, "value3": 0.0000012 }
But ogrinfo show truncated values:
$ ogrinfo -geom=NO -ro data.json OGRGeoJSON INFO: Open of `data.json' using driver `GeoJSON' successful. Layer name: OGRGeoJSON Geometry: Point Feature Count: 1 Extent: (10.330000, 44.800000) - (10.330000, 44.800000) Layer SRS WKT: GEOGCS["WGS 84", DATUM["WGS_1984", SPHEROID["WGS 84",6378137,298.257223563, AUTHORITY["EPSG","7030"]], AUTHORITY["EPSG","6326"]], PRIMEM["Greenwich",0, AUTHORITY["EPSG","8901"]], UNIT["degree",0.0174532925199433, AUTHORITY["EPSG","9122"]], AUTHORITY["EPSG","4326"]] value1: Real (0.0) value2: Real (0.0) value3: Real (0.0) OGRFeature(OGRGeoJSON):0 value1 (Real) = 0 value2 (Real) = 0 value3 (Real) = 1e-06
And a conversion to another format has the same result:
$ ogr2ogr -f CSV data.csv data.json $ cat data.csv value1,value2,value3 0,0,1e-06
Change History (3)
Note:
See TracTickets
for help on using tickets.
I made a test with GDAL 2.0-dev I can confirm your results. By reading the document page http://www.gdal.org/drv_geojson.html the driver does not support doubles:
"Schema detection will recognized fields of type String, Integer, Real, StringList, IntegerList and RealList. Starting with GDAL 2.0, Integer(Boolean), Date, Time and DateTime fields are also recognized."