Hi everybody
I need some help on the automation processin which I try to create several cost distance raster. In a polygon feature class I have several records and I should create for each record an individual cost distance raster. So far script looks like this:
rCost = "U:\Daten\WWFgis\CH\Projekte\Raumplanung\Landschaften\Test.gdb\F_Offen_Final"
fcStart = r"U:\Daten\WWFgis\CH\Projekte\Raumplanung\Landschaften\Test.gdb\Startorte"
cursor = arcpy.SearchCursor(fcStart)
count = 1
for row in cursor:
strcount = str(count)
CD = CostDistance(fcStart,rCost, "100000")
CD.save("U:\Daten\WWFgis\CH\Projekte\Raumplanung\Landschaften\Cost_Distance.gdb\C"+strcount)
count +=1
It perfectly runs as many times I have records in the feature class, but the result is always the same for every cost distance raster as all records of the feature were selected for the creation of the cost distance raster instead of only one and the next one in the next loop.
Any suggestions?
Thomas
Solved! Go to Solution.
At the moment your loop is not doing anything but using fcStart & rCost repeatedly.
If you want to create cost distances for each geometry in fcStart, you must read the geometry object.
btw, please use the advanced editor and python syntax for posting code.
And switch to using the da.cursor methods.
So something like this :
with arcpy.da.SearchCursor(fcStart, ["SHAPE@"]) as Cur: for row in Cur: polyGeom = row[0] CD = CostDistance(polyGeom, rCost, "100000")
Your Cost Distance calculation is on the whole Feature Class in every loop and not just the cursor feature:
CD = CostDistance(fcStart,rCost, "100000")
Isolate the cursor feature by creating a temporary layer for each cursor row and run the Cost Distance on that layer.
At the moment your loop is not doing anything but using fcStart & rCost repeatedly.
If you want to create cost distances for each geometry in fcStart, you must read the geometry object.
btw, please use the advanced editor and python syntax for posting code.
And switch to using the da.cursor methods.
So something like this :
with arcpy.da.SearchCursor(fcStart, ["SHAPE@"]) as Cur: for row in Cur: polyGeom = row[0] CD = CostDistance(polyGeom, rCost, "100000")
Thank you very much. Now it works as i hoped for.
Thomas,
could you mark this question as answered...