1

I am trying my hand at arcpy for the first time to create a conditional raster from a set of threshold values. I have 3 large GRID format rasters (mos_zb3, mos_zb4, pca_finb2) I am trying to feed into arcpy using the following code:

import arcpy

from arcpy import env 

from arcpy.sa import * 

arcpy.CheckOutExtension = "Spatial" 

env.workspace = "C:\final_mosaic_files\for_python"

Z3 = Raster("mos_zb3")

Z4 = Raster("mos_zb4")

PC2 = Raster("pca_finb2")

outCon = Con(Z4 < -0.9274,2, Con(Z3 <-0.6223,2, Con(PC2 > 1.13,2, Con(Z3 <-0.05342,2,1))))

outCon.save("C:\classifications\actual_real_deal\CART") 

I keep getting "dataset does not exist or is not supported" errors in the beginning when python tries to read the rasters in as objects. I know the rasters are in the workspace folder, and I have used them in several other analyses so am confident about their integrity. I have searched the other questions about this error message on the exchange and don't see a direct answer for my problem.

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Mo Correll
  • 107
  • 12

1 Answers1

3

Your error message is to do with the backslash being Python's escape character - try this instead:

import arcpy

from arcpy import env 

from arcpy.sa import * 

arcpy.CheckOutExtension = "Spatial" 

env.workspace = r"C:\final_mosaic_files\for_python"

Z3 = Raster("mos_zb3")

Z4 = Raster("mos_zb4")

PC2 = Raster("pca_finb2")

outCon = Con(Z4 < -0.9274,2, Con(Z3 <-0.6223,2, Con(PC2 > 1.13,2, Con(Z3 <-0.05342,2,1))))

outCon.save(r"C:\classifications\actual_real_deal\CART") 

Note how there is an unquoted "r" in front of any pathnames containing backslashes. Alternatives to using the unquoted "r" are to use single forward slashes or double backslashes in place of the single backslashes.

PolyGeo
  • 65,136
  • 29
  • 109
  • 338