laptop and a wrench

漏洞

When using arcpy.SelectLayerByAttribute() in ArcGIS Pro 2.6.X, all records are returned instead of just the selected records inside both the IDE and the ArcGIS Pro user interface.

上次发布: November 13, 2020 ArcGIS Pro
漏洞 ID 编号 BUG-000135234
已提交November 6, 2020
上次修改时间October 7, 2024
适用范围ArcGIS Pro
找到的版本2.6.1
操作系统Windows OS
操作系统版本10.0 64 Bit
状态Non-Reproducible

附加信息

The correct count is returned by the arcpy.SelectLayerByAttribute() function. This is verified by printing the derived output parameter in the second position of the returned object, which is the count of selected features, refer to https://pro.arcgis.com/en/pro-app/tool-reference/data-management/select-layer-by-attribute.htm or ensuring get count is called on the correct layer object: a = arcpy.management.SelectLayerByAttribute(, "NEW_SELECTION", "", None) print(arcpy.management.GetCount(a.getOutput(0).name)) The issue is related to the ambiguity of layer and feature class names.

解决办法

Options:

  1. Use arcpy.management.MakeFeatureLayer first before arcpy.management.SelectLayerByAttribute.
  2. Connect to the feature through the path to the project.
  3. Use the python window or Notebook within the ArcGIS Pro 2.5.1 User Interface

Example for option 1:

import arcpy

arcpy.management.MakeFeatureLayer(r"C:\Users\Desktop\Shapefile\Arcpy\esri\Testing.gdb\Polygons","Testl")

arcpy.management.SelectLayerByAttribute("Testl", "SUBSET_SELECTION", "LANDAREACODE = '021'", None)

print(arcpy.management.GetCount("Testl"))

Example for option 2:

import arcpy

import os

aprx = arcpy.mp.ArcGISProject(r"C:\ArcPy\ArcPy.aprx")

maps = aprx.listMaps()[0]

Polygon = maps.listLayers()[0]

print(Polygon)

arcpy.management.SelectLayerByAttribute(Polygon, "SUBSET_SELECTION", "LANDAREACODE = '021'", None)

print(arcpy.management.GetCount(Polygon))

Example for option 3:

import arcpy

arcpy.env.workspace = r"C:\Users\Desktop\Shapefile\Arcpy\esri\Testing.gdb"

a=arcpy.management.SelectLayerByAttribute("Polygons", "SUBSET_SELECTION", "LANDAREACODE = '021'", None)

print(arcpy.management.GetCount(a))

重现步骤

漏洞 ID: BUG-000135234

软件:

  • ArcGIS Pro

当漏洞状态发生变化时获得通知

下载 Esri 支持应用程序

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

获取来自 ArcGIS 专家的帮助

联系技术支持部门

下载 Esri 支持应用程序

转至下载选项