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 Support アプリのダウンロード

このトピックについてさらに調べる

ArcGIS エキスパートのサポートを受ける

テクニカル サポートへのお問い合わせ

Esri Support アプリのダウンロード

ダウンロード オプションに移動