Tutorial: Create a feature layer view

Learn how to use ArcGIS portal and scripting APIs to create a feature layer view.

feature-view-layer

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 Location 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.

  1. In your web browser, go to the Santa Monica Parcels item.

  2. 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 to your portal with your ArcGIS Location Platform account.

  1. In the top navigation bar, click Content.

  2. 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.
  3. Select Add Santa Monica Parcels.zip to publish the file as a hosted feature layer.

  4. Set the following information in the item details pane:

    • Title: Santa Monica Parcels
    • Tags: Santa Monica Parcels.
    • Summary: Parcels in the Santa Monica Mountains.
  5. Click Next to create the new feature layer and feature service.

  1. Import the required libraries.
  2. Implement authentication.
  3. Create and publish a portal item.
  4. Handle the results.
Expand
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# 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 portal, use the item page to create a view layer.

  1. In the source feature layer item page, click Create View Layer > View layer.
  2. In the Create View Layer dialog, under choose layers, ensure your layer is checked and click Next.
select-layer
  1. In Included layers, click on the layer, to define the fields and filters.
  2. Click Add Filter > + Add expression.
  3. In the expression dialog, in the first dropdown, select usetype. In the second dropdown, select is and in the last dropdown select Commercial.
add-expression
  1. Click the back arrow, under Layer definitions click Fields > Select fields.

  2. Select the following fields: situsfulla, usetype, usedescrip. Uncheck all the remaining fields.

  3. Click Done.

  4. Click the back arrow and click Next to open the Create view tab.

  5. 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
  6. Click Create. Once the view is created you will be redirected to the item page of the new feature layer view.

  7. Click the Data tab. You should see only the four fields you used in the expression.

  8. Click the Visualization tab. Only features with "usetype"='Commercial' should display.

  1. Import the required libraries.
  2. Implement authentication.
  3. Create and publish a portal item.
  4. Handle the results.
Expand
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# 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 your portal. 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.


Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.