SelectByAttribute Problem

1251
11
08-10-2017 08:13 AM
JonathanUrshan1
New Contributor

Hi, I am trying to write a script that selects a parcel number and writes it to a PDF. I am having trouble with the SelectLayerByAttribute tool.  I am writing the script in PyCharm not in the Python Window of ArcMap. This is what I have gathered from various sources online.  I am pretty sure its an issue with my syntax. Any help would be much appreciated.  This is what I have so far.

import arcpy

mxd = arcpy.mapping.MapDocument(r"//bondserv2/USERS-COUNTY/ahuber/Desktop/Bond.mxd")

parcel = "Parcel_Point"

df = arcpy.mapping.ListDataFrames(mxd, parcel)

layer = arcpy.mapping.ListLayers(mxd, "", df)

arcpy.SelectLayerByAttribute_management(layer, "NEW_SELECTION", "[PIN] = '021101104001'")

I run the SelectLayerByAttribute tool in the python window just like the above code and it works. But trying to get it working in the PyCharm IDE is being a real pain. I'm new to python and arcpy, this is my first attempt at automating some one my everyday tasks.

0 Kudos
11 Replies
JonathanUrshan1
New Contributor

I will be trying this today. If you don't mind me asking what is the fld = 'SHAPE@' portion of the code? 

And Yes the code will be ran with the mxd open. 

0 Kudos
XanderBakker
Esri Esteemed Contributor

That is a token used in the field list and refers to the geometry field, without having to worry about what the name of that field is.

For more information about those tokens see: SearchCursor—Help | ArcGIS Desktop 

  • SHAPE@XY —A tuple of the feature's centroid x,y coordinates.
  • SHAPE@TRUECENTROID —A tuple of the feature's true centroid x,y coordinates.
  • SHAPE@X —A double of the feature's x-coordinate.
  • SHAPE@Y —A double of the feature's y-coordinate.
  • SHAPE@Z —A double of the feature's z-coordinate.
  • SHAPE@M —A double of the feature's m-value.
  • SHAPE@JSON — The esri JSON string representing the geometry.
  • SHAPE@WKB —The well-known binary (WKB) representation for OGC geometry. It provides a portable representation of a geometry value as a contiguous stream of bytes.
  • SHAPE@WKT —The well-known text (WKT) representation for OGC geometry. It provides a portable representation of a geometry value as a text string.
  • SHAPE@ —A geometry object for the feature.
  • SHAPE@AREA —A double of the feature's area.
  • SHAPE@LENGTH —A double of the feature's length.
  • OID@ —The value of the ObjectID field.