[gdal-dev] ASCII Rasters and 'null' values in python-gdal
Chaitanya kumar CH
chaitanya.ch at gmail.com
Thu Feb 26 21:26:20 EST 2009
Oz,
NODATA_VALUES is supposed to be a pixel value (integer or real)
whereas "null" is a string. Try to convert all the "null" strings into
an unused pixel value like -9999 in raster1.asc
Regards,
--
Chaitanya kumar CH.
On Fri, Feb 27, 2009 at 2:34 AM, Oz Nahum <nahumoz at gmail.com> wrote:
> Hi,
> I have to ascii raster that I created using a text editor:
> the first is called raster1.asc and looks like this:
> 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:
> 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
>
>
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>
More information about the gdal-dev
mailing list