import arcpy from arcpy import env from arcpy.sa import * env.workspace = r"C:\folder1" list = [] for raster in arcpy.ListRasters("*"): list.append(raster) for n in list: env.workspace = r"C:\folder2" if n in arcpy.ListRasters("*"): ras2 = n outPlus1 = Plus(n, ras2) env.workspace = r"C:\folder3" if n in arcpy.ListRasters("*"): ras3 = n env.workspace = r"C:\folder4" if n in arcpy.ListRasters("*"): ras4 = n outPlus2 = Plus(ras3, ras4) outPlus3 = Plus(outPlus1, outPlus2) outPlus3.save(r"C:\output" + "\\" + n)
I tried incorporating this script to add rasters but I keep getting errors. Here's the code I used:
import arcpy, os
from arcpy import env
import arcpy.sa
env.workspace = 'D:/Batch_Research_Test/Add_Rasters/DN'
env.overwriteOutput = True
raster_list = []
for raster in arcpy.ListRasters("*"):
raster_list.append(raster)
for r in raster_list:
env.workspace = 'D:/Batch_Research_Test/Add_Rasters/Cloud'
if r in arcpy.ListRasters("*"):
cloud = r
outPlus1 = Plus(r, cloud)
env.workspace = 'D:/Batch_Research_Test/Add_Rasters/Shadow'
shadow = r
outPlus2 = Plus(outPlus1,shadow)
outPlus2.save(r"D:\Batch_Research_Test\Add_Rasters\Output" + "\\" + r)
Hi Angira,
What is the error you are receiving?
Hi Jake,
Thanks for your email. Here's what I get when I run the code:
==================================================================
"Traceback (most recent call last):
File
"C:\Python27\ArcGIS10.1\Lib\site-packages\Pythonwin\pywin\framework\scriptutils.py",
line 326, in RunScript
exec codeObject in __main__.__dict__
File "D:\Batch_Research_Test\Scripts\Test\Add_Rasters2.py", line 17, in
NameError: name 'Plus' is not defined"
===================================================================
Thanks!
Angira
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.