[GIS] Translate (convert format): Set the size of the output file

gdalgdal-translatepythonqgis

I have a raster .asc file with Pixel Size = 0.000863923,-0.000863923 (as given in Rightclick -> Properties -> Metadata -> Properties -> Pixel Size) and Dimensions = X: 5788 Y: 2315 (where X is width and Y is Height).

I want to export this raster (with a new name) after changing the properties into Pixel Size = 0.000833333,-0.000833333 and Dimensions = X: 6000 Y: 2400.

For this, I want to use Translate (convert format) in the Processing Toolbox -> GDAL/OGR -> [GDAL] Conversion.

In Translate (convert format), I am able to see an option :

Set the size of the output file (In pixels or %) 

What value should I give in order to get a raster with Pixel Size = 0.000833333,-0.000833333 and Dimensions = X: 6000 Y: 2400 (from a raster with the same extents; but with Pixel Size = 0.000863923,-0.000863923 and Dimensions = X: 5788 Y: 2315) ?

Also, I am able to see another option :

Output size is a percentage of input size

Do I have to select (select by ticking or by giving 'Yes') this option or not ?

If I give Set the size of the output file (In pixels) = 100, then the python code will be :

processing.runalg("gdalogr:translate","C:/Users/Sreeraj/Desktop/1.asc",100,False,"",0,"","96.993358471,98.9933584709,14.0067404817,17.0067404815",False,5,4,75,6,1,False,0,False,"","C:/Users/Sreeraj/Desktop/2.asc") 

You can see the value 100 in the above line of code (after the input file 1.asc).

If I want to give -outsize 6000 2400 ; then how can I change the given below python code (change from Set the size of the output file (In pixels) = 100 to -outsize 6000 2400) ?

processing.runalg("gdalogr:translate","C:/Users/Sreeraj/Desktop/1.asc",100,False,"",0,"","96.993358471,98.9933584709,14.0067404817,17.0067404815",False,5,4,75,6,1,False,0,False,"","C:/Users/Sreeraj/Desktop/2.asc")  

Best Answer

Conversion does not change the extent of the image. It you define the number of pixels then the size of the pixel is calculated automatically, of if you define the pixel size then the number of pixels comes automatically from equations "width/pixel size" and "height/pixel size"

The user interface in QGIS gives controls for a subset of the options of gdal_translate http://www.gdal.org/gdal_translate.html and what you want to do is not supported. Fortunately you can edit the generated command directly before executing it. You have two alternatives. Either set the size

gdal_translate -outsize 6000 2400 input.tif output.tif

or set the resolution

gdal_translate -tr 0.000833333 0.000833333 input.tif output.tif

Here is the place for doing the edits. Use the pen icon for enabling edits and press OK for running the process.

enter image description here

Related Question