[Gdal-dev] gdal_translate for netCDF to AAIGrid
Michael Toews
mwtoews at sfu.ca
Tue Oct 24 14:43:12 EDT 2006
Hi all,
'gdal_translate' on a netCDF file to an AAIGrid has odd behaviour using
GDAL 1.3.2.0 under Cygwin. My conversion:
$ gdal_translate -of AAIGrid -sds test.nc test.asc
$ mv test.asc1 test.asc
No errors were generated during the conversion.
The header of the AAIGrid output is:
ncols 86
nrows 225
xllcorner 747700.000000000000
yllcorner 5441461.627906977199
dx 98.837209302326
dy 99.555555555556
NODATA_value -9999
However, these headers should read:
ncols 86
nrows 225
xllcorner 747700
yllcorner 5441200
cellsize 100
NODATA_value -9999
The dx/dy in the output of the file was incorrectly calculated as:
dx=cellsize*(ncol-1)/ncol
dy=cellsize*(nrow-1)/nrow
which is both why they are different (dx != dy because ncols != nrows),
and why they are not correct, since they are multiplied by the ratio of
base0/base1 representations of their dimension lengths.
My netCDF file (attached) should has a cellsize of exactly 100, since my
data are spaced every 100 m in the x- and y-dims. This netCDF file was
produced using a custom python script, which uses Scientific.IO.NetCDF
for python 2.3. The file was later averaged, using 'ncra', which is part
of NCO (command viewed in 'history' global attribute). My netCDF file is
not perfect; I've recently discovered that my 'ydim' is 5463700,
5463600, ..., 5441300; or it is in reverse order (dy = -100). For netCDF
files, this should not matter (although I'll admit that it is a bit
sloppy); I've been able to use the file as normal with 'ncview' and NCO.
(As a caution, I have also seen some netCDF files which order their
latitudes from North to South, which is also in reverse order; I'm not
sure if this is tested, and corrected in GDAL, but I would highly advise
it for netCDF files).
I also get strange behaviour with 'gdalinfo'. Try:
$ gdalinfo test.nc
$ gdalinfo test.asc # using the correct header
Both the 'Size' and the 'Corner Coordinates' are pretty strange for the
test.nc file, as it seems to think that it is 512x512.
Thanks!
+mt
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.nc
Type: application/x-netcdf
Size: 79980 bytes
Desc: not available
Url : http://lists.osgeo.org/pipermail/gdal-dev/attachments/20061024/d9458190/test.nc
More information about the Gdal-dev
mailing list