raster operations in python

956
2
Jump to solution
03-25-2012 04:56 AM
RA1
by
New Contributor
How can I sum two rasters and after reclassify the value field of the result according to the value of both input rasters ?

I can do the outPlus = Plus(inRaster1, inRaster2)
after I can do a loop for each row in outPlus

rows = arcpy.SearchCursor(outPlus)
fields=arcpy.ListFields(outPlus)
for row in rows:
    for field in fields:
         (...)

How do I grab the row value that are in inRaster1 and inRaster2 from inside the loop ?
I want to do something like: if (inRaster=1 and inRaster2=8): new.row.value="area under development"
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
FabianBlau
Occasional Contributor II
Hi!

Read this:

http://help.arcgis.com/de/arcgisdesktop/10.0/help/index.html#//000v0000012z000000

You can adress the cells via array-indices with the numpy-array.

View solution in original post

0 Kudos
2 Replies
FabianBlau
Occasional Contributor II
Hi!

Read this:

http://help.arcgis.com/de/arcgisdesktop/10.0/help/index.html#//000v0000012z000000

You can adress the cells via array-indices with the numpy-array.
0 Kudos
curtvprice
MVP Esteemed Contributor
How do I grab the row value that are in inRaster1 and inRaster2 from inside the loop ?
I want to do something like: if (inRaster=1 and inRaster2=8): new.row.value="area under development"


If you meant cell by cell, this is easily done using map algebra, no need to resort to numpy.

The following code creates a new raster "new_area" for all cells where inRaster1 = 1 and inRaster2 = 8:

from arcpy.sa import *
inRaster1 = "e:\\work\\myraster1.tif"
inRaster2 = "e:\\work\\myraster2.tif"
outRaster = Con(inRaster1 == 1 and inRaster2 == 8,1)
outRaster.save("e:\\work\\new_area")
 
0 Kudos