HOW TO

Auswählen von ArcGIS-Datensätzen die ungerade oder gerade Werte in einem numerischen Feld enthalten mit Python in ArcGIS Pro

Last Published: September 13, 2023

Zusammenfassung

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.

The following image shows the example of records for selected odd numbers from a numeric field.

The example of records for selected odd numbers from a numeric field.

Vorgehensweise

  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')
  1. Press Enter.
  2. In the attribute field, click the Switch Selection The Switch Selection icon to select the opposite results of the previous 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')

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

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

Artikel-ID:000026383

Benachrichtigungen erhalten und Lösungen für neue oder häufige Probleme finden

Unser neuer KI-Chatbot stellt zusammengefasste Antworten und Videolösungen für Sie bereit.

Esri Support App herunterladen

Zugehörige Informationen

Weitere Informationen zu diesem Thema erkunden

Unterstützung durch ArcGIS-Experten anfordern

An den technischen Support wenden

Esri Support App herunterladen

Zu Download-Optionen wechseln