Select to view content in your preferred language

Search for Views Created from a User Provided Feature Layer

1069
5
Jump to solution
01-20-2022 12:02 PM
JaimieNevins2
Emerging Contributor

 

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!

JaimieNevins2_0-1642708724674.png

 

0 Kudos
1 Solution

Accepted Solutions
MehdiPira1
Esri Contributor

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

View solution in original post

5 Replies
MehdiPira1
Esri Contributor

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

JaimieNevins2
Emerging Contributor

Thank you so much!

0 Kudos
MehdiPira1
Esri Contributor

Not a problem @JaimieNevins2.

If my reply has answered your question, could you please Accept as Solution?

Thanks.

TristanMcHardie
Regular Contributor

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]

 

 

GunaNandeeshUppu
New Contributor

How can we get related items of a view ?

0 Kudos