0

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")  
4

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

  • If I add Set the size of the output file (in pixels) = 100, then the python code will be : gdal_translate -of GTiff -ot Float32 -outsize 100 100 -projwin 96.993358471 17.0067404816 98.9933584709 14.0067404817 -co COMPRESS=DEFLATE -co PREDICTOR=1 -co ZLEVEL=6 C:/Users/Sreeraj/Desktop/1.asc C:/Users/Sreeraj/Desktop/2.asc . – Sreeraj Feb 16 '18 at 9:00
  • 1
    But, I have to do this from the Translate option in the Processing Toolbox and when I do that, then my python code is : 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") . But, I can give only a single value in the option Set the size of the output file (in pixels) (here, =100). You can see this 100 in the above code just after the input file 1.asc. – Sreeraj Feb 16 '18 at 9:02
  • 1
    But, I want to give -outsize 6000 2400. For that, what value can I give in the option Set the size of the output file (in pixels) (instead of 100). Please note that I can give only a single value; and not 2 values like 6000, 2400. So please suggest me a solution because my python program (with Set the size of the output file (in pixels) = 100) is : 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") – Sreeraj Feb 16 '18 at 9:05
  • 1
    I have added this in the last part of my question. Please check that. Hope that you can solve this. – Sreeraj Feb 16 '18 at 9:12
  • 1
    You can give just one value from the GUI and it is hardcoded to create the gdal_tranlate command with the % syntax but the text box is editable. See my edited answer with a screenshot. Python is worth another question but I am sure you can do it by comparing the parameters of the gdal_translate command line. If you want to stick with the % syntax I am also sure that you calculate how many percent 6000 is compared to original 5788. Play with gdal_translate from command line and test how different parameters change the output. Continue to Python once you understand the basics. – user30184 Feb 16 '18 at 9:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.