Hosted feature layers

Feature layers displaying trailhead, trail, and park data stored as hosted feature layers

What is a hosted feature layer?

A hosted feature layer is a reference to a feature layer in a feature service used to store your data. A feature layer is a spatially-enabled table that contains features with a geometry and attributes. Applications can use feature layers to access, query, edit, and display features in a map or scene.

You use a hosted feature layer when you want to:

  • Import files such as CSV, XLS, or Google Sheets with coordinate information.
  • Store collections of geometry and attribute data as features.
  • Access and display features in maps and scenes.
  • Securely share data with applications and users.
  • Optimize accessing and displaying large amounts of features.
  • Edit data and track edits.
  • Perform SQL or spatial queries.
  • Update or export data.
  • Use feature data in offline applications.

How a hosted feature layer works

You create a hosted feature layer by using data management tools to import files such as CSV, XLS, GeoJSON, Shapefile, and File Geodatabase files or by publishing feature data. When a hosted feature layer is created, an item and a feature layer in a feature service are created. The item ID is a unique identifier for the layer. You use an item page to manage a feature layer and a feature service to access the data.

Data hosting

Access hosted feature layers and feature services from your applications.

Manage a feature layer

An item page allows you to manage the properties and capabilities for a hosted feature layer. You can access an item page by signing in to your developer dashboard or ArcGIS Online. You can set properties such as the name, description, and tags, as well as sharing, editing, and index settings.

View a feature layer item page

To access an item page directly, use a portal search URL with the ID for the item. The portal URL for data hosted in ArcGIS is https://www.arcgis.com. To use this URL, the item must be shared publicly.

Use dark colors for code blocksCopy
 
1
https://www.arcgis.com/home/item.html?id=<ID>

Example: https://www.arcgis.com/home/item.html?id=883cedb8c9fe4524b64d47666ed234a7

Access a feature layer

You can discover information about a feature layer by accessing the feature service endpoint with the layer ID. The ID is typically an integer such as "0" if there is only one layer in the feature service. Accessing the endpoint in a web browser allows you to view properties such as the name, geometry type, drawing information, extent, and fields. Most APIs will use the endpoint to perform other operations such as querying data.

Get feature layer properties

To access a feature layer or get properties, use the host, unique service ID, service name, and the layer ID.

Use dark colors for code blocksCopy
 
1
https://<HOST>/<UNIQUE_ID>/ArcGIS/rest/services/<SERVICE_NAME>/FeatureServer/<LAYER_ID>

Example: https://services3.arcgis.com/GVgbJbqm8hXASVYi/ArcGIS/rest/services/Trailheads/FeatureServer/0

Get feature layer data

To get feature layer data, use the host, unique service ID, service name, layer ID, and a query operation with parameters. You can provide a SQL or spatial query and the data can be returned as HTML, JSON, or GeoJSON.

Use dark colors for code blocksCopy
 
1
https://<HOST>/<UNIQUE_ID>/ArcGIS/rest/services/<SERVICE_NAME>/FeatureServer/0/query?<PARAMS>

Examples:

HTML: https://services3.arcgis.com/GVgbJbqm8hXASVYi/ArcGIS/rest/services/Trailheads/FeatureServer/0/query?where=1=1&outFields=*&f=html

JSON: https://services3.arcgis.com/GVgbJbqm8hXASVYi/ArcGIS/rest/services/Trailheads/FeatureServer/0/query?where=1=1&outFields=*&f=json

GeoJSON: https://services3.arcgis.com/GVgbJbqm8hXASVYi/ArcGIS/rest/services/Trailheads/FeatureServer/0/query?where=1=1&outFields=*&f=geojson

Code examples

Display a feature layer

To display a hosted feature layer, you reference the layer by its URL or ID, and then add it to a map or scene. The API communicates with the feature service to retrieve data for the current visible extent. ArcGIS APIs optimize data access by utilizing feature service functionality such as spatial indexes and caching. APIs also need to specify which data attributes to return.

