Looking for a way to query all the Views created from a provided Feature Layer. In AGOL, this information is provided on the Overview page under the Details : Other Views (see below). How do I access this data using ArcGIS API for Python?
Thanks in advanced!
Solved! Go to Solution.
Hi @JaimieNevins2 ,
Here's a sample script which lists all the layer views of a hosted feature layer:
from arcgis import GIS
from arcgis.features import FeatureLayerCollection
gis = GIS("portal_url", "username", "password")
source_item = gis.content.search("feature_layer")[0]
flc = FeatureLayerCollection.fromitem(source_item)
for view in flc.layers[0].manager.properties.adminLayerInfo.layerViews:
print(view.serviceName)
Hope that helps.
Mehdi
Hi @JaimieNevins2 ,
Here's a sample script which lists all the layer views of a hosted feature layer:
from arcgis import GIS
from arcgis.features import FeatureLayerCollection
gis = GIS("portal_url", "username", "password")
source_item = gis.content.search("feature_layer")[0]
flc = FeatureLayerCollection.fromitem(source_item)
for view in flc.layers[0].manager.properties.adminLayerInfo.layerViews:
print(view.serviceName)
Hope that helps.
Mehdi
Thank you so much!
Not a problem @JaimieNevins2.
If my reply has answered your question, could you please Accept as Solution?
Thanks.
Here's an additional solution, to complement @MehdiPira1's.
You can get a list of items that are views of a hosted feature layer by calling related_items with rel_type="Service2Service" and direction="forward":
import arcgis
gis = arcgis.gis.GIS("home")
hfl_item = gis.content.get("...")
views_items = hfl_item.related_items(rel_type="Service2Service", direction="forward")
for view_item in view_items:
print(view_item.title)
Conversely, you can get the source hosted feature layer for a view item by calling related_items with rel_type="Service2Service" and direction="reverse":
# Returns a list containing only one item.
source_hfl = item.related_items(rel_type="Service2Service", direction="reverse")
source_hfl = source_hfl[0]
How can we get related items of a view ?