Quantcast
Channel: Question and Answer » arcpy
Viewing all articles
Browse latest Browse all 767

Raster math with iterator (arcpy)

$
0
0

I know what I am trying to do here is wrong. But I was hoping for something similar that would do the job.

Basically, I need a placeholder for values and raster calculations until I sum them together at the end. I am trying to not have to repeat the same code 6 or 7 times.

How do I put an iterator into the definition of a output (i.e. NAME + n = … where n is the iterator)?

import arcpy, os, sys, datetime, time, fileinput
from arcpy.sa import *
Output = r'G:TEMPTEMP2Test'
ESO1 = Output + '\eso_1'
ESO2 = Output + '\eso_2'
ESO3 = Output + '\eso_3'
ESO4 = Output + '\eso_4'
ESO5 = Output + '\eso_5'
ESO6 = Output + '\eso_6'
ESO7 = Output + '\eso_7'
ESO1_NORM2 = Output + '\ESO_NORM_1'
ESO2_NORM2 = Output + '\ESO_NORM_2'
ESO3_NORM2 = Output + '\ESO_NORM_3'
ESO4_NORM2 = Output + '\ESO_NORM_4'
ESO5_NORM2 = Output + '\ESO_NORM_5'
ESO6_NORM2 = Output + '\ESO_NORM_6'

Array = [ESO1, ESO2, ESO3, ESO4, ESO5, ESO6, ESO7]
Array2 = [ESO1_MAX, ESO2_MAX, ESO3_MAX, ESO4_MAX, ESO5_MAX, ESO6_MAX, ESO7_MAX]
Array3 = [ESO1_NORM, ESO2_NORM, ESO3_NORM, ESO4_NORM, ESO5_NORM, ESO6_NORM]
Array4 = [ESO1_NORM2, ESO2_NORM2, ESO3_NORM2, ESO4_NORM2, ESO5_NORM2, ESO6_NORM2]
n = 0
for r in Array:
#Get the maximum value of each raster 
    Array2[n] = arcpy.GetRasterProperties_management(r, "MAXIMIUM").getOutput(0)
    n += 1

a = 0
while a < 7:
    for b in Array:
        #Discover the normalization factor knowing ESO7_MAX is the maximum value for any raster
        Array3[a] = Array[a] / ESO7_MAX
        #Step not really needed, but stops very large values in the final output by scaling all rasters in between 0 and 1.
        Array4[a] = (Array[a] * Array3[a]) / ESO7_MAX
        a += 1

Result = Array4[0] + Array4[1] + Array4[2] + Array4[3] + Array4[4] + Array4[5] + (ESO7 / ESO7_MAX)
Result.save(Output + 'Result')

Viewing all articles
Browse latest Browse all 767

Latest Images

Trending Articles



Latest Images