Steps

  1. Create a map or scene.
  2. Get the hosted feature layer URL.
  3. Add the layer.

ArcGIS Maps SDK for JavaScriptArcGIS Maps SDK for JavaScriptArcGIS Maps SDK for .NETArcGIS Maps SDK for KotlinArcGIS Maps SDK for SwiftArcGIS Maps SDK for JavaArcGIS Maps SDK for Qt (C++)ArcGIS Maps SDK for Qt (QML)ArcGIS API for PythonEsri LeafletMapLibre GL JSOpenLayersCesiumJS
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
      const trailheadsLayer = new FeatureLayer({
        url: "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads_styled/FeatureServer/0"
      });
      map.add(trailheadsLayer);

      const trailsLayer = new FeatureLayer({
        url: "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trails_styled/FeatureServer/0"
      });
      map.add(trailsLayer,0);

      const parksLayer = new FeatureLayer({
        url: "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Parks_and_Open_Space_styled/FeatureServer/0"
      });
      map.add(parksLayer,0);

Query a feature layer (Spatial)

To retrieve a sub-set of data for a hosted feature layer, you can query features using a spatial relation and a geometry. This example uses a spatial query to access a sub-set of parcels from a feature layer that contains 2.4 million features.

Steps

  1. Create a map or scene.
  2. Get the hosted feature layer URL.
  3. Create and execute a spatial query.
  4. Show the features.

APIs

ArcGIS Maps SDK for JavaScriptArcGIS Maps SDK for JavaScriptArcGIS Maps SDK for .NETArcGIS Maps SDK for KotlinArcGIS Maps SDK for SwiftArcGIS Maps SDK for JavaArcGIS Maps SDK for Qt (C++)ArcGIS Maps SDK for Qt (QML)ArcGIS API for PythonEsri LeafletMapLibre GL JSOpenLayersCesiumJS
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
  <title>ArcGIS Maps SDK for JavaScript Tutorials: Query a feature layer (spatial)</title>
  <style>
    html, body, #viewDiv {
      padding: 0;
      margin: 0;
      height: 100%;
      width: 100%;
    }
  </style>
    <link rel="stylesheet" href="https://js.arcgis.com/4.26/esri/themes/light/main.css">
    <script src="https://js.arcgis.com/4.26"></script>
  <script>
    require([
      "esri/config",
      "esri/Map",
      "esri/views/MapView",
      "esri/widgets/Sketch",
      "esri/layers/GraphicsLayer",
      "esri/layers/FeatureLayer"

    ], function(esriConfig,Map, MapView, Sketch, GraphicsLayer, FeatureLayer) {

      esriConfig.apiKey = "YOUR_API_KEY";

      const map = new Map({
        basemap: "arcgis-topographic" //Basemap styles service
      });

      const view = new MapView({
        container: "viewDiv",
        map: map,
        center: [-118.80543,34.03000], //Longitude, latitude
        zoom: 13
      });

      // Add sketch widget
      const graphicsLayerSketch = new GraphicsLayer();
      map.add(graphicsLayerSketch);

      const sketch = new Sketch({
        layer: graphicsLayerSketch,
        view: view,
        creationMode: "update" // Auto-select
      });

      view.ui.add(sketch, "top-right");

      // Add sketch events to listen for and execute query
      sketch.on("update", (event) => {

        // Create
        if (event.state === "start") {
          queryFeaturelayer(event.graphics[0].geometry);
        }
        if (event.state === "complete"){
          graphicsLayerSketch.remove(event.graphics[0]); // Clear the graphic when a user clicks off of it or sketches new one
        }
        // Change
        if (event.toolEventInfo && (event.toolEventInfo.type === "scale-stop" || event.toolEventInfo.type === "reshape-stop" || event.toolEventInfo.type === "move-stop")) {
          queryFeaturelayer(event.graphics[0].geometry);
        }

      });

      // Reference query layer
      const parcelLayer = new FeatureLayer({
        url: "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/LA_County_Parcels/FeatureServer/0",
      });

      function queryFeaturelayer(geometry) {

        const parcelQuery = {
         spatialRelationship: "intersects", // Relationship operation to apply
         geometry: geometry,  // The sketch feature geometry
         outFields: ["APN","UseType","TaxRateCity","Roll_LandValue"], // Attributes to return
         returnGeometry: true
        };

        parcelLayer.queryFeatures(parcelQuery)
        .then((results) => {

          console.log("Feature count: " + results.features.length)

          displayResults(results);

        }).catch((error) => {
          console.log(error);
        });

      }

      // Show features (graphics)
      function displayResults(results) {

      // Create a blue polygon
        const symbol = {
          type: "simple-fill",
          color: [ 20, 130, 200, 0.5 ],
          outline: {
            color: "white",
            width: .5
          },
        };

        const popupTemplate = {
          title: "Parcel {APN}",
          content: "Type: {UseType} <br> Land value: {Roll_LandValue} <br> Tax Rate City: {TaxRateCity}"
        };

        // Set symbol and popup
        results.features.map((feature) => {
          feature.symbol = symbol;
          feature.popupTemplate = popupTemplate;
          return feature;
        });

        // Clear display
        view.popup.close();
        view.graphics.removeAll();
       // Add features to graphics layer
        view.graphics.addMany(results.features);

      }

    });
  </script>
