[gdal-dev] How to retain double precision in GDAL?

Even Rouault even.rouault at mines-paris.org
Fri Aug 6 04:08:30 EDT 2010


Ole,

the current code in the AAIGRID driver autodetects if its a integer grid or a 
floating point grid, and in the later case it uses Float32 as a datatype, so 
that explains the loss of precision you've seen.

In the latest SVN code (see http://trac.osgeo.org/gdal/changeset/20179 and 
http://trac.osgeo.org/gdal/changeset/20180 ), the situation is now improved so 
that you now can set the configuration option AAIGRID_DATATYPE to Float64 to 
force Float64 being used to avoid the loss of precision.

If I try with your script,
AAIGRID_DATATYPE=Float64 python gdal_precision_test.py

I get now :
ASCII datatype: 7 float64
TIF datatype:   7 float64

Data GDAL (ASC): 50.814723686393002
Data GDAL (TIF): 50.814723686393002
Data REF:        50.814723686393002

Error (ASC):     0.000000000000000
Error (TIF):     0.000000000000000

Best regards,

Even

Le vendredi 06 août 2010 08:50:15, Ole Nielsen a écrit :
> Dear group
> 
> We are using GDAL - both command line and Python bindings -  for much of
> our modelling work. However, we find that the library wants to round
> floating point numbers down to single precision (Float32 or DataType=6)
> where what we need for scientific computing is double precision (Float64
> or DataType=7). We have been digging around the documentation and the
> Python binding source codes, but are running out of ideas.
> 
> Please find attached a small Python script with an ASCII test grid that
> reveals the issue. Data which is originally in double precision gets
> rounded to 6 decimal places if read directly by Gdal and also if converted
> first to GeoTIFF using gdal_translate -ot Float64 ... .
> 
> 
> The output of the attached script is
> 
> 
> ASCII datatype: 6 float32
> TIF datatype:   7 float64
> 
> Data GDAL (ASC): 50.814723968505859
> Data GDAL (TIF): 50.814723968505859
> Data REF:        50.814723686393002
> 
> Error (ASC):     0.000000282112858
> Error (TIF):     0.000000282112858
> 
> 
> 
> 
> Grateful for your help
> Cheers
> Ole
> 
> 
> Dr Ole Nielsen
> Numerical Modeller
> Australia-Indonesia Facility for Disaster Reduction
> Mobile: +62 811 820 4637 | Phone: +62 21 398 30088 x1007 | Fax: +62 21 398
> 30068


More information about the gdal-dev mailing list