Create a new feature layer

Learn how to create a new hosted feature layer and feature service.

You can use tools in your developer dashboard, ArcGIS Online and scripting APIs to define a new dataset in the cloud as a hosted feature layer. A hosted feature layer is also referred to as a feature layer. A feature layer is used to store point, line, or polygon geometries with attributes. After a feature layer is created, applications can access it by ID or URL and then query, edit, and display features.

In this tutorial, you use data management tools and scripting APIs to create and define a new feature layer that can store points with attributes. You also use Map Viewer or scripting APIs to add new features and set field values.

Prerequisites

You need an ArcGIS Developer or ArcGIS Online account to access and manage hosted layers.

Steps

Create a point feature layer

Use data management tools and scripting APIs to create a point feature layer that is powered by a feature service. The feature service will contain point geometries and attributes.

Steps to use the developer dashboardSteps to use ArcGIS OnlineSteps to use scripting APIs
  1. Go to your developer dashboard.

  2. Click Layers > Create data > New hosted layer (Feature layer).

  3. In the Data Structure pane, set the Geometry type to: Point.

  4. Under Fields, click Add field to create the following attribute fields for the point layer:

    • Field 1
      • Name:id
      • Alias:id
      • Type:Integer
      • Click: Add field
    • Field 2
      • Name:name
      • Alias:name
      • Type:String
      • Click: Add field
    • Field 3
      • Name:rating
      • Alias:rating
      • Type:string
      • Click: Add Field
    • Click Next to continue.
  5. In the Item Details pane, set the following properties:

    • Title: My Points
    • Tags: Beach access Malibu
    • Description: Place points along the California coast line.
  6. Click Create Layer to create the new My Points feature layer and feature service.

Find the hosted layer ID and URL

Your Layer ID and service URL will be unique. To access a private feature layer in an application, reference its service URL using an API key or token.

  1. Go to the item page of your new hosted feature layer.

  2. In the Overview, find the Layer ID and Service URL. It should look something like this:

  1. Go to ArcGIS Online and sign in.

  2. In the top navigation bar, click Content.

  3. Click New item > Feature Layer > Define your own layer.

  4. Set the following properties of the feature layer:

    • Name: my_points
    • Type: Point layer.
  5. Set the following properties of the ArcGIS Online item:

    • Title: My Points
    • Tags: Beach access Malibu
    • Summary: Place points along the California coast line.
  6. Click Next to create the new My Points feature layer and feature service.

  7. In the item page of the My Points layer, click the Data tab > Fields > Add.

  8. Create the following fields in the Fields window:

    • Field 1
      • Field Name:id
      • Display Name:id
      • Type:Integer
      • Click: Add New Field
    • Field 2
      • Click Add.
      • Field Name:name
      • Display Name:name
      • Type:String
      • Length: 256
      • Click: Add New Field
    • Field 3
      • Click Add
      • Field Name:rating
      • Display Name:rating
      • Type:String
      • Length: 256
      • Click: Add New Field

Find the hosted layer ID and URL

Your Layer ID and service URL will be unique. To access a private feature layer in an application, reference its service URL using an API key or token.

  1. Go to the item page of your new hosted feature layer and click the Overview tab.

  2. Scroll down to find the service URL. For example: https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/my_points/FeatureServer

  3. Click View to access the metadata for the feature layer. Find the Service ItemId. For example: 70264c2e37784a819e235d3a0129832f.

  1. Import libraries.
  2. Provide authentication.
  3. Create the service.
  4. Add the layer definition.
  5. Handle the results.
ArcGIS REST JSArcGIS REST JSArcGIS API for Python
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
  // create the service
  const newService = await createFeatureService({
    authentication: auth,
    item: {
      name: 'My Points',
      capabilities: 'Query, Extract',
      description: 'Place points along the California coast line',
      units: 'esriMeters',
      initialExtent: {
        xmin: -134.74729261792592,
        ymin: 23.56096242376989,
        xmax: -55.695547615409396,
        ymax: 50.309217030288835,
        spatialReference: { wkid: 4326 },
      },
      spatialReference: { wkid: 4326 },
    },
  });

  // create layer
  const newFeatureLayer = await addToServiceDefinition(newService.serviceurl, {
    authentication: auth,
    layers: layerSchema,
  });

  console.log(
    `New item created:\n\tid:${newService.itemId}\n\turl:${newService.serviceurl}`
  );

