3

In a for loop, the code tried to select one dam feature out from a set of dams and create a new shapefile so to perform cost path analysis with it. However, it seems field value of the new shapefile cannot be extracted or used to perform a cost path analysis. The shapefile was selected and created correctly and I was able to see fields when adding data to ArcMap.

Here's the code:

rows = arcpy.SearchCursor(inPtFeatures)   
for row in rows:     
  gId = row.getValue(keyAttr)

print ("Processing "+str(gId)+"...") 
elev = row.getValue(keyAttr2)

  if os.path.exists(procDir+"/"+str(gId)):
    shutil.rmtree(procDir+"/"+str(gId))

os.mkdir(procDir+"/"+str(gId))
currentDir = procDir+"/"+str(gId)
currentPtFeat = currentDir+"/pt_"+str(gId)+".shp"

whereSQL = '"GRAND_ID" = '+str(gId)
arcpy.Select_analysis(inPtFeatures,currentPtFeat,whereSQL)
print ("test2")

method = "EACH_CELL"
destField = "FID"
outCostPath = arcpy.sa.CostPath(currentPtFeat,inDem,inFdir,method,destField)
outCostPath.save(currentRastPath)

and error message:

\Functions.py", line 688, 
in CostPath     destination_field)   File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\sa\Utils.py", line 47, 
in swapper     result = wrapper(*args, **kwargs)   File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\sa\Functions.py", line 681, 
in wrapper     destination_field)   File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\geoprocessing\_base.py", line 498, 
in <lambda>     return lambda *args: val(*gp_fixargs(args, True)) 
ExecuteError: ERROR 000860: Input raster or feature destination data: is not the type of Composite Geodataset, or does not exist. ERROR 001000: Destination field: Field FID does not exist 
  • The spacing in the code was all over the place, I've tried to correct it, but please check it is as expected. – nmtoken Jul 11 '17 at 19:39
  • sorry about spacing in the text. sth wrong with it when copying the code. I think I found the reason of the error. it looks the point location (input feature) is at boarder and that cause some issue – Michelle Jul 12 '17 at 16:21
  • @Michelle Please consider adding a detailed answer to your question (based on your comment) so we can consider this question resolved. – Aaron Sep 19 '18 at 2:51
2

The problem may be that you are referencing a shapefile and not a feature class. Or that the path to the shapefile is not being found.

One thing that I usually do when running a new Python script is printouts so that I can see what is being passed along in the code. I see that you are doing one print maybe add some more in at different places.

Try changing this - currentPtFeat = currentDir+"/pt_"+str(gId)+".shp"

To this - currentPtFeat = currentDir+"/pt_"+str(gId)

Or giving the full path.

As it notes in this help topic:

https://geonet.esri.com/thread/34477

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.