[gdal-dev] Python Interfaces to gdal warp and gdal translate behave differently than command line

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[gdal-dev] Python Interfaces to gdal warp and gdal translate behave differently than command line

Christoph Paulik

Hi,

In my original email I had a small (300KB) test geotiff attached but
this was rejected by the mailing list. So here the original email again:

If we warp or translate the a GeoTIFF using the Python API
in the attached python file then the output pixel precision is
truncated (even when 15 digtis precison is specified) depending on the
number of 0 preceding the first non-zero number after the first digit (see
testwarpsmall.py).
The system calls work as expected though.

Tested on gdal 2.2.3.

Example:
1) if                    xres = 0.88888888888889
       ouput Pixel_size = 0.88888888889000
2) if                    xres = 0.08888888888889
       ouput Pixel_size = 0.08888888888900
3) if                    xres = 0.00888888888889
       ouput Pixel_size = 0.00888888888890
4) if                    xres = 0.00088888888889
       ouput Pixel_size = 0.00088888888889

In detail:

$ python testwarpsmall.py

$ gdalinfo output_test.tif

Driver: GTiff/GeoTIFF
Files: output_test.tif
Size is 11, 11
Coordinate System is:
GEOGCS["WGS 84",
    DATUM["WGS_1984",
        SPHEROID["WGS 84",6378137,298.257223563,
            AUTHORITY["EPSG","7030"]],
        AUTHORITY["EPSG","6326"]],
    PRIMEM["Greenwich",0],
    UNIT["degree",0.0174532925199433],
    AUTHORITY["EPSG","4326"]]
Origin = (-180.000000000000000,-20.000000000137490)
Pixel Size = (0.088888888888900,-0.088888888888900)
Metadata:
  AREA_OR_POINT=Area
Image Structure Metadata:
  INTERLEAVE=BAND
Corner Coordinates:
Upper Left  (-180.0000000, -20.0000000) (180d 0' 0.00"W, 20d 0' 0.00"S)
Lower Left  (-180.0000000, -20.9777778) (180d 0' 0.00"W, 20d58'40.00"S)
Upper Right (-179.0222222, -20.0000000) (179d 1'20.00"W, 20d 0' 0.00"S)
Lower Right (-179.0222222, -20.9777778) (179d 1'20.00"W, 20d58'40.00"S)
Center      (-179.5111111, -20.4888889) (179d30'40.00"W, 20d29'20.00"S)
Band 1 Block=11x11 Type=Int16, ColorInterp=Gray
  NoData Value=0

$ gdal_translate -tr 0.8888888888888888 0.88888888888888888 input_test.tif output_test.tif
Input file size is 375, 375
0...10...20...30...40...50...60...70...80...90...100 - done.

$ gdalinfo output_test.tif                                                                
Driver: GTiff/GeoTIFF
Files: output_test.tif
Size is 1, 1
Coordinate System is:
GEOGCS["WGS 84",
    DATUM["WGS_1984",
        SPHEROID["WGS 84",6378137,298.257223563,
            AUTHORITY["EPSG","7030"]],
        AUTHORITY["EPSG","6326"]],
    PRIMEM["Greenwich",0],
    UNIT["degree",0.0174532925199433],
    AUTHORITY["EPSG","4326"]]
Origin = (-180.000000000000000,-20.000000000137490)
Pixel Size = (0.888888888888889,-0.888888888888889)
Metadata:
  AREA_OR_POINT=Area
Image Structure Metadata:
  INTERLEAVE=BAND
Corner Coordinates:
Upper Left  (-180.0000000, -20.0000000) (180d 0' 0.00"W, 20d 0' 0.00"S)
Lower Left  (-180.0000000, -20.8888889) (180d 0' 0.00"W, 20d53'20.00"S)
Upper Right (-179.1111111, -20.0000000) (179d 6'40.00"W, 20d 0' 0.00"S)
Lower Right (-179.1111111, -20.8888889) (179d 6'40.00"W, 20d53'20.00"S)
Center      (-179.5555556, -20.4444444) (179d33'20.00"W, 20d26'40.00"S)
Band 1 Block=1x1 Type=Int16, ColorInterp=Gray
  NoData Value=0



--

-------------------------------------------------------
Christoph Paulik
VanderSat // Remote Sensing Scientists
Wilhelminastraat 43a, 2011 VK, Haarlem (NL), The Netherlands
W: www.vandersat.com
PGP: 8CFC D7DF 2867 B2DC 749B  1B0A 6E3B A262 5186 A0AC

_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev

testwarpsmall.py (380 bytes) Download Attachment
signature.asc (847 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Python Interfaces to gdal warp and gdal translate behave differently than command line

Even Rouault-2

On mardi 13 février 2018 17:45:18 CET Christoph Paulik wrote:

> Hi,

>

> In my original email I had a small (300KB) test geotiff attached but

> this was rejected by the mailing list. So here the original email again:

>

> If we warp or translate the a GeoTIFF using the Python API

> in the attached python file then the output pixel precision is

> truncated (even when 15 digtis precison is specified) depending on the

> number of 0 preceding the first non-zero number after the first digit (see

> testwarpsmall.py).

> The system calls work as expected though.

>

> Tested on gdal 2.2.3.

>

> Example:

> 1) if xres = 0.88888888888889

> ouput Pixel_size = 0.88888888889000

> 2) if xres = 0.08888888888889

> ouput Pixel_size = 0.08888888888900

> 3) if xres = 0.00888888888889

> ouput Pixel_size = 0.00888888888890

> 4) if xres = 0.00088888888889

> ouput Pixel_size = 0.00088888888889

>

 

Christoph,

 

The issue was that the numeric arguments were converted to string with str(x) which doesn't use enough precision. I've fixed this in trunk per

https://trac.osgeo.org/gdal/changeset/41472

 

You could workaround the issue by using:

 

gdal.Translate('out.tif', 'src.tif', options = '-tr 0.0888888888888888888 0.0888888888888888888 -projwin -180.0 -20.0 -179 -21')

 

Even

 

--

Spatialys - Geospatial professional services

http://www.spatialys.com


_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev