1

I'm trying to do the raster calculator with this script but something goes wrong. It seems that the program doesn't found the files, but they exist. I've tried to remove path from the variables (raster1, raster2 etc) but it is the same.

enter image description here

import arcpy
from arcpy import env
from arcpy.sa import *
arcpy.env.workspace = "C:\Users\Elisa\Model_Builder\raster_calc\input"
arcpy.env.overwriteOutput = True
raster1 = "C:\Users\Elisa\Model_Builder\raster_calc\input\lito2016_area_studio_cross_curv.img"
raster2 = "C:\Users\Elisa\Model_Builder\raster_calc\input\lito2016_area_studio_flowacc.img"
raster3 = "C:\Users\Elisa\Model_Builder\raster_calc\input\lito2016_area_studio_long_curv.img"
outRas = Raster("raster1") * Raster("raster3")
outRas.save("C:\Users\Elisa\Model_Builder\raster_calc")
PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Jun 13, 2018 at 12:04
1
  • Please always provide errors as text rather than pictures. Commented Jun 13, 2018 at 20:28

1 Answer 1

3

The path slashes are being interpreted as escape characters, use one of the following path slash formats instead:

raster1 = "C:/Users/Elisa/... 
raster1 = r"C:\Users\Elisa\... 
raster1 = "C:\\Users\\Elisa\\...
answered Jun 13, 2018 at 12:11
4
  • i've tried to do it but it still doesn't work Commented Jun 13, 2018 at 13:10
  • Are you reeving the same or different error? Commented Jun 13, 2018 at 14:23
  • The same. I've tried another function in map algebra and it is ok. The problem is in the variable recall but i don't know how to solve it. Commented Jun 13, 2018 at 14:41
  • 1
    @ElisaMammoliti remove the quotes in line outRas = Raster("raster1") * Raster("raster3") Commented Jun 13, 2018 at 16:16

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.