Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have 25km by 25km squares of the world in a relational database. Each square has coordinates for the top left and lower right corner as latitudes and longitudes. Each square also has an index ilat and ilong value starting at the lower left corner with (0,0) to (maxlong, maxlat) for the top right corner. Each square also has measurements (X, Y, Z). I would like to transform this data into the ASCII Grid Format:

link

for each measurement. Here is some example data taken from the Internet:

ncols         419
nrows         407
xllcorner     823678.99884033
yllcorner     1151760.4752197
cellsize      14.314150820378
NODATA_value  -9999
-9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 

I understand what ncol and nrows is but I am not too sure about xllcorner, yllcorner, cellsize. Could someone please advise me what these values would be in my situation? Do you reckon I can transform my data from my tile/square format into the ASCII Grid Format.


Actually my grid is as follows:

Latitude is in the range [-90 ... 90] and longitude [-180 ... 180]. A square’s cell’s size is 2.5 degrees

I have been told that corresponds to 25 square kilometres.

share|improve this question
    
Actually my grid is as follows. Latitude is in the range [-90 ... 90] and longitude [-180 ... 180]. A square’s/cell’s size is 2.5 degrees – I have been told that corresponds to 25 square kilometres. –  csetzkorn Oct 24 '11 at 12:16
    
your dataset is unprojected, which is fine, but you can't directly compare it to projected units (metres, km). An approximation of 2.5°×2.5° ≈ 25 km² is impossible, and I'd ignore it since it's distracting. –  Mike T Oct 24 '11 at 18:58

1 Answer 1

up vote 2 down vote accepted

Here is a two step solution, using GDAL >= 1.8 (e.g., OSGeo4W for MS Windows).

The first step is to make an ASCII Gridded XYZ file:

...with (at least) 3 columns, each line containing the X and Y coordinates of the center of the cell and the value of the cell.

The spacing between each cell must be constant and no missing value is supported. Cells with same Y coordinates must be placed on consecutive lines. For a same Y coordinate value, the lines in the dataset must be organized by increasing X values. The value of the Y coordinate can increase or decrease however. The supported column separators are space, comma, semicolon and tabulations.

assuming you have no gaps/missing data, something like this should produce the appropriate XYZ file:

sqlcmd -S myServer -d myDB -E -o "raster.xyz" ^
    -Q "SELECT lon, lat, alt FROM foo ORDER BY lat, lon" ^
    -W -w 999 -s","

(not tested! more details here)

Then convert the XYZ ASCII format to an Esri ASCII grid file (raster.asc) using gdal_translate:

gdal_translate -of AAIGrid raster.xyz raster.asc
share|improve this answer
    
Thanks I will have a look into this. –  csetzkorn Oct 20 '11 at 10:03
    
I think I would rather implement something myself. Could you please shed some light on what xllcorner, yllcorner, cellsize mean? –  csetzkorn Oct 21 '11 at 7:43
    
Take a look here or here –  Mike T Oct 21 '11 at 20:24
    
I was looking at them it is still confusing as it meantions easting and northing - but there are several types aren't there? one of the links seems to be in degrees though ... –  csetzkorn Oct 24 '11 at 12:17
    
you need a perfect grid pattern. Units can be either metres (sometimes kms) or degrees. What is the distance between points? is it constant? –  Mike T Oct 24 '11 at 17:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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