GDAL Translate – Resolving Raster Extent Issues

gdalgdal-translate

My input is this file
which gives me an output file through the code:

inputraster=gdal.Open('input_file.tif'),gdal.GA_ReadOnly)
optt=gdal.TranslateOptions(format='PCRaster',bandList=[1],outputSRS='EPSG:4326',outputType=gdalconst.GDT_Int32,metadataOptions='VS_SCALAR')
gdal.Translate('output_file.map',inputraster,options=optt)

which has other extent and other resolution.
So, why I get this?

Best Answer

Your input file has different height and width for pixels

Pixel Size = (0.002914560266800,0.002632654436743)

The comment in a the source code https://github.com/OSGeo/gdal/blob/master/frmts/pcraster/pcrasterdataset.cpp says that PCRaster does not support that.

"only the same width and height for cells is supported."

What you did should probably give an error but PCRaster is rather exotic format and probably not thoroughly tested.

You have a few options, maybe the easiest is to convert the source data to have square pixels with gdalwarp

gdalwarp input_file.tif input_modified_file.tif

and then

gdal_translate -of PCRaster input_modified_file.tif output_file3.map

Now both files have same values

Size is 1259, 1138
Pixel Size = (0.002777186609872,-0.002777186609872)
Corner Coordinates:
Upper Left  (  42.4506362,  55.4787962) ( 42d27' 2.29"E, 55d28'43.67"N)
Lower Left  (  42.4506362,  52.3183578) ( 42d27' 2.29"E, 52d19' 6.09"N)
Upper Right (  45.9471142,  55.4787962) ( 45d56'49.61"E, 55d28'43.67"N)
Lower Right (  45.9471142,  52.3183578) ( 45d56'49.61"E, 52d19' 6.09"N)
Center      (  44.1988752,  53.8985770) ( 44d11'55.95"E, 53d53'54.88"N)
Related Question