Skip To Content ArcGIS for Developers Sign In Dashboard

ArcGIS Runtime SDK for .NET

Feature layer definition expression

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

Limit the features to display on the map using a definition expression.


Use case

One use case includes improving application performance by restricting the amount of features returned from a feature service. The definition expression is applied to visualized features as well as the underlying feature table. Another use case is the data in a FeatureLayer may be sensitive and require a certain level of authorization/permission to view. By setting a definition expression to only those records specified the data is protected from unauthorized access.

How to use the sample

Press the 'Apply Expression' button to limit the features requested from the feature layer to those specified by the SQL query definition expression. Click the 'Reset Expression' button to remove the definition expression on the feature layer, which returns all the records.

How it works

  1. Create a service feature table from a URL.
  2. Create a feature layer from the service feature table.
  3. Set the limit of the features on your feature layer using the DefinitionExpression.

Relevant API

  • DefinitionExpression
  • FeatureLayer
  • ServiceFeatureTable


DefinitionExpression, ServiceFeatureTable, definition expression, filter, limit data, query, restrict data, sql where clause

Sample Code

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns=""
            <RowDefinition Height="auto" />
            <RowDefinition Height="*" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
        <Button Clicked="OnApplyExpressionClicked" Text="Apply Expression" Grid.Row="0" Grid.Column="0" />
        <Button Clicked="OnResetButtonClicked" Text="Reset" Grid.Row="0" Grid.Column="1" />
        <esriUI:MapView x:Name="MyMapView" Grid.Row="1" Grid.ColumnSpan="2" />
// Copyright 2016 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 Xamarin.Forms;

namespace ArcGISRuntime.Samples.FeatureLayerDefinitionExpression
        "Feature layer definition expression",
        "This sample demonstrates how to apply definition expression to a feature layer for filtering features. It also shows how to reset the definition expression.",
    public partial class FeatureLayerDefinitionExpression : ContentPage
        //Create and hold reference to the feature layer
        private FeatureLayer _featureLayer;

        public FeatureLayerDefinitionExpression()
            InitializeComponent ();

            //setup the control references and execute initialization 

        private void Initialize()
            // Create new Map with basemap
            Map myMap = new Map(Basemap.CreateTopographic());

            // Create a MapPoint the map should zoom to
            MapPoint mapPoint = new MapPoint(
                -13630484, 4545415, SpatialReferences.WebMercator);

            // Set the initial viewpoint for map
            myMap.InitialViewpoint = new Viewpoint(mapPoint, 90000);

            // Provide used Map to the MapView
            MyMapView.Map = myMap;

            // Create the uri for the feature service
            Uri featureServiceUri = new Uri(

            // Initialize feature table using a url to feature server url
            ServiceFeatureTable featureTable = new ServiceFeatureTable(featureServiceUri);

            // Initialize a new feature layer based on the feature table
            _featureLayer = new FeatureLayer(featureTable);

            //Add the feature layer to the map

        private void OnApplyExpressionClicked(object sender, EventArgs e)
            // Adding definition expression to show specific features only
            _featureLayer.DefinitionExpression = "req_Type = 'Tree Maintenance or Damage'";

        private void OnResetButtonClicked(object sender, EventArgs e)
            // Reset the definition expression to see all features again
            _featureLayer.DefinitionExpression = "";