0

I have two raster datasets that I need to loop through by order and select the first raster from the first dataset with the first raster from the second dataset to perform a function. I keep getting error 000732 raster dataset not found, but it does exist. My code so far, I'm not an expert:

import arcpy
from arcpy import*
from arcpy.sa import *
arcpy.CheckOutExtension('Spatial')
arcpy.env.overwriteOutput = True

arcpy.env.workspace= r'C:/Time slices/U_sqaurred'
Urasters= arcpy.ListRasters('*.tif*')
arcpy.env.workspace= r'C:/Time slices/V_squarred'
Vrasters=arcpy.ListRasters('*.tif*')



for idx in range(0, len(Urasters)-1):
    ras1= Urasters [idx]
    ras2= Vrasters [idx]
    outraster= SquareRoot (Raster(ras1) + Raster(ras2))
    outpath= "C:/Time slices/magnitude"
    outpath = outpath + ras1
    outraster.save(outpath)
7
  • could it be a problem to have spaces in folder names? Try to move your raster to a folder with no spaces in the name
    – Vale
    Jan 11, 2019 at 9:34
  • I just renamed the folder and removed all spaces, but still same error: outraster= SquareRoot (Raster(ras1) + Raster(ras2)) RuntimeError: ERROR 000732: Input Raster: Dataset Jan_U_10_0.tif does not exist or is not supported
    – Crystal_01
    Jan 11, 2019 at 9:45
  • Try to remove the asterisk after .tif in : Urasters= arcpy.ListRasters('.tif') Jan 11, 2019 at 9:58
  • The code runs without error when I remover the asterisk but there's no output
    – Crystal_01
    Jan 11, 2019 at 11:33
  • '*.tif' is correct usage, if you want to list just TIFFs.
    – fatih_dur
    Jan 11, 2019 at 11:37

1 Answer 1

1

You are setting the env.workspace to Vrasters but trying to process the raster (name) coming from Urasters folder. Your Raster(ras2) should be fine but the problem is with Raster(ras1). The problem is that ListRasters just registers the file names in that folder, not their path! Change this to Raster(os.path.join(r'C:/Time slices/U_sqaurred', ras1)) after importing os module.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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