Overview

You will learn: how to add, edit, and remove features from ArcGIS Feature Services.

ArcGIS Feature Services can access, edit, and store spatial data in feature layers. Feature layers define the spatial reference, geometry type (points, lines or polygons), attribute fields, and the permission settings for the data. If you want to create an application that can edit feature layer data you can use the ArcGIS REST API and the applyEdits operation. All you need to do is either pass in the features to create or update, or pass in the ObjectIDs to delete, and the service will perform the operation. To learn more about the capabilities of feature services, please visit the documentation.

In this lab you will use the ArcGIS REST API to access a hosted feature layer to add, edit and remove features.

Before you begin

Install Postman to execute HTTP requests. Go to this lab if you need an access token.

Steps

Find your Feature Layer's URL

  1. Go to ArcGIS for Developers and sign in.

  2. Click Dashboard > View All Layers and find the "Griffith Park Access" layer you created in the Create a new dataset lab.

  3. Copy the Service URL in the right hand column.

NOTE: If you don't have the dataset in your account, please complete the Create a new dataset lab now. This will step you through the process of creating a new feature layer.

Create a request to access the feature service

  1. Open Postman and click [+] in the tab bar to create a new request.

  2. In the new tab, set the following:

    • HTTP Method: POST
    • Request URL: Paste in your layer URL from above and add /0/applyEdits to the end. It should look something like this:

    https://services.arcgis.com/uCXeTVveQzP4IIcx/arcgis/rest/services/griffith_park_access/FeatureServer/0/applyEdits

Add parameters to add a new feature

  1. Click on Body and add the following Key/Value pairs:

    • f: json
    • token: A token from the Get an access token lab.
    • adds:
      [
        {
          "geometry" : {
            "x": -118.28910,
            "y": 34.15542,
            "spatialReference": {
              "wkid": 4326
            }
          },
          "attributes" : {
            "name" : "West Trail",
            "type" : "Hiking Path",
            "surface" : "Dirt"
          }
        }
      ]
      
  2. Click Send to run the request.

  3. In the response window, change the view to JSON. It should look something like this:

    {
      "addResults": [
          {
              "objectId": 1,
              "globalId": null,
              "success": true
          }
      ],
      "updateResults": [],
      "deleteResults": []
    }
    
  4. Find the objectId in the response. This is the unique ID of the feature you will use in the next steps.

Update the parameters to edit an existing feature

  1. In the Body, remove the adds parameter and add the updates parameter and change surface to Gravel. Set it to the following:

    • updates:
    [
      {
        "attributes" : {
          "objectId": 1,
            "name" : "West Trail",
            "type" : "Hiking Path",
            "surface" : "Gravel"
        }
      }
    ]
    
  2. Click Send to run the request.

  3. In the response window, change the view to JSON. It should look something like this:

    {
      "addResults": [],
      "updateResults": [
          {
              "objectId": 1,
              "globalId": null,
              "success": true
          }
      ],
      "deleteResults": []
    }
    

Update the parameters to delete a feature

  1. In the Body, remove the updates parameter and add a deletes parameter. Set it to the following:

    • deletes: The objectId of the feature from step 6.
  2. Click Send to run the request.

  3. In the response window, change the view to JSON. It should look something like this:

    {
      "addResults": [],
      "updateResults": [],
      "deleteResults": [
          {
              "objectId": 1,
              "globalId": null,
              "success": true
          }
      ]
    }
    

  1. In Postman click Code below the Send button. Select a programming language and use Postman to generate sample code for your application to run this request.

Congratulations, you're done!

You have successfully added, edited, and removed a feature from a feature service.

Challenge

Add, edit, or delete features in bulk with applyEdits

Try using the applyEdits operation on a feature layer to add, edit, and delete features in a single request.

Configure editing settings

Feature layer editing permissions are highly configurable. Sign into ArcGIS for Developers and click Dashboard > View All Layers and find the "Griffith Park Access" layer you created in the Create a new dataset lab. click Settings and explore the Permissions Settings.

As the layer's owner, these permission settings do not apply to you. However, they impact other users if you make your layer public or share it with any other ArcGIS Online users.

Editing a public layer

Feature layers can be made public and edits can be done by unauthenticated users without the need of a token. Try the Share maps and layers dev lab and share your layer publicly. You will be able to omit the token parameter in your requests.