2

I'm using the select by attributes to find unique values that I am copy pasting from a spreedsheet.

EX "jobnumber" = 1111116 OR "jobnumber" = 2222245 OR "jobnumber" = 5555655 .. etc

The problem is I have thousands of values and hit the character limit. I can do select by attribute again and just add to the selection, but this would require doing many, many times and would be pretty tedious.

I want to know if there is a better way of getting large numbers of unique values selected all at the same time, maybe using ArcMap's Python console, or making the spreedsheet into a table in ArcMap and relating it to the target layer.

Vince
20.5k16 gold badges49 silver badges65 bronze badges
asked Aug 4, 2018 at 18:51
2

1 Answer 1

2

This should work:

  1. Add the excel file to ArcMap
  2. Copy excel table to a file geodatabase
  3. Join the copy to your layer
  4. Select by attribute rows that are not Null in the jobnumber column

But if you want to use arcpy add the excel and layer to ArcMap and paste this in the Python window after adjusting commented lines:

import arcpy
excel = 'Data$' #Change
excel_fieldname = 'jobnumber' #Change
layer = 'Polygons123' #Change
layer_fieldname = 'jobnumber' #Change
jobnumbers = [str(i[0]) for i in arcpy.da.SearchCursor(excel, excel_fieldname)]
sql = """{0} IN({1})""".format(arcpy.AddFieldDelimiters(layer, layer_fieldname),','.join(jobnumbers))
arcpy.SelectLayerByAttribute_management(layer,where_clause=sql)

Im using the IN operator:

The IN operator is a shorthand for multiple OR conditions.

answered Aug 4, 2018 at 19:00

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.