0

I am looking to create a sql expression regarding point feature class and selection based on 'Name' field to pass to arcpy.sa.CostDistance() param[0].

similat to:

savepath = env.workspace = r'G:\Xcel\Route Tool\Potter\Scratch.gdb'
weighted_Raster = r'G:\Xcel\Route Tool\Potter\Scratch.gdb\weighted_Raster'
fc = r'G:\Xcel\Route Tool\Potter\Data.gdb\Subs_w_dist'
Field = 'Name'
destValue = 'Coulter'
where_clause = createSQL(Field, destValue)


#Calculate the least accumulative cost distance for each cell to the nearest source over a cost surface.
outCostDist = arcpy.sa.CostDistance(where_clause, weighted_Raster,"", 'Output_Backlink')
outCostDist.save('distance_Raster')

How do I use make feature layer using variables as input. Similar to:

savepath = env.workspace = r'G:\Xcel\Route Tool\Potter\Scratch.gdb'
weighted_Raster = r'G:\Xcel\Route Tool\Potter\Scratch.gdb\weighted_Raster'
fc = r'G:\Xcel\Route Tool\Potter\Data.gdb\Subs_w_dist'
Field = 'Name'
destValue = 'Coulter'

destination = arcpy.MakeFeatureLayer_management(fc,'dest_Selection', [Field] = destValue)

#Calculate the least accumulative cost distance for each cell to the nearest source over a cost surface.
outCostDist = arcpy.sa.CostDistance(destination,weighted_Raster,"",'Output_Backlink')
outCostDist.save('distance_Raster')
distance_Raster = "distance_Raster"
1

the input of cost distance should be a raster or a feature layer. You should create a feature layer using your feature class and your where clause, and use this layer as input in Cost distance. See the help on makeFeatureLayer here

in you example, the SQL statement should look like this (for shapefiles and file gdb) :

sql = '"' + fieldname + """" = '""" + value + "'"

or (personal gdb)

sql = "[" + fieldname + "] = '" + value + "'"

where fieldname and value are strings.

  • Thanks for the reply. But how do I make sql statement using variables as input? (See additional code above) – wtgeographer Mar 27 '14 at 14:53

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.