3

I was able to run the below script from @EmilBrundage.

However, the raster to be calculated were not paired correctly.

I am trying to loop files from 2 folders and perform raster calculation afterwards. The sequence of calculation must be:

(1st) out-0225*out-0225 [from clip qx folder] + out-0225*out-0225 [from clip qy folder]

(2nd) out-0226*out-0226 [from clip qx folder] + out-0226*out-0226 [from clip qy folder]

(3rd) out-0227*out-0227 [from clip qx folder] + out-0227*out-0227 [from clip qy folder]

and so on.

But then the script calculates like the image below.

File pairing

The script used is the ff:

import arcpy, os, math
arcpy.CheckOutExtension("Spatial")

ws1 = r"E:\clip_qx"
ws2 = r"E:\clip_qy"
outws = r"E:\ras_calc_qxy"

arcpy.env.workspace = ws1

rasterlist  = arcpy.ListRasters()

for r in rasterlist:
    r1 = arcpy.sa.Raster(r)
    r2 = arcpy.sa.Raster(os.path.join(ws2,r1))
    result =  (r1*r1) + (r2*r2)
    result.save(os.path.join(outws, r))
  • 1
    What do you mean by "not paired correctly"? Do they not line up or something? I am confused. – jbchurchill Aug 3 '17 at 15:13
  • @jbchurchill, i edited the question. Kindly check it out. Thanks again – F Viray Aug 4 '17 at 0:22
3

In line

r2 = arcpy.sa.Raster(os.path.join(ws2,r1))

you write r1 at the end of the bracket.

I think this should be just r.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.