laptop and a wrench

Erro

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.

Última Publicação: November 13, 2020 ArcGIS Pro
Número de ID do Erro BUG-000135234
EnviadoNovember 6, 2020
Última ModificaçãoOctober 7, 2024
Aplica-se àArcGIS Pro
Versão encontrada2.6.1
Sistema OperacionalWindows OS
Versão do Sistema Operacional10.0 64 Bit
StatusNon-Reproducible

Informações Adicionais

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.

Solução Provisória

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

Etapas para Reproduzir

ID do Erro: BUG-000135234

Software:

  • ArcGIS Pro

Seja notificado quando o status de um erro mudar

Baixe o Aplicativo de Suporte da Esri

Descubra mais sobre este tema

Obtenha ajuda de especialistas do ArcGIS

Entre em contato com Suporte Técnico

Baixe o Aplicativo de Suporte da Esri

Ir para as opções de download