Select to view content in your preferred language

Expected Field not found or retrieved - Python SelectLayerByLocation

8405
3
11-13-2011 08:17 PM
KendraRodgers
Emerging Contributor
Hello,
I'm trying to complete a select by layer on a layer I just made and keep getting an error code in PythonWin that "An expected Field was not found or could not be retrieved properly." It repeats this seveal times and references the dataset at as well in some of the lines and finishes with an error for SelectLayerbyLocation.  This is for a class I'm taking... I just can't seem to figure out what is causing this error code.

I'd appreciate any input or direction to reading materials to figure out what I'm doing wrong. Below is the errro code and I've attached my .py.
Thanks!!

>>> made feature
"NAME" ="North Central"
Traceback (most recent call last):
  File "C:\Python26\ArcGIS10.0\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 312, in RunScript
    exec codeObject in __main__.__dict__
  File "C:\WCGIS\GEOG485\Lesson3\simplifiedstepback.py", line 29, in <module>
    arcpy.SelectLayerByLocation_management("GraffitiIncidentsLayer", "CONTAINED_BY", "CurrentPatrolZoneLayer")
  File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\management.py", line 4381, in SelectLayerByLocation
    raise e
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. [PatrolZones]
An expected Field was not found or could not be retrieved properly.
An expected Field was not found or could not be retrieved properly. [PatrolZones]
Failed to execute (SelectLayerByLocation).
Tags (2)
0 Kudos
3 Replies
JakeSkinner
Esri Esteemed Contributor
Hi SpringsGirl,

I believe your queryString is incorrect.  You will want the query to be:

"NAME" = 'North Central' instead of "NAME" = "North Central"

Try changing your queryString to:

queryString = '"' + nameField + '" =' + "'" + currentPatrolZone + "'"
0 Kudos
KendraRodgers
Emerging Contributor
Thanks Jake!
That is exactly what I had wrong.  Although I did that intentionally... I fear I do no yet completely understand using quotes. In my mind it went something like this. I was using a field name equal to a string so it would look like this intially

"Field_Name" = 'str'

and I didn't think I could have " " = ' '   so I made sure to get the other side into " "

"Field_Name" = "Name"

Does this have anything to do with the fact that my code was referencing variables for strings and not strings themselves??

Thanks again for your speedy response!
0 Kudos
JakeSkinner
Esri Esteemed Contributor
Hi Kendra,

I too get confused with syntax for queries, especially for fields.  You can refer to the following link for help with syntax:

http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00s500000033000000.htm
0 Kudos