Select to view content in your preferred language

Error Message Select By Attribute

365
1
09-22-2013 05:56 AM
RachelAlbritton
Occasional Contributor III
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?

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
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
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).
Tags (2)
0 Kudos
1 Reply
TimDonoyou
Occasional Contributor
Hi there,

As far as I know the MakeFeatureLayer tool just creates a temporary layer for use within the current tool or mxd and does not save it to disc (copy features will do this if needed) and therefore your "OutPolyLyr" does not actually exist in your "C:/ArcGIS/SurfCityData/Scratch/ViewshedPolys" folder and the Select by attribute tool cannot find it.

If you remove or comment out the OutPolyLyr = OutPoly.split(".")[0]+"_Lyr" line from your script then I think it should work.

Hope this helps

thnaks

Tim
0 Kudos