AnsweredAssumed Answered

Iteration with "For" does not works for Raster Object in Arcgis Pro 2.5

Question asked by jauntaesri-co-esridist Employee on Mar 27, 2020
Latest reply on Apr 23, 2020 by matthew.sharr_noaa


I was trying to iterate through folder with rasters for some calculations between the bands of each one.


I have a script that is stored in a toolbox and ask for couple of parameters. when I run the script, it makes the process for the first image but after that it does not works for the next one and the following error appears:



I should mention that I tried the same but running the script as stand-alone using the python command promt and it works


Then I tried something easy in the python window in ArcgisPRO: 


import arcpy
from import *
from arcpy import env
import os
arcpy.env.workspace = 'C:\\Imagenes_Satelitales\\2018\\Junio\\Poligono3'
arcpy.env.overwriteOutput = True
LR = arcpy.ListSpatialReferences('*SR_clip*')
['20180607_145218_0f4e_3B_AnalyticMS_SR_clip.tif', '20180607_145219_0f4e_3B_AnalyticMS_SR_clip.tif', '20180607_145220_0f4e_3B_AnalyticMS_SR_clip.tif']
for raster in LR:
   #getting bands
   Image = Raster(raster)
   b3 = Image.getRasterBands()[2]
   b4 = Image.getRasterBands()[3]
   result = - b3)

   name = os.path.splitext(raster)[0]'C:\\Imagenes_Satelitales\\2018\\Junio\\Poligono3', name + 'result.tif')


Traceback (most recent call last):
File "<string>", line 3, in <module>
File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\sa\", line 79, in __new__
return super().__new__(cls, in_raster, is_multidimensional)
RuntimeError: ERROR 000732: Input Raster: Dataset 20180607_145218_0f4e_3B_AnalyticMS_SR_clip.tif does not exist or is not supported


That type of error is the same that I got when I run the complete script.



For now, I am going to continue using the python command promt for running the script but I would like to do it from the toolbox that I have for that purpose. 




Jhon Eric