HOW TO

Abrufen von in einem veröffentlichten Feature-Layer verwendeten Quell-Feature-Classes und -Tabellen

Last Published: August 1, 2025

Zusammenfassung

In manchen Fällen ist es erforderlich, die verwendeten Feature-Classes der Quell-Enterprise-Geodatabase und die Enterprise-Geodatabase-Tabellen im veröffentlichten referenzierten Feature-Layer abzugleichen. Dieser Layer kann über mehrere Sublayer und Tabellen verfügen. Das folgende Skript ruft den Namen des Sublayers/der Tabelle, die ID/den Index und den Namen der Quelltabelle/Feature-Class in der SDE-Verbindung ab.

Vorgehensweise

Führen Sie das folgende Skript in der ArcGIS Pro-Python-Umgebung aus:

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

Artikel-ID: 000032337

Holen Sie sich Unterstützung mit KI

Lösen Sie Ihr Problem schnell mit dem Esri Support AI Chatbot.

Beginnen Sie jetzt mit dem Chatten

Zugehörige Informationen

Weitere Informationen zu diesem Thema erkunden

Unterstützung durch ArcGIS-Experten anfordern

An den technischen Support wenden

Beginnen Sie jetzt mit dem Chatten

Zu Download-Optionen wechseln