When starting to work with Python and ArcGIS 9.3, I assumed there would be a simple way to get a raster image into a Python array so that I can manipulate it before storing it back as another raster image. However, I can't seem to find out how to do this. Is it possible? If so, how?
I don't think this is possible with ArcGIS <= 9.3.1 I use the open source GDAL API for tasks such as this. |
|||||||||
|
http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/RasterToNumPyArray/000v0000012z000000/ ArcGIS 10 has the ability to write and read numPy arrays. |
|||||
|
fmark already answered the question, but here is some example OSGEO Python code that I wrote to read a raster (tif) into a NumPy array, reclass the data and then write it out to a new tif file. You can read and write any gdal supported format.
|
|||||
|
This thread discusses integration of arcobjects with python. Perhaps the code in this sample could be adapted so that it could be called from python. I'm not sure if there's a way to pass an array byref back to python. If there is, then IPixelBlock.PixelDatabyRef would be worth trying. |
|||
|
You can save your raster as an ESRI ascii grid and read/manipulate that file with numpy. This provides some starting points: http://sites.google.com/site/davidpfinlayson2/esriasciigridformat But watch out - it seems the ascii grid format doesn't always follow spec, so reading them properly every time can be a challenge. |
|||
|
I'm not sure you can manipulate the raster pixel by pixel, but you can use the geoprocessing objects in conjuntion with python API. You can use any toolbox for that kind of manipulation. A sample script would be:
Here is a follow up on your question. Still not possible. Not sure on version 10.0. |
|||||||||
|
The easiest way would be to convert the raster to netCDF and then open that and walk through the grid. I did very much the same thing for a project involving turning rasters into feature data based on data assigned to the raster cells. I looked at this for ages, and come to the conclusion walking the grid data would be easier from netCDF. Hope it helps. |
|||
|