How to check if an ArcGIS Online Feature Service is a View Layer with the ArcGIS API for Python

Table of Contents

The Video

Introduction

I was recently doing an ArcGIS Online audit for an organisation and needed to know whether a Feature Service was a View Service or the main Hosted Feature Service. When performing a search() with the ContentManager using the ArcGIS API for Python all Feature Services were returned with no distinction between the original and a View. I found I could check the size and it would be zero for a View, but I wondered if there were any definitive properties that I could check to see if the service was indeed a View or not. I found two. One via the typeKeywords property for an Item object and a FeatureLayerCollection object will will have an isView property if it is indeed a view, and omitted if not.

Automate ArcGIS Online Feature Service Workflows with the ArcGIS API for Python | A Complete Guide from Beginner to Advanced | Full Course

Free on YouTube! A set of videos detailing ArcGIS Online Feature Services workflows using the ArcGIS API for Python. We will do a deep dive into properties and methods available, along with custom workflows for automating with Feature Services and the ArcGIS API for Python.

arcgis modules

The API provides access to your organisations ArcGIS Online via the GIS class in the gis module. This GIS class is the gateway to ArcGIS Online. We will also utilise the FeatureLayerCollection class that will enable us to access object properties to check for the isView property.

				
					## provides access to ArcGIS Online
from arcgis.gis import GIS

## the FeatureLayerCollection class
from arcgis.features import FeatureLayerCollection
				
			

Accessing ArcGIS Online

Our first port of call is to access your ArcGIS Online via the GIS class. There are a handful of ways to achieve access, if you are logged into your ArcGIS Online in ArcGIS Pro you can simply use "home", otherwise, another common way is to provide the ArcGIS Online URL, followed by your username and password.
				
					## Access AGOL
agol = GIS("home")
				
			
				
					## Access AGOL
agol = GIS(
    url = "https://your_organisation.maps.arcgis.com/",
    username = "Your_Username",
    password = "Your_Password"
)
				
			

Required inputs

Only one  required parameter, the url to the Item ID for the Feature Service to query.

				
					## the ArcGIS Content Item Id for the Service
item_id = "ITEM_ID"
				
			

Option 1: Checking the Item Object typeKeywords property

We first create an Item object for the Feature Service of interest. An Item object has a typeKeywords property that helps ArcGIS Online know what type of Item the content item is. If the typeKeywords list contain “View Service”, well then the service is a View made from another Hosted Feature Service., otherwise it is a Hosted Feature Service and not a View.

				
					## get the Feature Service as an Item object
item = agol.content.get(item_id)

if "View Service" in item.typeKeywords:
    print("View Service")
else:
    print("Feature Service")
				
			

Option 2: FeatureLayerCollection Object isView property

We can create a FeatureLayerCollection object from an Item object that represents a Feature Service. While an Item object represents the content item in ArcGIS Online, a FeatureLayerCollection object represents a Feature Service. We check if the FeatureLayerCiollection object has a property called “isView”, and if that property is set to True, then the service is a View, otherwise it is a Hosted Feature Service and not a View. 

				
					## create a FeatureLayerCollection object from an Item object
flc = FeatureLayerCollection.fromitem(
    item = item
)

if hasattr(flc.properties, "isView"):
    if flc.properties.isView == True:
        print("View Service")
    else:
        print("Feature Service")

else:
    print("Feature Service")
				
			

If you’ve found these blogs helpful and would like to support the project, please consider making a donation. All learning material is provided free of charge to help GIS professionals, students, and developers learn ArcPy, the ArcGIS API for Python, ArcGIS Pro, and ArcGIS Online. Donations help cover website hosting, software licensing, domain costs, and the time involved in creating and maintaining tutorials, courses, and learning resources. Your support helps keep this content freely available to everyone and allows new courses and materials to be developed for the GIS community. If the content has helped you solve a problem, learn a new skill, or advance your career, please consider supporting the project with a donation. Every contribution, no matter the size, is greatly appreciated.

All the code in one place

You can find the entire code workflow below with links to important components in the documentation that were used.

				
					from arcgis.gis import GIS
from arcgis.features import FeatureLayerCollection

################################################################################
## API Reference Links:
##  https://developers.arcgis.com/python/latest/api-reference/arcgis.gis.toc.html#gis
##  https://developers.arcgis.com/python/latest/api-reference/arcgis.gis.toc.html#item
##  https://developers.arcgis.com/python/latest/api-reference/arcgis.gis.toc.html#arcgis.gis.ContentManager.get
##  https://developers.arcgis.com/python/latest/api-reference/arcgis.features.toc.html#featurelayercollection
##  https://developers.arcgis.com/python/latest/api-reference/arcgis.features.toc.html#arcgis.features.FeatureLayerCollection.properties
##
################################################################################


################################################################################
## ACCESS ARCGIS ONLINE ########################################################

agol = GIS("home")

################################################################################
## USER INPUT ##################################################################

## the ArcGIS Content Item Id for the Service
item_id = "ITEM_ID"

################################################################################
## CREATE AN ITEM OBJECT #######################################################

## get the Feature Service as an Item object
item = agol.content.get(item_id)

if "View Service" in item.typeKeywords:
    print("View Service")
else:
    print("Feature Service")

################################################################################
## CREATE A FEATURELAYERCOLLECTION OBJECT ######################################

## create a FeatureLayerCollection object from an Item object
flc = FeatureLayerCollection.fromitem(
    item = item
)

if hasattr(flc.properties, "isView"):
    if flc.properties.isView == True:
        print("View Service")
    else:
        print("Feature Service")

else:
    print("Feature Service")

################################################################################
print("\nSCRIPT COMPLETE")
				
			

Leave a Comment