#Set environment and declare varibles # arcpy.env.overwriteOutput = True arcpy.env.workspace = "C:/CustomTools/DeerSurveyRoutes/rtsScratch.gdb" coPath = "C:/CustomTools/DeerSurveyRoutes/RtsAnlysVectors.gdb/County" rasPath = "C:/CustomTools/DeerSurveyRoutes/RtsAnlysRasters.gdb/WVUReclass" opnFrstdRas = arcpy.Raster("C:/CustomTools/DeerSurveyRoutes/RtsAnlysRasters.gdb/WVUReclass") rasCellSz = (opnFrstdRas.meanCellHeight + opnFrstdRas.meanCellWidth) / 2 rtsPath = "C:/CustomTools/DeerSurveyRoutes/RtsAnlysVectors.gdb/SmplRts2012Edited4CountyAnalysis" #Tabulate Forested/Open for county # arcpy.CheckOutExtension("Spatial") arcpy.env.snapRaster = rasPath znFld = "CoZoneName" clsFld = "Value" outTble = "CoTbleOpenFrst" arcpy.sa.TabulateArea(coPath,znFld,opnFrstdRas,clsFld,outTble,rasCellSz) #Create Cursor to iterate through rts and dictionary to hold county forested/open value # updtCur = arcpy.UpdateCursor(rtsPath) row = updtCur.next() coOFDict = dict([((r.COZONENAME, f.name),r.getValue(f.name)) for f in arcpy.ListFields(outTble) for r in arcpy.SearchCursor(outTble)]) #Loop to find buffer distance of each route that will contain the same forested percent as the county return BuffDist # for row in updtCur: buffDist = 402 #This will be meters as all my inputs are projected to UTM frstPrcnt = 0 frstd = coOFDict[(row.getValue(znFld),'VALUE_2')] opn = coOFDict[(row.getValue(znFld),'VALUE_1')] nHbt = coOFDict[(row.getValue(znFld),'VALUE_0')] lpChkVal = frstd / (frstd + opn + nHbt) minLpChkVal = lpChkVal - (lpChkVal * .05) maxLpChkVal = lpChkVal + (lpChkVal * .05) newBuffVal = buffDist x = 0 while frstPrcnt < minLpChkVal or frstPrcnt > maxLpChkVal: thisFID = row.getValue('RouteID') arcpy.MakeFeatureLayer_management(rtsPath, "selectedLine", ("RouteID" = thisFID) arcpy.Buffer_analysis("selectedLine","lineBuffer",buffDist,"FULL","FLAT","ALL","RouteID") arcpy.sa.TabulateArea("lineBuffer","RouteID",rasPath,clsFld,"BufferOFTble",rasCellSz) rtOFDict = dict([((rRt.ROUTEID, fRt.name),rRt.getValue(fRt.name)) for fRt in arcpy.ListFields("BufferOFTble") for rRt in arcpy.SearchCursor("BufferOFTable")]) rtFrstd = rtOFDict[(row.getValue('RouteID'),'VALUE_2')] rtOpn = rtOFDict[(row.getValue('RouteID'),'VALUE_1')] rtNHbt = rtOFDict[(row.getValue('RouteID'),'VALUE_0')] frstPrcnt = rtFrstd / (rtFrstd + rtOpn + rtNHbt) newBuffVal = buffDist x += 1 buffDist = buffDist + (x * 5 * rasCellSz) row.setValue('BuffDist',newBuffVal) updtCur.updateRow(row) del row, updtCur, f, r, fRt, rRt
thisFID = row.getValue('RouteID') arcpy.MakeFeatureLayer_management(rtsPath, "selectedLine", ("RouteID" = thisFID)
Solved! Go to Solution.
thisFID = row.getValue('RouteID')
arcpy.MakeFeatureLayer_management(rtsPath, "selectedLine", ("RouteID" = thisFID)
and changed the syntax of the where clause multiple times
'"RouteID" = thisFID'
"[RouteID] = thisFID"
I am working in ArcINFO 10.0 with file geodatabase in the python window.
Frustrated!
Alicia
thisFID = row.getValue('RouteID')
arcpy.MakeFeatureLayer_management(rtsPath, "selectedLine", ("RouteID" = thisFID)
and changed the syntax of the where clause multiple times
'"RouteID" = thisFID'
"[RouteID] = thisFID"
I am working in ArcINFO 10.0 with file geodatabase in the python window.
Frustrated!
Alicia
The where clause has to be contained in a quoted string within the MakeFeatureLayer method. But the ThisFID has to be translated from a number into a string before it can be appended to the where clause string. So it needs to be written as:
arcpy.MakeFeatureLayer_management(rtsPath, "selectedLine", '"RouteID" = ' + str(ThisFID) + '"' ...
Making progress but still an error:
Runtime error <class 'arcgisscripting.ExecuteError'>: ERROR 999999: Error executing function. An invalid SQL statement was used. An invalid SQL statement was used. [SmplRts2012Edited4CountyAnalysis] An invalid SQL statement was used. [SELECT * FROM SmplRts2012Edited4CountyAnalysis WHERE "RouteID" =26.2.00] An invalid SQL statement was used. An invalid SQL statement was used. [SmplRts2012Edited4CountyAnalysis] An invalid SQL statement was used. [SELECT * FROM SmplRts2012Edited4CountyAnalysis WHERE "RouteID" =26.2.00] An invalid SQL statement was used. An invalid SQL statement was used. [SmplRts2012Edited4CountyAnalysis] An invalid SQL statement was used. [SELECT OBJECTID FROM SmplRts2012Edited4CountyAnalysis WHERE "RouteID" =26.2.00] Failed to execute (Buffer).
I would like to add that the selectedLine seems to be created, but empty. Open table and it has all fields but no data.
I tried to find this lyr in catalog (both inside of ArcInfo in catalog and in ArcCatalog) and cant find it. I thought I might need to delete it and get started clean. The properties of the lyr says:
File Geodatabase Feature Class
Location: C:\CustomTools\DeerSurveyRoutes\RtsAnlysVectors.gdb
Feature Class: SmplRts2012Edited4CountyAnalysis
Feature Type: Simple
Geometry Type: Line
I would have assumed it would be in the "C:/CustomTools/DeerSurveyRoutes/rtsScratch.gdb" as set up in my env.workspace earlier. In any case. I can not find it, even after I shut everything down and bring it back up.
Thanks!
Alicia
I assumed RouteID was a number. However, if the value "26.2.00" is a correct RouteID representation then it must be a string, not a number. If that is the case the SQL where clause would be:
arcpy.MakeFeatureLayer_management(rtsPath, "selectedLine", '"RouteID" = \'' + ThisFID + '\'"' ...
Single quotes have to enclose the ThisFID value within the where clause string so that when it finally is translated to SQL it will appear as:
"RouteID" = '26.2.00'
#Set environment and declare varibles # arcpy.env.overwriteOutput = True arcpy.env.workspace = "C:/CustomTools/DeerSurveyRoutes/rtsScratch.gdb" coPath = "C:/CustomTools/DeerSurveyRoutes/RtsAnlysVectors.gdb/County" rasPath = "C:/CustomTools/DeerSurveyRoutes/RtsAnlysRasters.gdb/WVUReclass" opnFrstdRas = arcpy.Raster("C:/CustomTools/DeerSurveyRoutes/RtsAnlysRasters.gdb/WVUReclass") rasCellSz = (opnFrstdRas.meanCellHeight + opnFrstdRas.meanCellWidth) / 2 rtsPath = "C:/CustomTools/DeerSurveyRoutes/RtsAnlysVectors.gdb/SmplRts2012Edited4CountyAnalysis" #Set environemt and create variables for County area tabulation # arcpy.CheckOutExtension("Spatial") arcpy.env.snapRaster = rasPath znFld = "CoZoneName" clsFld = "Value" outTble = "CoTbleOpenFrst" # Tabulate area of each class in raster and set up dictionary to hold values in table. # arcpy.sa.TabulateArea(coPath,znFld,opnFrstdRas,clsFld,outTble,rasCellSz) coOFDict = dict([((r.COZONENAME, f.name),r.getValue(f.name)) for f in arcpy.ListFields(outTble) for r in arcpy.SearchCursor(outTble)]) del r, f #Create dictionary of Rts Containing the CoZoneName, RouteID and BufferDist rtDict = dict([((r.RouteID, f.name),r.getValue(f.name)) for f in arcpy.ListFields(rtsPath) for r in arcpy.SearchCursor(rtsPath)]) del r, f #Loop to find buffer distance of each route that will contain the same forested percent as the county return BuffDist # buffCur = arcpy.SearchCursor(rtsPath) #row = buffCur.next() for row in buffCur: buffDist = 402 frstPrcnt = 0 frstd = coOFDict[(row.getValue(znFld),'VALUE_2')] opn = coOFDict[(row.getValue(znFld),'VALUE_1')] nHbt = coOFDict[(row.getValue(znFld),'VALUE_0')] lpChkVal = frstd / (frstd + opn + nHbt) minLpChkVal = lpChkVal - (lpChkVal * .05) maxLpChkVal = lpChkVal + (lpChkVal * .05) x = 0 #Set up feature layer for Buffer analysis #thisRtID = row.getValue('RouteID') #arcpy.MakeFeatureLayer_management(rtsPath, "selectedLine", '"RouteID" = \'' + thisRtID + '\'') while frstPrcnt < minLpChkVal or frstPrcnt > maxLpChkVal: arcpy.Buffer_analysis(row.shape, "lineBuffer", buffDist,"FULL","FLAT","ALL") arcpy.sa.TabulateArea("lineBuffer","OBJECTID",rasPath,clsFld,"BufferOFTble",rasCellSz) rtOFDict = dict([((r.OBJECTID, f.name),r.getValue(f.name)) for f in arcpy.ListFields("BufferOFTble") for r in arcpy.SearchCursor("BufferOFTble")]) del r, f rtFrstd = rtOFDict[(1,'VALUE_2')] rtOpn = rtOFDict[(1,'VALUE_1')] rtNHbt = rtOFDict[(1,'VALUE_0')] frstPrcnt = rtFrstd / (rtFrstd + rtOpn + rtNHbt) newBuffVal = buffDist x += 1 buffDist = buffDist + (x * 5 * rasCellSz) rtDict[(row.getValue('RouteID'), 'BufferDist')] = newBuffVal #Create Cursor to iterate through rts and dictionary to update buffer distance. # updtCur = arcpy.UpdateCursor(rtsPath) for rows in updtCur: dist = rtDict[(rows.getValue('RouteID'), 'BufferDist')] rows.setValue('BufferDist', dist) updtCur.updateRow(rows) del rows, updtCur, row, buffCur