HOW TO
In an organization, view layers are created to use or display the data contained within a hosted feature layer while removing the risk of accidental modifications or deletion of the original hosted feature layer. When a large amount of hosted feature layer views is involved, identifying the parent hosted feature layer becomes important as it avoids deletion, which affects the view layer. It is possible to identify the host layer through the ArcGIS Online REST Services Directory. To simplify identifying multiple views at a time, ArcGIS API for Python can be used to automate the process, and this article describes the workflow. The following script can be run using a stand-alone .py file or in ArcGIS Notebook.
from arcgis.gis import GIS from arcgis.features import FeatureLayerCollection import requests gis = GIS("https://www.arcgis.com", "username", "password")
view_id = "<view_layer_id>"
vw_item = gis.content.get(view_id) relationships = vw_item.related_items(rel_type="Service2Data") print (relationships)
vw_item = gis.content.get(view_id)
sources_url = f"{vw_item.url}/sources"
data = {"token": gis._con.token, "f": "json"}
r = requests.post(sources_url, data=data)
print (r.json())
The code block below shows the full working script to identify the referenced hosted feature layer with the view layer id.
from arcgis.gis import GIS from arcgis.features import FeatureLayerCollection gis = GIS("https://www.arcgis.com", "user", "passwd") view_id = "425b785aa3564a7d8dasfsevrsaef23rfwe" vw_item = gis.content.get(view_id) relationships = vw_item.related_items(rel_type="Service2Data") print (relationships)
Article ID: 000032893
Get help from ArcGIS experts
Download the Esri Support App