I have seen several similar posts related to this technique but I am still having issues. The following script is intended to select all points from one shapefile that are within the boundaries of a second polygon shapefile, then edit the number of points selected into one of the polygon fields. I have not been able to get the where clause statement to function properly although from the error message it appears to be correct. Both shapefiles are within a file geodatabase and feature layers where created for both in order to use the selection functions.
arcpy.MakeFeatureLayer_management("treatment_maps",'maps')
arcpy.MakeFeatureLayer_management("points_2014",'points')
cursor=arcpy.UpdateCursor("treatment_maps")
for row in cursor:
map=row.getValue('map_name')
where='"map_name"' + '=' + '\'' + str(map) + '\''
arcpy.SelectLayerByAttribute_management("maps","NEW_SELECTION",where)
arcpy.SelectLayerByLocation_management("points","COMPLETELY_WITHIN","maps")
count=arcpy.GetCount_management("points")
row.setValue('DI_Count', count)
cursor.updateRow(row)
Error Message:
Executing: SelectLayerByAttribute maps NEW_SELECTION "map_name"='Airport'
Start Time: Wed Jan 15 13:00:56 2014
ERROR 000358: Invalid expression
Cannot acquire a lock.
Cannot acquire a lock.
Failed to execute (SelectLayerByAttribute).
Failed at Wed Jan 15 13:00:56 2014 (Elapsed Time: 0.00 seconds)
The treatment_maps features class contains polygons and counts (DI_Count) for points located within each polygon, which need to be updated. I'm hoping to get this script to work properly as I have around 100 polygons to update. Thank you for any help or advice!
Update: After experimenting with each line I've discovered that the select by attribute 'where' statement is functioning properly but the select by attribute function does not work while the cursor is set on the same object. I still need a solution though.