[gdal-dev] ASCII Rasters and 'null' values in python-gdal

Oz Nahum nahumoz at gmail.com
Thu Feb 26 16:04:51 EST 2009


Hi,
I have to ascii raster that I created using a text editor:
the first is called raster1.asc and looks like this:
<http://forum.qgis.org/viewtopic.php?f=2&t=4552#>ncols         6
nrows         4
xllcorner     3366820.0000019
yllcorner     5814589.0300007
cellsize      10
NODATA_value  -9999
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 -9999 -9999
The second is called raster2.asc and looks like this:
<http://forum.qgis.org/viewtopic.php?f=2&t=4552#>ncols         6
nrows         4
xllcorner     3366820.0000019
yllcorner     5814589.0300007
cellsize      10
NODATA_value  null
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 null null

When I import them into python I find out the lower right corner of the
first raster is not giving the correct value: instead of 'null' qgis
displays the value '31081'.
The other raster is imported correctly and it showing 'null's for the two
last data cells.

>>> dataset = gdal.Open('raster2.asc', GA_ReadOnly)
>>> b = gdal_array.DatasetReadAsArray(dataset)
>>> b
array([[1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 0, 0]], dtype=int16)
>>> dataset = gdal.Open('raster1.asc', GA_ReadOnly)
>>> a = gdal_array.DatasetReadAsArray(dataset)
>>> a
array([[    1,     1,     1,     1,     1,     1],
       [    1,     1,     1,     1,     1,     1],
       [    1,     1,     1,     1,     1,     1],
       [    1,     1,     1,     1, -9999, 31081]], dtype=int16)
>>>


So before I go and open a bug, I just wanted to know - what is wrong ? Maybe
it's my system setup ? Maybe i don't write correct ascii rasters ? Also,
another thing I would like to bypass is the fact that 'null' values are
formed as zeros in gdal-numpy - this could lead to error when doing some
raster manipulations. Is there a way to by pass this (besides being
aware...)?

I use Debian Lenny the latest relevant packages from.

Thanks,
Oz N,
Grad Studend,
Universität Tübingen



-- 

----
           Imagine there's no countries
           It isn't hard to do
           Nothing to kill or die for
           And no religion too
           Imagine all the people
           Living life in peace
----
          You all must read 'The God Delusion'
          http://en.wikipedia.org/wiki/The_God_Delusion
---
when one person suffers from a delusion it is called insanity. When many
people suffer from a delusion it is called religion."
Robert Pirsig, Zen and the Art of Motorcycle Maintenance
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20090226/147dc840/attachment.html


More information about the gdal-dev mailing list