[GIS] QGIS ASCII Grid output problem

esri-ascii-rasterqgisrasterraster-conversion

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:

ncols        
nrows         
xllcorner    
yllcorner    
cellsize 
NODATA_value

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?

Best Answer

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.

Related Question