0

I want to write a conditional statement and save it as a .tif file. I have looked through the documentation from ArcGIS and as far as I can tell, my code should work, but I keep getting an error that the computer can't save what I want as a raster. I have saved .tif files earlier in my code, so I'm not sure what the problem is. I've tried to save in different file formats as well, but I got the same error message.

import arcpy
from arcpy import env
arcpy.CheckOutExtension("Spatial")
from arcpy.sa import * 

path = 'folderlocation'
env.workspace = path  #this is the work environment
template = 'actualrd.tif'
env.extent = template  #set the extent
env.cellSize = template  #set the cell size
env.overwriteOutput = True  #set overwrite output to true

tempEuc = 'temp_dist.tif'
outEucDist = EucDistance(actualrd, 500)
outEucDist.save(tempEuc)

tempCon = r'temp_con.tif'
outCon = Con(((tempEuc >=0) & ('actualrd' == 1)), 1)
outCon.save(tempCon)

I can save the euclidean distance raster file, but not the conditional statement raster file.

RuntimeError: ERROR 010240: Could not save raster dataset to [file location] with output format TIFF.

I am using ArcGIS 10.4.1

5
  • Please edit the question to specify the version of ArcGIS in use.
    – Vince
    Commented Oct 9, 2016 at 13:56
  • I wrote something very similar the other day, and it worked fine. You have genericized the code block to hide your actual code, and I suspect that has masked the issue. As presented here, this code should return Python errors, not ArcPy ones. Please it the question to be an MCVE
    – Vince
    Commented Oct 9, 2016 at 14:13
  • @Vince I added more information, not sure if that helps... Maybe it would help to know that I am trying to run this code in a loop, but even outside of the loop, this code doesn't work.
    – Leticia
    Commented Oct 9, 2016 at 14:48
  • The 'actualrd' == 1 statement doesn't make sense. You are comparing a string to an integer. Shouldn't this be Raster('actualrd') == 1? Commented Oct 9, 2016 at 15:20
  • Your folder location is possibly the problem. What is the actual path? If you're trying to save to a GDB you'll get that error.
    – user2856
    Commented Oct 9, 2016 at 19:43

1 Answer 1

1
  • Make sure your output path is correct (i.e. you can't save tiffs to a GDB).
  • You have a number of errors in your code, try the following:
actualrd = Raster('actualrd.tif') #Make template a Raster object
env.extent = actualrd  #set the extent
env.cellSize = actualrd  #set the cell size
env.overwriteOutput = True  #set overwrite output to true

tempEuc = 'temp_dist.tif'
outEucDist = EucDistance(actualrd, 500)
outEucDist.save(tempEuc)

tempCon = r'temp_con.tif'
outCon = Con(((outEucDist >=0) & (actualrd == 1)), 1) #use outEucDist not tempEuc and actualrd Raster object not 'actualrd' string

outCon.save(tempCon)
2
  • Wow thank you! That worked! Do you know why putting the raster file name (instead of outEucDistance) in the conditional statement not work?
    – Leticia
    Commented Oct 10, 2016 at 3:07
  • 1
    Because you need to use a raster in the expression not a string. The file name is not a raster to arcpy, it is a string.
    – user2856
    Commented Oct 10, 2016 at 3:10

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.