0% found this document useful (0 votes)
921 views

How To Select Even or Odd (ArcGIS Calc)

This document provides instructions for selecting ArcGIS records with odd or even values in a numeric field using Python. It describes using the SelectLayerByAttribute method to select records where the modulo of the field value and 2 equals 0 to select even values or equals 1 to select odd values. It also notes that field values can then be changed from odd to even or vice versa using field calculation.

Uploaded by

dejenab
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
921 views

How To Select Even or Odd (ArcGIS Calc)

This document provides instructions for selecting ArcGIS records with odd or even values in a numeric field using Python. It describes using the SelectLayerByAttribute method to select records where the modulo of the field value and 2 equals 0 to select even values or equals 1 to select odd values. It also notes that field values can then be changed from odd to even or vice versa using field calculation.

Uploaded by

dejenab
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

How To: Select ArcGIS records containing odd or even

values in a numeric field using Python in ArcGIS Pro


Summary
In ArcGIS Pro, it is possible to select specific records containing odd or even numbers from a
numeric field in the attribute table using Python.

Procedure
1. In ArcGIS Pro, click the Analysis tab on the top ribbon. Click the drop-down menu next
to Python, and click Python window.
2. In the Python window, insert the following command to select records with EVEN
values in a numeric field:

arcpy.management.SelectLayerByAttribute('<Feature layer>', 'SUBSET_SELECTION',


'MOD ("<Field name>", 2) = 0')

[SAMPLE: I select even values in an ODD_No field, to make them even later --
arcpy.management.SelectLayerByAttribute('House_Number', 'SUBSET_SELECTION', 'MOD ("ODD_HN",
2) = 0')]

3. Press Enter.
4. In the attribute field, click the Switch Selection option to select records with ODD
values in the numeric field.

Alternatively, in the Python window, insert the following command to select records with odd
values in the numeric field:

arcpy.management.SelectLayerByAttribute('<Feature layer>', 'SUBSET_SELECTION',


'MOD ("<Field name>", 2) = 1')

[SAMPLE: I select odd values in an EVEN_No field, to make them odd later --
arcpy.management.SelectLayerByAttribute('House_Number', 'SUBSET_SELECTION', 'MOD ("EVEN_HNo",
2) = 1')]

To use both Python commands consecutively, insert the following command to remove the
previous selection before selecting new records or click the Clear option in the Selection
group:

arcpy.management.SelectLayerByAttribute('<Feature layer>', 'CLEAR_SELECTION')

Last Published: 9/16/2021

Additions: to change odd/even field values to even/odd, use field calc on the right field and enter <field
Name> + 1. This applies to both sides following the selection using the above python script!

You might also like