1

I want to create a tool box in ArcMap. I wrote this code:

 # Import system modules
  import arcpy, os,sys
  from arcpy import env
  from arcpy.sa import *

  # Set input raster
  InputRaster=arcpy.GetParameterAsText(0)

  # Set local variables
  x = Raster(InputRaster)
  a = arcpy.GetParameterAsText(1)
  b = arcpy.GetParameterAsText(2)
  c = arcpy.GetParameterAsText(3)
  d = arcpy.GetParameterAsText(4)

 #Execute
 outRaster=Con((x>=a)&(x<=b),(x-a)/(b-a),Con((x>b)&(x<=c),1,Con((x>c)&(x<=d),(d-x)/(d-c),0)))
 outRaster.save("C:/Users/sk/Desktop/out.tif")

and when I run it , this Error occurs:

Executing: fuzzy well_dist 100 200 500 1000
Start Time: Sat Dec 29 21:14:42 2018
Running script fuzzy...
Failed script fuzzy...

Traceback (most recent call last):
File "C:\Users\sk\Desktop\Script3.py", line 17, in <module>
outRaster=Con((x>=a)&(x<=b),(x-a)/(b-a),Con((x>b)&(x<=c),1,Con((x>c)&(x<=d), (d-x)/(d-c),0)))
File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\sa\Functions.py", line 3924, in GreaterThanEqual
in_raster_or_constant2)
 File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\sa\Utils.py", line 53, in swapper
result = wrapper(*args, **kwargs)
 File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\sa\Functions.py", line 3921, in Wrapper
["GreaterThanEqual", in_raster_or_constant1, in_raster_or_constant2])
RuntimeError: ERROR 000732: Input Raster: Dataset 100 does not exist or is not supported

Failed to execute (fuzzy).
Failed at Sat Dec 29 21:14:47 2018 (Elapsed Time: 4.85 seconds)

What is wrong ?

  • 1
    Welcome Somaye. You might consider breaking apart that Con line into three or four separate commands. Though your syntax tentatively looks ok, arcpy does sometimes freak out when you nest things too deeply. It would make it easier to troubleshoot as well. – J Kelly Dec 30 '18 at 0:14
2

GetParameterAsText gets the value AS TEXT.

Therefore a,b,c,d are all strings. You need to convert them to a numeric format before asking Con to compare them to x.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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