1

I am attemping to call arcpy.sa.CostDistance to calculate the cost distance to a source point as well as generate the optional Cost Back link raster:

arcpy.sa.CostDistance("input", cost, "costDist", "", "costBackLink")

Which yields this error when executed within the Python Windows of ArcGIS:

>>> arcpy.sa.CostDistance("input", cost, "costDist", "", "costBackLink")
Runtime error 
Traceback (most recent call last):
  File "<string>", line 1, in <module>
TypeError: CostDistance() takes at most 4 arguments (5 given)

Oddly though, the exact same processing when executed via the Toolbox executes fine. The inline help that appears next to the Python Window when entering a function name also references the 5 arguments.

Why is this happening?

1 Answer 1

3

Take a look at the input guidelines here. There are four inputs. Also, the third input is a distance value and should thus be either a hard coded number or a variable representing a number. Your return should be assigned to the operation itself:

returnRaster = arcpy.sa.CostDistance("input", cost, numericValue, "costBackLink")
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.