操作方法

操作方法:在 ArcGIS Pro 中使用 Python 选择数值字段中包含奇数或偶数值的 ArcGIS 记录

Last Published: September 13, 2023

摘要

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.

过程

  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')

文章 ID: 000026383

接收通知并查找新问题或常见问题的解决方案

从我们全新的 AI 聊天机器人中获得简明答案和视频解决方案。

下载 Esri 支持应用程序

相关信息

发现关于本主题的更多内容

获取来自 ArcGIS 专家的帮助

联系技术支持部门

下载 Esri 支持应用程序

转至下载选项