HOW TO

Identify a hosted feature layer referenced by a view layer using ArcGIS API for Python

Last Published: June 27, 2024

Summary

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.

Procedure

  1. Import the necessary modules and specify the credentials.
from arcgis.gis import GIS
from arcgis.features import FeatureLayerCollection
import requests

gis = GIS("https://www.arcgis.com", "username", "password")
  1. Specify the view layer id.
view_id = "<view_layer_id>"
  1. Obtain the information details from the view layer using one of the following scripts.
  • Identify the referenced hosted feature layer with the view layer id:
vw_item = gis.content.get(view_id)
relationships = vw_item.related_items(rel_type="Service2Data")

print (relationships)
  • Identify the referenced hosted feature layer with the view layer source endpoint:
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

Software:
  • ArcGIS Online
  • Portal for ArcGIS
  • ArcGIS API for Python 1 x
  • ArcGIS Enterprise 11 0
  • ArcGIS Enterprise 11 1
  • ArcGIS Enterprise 11 3
  • ArcGIS Enterprise 11 2

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options