Still not running Please help!

626
6
Jump to solution
10-17-2013 10:27 AM
AliciaMein
New Contributor III
#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 

I am getting this error.  Processing seems to be stopping at the Buffer.  selectedLine is created with no data.
Error message:
untime error <class 'arcgisscripting.ExecuteError'>: ERROR 999999: Error executing function. An expected Field was not found or could not be retrieved properly. An expected Field was not found or could not be retrieved properly. [SmplRts2012Edited4CountyAnalysis] An expected Field was not found or could not be retrieved properly. An expected Field was not found or could not be retrieved properly. [SmplRts2012Edited4CountyAnalysis] An expected Field was not found or could not be retrieved properly. An expected Field was not found or could not be retrieved properly. [SmplRts2012Edited4CountyAnalysis] Failed to execute (Buffer).
>>>
I have also moved the following code out of the while and into the for with the same results.
  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
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RichardFairhurst
MVP Honored Contributor
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) + '"' ...

View solution in original post

0 Kudos
6 Replies
RichardFairhurst
MVP Honored Contributor
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) + '"' ...
0 Kudos
AliciaMein
New Contributor III
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
0 Kudos
RichardFairhurst
MVP Honored Contributor
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'
0 Kudos
AliciaMein
New Contributor III
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'


Im confused by the syntax.  Which are single and which are double quotes and the \ is to make something "raw"?  Sorry!  I really appreciate the help.  I have borrowed from many of your posts  and absolutely appreciate you help!
Alicia
0 Kudos
AliciaMein
New Contributor III
I got the syntax and moved forward only to find I can not access the table while the update cursor is active.  Do I have to start over and write new code or is there another solution?
Error:
Runtime error <class 'arcgisscripting.ExecuteError'>: ERROR 999999: Error executing function. Cannot acquire a lock. Cannot acquire a lock. [The table SmplRts2012Edited4CountyAnalysis is being written by another process.] Cannot acquire a lock. Cannot acquire a lock. [The table SmplRts2012Edited4CountyAnalysis is being written by another process.] Cannot acquire a lock. Cannot acquire a lock. [The table SmplRts2012Edited4CountyAnalysis is being written by another process.] The table was not found. [lineBuffer] Failed to execute (Buffer).
>>>
0 Kudos
AliciaMein
New Contributor III
I did it!!!
I got it running.
#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


I moved update cursor to the end.  Used my rtDict and just updated the BufferDist when is was found in the loop.  Then passed that into the update and got my values.!!!!!
Also used row.shape as an arg in the Buffer tool.

thanks
0 Kudos