Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

Error Message Select By Attribute

$
0
0
I'm getting an error message in my Select by Attribute statement saying the layer file doesn't exist, however, the output of the Make Feature Layer completed successfully. Thoughts?

Code:

fc = arcpy.ListFeatureClasses()
for f in fc:

    #Run Viewshed
    outViewshed = ViewshedRasters+"/"+"view_"+f[6:].split(".")[0]
    arcpy.Viewshed_3d(Elevation,f, outViewshed,1)
    print arcpy.GetMessages()

    #convert viewshed to polygon
    OutPoly = ViewshedPolys+"/"+os.path.basename(outViewshed).split(".")[0]+"_poly.shp"
    arcpy.RasterToPolygon_conversion(outViewshed,OutPoly)
    arcpy.AddField_management(OutPoly,"COUNT","SHORT")
    OutPolyLyr = OutPoly.split(".")[0]+"_Lyr"
    arcpy.MakeFeatureLayer_management(OutPoly,OutPolyLyr)
    print arcpy.GetMessages()
    WhereClause = '"COUNT" = \'1\''
    print WhereClause
    arcpy.SelectLayerByAttribute_management(OutPolyLyr,"NEW_SELECTION",WhereClause)
    print arcpy.GetMessages()
    view = arcpy.GetCount_management(OutPolyLyr)
    print "There are",view,"selected"

Output from Make Feature Layer
Code:

Executing: MakeFeatureLayer C:/ArcGIS/SurfCityData/Scratch/ViewshedPolys/view_0_poly.shp C:/ArcGIS/SurfCityData/Scratch/ViewshedPolys/view_0_poly_Lyr # # "FID FID VISIBLE NONE;Shape Shape VISIBLE NONE;ID ID VISIBLE NONE;GRIDCODE GRIDCODE VISIBLE NONE;COUNT COUNT VISIBLE NONE"
Start Time: Sun Sep 22 09:41:28 2013
Succeeded at Sun Sep 22 09:41:28 2013 (Elapsed Time: 0.00 seconds)

Error Message
Code:

Traceback (most recent call last):
  File "C:\Python27\ArcGIS10.1\Lib\site-packages\Pythonwin\pywin\framework\scriptutils.py", line 326, in RunScript
    exec codeObject in __main__.__dict__
  File "C:\ArcGIS\SurfCityData\Code\SC_ViewShed.py", line 127, in <module>
    arcpy.SelectLayerByAttribute_management(OutPolyLyr,"NEW_SELECTION",WhereClause)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\management.py", line 6435, in SelectLayerByAttribute
    raise e
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Layer Name or Table View: Dataset C:/ArcGIS/SurfCityData/Scratch/ViewshedPolys/view_0_poly_Lyr does not exist or is not supported
Failed to execute (SelectLayerByAttribute).


Viewing all articles
Browse latest Browse all 2485

Trending Articles