You are here: > ESRI Forums > arcgis desktop discussion forums > Thread Replies

ArcGIS Desktop Discussion Forums

ArcGIS Desktop - Geoprocessing Scripting (Python, JavaScript, VB) forum

Get grid cell value from Python   David Finlayson Aug 11, 2004
Re: Get grid cell value from Python   Steve Lynch Aug 18, 2004
Re: Get grid cell value from Python   David Finlayson Aug 18, 2004
Re: Get grid cell value from Python   Sean Gillies Aug 20, 2004
Re: Get grid cell value from Python   Didrik Pinte Apr 29, 2005
Re: Get grid cell value from Python   Byron Amerson May 31, 2006
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Get grid cell value from Python 
Author David Finlayson 
Date Aug 11, 2004 
Message I want to query a GRID and return the cell value at a given location from a Python script. For example something like this:

cellValue = GP.GetCellValue(RasterName, X, Y)

Surely, there is an easy way to do this.

If no functionality currently exists to do this, what is the best route to build it in? I have thought about writing a VB Tool that can bridge ArcObjects to Python (using PixelBlock or RasterCursor and IDispatch) but that seems like a lot of work. 
  --
David Finlayson
Shoreline Geomorphologist
School of Oceanography
University of Washington, Seattle, WA 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Get grid cell value from Python 
Author Steve Lynch 
Date Aug 18, 2004 
Message David

I would suggest that you use

gp.ExtractValuesToPoints_sa(.....

Steve Lynch
ESRI
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Get grid cell value from Python 
Author David Finlayson 
Date Aug 18, 2004 
Message Too much overhead. (create a new shapefile for each point?)

Here is the problem: I have AML scripts that start at the base of a river (FlowAccumulation output) and "walks" up the river channel by stepping into the cell with the next highest dicharge.

As the "cursor" walks up the stream it outputs to a text file the current elevation, river mile, slope and other attributes.

This type of query and response of the DEM allows a script to create new tools that ESRI hasn't thought about (whithout going through ArcObjects). Like new ways of generalizing data, smoothing, aggregating maybe you want to calculate wind fetch on a lake, or like in my example, creating a river profile.

None of this is possible without the ability to read individual pixel values efficiently. Ideally, we would also have the ability to post new data to an empty raster (or modify a dem) using a similar syntax.

Today I tend to dump grids to floating point binary files, load them into python as arrays and work with them that way. The results are put back at the end of the script. There is a lot of overhead associated with dumping and reforming the grids.

What I envision is some kind of efficient cursor into a raster dataset like you have provided for vector tables. 
  --
David Finlayson
Shoreline Geomorphologist
School of Oceanography
University of Washington, Seattle, WA 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Get grid cell value from Python 
Author Sean Gillies 
Date Aug 20, 2004 
Message In the meanwhile, you may want to check out Frank Warmerdam's GDAL library. It can load rasters in many formats

http://www.remotesensing.org/gdal/formats_list.html

and will give you the grid cell access you are looking for. Also integrates with Numeric Python. 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Get grid cell value from Python 
Author Didrik Pinte 
Date Apr 29, 2005 
Message Did someone find any solution to do this within ArcGIS API and without loading an external library ?

I'm trying to write a script that export ArcGIS rasters to Matlab MAT file. I don't want that the user have to install gdal or PIL to read and access rasters.

There must be an easy way to access rasters values ...

Didrik 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Get grid cell value from Python 
Author Byron Amerson 
Date May 31, 2006 
Message Hi Steve,

Is there any update on this functionality that David asked about last year??

I happen to be attempting to use the same approach with the very same aml that David obliquely referred to. In ArcInfo worksation (or an aml), it is straightforward to call CELLVALUE and use the output directly or dump it to a text file.

Given that the CELLVALUE command still works in workstaion, is there a way to get to it from a script without resorting to complex VBA or any of the other workarounds that David mentioned?