I have this .asc file of maximum temperature of a local place. This file is a result of vector to raster (GeoTIFF) conversion then GeoTIFF to ASCII grid conversion, both using QGIS. Here is a snippet of the actual file when loaded into WordPad:

ncols        3000
nrows        3000
xllcorner    122.612907409668
yllcorner    9.038180351257
dx           0.000241035461
dy           0.000458419800
 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

I need this file as an input for a niche modelling program (DesktopGARP) and when I upload it in the DatasetManager it outputs an error:

> Error loading file contains an invalid ASCII Grid

I'm not sure where the problem is, however I found out that CELLSIZE is needed instead of DX and DY. The first 6 rows, instead, should look something like this:


I found a similar question Arc ASCII Grid output problem in QGIS 2.0 but the answer says to use FORCE_CELLSIZE=TRUE. But if I force the DX value into the CELLSIZE value, the raster image would shrink since the values of dx and dy are not nearly the same. Is there a way to manipulate the values without changing the raster's overall size?

2 Answers 2


QGIS seems to default to the Golden Surfer version of AAIGrid is pixels are not square but puts out a "traditional" ASC header if they are square. Most systems will not support the dx/dy options (apart from Golden Surfer). You are also right that forcing the cell size sets the cellsize to be the X cell size and that could cause distortion. Alternatively, you can resample the image to ensure square pixels or, if you are worried about the effects of resampling, repeat the vector to raster conversion and ensure you will get square cells at that point.

To resample you can use the raster calculator. Check your current X and Y resolutions by looking at the Metadata tab in layer's properties. Let's say you have resolutions of x=9.876 and y=10.123. I would opt for a desirable resolution of 10. Now switch to raster calculator. Set your raster as the only input and click the button for "Current Layer Extent". Then subtract the min x from the max X and divide by your desired resolution (10 in our example). This gives you the number of columns. Repeat the same calculation for the min Y and max Y to get the number of rows. You will probably have to very slightly adjust the extent to ensure square pixels but you can balance the change between the min and max values.

Better yet is to constrain the cell size at the point of creating the raster (avoiding any resampling). In your case it was the vector to raster conversion. I presume you went with the default size in pixels and that would have merely done the division we did above but not normalised the x and y sizes. Instead, choose the second option of "Raster size in map units per pixel" and set the horizontal and vertical values to be identical and of a suitable resolution for your use-case/data.

  • I did play with the vector to raster conversion. Doing trial and error with the pixels helped. Thanks!
    – Alloy052
    Oct 16, 2014 at 8:45

You can do the rescaling using gdalwarp and Geotiff for temporary output:

gdalwarp -overwrite -of GTiff -tr 0.000241 0.000241  D:\Download\NEU\asc.txt D:/Download/NEU/asc-square.tif

and then convert to ASCII grid:

gdal_translate -of AAIGrid D:/Download/NEU/asc-square.tif D:/Download/NEU/asc-square.asc

Alternatively, you can use gdal_translate with -outsize and -co CELLSIZE=TRUE option, but you have to calculate lines and/or rows manually.

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.