totalbaluba

Search cursors, when do they work as imput for tools?

Discussion created by totalbaluba on Mar 26, 2012
Latest reply on Mar 30, 2012 by totalbaluba
Hi, I???m a python n00b (4 days) and I???m really still trying to get a grasp of the basics. My motivation for using python is the possibility of making nested loops. In various help and documentations I???ve seen that it is common to iterate through search cursors, opposed to making a ??? for i in range(x,y):??? ???loop and then selecting features based on eg. FID. What confuses me is that the search cursors work in some tools but not in others.

import arcpy
import sys
import os

arcpy.env.overwriteOutput = True

# points 
a= "M:\\My Documents\\Ingeborg2\\TEMP\\0elv.shp"
# costdistance raster
cost="M:\\My Documents\\Ingeborg2\\TEMP\\0cost"
# backlink raster
back="M:\\My Documents\\Ingeborg2\\TEMP\\0bc"

out_workspace = "M:/My Documents/Ingeborg2/PYTHONTEST/"

# making buffers based on search cursor works
locations= arcpy.SearchCursor(a)
for i in locations:
    fid=i.getValue("FID")
    fids= "%s%s" % (fid,"Buff.shp")
    output=os.path.join(out_workspace,fids)
    arcpy.Buffer_analysis(i.shape,output,2500)


Making buffers for points based on search cursor works. However, doing the same with a different tool fails

arcpy.CheckOutExtension("Spatial")
locations= arcpy.SearchCursor(a)
for j in locations:
    cdpa= arcpy.sa.CostPath(j.shape,cost,back,"EACH_CELL","UTLOPID")


By selecing and saving the current row shape the tool works. (I have to change the "destination field" from "UTLOPID" to "Id" since the select "k.shape" looses all the attribute data.)
locations= arcpy.SearchCursor(a)
for k in locations:
    fid=k.getValue("FID")
    fids= "%s%s" % (fid,"Costpath.shp")
    output=os.path.join(out_workspace,fids)
    arcpy.Select_analysis(k.shape,output)
    cdpa= arcpy.sa.CostPath(output,cost,back,"EACH_CELL","Id")


So I???m wondering if I???m completely misunderstanding how to use search cursors in geoprosessing tools, or if they only work as input for certain tools?

Any help would be much appreciated!

Outcomes