Skip to Content.

mget-help - RE: [mget-help] Difficulty using ArcGISRaster.ToNumpyArray

Please Wait...

Subject: Marine Geospatial Ecology Tools (MGET) help

Text archives


From: "Jason Roberts" <>
To: <>
Cc: <>
Subject: RE: [mget-help] Difficulty using ArcGISRaster.ToNumpyArray
Date: Fri, 14 May 2010 09:47:15 -0400
Hi James,

The ArcGISRaster.ToNumpyArray method actually returns a tuple:

numpyArray, noDataValue = ArcGISRaster.ToNumpyArray(raster[, band[,
tempRasterPath]])

You should modify your code to look like this:

>>> ras1, noDataValue =
ArcGISRaster.ToNumpyArray(r"D:\James_S\Map_Algebra_Test\os_10m_dtm")

Or if you want to not bother with the noDataValue, just extract the first
element of the returned tuple:

>>> ras1 =
ArcGISRaster.ToNumpyArray(r"D:\James_S\Map_Algebra_Test\os_10m_dtm")[0]

Note that there is a bug in MGET where the noDataValue is sometimes
incorrect. Please check the value to be sure it is correct. I think it is
generally right when working with integer rasters, but may be wrong when
working with floating point rasters. As an alternative, you can get the No
Data value from the geoprocessor's Describe object, e.g.:

noDataValue =
gp.Describe(r"D:\James_S\Map_Algebra_Test\os_10m_dtm").NoDataValue

We have not fixed this yet because we are rewriting a large portion of our
raster processing code, so the existing code will ultimately be replaced
completely. (The rewrite will make MGET aware of 3D and 4D data, e.g. data
that has time and/or depth dimensions, as well as greatly reduce MGET's
dependency on ArcGIS.)

Many of MGET's functions are documented in the GeoEco Python Reference that
is installed on your system or available on the web at:

http://code.nicholas.duke.edu/projects/mget/export/HEAD/MGET/Trunk/PythonPac
kage/dist/TracOnlineDocumentation/Documentation/PythonReference/PythonRefere
nce.html

Drill into the GeoEco Module Index link. The documentation is very much a
work in progress.

Let us know if there's anything else we can help you with.

Best,
Jason

-----Original Message-----
From: 

 
[mailto:]
 
Sent: Friday, May 14, 2010 9:25 AM
To: 

Subject: [mget-help] Difficulty using ArcGISRaster.ToNumpyArray

Hi all,

I'm new to Python (and to coding in general), so I'm probably just being
thick,
but I'm having some trouble with MGET's ArcGISRaster.ToNumpyArray method.

My code executes successfully and the result appears to be a numpy.ndarray,
but
it doesn't behave like one. It doesn't have a shape, for example, and it
doesn't have the usual mathematical properties of an array. Instead, Python
seems to think that it's a 'tuple object', whatever that is. My simple test
code is as follows:

>>> import arcgisscripting
>>> import numpy as n
>>> from GeoEco.DataManagement.ArcGISRasters import ArcGISRaster
>>> gp = arcgisscripting.create(9.3)
>>> ras1 =
ArcGISRaster.ToNumpyArray(r"D:\James_S\Map_Algebra_Test\os_10m_dtm")
>>> ras1
(array([[205, 205, 205, ...,  45,  45,  45],
       [203, 204, 204, ...,  44,  44,  44],
       [202, 202, 203, ...,  43,  43,  43],
       ..., 
       [230, 231, 232, ...,  68,  67,  66],
       [230, 231, 232, ...,  68,  67,  66],
       [231, 232, 233, ...,  67,  66,  65]], dtype=int16), -32768)
>>> ras1.shape
Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
AttributeError: 'tuple' object has no attribute 'shape'
>>> ras1 + 1
Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
TypeError: can only concatenate tuple (not "int") to tuple
>>> isinstance(ras1, n.ndarray)
False

What am I doing wrong? 'ras1' looks like an array to me, but Python doesn't
think so. Shouldn't the output from ArcGISRaster.ToNumpyArray have a shape,
and
shouldn't I be able to add 1 to each element by typing 'ras1 + 1'?

All feedback very much appreciated, and thanks for putting together such a
great set of tools!

Best wishes,


James.

Archives powered by MHonArc.
Top of Page