I am new to GDAL and have been having some hard time figuring out how to change a raster's resolution and how to align it to another existing raster.

I have come to the point where I have a raster made of a numpy array class. I exported it into an ASCII file. It looks similar to this (as an example, this is the ascii file)...


ncols 4
nrows 4
xllcorner 20
yllcorner 8.5
cellsize 0.5
nodata_value -9999
0.1 0.2 0.3 0.4
0.2 0.3 0.4 0.5
0.3 0.4 0.5 0.6
0.4 0.5 0.6 0.7

As you can see, it contains no projection information. On the other side I have an existing raster saved on the computer which is in WGS84 UTM32N, and has a different resolution.

I tried to google around to find how I can use GDAL to change resolution of the ASCII raster while aligning it to the existing raster on my computer.

Does the ASCII raster need to have some projection data or other kind of information? Could somebody explain to me how to use gdalwarp with Python?

1 Answer 1


The ASCII raster needs a projection data file just as an ESRI shapefile. You can test it with one GTiff raster in QGIS using the Raster -> Conversion -> Translate (Convert Format) menu option where Arc/Info ASCII Grid format is chosen for output raster. You will see the *.prj associate file in the raster directory when conversion is over.

On the other hand, if you check up the gdalwarp documentation in http://www.gdal.org/gdalwarp.html you can observe that the [-tr xres yres] and [-te xmin ymin xmax ymax] parameters could be used for controlling the raster's resolution and for aligning it to another existing raster. The following example works well (at the Python Console of QGIS) for transformation of raster resolution from 30x30 to 15x15.

from os import system
system ('gdalwarp -overwrite -s_srs EPSG:32612 -tr 15 15 -of GTiff C:/pyqgis_data/ndvi.tif C:/pyqgis_data/ndvi2.tif')

Aligning problems could be arisen if (major resolution/minor resolution) ratio is not an integer number.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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