HOW TO
A view is created from a hosted feature layer to filter desired features or display fields in a map. The view is added as a feature layer to the Content tab and can be shared. Refer to Portal for ArcGIS: Create hosted feature layer views for detailed steps.
The view definition is defined at the service level, and the viewDefinitionQuery property is updated. Navigate to Portal REST API Directory > the layer ID > JSON to define and update the view. The property is displayed as shown in the image below:
Note: Changing the value of viewDefinitionQuery also updates the related definitionQuery property.
Alternatively, views are also created using ArcGIS API for Python. Creating views using ArcGIS API for Python eliminates the need to open the Portal for ArcGIS application.
The following steps describe how to create a view and view definition using ArcGIS API for Python:
from arcgis import GIS from arcgis.features import FeatureLayerCollection gis = GIS("https://www.arcgis.com", "username","password")
source_search = gis.content.search("FEATURE_LAYER")[0] source_flc = FeatureLayerCollection.fromitem(source_search)
new_view = source_flc.manager.create_view(name="VIEW_NAME")
view_search = gis.content.search("VIEW_NAME")[0] view_flc = FeatureLayerCollection.fromitem(view_search)
service_layer = view_flc.layers[0]
update_dict = {"viewDefinitionQuery" : "TEST_QUERY"}
service_layer.manager.update_definition(update_dict)
The following shows the full script.
from arcgis import GIS from arcgis.features import FeatureLayerCollection gis = GIS("https://www.arcgis.com", "username","password") source_search = gis.content.search("world_earthquakes")[0] source_flc = FeatureLayerCollection.fromitem(source_search) new_view = source_flc.manager.create_view(name="worldEQView") view_search = gis.content.search("worldEQView")[0] view_flc = FeatureLayerCollection.fromitem(view_search) service_layer = view_flc.layers[0] update_dict = {"viewDefinitionQuery" : "year_ < 1988"} service_layer.manager.update_definition(update_dict)
To verify, check the Set View Definition settings.
Get help from ArcGIS experts
Download the Esri Support App