Select to view content in your preferred language

Script for selecting values that are multiples

474
2
01-19-2012 05:09 AM
TomKoritansky
New Contributor
Hello everyone,

I am wondering if there is a script available that will select attribute values that are multiples of 10.  I have a large dataset of USNG 100 meter polygons that I would like to simplify.  I have attribute columns for easting and northing values that are short integers.  My goal is to select every tenth easting row and northing column beginning at a certain value.  For example, I'm beginning with an easting value of 590 and I'd like to then select the 600 easting column, 610, 620 and so on.  Any help would be appreciated.

Thanks,
Tom
Tags (2)
0 Kudos
2 Replies
JakeSkinner
Esri Esteemed Contributor
You could do this using the SelectLayerByAttributes function.  Here is an example:

import arcpy
from arcpy import env
env.workspace = r"C:\temp\python\test.gdb"

fc = "USNG_100Meter"
arcpy.MakeFeatureLayer_management(fc, "USNG_lyr")

x = 590
y = 1000

while x <= 740: # alter to the max value of the Easting
    arcpy.SelectLayerByAttribute_management("USNG_lyr", "NEW_SELECTION", '"Easting" = ' + str(x) + "AND" + '"Northing" = ' + str(y))
    # do something to selection
    x += 10
    y += 10
0 Kudos
ChrisSnyder
Regular Contributor III
Related, you can use the built in "divmod" function in Python to evalute/test for multiples.

For example:

>>> divmod(120, 10)
(12, 0)
and
>>> divmod(121, 10)
(12, 1)

for i in range (0,1001):
   if divmod(i, 10)[1] == 0: #if the remainder is 0 when dividing by 10...
      print "Processing #" + str(i)
0 Kudos