Skip To Content ArcGIS for Developers Sign In Dashboard

ArcGIS Runtime SDK for .NET

Delete features (feature service)

This code sample is available for these platforms:
View Sample on GitHub

Delete features from an online feature service.

Image of delete features feature service

Use case

Sometimes users may want to delete features from an online feature service.

How to use the sample

To delete a feature, tap it, then tap 'Delete incident'.

How it works

  1. Create a ServiceFeatureTable object from a URL.
  2. Create a FeatureLayer object from the service feature table.
  3. Select features from the feature layer via FeatureLayer.SelectFeatures().
  4. Remove the selected features from the service feature table using ServiceFeatureTable.DeleteFeatureAsync().
  5. Update the table on the server using ServiceFeatureTable.ApplyEditsAsync().

Relevant API

  • Feature
  • FeatureLayer
  • ServiceFeatureTable


deletion, feature, online, Service, table

Sample Code

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns=""
        <esriUI:MapView x:Name="MyMapView" Style="{StaticResource MapWithFormStyle}"
                        BindingContext="{x:Reference Name=ResponsiveFormContainer}" />
        <resources:ResponsiveFormContainer x:Name="ResponsiveFormContainer">
                <Label Text="Tap to select a feature to delete."
                <Button x:Name="DeleteButton" 
                        Text="Delete feature"
// Copyright 2019 Esri.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an 
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific 
// language governing permissions and limitations under the License.

using Esri.ArcGISRuntime.Data;
using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Mapping;
using System;
using System.Linq;
using Xamarin.Forms;

namespace ArcGISRuntimeXamarin.Samples.DeleteFeatures
        name: "Delete features (feature service)",
        category: "Data",
        description: "Delete features from an online feature service.",
        instructions: "To delete a feature, tap it, then tap 'Delete incident'.",
        tags: new[] { "Service", "deletion", "feature", "online", "table" })]
    public partial class DeleteFeatures : ContentPage
        // Path to the feature service.
        private const string FeatureServiceUrl = "";

        // Hold a reference to the feature layer.
        private FeatureLayer _damageLayer;

        // Hold a reference to the most recently tapped feature.
        private Feature _tappedFeature;

        public DeleteFeatures()

        private void Initialize()
            // Create the map with streets basemap.
            MyMapView.Map = new Map(Basemap.CreateStreets());

            // Create the feature table, referring to the Damage Assessment feature service.
            ServiceFeatureTable damageTable = new ServiceFeatureTable(new Uri(FeatureServiceUrl));

            // Create a feature layer to visualize the features in the table.
            _damageLayer = new FeatureLayer(damageTable);

            // Add the layer to the map.

            // Listen for user taps on the map - on tap, a callout will be shown.
            MyMapView.GeoViewTapped += MapView_Tapped;

            // Zoom to the United States.
            MyMapView.SetViewpointCenterAsync(new MapPoint(-10800000, 4500000, SpatialReferences.WebMercator), 3e7);

        private async void MapView_Tapped(object sender, Esri.ArcGISRuntime.Xamarin.Forms.GeoViewInputEventArgs e)
            // Clear any existing selection.

            // Reconfigure the button.
            DeleteButton.IsEnabled = false;
            DeleteButton.Text = "Delete feature";

                // Perform an identify to determine if a user tapped on a feature.
                IdentifyLayerResult identifyResult = await MyMapView.IdentifyLayerAsync(_damageLayer, e.Position, 5, false);

                // Do nothing if there are no results.
                if (!identifyResult.GeoElements.Any())

                // Otherwise, get the ID of the first result.
                long featureId = (long) identifyResult.GeoElements.First().Attributes["objectid"];

                // Get the feature by constructing a query and running it.
                QueryParameters qp = new QueryParameters();
                FeatureQueryResult queryResult = await _damageLayer.FeatureTable.QueryFeaturesAsync(qp);
                _tappedFeature = queryResult.First();

                // Select the feature.

                // Update the button to allow deleting the feature.
            catch (Exception ex)
                await Application.Current.MainPage.DisplayAlert("Error", ex.ToString(), "OK");

        private void ConfigureDeletionButton(Feature tappedFeature)
            // Create a button for deleting the feature.
            DeleteButton.Text = $"Delete incident {tappedFeature.Attributes["objectid"]}";
            DeleteButton.IsEnabled = true;

        private async void DeleteButton_Click(object sender, EventArgs e)
            // Reconfigure the button.
            DeleteButton.IsEnabled = false;
            DeleteButton.Text = "Delete feature";

            // Guard against null.
            if (_tappedFeature == null)

                // Delete the feature.
                await _damageLayer.FeatureTable.DeleteFeatureAsync(_tappedFeature);

                // Sync the change with the service.
                ServiceFeatureTable serviceTable = (ServiceFeatureTable) _damageLayer.FeatureTable;
                await serviceTable.ApplyEditsAsync();

                // Show a message confirming the deletion.
                await Application.Current.MainPage.DisplayAlert("Success!", $"Deleted feature with ID {_tappedFeature.Attributes["objectid"]}", "OK");
            catch (Exception ex)
                await Application.Current.MainPage.DisplayAlert("Error", ex.ToString(), "OK");