</head>
<body>
  <div id="viewDiv"></div>
</body>
</html>

REST API

cURLcURLHTTP
Use dark colors for code blocksCopy
       
1
2
3
4
5
6
7
curl https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/LA_County_Parcels/FeatureServer/0/query? \
-d "where=1=1" \
-d "outFields=*" \
-d "f=json" \
-d "geometry = {"x":-118.807,"y":34.002,"spatialReference":{"wkid":4326}}" \
-d "geometryType=esriGeometryPoint" \
-d "spatialRel = esriSpatialRelIntersects"

Query a feature layer (SQL)

To retrieve a sub-set of data for a hosted feature layer, you can query features using a SQL where clause. This example uses a SQL where clause to access a sub-set of parcels from a feature layer that contains 2.4 million features.

Steps

  1. Create a map or scene.
  2. Get the hosted feature layer URL.
  3. Create and execute a SQL query.
  4. Show the features.

APIs

ArcGIS Maps SDK for JavaScriptArcGIS Maps SDK for JavaScriptArcGIS Maps SDK for .NETArcGIS Maps SDK for KotlinArcGIS Maps SDK for SwiftArcGIS Maps SDK for JavaArcGIS Maps SDK for Qt (C++)ArcGIS Maps SDK for Qt (QML)ArcGIS API for PythonEsri LeafletMapLibre GL JSOpenLayersCesiumJS
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
      // Get query layer and set up query
      const parcelLayer = new FeatureLayer({
        url: "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/LA_County_Parcels/FeatureServer/0",
      });

      function queryFeatureLayer(extent) {
        const parcelQuery = {
         where: whereClause,  // Set by select element
         spatialRelationship: "intersects", // Relationship operation to apply
         geometry: extent, // Restricted to visible extent of the map
         outFields: ["APN","UseType","TaxRateCity","Roll_LandValue"], // Attributes to return
         returnGeometry: true
        };
        parcelLayer.queryFeatures(parcelQuery)
        .then((results) => {
          displayResults(results);
        }).catch((error) => {
          console.log(error.error);
        });
      };

REST API

cURLcURLHTTP
Use dark colors for code blocksCopy
     
1
2
3
4
5
curl https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/LA_County_Parcels/FeatureServer/0/query? \
-d "where=UseType = 'Residential'" \
-d "resultRecordCount=1" \
-d "outFields=*" \
-d "f=json"

Tutorials

Services

Feature service

Add, update, delete, and query feature data.


Vector tile service

Store and access vector tile data.


Image tile service

Store and access image tile data.

API support

Full supportPartial supportNo support
  • 1. Access portal via HTTP request and authentication.
  • 2. Access via ArcGIS REST JS.
  • 3. Requires manual application of renderers

Tools

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