Enable editing

To add, update, and delete features in your feature layer, you need to enable editing.

Steps to use the developer dashboardSteps to use ArcGIS OnlineSteps to use scripting APIs
  1. In the developer dashboard, go to the item page of the My Points feature layer.

  2. In the item page, click the Settings tab.

  3. Under Layer access (Sharing), ensure that People with access is set to Private (authentication required).

  4. Under Editing settings, check Allow editing and leave the default selections.

  5. Click Save settings.

  1. In ArcGIS Online, click Content > My points.

  2. In the item page, click Share to ensure that sharing permissions are set to Owner > Save.

  3. Click the Settings tab.

  4. Under Feature layer (hosted), click Enable editing.

  5. Click Save.

  1. Provide authentication.
  2. Import libraries.
  3. Reference feature service.
  4. Execute updateDefinition operation.
  5. Handle results.
ArcGIS REST JSArcGIS REST JSArcGIS API for Python
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
import { ArcGISIdentityManager, request } from '@esri/arcgis-rest-request';
import {
  getLayer,
  getServiceAdminInfo,
  updateServiceDefinition,
} from '@esri/arcgis-rest-feature-service';

const getIdentity = async () => {
  return await ArcGISIdentityManager.fromToken({
    token: '<YOUR_ACCESS_TOKEN>',
  });
};

const enableEditing = async () => {
  // login to the portal
  const auth = await getIdentity();

  // feature service URL to update
  const featureServiceURL =
    '<YOUR_FEATURE_SERVICE_URL>';

  // get serviceAdminInfo
  const layerAdminInfo = await getServiceAdminInfo(featureServiceURL, auth);
  layerAdminInfo.capabilities =
    'Query, Extract, Editing, Create, Delete, Update';

  const results = await updateServiceDefinition(featureServiceURL, {
    authentication: auth,
    updateDefinition: layerAdminInfo,
  });

  console.log(results);
};

enableEditing();

Add features

Steps to use Map ViewerSteps to use scripting APIs

Map Viewer can be used to add and edit feature layer data. Use it to position the map to the Santa Monica mountains and then add new point features interactively.

  1. Open Map Viewer.

  2. Sign in to your account.

  3. In the left panel, click Layers > Add > My Points > Add to Map.

  4. On the right panel, click Map tools > Search. Type in 34.01757,-118.82549 and zoom to Zuma Beach.

  5. On the bottom of the right panel, click Edit to open the editor.

  6. In the Editor, click New Feature and click on the map to create a new point. Set the following attribute values:

    • id: 1
    • name: Zuma Beach
    • rating: Good
    • Click Create
  7. Add another point to the map at Westward Beach:

    • Search for Westward Beach at the following coordinates: 34.00637,-118.812791
    • Click Edit > New Feature and create a new point at the coordinates with the following attribute values:
      • id: 2
      • name: Westward Beach
      • rating: Excellent
      • Click Create
  8. Add another point to the map at Point Dume County Beach:

    • Search for Point Dume County Beach at the following coordinates: 34.00339,-118.80485
    • Click Edit > New Feature and create a new point at the coordinates with the following attribute values:
      • id: 3
      • name: Point Dume County Beach
      • rating: Poor
      • Click Create
  9. Add any additional points you would like to include on your map using the method described above.

  10. In the left panel, click Layers > My Points > ... > Show table to view the attribute data of your hosted feature layer. This opens the table view that you can use to inspect and edit data values.

  1. Import libraries.
  2. Provide authentication.
  3. Create new features.
  4. Execute edit operation.
  5. Handle results.
ArcGIS REST JSArcGIS REST JSArcGIS API for Python
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
  // execute method
  const results = await addFeatures({
    authentication: auth,
    url: '<YOUR_FEATURELAYER_URL>',
    features: newFeatures,
  });

  // handle results
  results.addResults.forEach(res=>{
    console.log(res)
  })

You now have a hosted feature layer and feature service. You can access the hosted layer with its URL or layer ID in your applications. To manage your hosted layer 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:

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