CÓMO

Recuperar clases de entidad de origen y tablas utilizadas en una capa de entidades publicada

Last Published: August 1, 2025

Resumen

A veces queremos hacer coincidir las clases de entidad y las tablas de la geodatabase corporativa de origen utilizadas en la capa de entidades referenciada publicada. Esta capa puede tener varias subcapas y tablas utilizadas. La siguiente secuencia de comandos recuperará el nombre de la subcapa/tabla, su Id./índice y el nombre de la tabla/clase de entidad de origen en la conexión .sde.

Procedimiento

Ejecute la siguiente secuencia de comandos utilizando el entorno de Python de ArcGIS Pro:

from arcgis.gis import GIS
from arcgis.features import FeatureLayerCollection
import arcpy
import re

#Log in to ArcGIS Enterprise
portalurl = 'https://hostname.esri.com/portal'
username = 'admin'
password = 'admin123'
gis = GIS(portalurl,username,password)
arcpy.SignInToPortal(portalurl,username,password)

#Specify the referenced Feature Layer item ID
featurelayeritem = gis.content.get('c800e0fe96b844cfb7e6a684383da43f')

#Specify the workspace to be the REST URL of the feature layer
arcpy.env.workspace = f"{featurelayeritem.url}"
#Identify a list of all source feature classes and tables

featureclasses = arcpy.ListFeatureClasses()
sourcetables = arcpy.ListTables()

"""The above will create a list of strings with source feature
classes and another for source tables used in the layer.
The result will be ['L<id><featureclass>']. For examble, if
the feature class is called 'Addresses', and the associated
layer id is '3', it will be ['L3Addresses']."""

#The below is to retrieve layers and tables information from the web feature layer 
featurelayercollection = FeatureLayerCollection.fromitem(featurelayeritem)
layers = featurelayercollection.properties['layers']
tables = featurelayercollection.properties['tables']


#Looping through each layer
for layer in layers:
    #Retrieving the layer name and its id
    layername =  layer['name']
    layerid = layer['id']
    
    #Looping through the source feature classes
    for featureclass in featureclasses:
        #Retrieving only the feature class name that starts with "L<layerid>"
        if featureclass.startswith(f'L{layerid}'):
            """Making sure that, for example, the layer wth id 33
            doesn't get retrieved with the one with 3 id. So we
            make sure that the character after L<layerid> is a
            letter not a number as feature classes can only start
            with letters"""
            prefixlength = len(f'L{layerid}')
            if re.match(r'[A-Z,a-z]',featureclass[prefixlength:]):
                #Identifying the sourcename without 'l<layerid>'
                sourcename = featureclass[prefixlength:]

    #Printing  the result
    print(f'Layer name: {layername}')
    print(f'Layer ID: {layerid}')
    print(f'Source Feature Class: {sourcename}')
    print('-----------------------------------')
    
#Looping through each table
for table in tables:
    #Retrieving the table name and its id
    tablename =  table['name']
    tableid = table['id']

    #Looping through the source tables
    for sourcetable in sourcetables:
        #Retrieving only the table name that starts with "L<tableid>"
        if sourcetable.startswith(f'L{tableid}'):
            """Making sure that, for example, the table wth id 33
            doesn't get retrieved with the one with 3 id. So we
            make sure that the character after L<tableid> is a
            letter not a number as feature classes can only start
            with letters"""
            prefixlength = len(f'L{tableid}')
            if re.match(r'[A-Z,a-z]',sourcetable[prefixlength:]):
                #Identifying the sourcename without 'l<tableid>'
                sourcename = sourcetable[prefixlength:]

    #Printing  the result
    print(f'Table name: {tablename}')
    print(f'Table ID: {tableid}')
    print(f'Source Table: {sourcename}')
    print('-----------------------------------')

Id. de artículo: 000032337

Obtenga soporte con IA

Resuelva su problema rápidamente con el chatbot de inteligencia artificial de soporte de Esri.

Empieza a chatear ahora

Información relacionada

Descubrir más sobre este tema

Obtener ayuda de expertos en ArcGIS

Contactar con el soporte técnico

Empieza a chatear ahora

Ir a opciones de descarga