Learn how to use ArcGIS.com and scripting APIs to create a feature layer view.
Feature layer views are created from existing feature services. In this tutorial, you create a feature layer view from an existing feature service by limiting the number of fields available and setting an expression to limit the types of features available. You will also manage the feature layer view settings and display the feature layer using a client-side API.
Prerequisites
You need an account for ArcGIS Platform, ArcGIS Online, or ArcGIS Enterprise to create hosted data services. If you need an account, go to Get started.
Steps
Download the data
For this workflow, you will use the Santa Monica Parcels dataset.
-
In your web browser, go to the Santa Monica Parcels item.
-
Click the Download button to download the zip file locally. Do not unzip this file.
Create a feature layer in a feature service
You can upload data into ArcGIS in supported file types such as CSV, XLS, GeoJSON, shapefile, and File Geodatabase. To create a feature service for the parcel data, import the shapefile by either using a data management tool or scripting API.
Follow the steps below to use Data management tools or Scripting APIs:
In your web browser, go to ArcGIS.com and sign in with your ArcGIS Developer account.
-
In the top navigation bar, click Content.
-
Click New item. To upload the Santa Monica Parcels shapefile, you can either:
- Drag and drop the file.
- Or, click Your device and navigate to the file path.
-
Select Add Santa Monica Parcels.zip to publish the file as a hosted feature layer.
-
In Fields, leave all fields at their default settings and click Next.
-
In Location settings, leave the default settings and click Next.
-
Set the following information in the item details pane:
- Title:
Santa Monica Parcels
- Tags:
Santa Monica
Parcels
. - Summary:
Parcels in the Santa Monica Mountains.
- Title:
-
Click Next to create the new feature layer and feature service.
In your web browser, go to ArcGIS.com and sign in with your ArcGIS Online account.
-
In the top navigation bar, click Content.
-
Click New item. To upload the Santa Monica Parcels shapefile, you can either:
- Drag and drop the file.
- Or, click Your device and navigate to the file path.
-
Select Add Santa Monica Parcels.zip to publish the file as a hosted feature layer.
-
In Fields, leave all fields at their default settings and click Next.
-
In Location settings, leave the default settings and click Next.
-
Set the following information in the item details pane:
- Title:
Santa Monica Parcels
- Tags:
Santa Monica
Parcels
. - Summary:
Parcels in the Santa Monica Mountains.
- Title:
-
Click Next to create the new feature layer and feature service.
In your web browser, go to your ArcGIS Enterprise portal website and sign in with your ArcGIS Enterprise account.
-
In the top navigation bar, click Content.
-
Click New item. To upload the Santa Monica Parcels shapefile, you can either:
- Drag and drop the file.
- Or, click Your device and navigate to the file path.
-
Select Add Santa Monica Parcels.zip to publish the file as a hosted feature layer.
-
In Fields, leave all fields at their default settings and click Next.
-
In Location settings, leave the default settings and click Next.
-
Set the following information in the item details pane:
- Title:
Santa Monica Parcels
- Tags:
Santa Monica
Parcels
. - Summary:
Parcels in the Santa Monica Mountains.
- Title:
-
Click Next to create the new feature layer and feature service.
You can use ArcGIS Pro to import shapefile data.
- Unzip the Santa Monica parcels zip file.
- The zip file contains the Parcels_Public.shp file.
- Launch ArcGIS Pro.
- Create a new map project.
- A map with
World Topographic Map
andWorld Hillshade
basemap layers will be created.
- In the Map ribbon, click on Add Data > Data and select Parcels_Public.shp file.
The Parcels_Public.shp file is added as a feature layer to the map.
Publish as web layer
Before you can share the feature layer as a hosted feature layer, you will need to enable Allow assignment of unique numeric IDs for sharing web layers option. By default, this option is not enabled. Enabling this option will allow you to assign static IDs to feature layers in your project.
- In the Contents pane, right-click the Map > Properties
- In the General section, enable Allow assignment of unique numeric IDs for sharing web layers.
With that option enabled, you can now publish the Santa Monica Parcels polygon feature layer as a hosted feature layer.
- Right-click on feature layer and click Sharing > Share as Web Layer.
- The Share As Web Layer pane will be displayed.
- Set the following required information in the General tab:
- Name:
Santa Monica Parcels
- Summary:
Parcels in the Santa Monica Mountains
- Tags:
Santa Monica Parcels
- Layer Type:
Feature
- Set a location in your organization in Location
- Name:
- Click Analyze
- Any errors or warnings during the analyze process will be displayed in the Messages tab.
- Click Publish
A success message will be displayed with Manage the web layer link allowing you to visit the item page details of the hosted feature layer.
- Import the required libraries.
- Provide an access token.
- Create and publish a portal item.
- Handle the results.
# local path to shapefile zip file
input_file_path = str(
Path(__file__).parent / "Santa_Monica_Public_Parcels.zip"
)
# add the zip file as an item to portal
shp_item = portal.content.add(
{
"title": "Santa Monica Public Parcels",
"description": "Santa Monica public parcels",
"tags": "Santa, Monica, public, parcels",
"type": "Shapefile",
},
input_file_path,
)
# publish the item to create a hosted featurelayer
shp_service = shp_item.publish(None)
print(f"New item id : {shp_service.id, }, url: {shp_service.layers[0].url}")
Create the feature layer view
To create a hosted feature layer view from a feature service, you can use data management tools or scripting APIs. Use a tool or API to create a view layer that contains only commercial parcels.
Follow the steps below to use Data management tools or Scripting APIs:
In ArcGIS.com, use the item page to create a view layer.
- In the source feature layer item page, click Create View Layer > View layer.
- In the Create View Layer dialog, under choose layers, ensure your layer is checked and click Next.
- In Included layers, click on the layer, to define the fields and filters.
- Click Add Filter > + Add expression.
- In the expression dialog, in the first dropdown, select
usetype
. In the second dropdown, selectis
and in the last dropdown selectCommercial.
-
Click the back arrow, under Layer definitions click Fields > Select fields.
-
Select the following fields:
situsfulla
,usetype
,usedescrip
. Uncheck all the remaining fields. -
Click Done.
-
Click the back arrow and click Next to open the Create view tab.
-
In the Create pane, Set the following parameters:
- Title: Santa Monica commercial parcels view
- Tags: view, public, parcels, santa, monica, commercial, tutorial
- Summary: Feature layer view representing commercial parcels in Santa Monica, CA
-
Click Create. Once the view is created you will be redirected to the item page of the new feature layer view.
-
Click the Data tab. You should see only the four fields you used in the expression.
-
Click the Visualization tab. Only features with
"usetype"='Commercial'
should display.
In ArcGIS.com, use the item page to create a view layer.
- In the source feature layer item page, click Create View Layer > View layer.
- In the Create View Layer dialog, under choose layers, ensure your layer is checked and click Next.
- In Included layers, click on the layer, to define the fields and filters.
- Click Add Filter > + Add expression.
- In the expression dialog, in the first dropdown, select
usetype
. In the second dropdown, selectis
and in the last dropdown selectCommercial.
-
Click the back arrow, under Layer definitions click Fields > Select fields.
-
Select the following fields:
situsfulla
,usetype
,usedescrip
. Uncheck all the remaining fields. -
Click Done.
-
Click the back arrow and click Next to open the Create view tab.
-
In the Create pane, Set the following parameters:
- Title: Santa Monica commercial parcels view
- Tags: view, public, parcels, santa, monica, commercial, tutorial
- Summary: Feature layer view representing commercial parcels in Santa Monica, CA
-
Click Create. Once the view is created you will be redirected to the item page of the new feature layer view.
-
Click the Data tab. You should see only the four fields you used in the expression.
-
Click the Visualization tab. Only features with
"usetype"='Commercial'
should display.
In your ArcGIS Enterprise portal, use the item page to create a view layer.
- In the source feature layer item page, click Create View Layer > View layer.
- In the Create View Layer dialog, under choose layers, ensure your layer is checked and click Next.
- In Included layers, click on the layer, to define the fields and filters.
- Click Add Filter > + Add expression.
- In the expression dialog, in the first dropdown, select
usetype
. In the second dropdown, selectis
and in the last dropdown selectCommercial.
-
Click the back arrow, under Layer definitions click Fields > Select fields.
-
Select the following fields:
situsfulla
,usetype
,usedescrip
. Uncheck all the remaining fields. -
Click Done.
-
Click the back arrow and click Next to open the Create view tab.
-
In the Create pane, Set the following parameters:
- Title: Santa Monica commercial parcels view
- Tags: view, public, parcels, santa, monica, commercial, tutorial
- Summary: Feature layer view representing commercial parcels in Santa Monica, CA
-
Click Create. Once the view is created you will be redirected to the item page of the new feature layer view.
-
Click the Data tab. You should see only the four fields you used in the expression.
-
Click the Visualization tab. Only features with
"usetype"='Commercial'
should display.
- Import the required libraries.
- Provide an access token.
- Create and publish a portal item.
- Handle the results.
# Create the view layer
view_item = flc.manager.create_view(name="Santa monica commercial parcels (view)")
# reduce the number of fields included in the view
# Get the current field list
view_flds = view_item.layers[0].properties.fields
# Set only the fields we want to visible, also include OID
vis_flds = [
{"name": f"{f.name}", "visible": True}
if f.name in ["apn", "situsfulla", "usetype", "usedescrip"]
or f.type == "esriFieldTypeOID"
else {"name": f"{f.name}", "visible": False}
for f in view_flds
]
layer_def = {"viewDefinitionQuery": "usetype = 'Commercial'", "fields": vis_flds}
view_item.layers[0].manager.update_definition(layer_def)
print(f"Feature layer view created\n\t ItemID : {view_item.id}\n\t URL:{view_item.url}")
You now have a feature layer view hosted in ArcGIS. You can access the view layer with its service URL or ID in your applications. To manage your hosted layer (item) properties and capabilities, visit the Manage a feature layer tutorial.
What's next?
Learn how to use additional tools, APIs, and location services in these tutorials:
Define a new feature layer
Use data management tools to define and create a new empty feature layer in a feature service.
Manage a feature layer
Use a hosted feature layer item to set the properties and settings of a feature layer in a feature service.
Create a vector tile service
Use data management tools to create a new vector tile service from a feature service.
Add a feature layer
Access and display point, line, and polygon features from a feature service.
Add a vector tile layer
Access and display a vector tile layer in a map.
Add a map tile layer
Access and display a map tile layer in a map.
Style a feature layer
Use symbols and renderers to style feature layers.
Query a feature layer (spatial)
Execute a spatial query to get features from a feature layer.
Query a feature layer (SQL)
Execute a SQL query to access polygon features from a feature layer.
Edit feature data
Add, update, and delete features in a feature service.
Display a popup
Format a popup to show attributes in a feature layer.