Skip To Content

Access feature data in the cloud

In this topic

An ArcGIS feature service provide features (geometry, attributes, and symbology) from a REST endpoint. ArcGIS Runtime SDK applications can query a service to get a set of features to display in the map. You can display features with the symbols that have been defined with the service, or create custom ones.

This tutorial introduces you to using ArcGIS feature services for displaying information in your map. You will learn the basic techniques involved for working with feature services both in XAML and programmatically using C# or Visual Basic .NET (VB .NET). Your completed app will display a filtered subset of features from a feature service using a custom symbol. You will also add identify functionality to show feature attributes when a feature is clicked on the map.

Prerequisites

This tutorial requires a supported version of Microsoft Visual Studio and ArcGIS Runtime SDK for .NET. Refer to the appropriate topics in the guide for information on installing the SDK and system requirements.

Familiarity with Visual Studio and a basic understanding of XAML and C# or VB .NET is recommended.

Create a Windows Store app

You'll use Visual Studio to create a Windows Store app.

  1. Open a supported version of Microsoft Visual Studio.
  2. Choose File > New > Project (or click New Project on the Start page) to create a project.
  3. Click Store Apps > Windows Apps > Blank App (Windows) in the New Project dialog box (you can create your project in either C# or VB .NET).
    Note:

    Visual Studio 2015 organizes project types slightly differently. You'll find Store projects under Windows 8 > Windows

    Tip:

    ArcGIS Runtime SDK for .NET provides a project template for creating your mapping app, called ArcGIS Runtime 10.2.7 for .NET App. Creating your project from the template will add the appropriate references and a page with a map view containing a single base layer. In this tutorial, you'll build your app from a blank template.

  4. Choose a folder location for your new project and name it AccessFeatureData.

    Visual Studio New Project dialog box

  5. Click OK to create the project.

    Your project opens in Visual Studio and contains a single page called MainPage.xaml.

  6. Next, you'll add a reference to the ArcGIS Runtime SDK for .NET API assembly.
  7. Right-click the References node under the AccessFeatureData project listing in the Visual Studio Solution Explorer window, and click Add Reference in the context menu.
  8. Check the listing for the ArcGIS Runtime for Windows Store apps assembly under Windows 8.1 > Extensions.

    Visual Studio Reference Manager dialog box

  9. Click OK to add the reference to ArcGIS Runtime for .NET.

    Visual Studio project references

  10. Note:

    In order for your app to build, you need to specify a build target for the project. The default value of Any CPU will not work and is why the new references are shown with a yellow warning icon.

    You will now specify a build platform for the app.

  11. Choose BUILD > Configuration Manager.
  12. Choose x86 in the Active solution platform drop-down menu. This will target a 32-bit platform for the app.

  13. Click Close in the Configuration Manager dialog box.

    The warning icons no longer appear in the Solution Explorer window for these references.

Create a map control with an imagery basemap

Now that you've created a simple project and added a reference to ArcGIS Runtime, you're ready to add a map to your app. ArcGIS Runtime allows you to work with geographic data from a variety of sources, including those local to your app as well as data provided remotely as an Internet service. In your map, you'll display satellite imagery data from a public map service provided by ArcGIS Online.

    To use the library in the XAML designer, you must first make a reference to the XML namespace for ArcGIS Runtime.
  1. Open the MainPage.xaml file in the Visual Studio designer.
  2. Go to the XAML view of the designer, and add the following XML namespace reference to the Page XAML element. Visual Studio offers IntelliSense to help complete the URL portion of the statement.
    xmlns:esri="using:Esri.ArcGISRuntime.Controls"
    xmlns:layers="using:Esri.ArcGISRuntime.Layers"
    xmlns:data="using:Esri.ArcGISRuntime.Data"
    xmlns:sym="using:Esri.ArcGISRuntime.Symbology"
  3. Next, you'll add a MapView containing a Map control to the window and define a basemap layer.
  4. Add the following XAML inside the <Grid> element to define a new MapView control on the page:
    <esri:MapView x:Name="MyMapView">
       <esri:Map x:Name="MyMap">
       </esri:Map>
     </esri:MapView>
  5. Add the following XAML inside the Map element to define an ArcGIS Online basemap layer to display in the map:
    <layers:ArcGISTiledMapServiceLayer ID="BaseMap" 
        ServiceUri="http://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer"/>

    Basemaps provide the context and a framework for working with information geographically. A basemap is used for locational reference and presents a framework on which to overlay your operational layers, perform tasks, and visualize geographic information. In the following steps, you'll overlay a feature layer with the basemap.

    Tip:

    In addition to the World imagery map, ArcGIS Online provides basemaps of streets, topographic data, historical maps, and many others. Visit Living Atlas of the World to browse some of the available basemaps. If you find a basemap you'd like to use in your app, you can copy the service URI from its description page.

Add a feature layer to provide operational data

Next, you'll add a FeatureLayer to serve as your operational layer. Operational layers are layers whose data is generally more dynamic and represents the focus of the work performed in the map, such as performing analysis or edits on features.

  1. Add the following XAML to define a FeatureLayer to display on top of the imagery basemap layer you defined earlier. Note that layers appearing first inside the Map contents display below layers that are defined later. The following XAML, therefore, is placed below the XAML that defines the basemap layer.
    <layers:FeatureLayer ID="PoolPermits">    
        <layers:FeatureLayer.FeatureTable>
            <data:ServiceFeatureTable
        ServiceUri="http://sampleserver6.arcgisonline.com/arcgis/rest/services/PoolPermits/FeatureServer/0"/>
        </layers:FeatureLayer.FeatureTable>
    </layers:FeatureLayer>

    The FeatureLayer represents a single layer from an ArcGIS feature service. The ID property provides a unique identifier for the layer that can be used to refer to the layer programmatically. The FeatureTable defines the data source for the layer by specifying a ServiceFeatureTable and its ServiceUri property. The layer above will display parcels in Riverside, California. It has attributes to describe whether or not each parcel has a swimming pool and whether the proper permit has been obtained.

  2. Since the operational layer in your app is focused on a small area of the city of Riverside California, you'll define an initial extent for the map that centers on the area of interest.
  3. Add the following XAML inside your Map element:
    <esri:Map.InitialViewpoint>
        <esri:ViewpointExtent XMin="-13075816.40" 
                       YMin="4014771.46" 
                       XMax="-13073005.67" 
                       YMax="4016869.78"/>
     </esri:Map.InitialViewpoint>

    The values for the initial map extent were obtained by consulting the REST page for the pool permits layer (available through the ServiceUri property). This ensures that the map extent contains the full extent of the operational layer when the app is initially started.

  4. You are now ready to test your app.
  5. Click the Start button on the Standard toolbar (or DEBUG > Start Debugging) to start your app. A map similar to the following is displayed:

    App showing imagery and pool permits layer for Riverside, CA

    The map displays an imagery basemap overlaid with the swimming pool permits layer at the extent of the operational layer. The features in red are lots that have a pool but have not been issued a permit for one. To simplify the map display, you'll filter this layer to include only the parcels that are in violation and display them with a custom polygon symbol.

Filter features displayed in the feature layer

When working with a feature layer, you have the option of filtering the display of features in the layer based on an attribute expression. This allows you to customize the data source to fit your app by excluding irrelevant information.

You'll use the service's REST page to see what attribute values are available for the layer.

  1. Open a web browser and navigate to the URI for the pool permits layer: http://sampleserver6.arcgisonline.com/arcgis/rest/services/PoolPermits/FeatureServer/0.
  2. Scroll to the Fields section.

    REST page for the pool permits layer

    To filter the display of the features in your pool permits layer, you'll use values in the pool_permit and has_pool fields. Notice that these fields are of integer type, and based on the coded value domain, a value of 0 means "No" and 1 means "Yes".

  3. Add the following XAML to the GeodatabaseFeatureTable element to define the Where property for the FeatureLayer:

    <layers:FeatureLayer ID="PoolPermits">
      <layers:FeatureLayer.FeatureTable>
        <data:ServiceFeatureTable Where="has_pool = 1 AND pool_permit = 0"
           ServiceUri="http://sampleserver6.arcgisonline.com/arcgis/rest/services/PoolPermits/FeatureServer/0"/>
      </layers:FeatureLayer.FeatureTable>
    </layers:FeatureLayer>

  4. Run the app. Your map now displays only those features that meet the criteria you've specified: lots with a pool that do not have a permit.

    Map filtered to show only lots that have a pool but no permit

Customize feature layer display

In addition to controlling which features appear in a feature layer, you can also apply your own rendering suited to your app. In the following steps, you'll symbolize the pool permits layer with your own polygon symbol rather than the rendering defined in the feature service.

  1. Add the following XAML inside the FeatureLayer element to define a new SimpleRenderer for the layer. This defines a simple renderer with a single fill symbol. The symbol will have a hashed aqua fill and a dotted red outline.

    <layers:FeatureLayer.Renderer>
      <sym:SimpleRenderer>
        <sym:SimpleFillSymbol Color="Aqua" Style="DiagonalCross">
           <sym:SimpleFillSymbol.Outline>
              <sym:SimpleLineSymbol Color="Firebrick" Width="4" Style="Solid"/>
           </sym:SimpleFillSymbol.Outline>
        </sym:SimpleFillSymbol>
      </sym:SimpleRenderer>
    </layers:FeatureLayer.Renderer>

  2. Run the app. Your custom symbology is applied to the features.

    Pool permits layer with new symbol applied

Display information about features

A map or feature service can also be accessed programmatically to return information about particular features. In the following steps, you'll create functionality to retrieve information about a feature clicked by the user on the map. This functionality will work for all features in the service, including those that are not currently shown on the map.

  1. Add the following XAML to define a UI for displaying parcel information (APN and address). This XAML should go below the XAML that defines your MapView to ensure it displays on top of that control.

    <StackPanel Orientation="Vertical" Background="Blue" Opacity=".8"
           HorizontalAlignment="Left" VerticalAlignment="Top">
        <StackPanel Orientation="Horizontal" Margin="5">
            <TextBlock Text="Address:" FontWeight="Bold"/>
            <TextBlock x:Name="AddressTextBlock" Text="--" Margin="5,0"/>
        </StackPanel>
        <StackPanel Orientation="Horizontal" Margin="5">
            <TextBlock Text="APN:" FontWeight="Bold"/>
            <TextBlock x:Name="ApnTextBlock" Text="--" Margin="5,0"/>
        </StackPanel>
            <Button x:Name="GetParcelAddressButton" Content="Get Parcel Info"/>
    </StackPanel>

  2. Add the following XAML to the GetParcelAddressButton button to define an event handler for the Click event. When prompted by IntelliSense, create a new event handler. The event handler is given the default name of GetParcelAddressButton_Click.

    <Button x:Name="GetParcelAddressButton" 
        Content="Get Parcel Info" 
        Click="GetParcelAddressButton_Click"/>

  3. In the XAML Editor, right-click the name of the event handler (GetParcelAddressButton_Click) and choose Go To Definition in the context menu that appears.

    Visual Studio Go To Definition context menu.

    Visual Studio takes you to the Code Editor view. Before working on the code for the button click handler, you need to add a couple of using statements for required namespaces.

  4. At the top of your MainPage.xaml.cs code module, add the following using statements:

    using Esri.ArcGISRuntime.Layers;
    using Esri.ArcGISRuntime.Tasks.Query;

  5. While the MapView control exposes interaction events, such as MouseUp, MouseDown, TouchUp, and TouchDown, these events aren't always the best places to capture geometry from the user. Such events on the control will fire when the user zooms and pans on the map, which might require you to add logic to handle multiple types of map interaction.

    Each MapView control has an associated Editor that is accessible from the Editor property. In addition to helping you configure editing functionality, the Editor class provides methods for obtaining geometry from the user. You'll use the RequestPointAsync method on the Editor to get a point for identifying a parcel on the map.

  6. Return to the GetParcelAddressButton_Click event handler. Start your function with the following code to get the map point for the location clicked by the user:

    var mapPoint = await MyMapView.Editor.RequestPointAsync();

    Using the await keyword, your query will complete asynchronously before the code below it is executed. The compiler treats this code as a callback for the function called with await. To use the await keyword, however, you must mark the function containing it with the async keyword.

    Note:

    See the Asynchronous programming topic for more information about the .NET task-based asynchronous pattern.

  7. Add the async keyword to the definition of the GetParcelAddressButton_Click handler.

    private async void GetParcelAddressButton_Click(object sender, RoutedEventArgs e)

  8. Return to the body of your function. Add the following code to set up a QueryTask object that will find a feature at the location specified by the user:

    var poolPermitUrl = "http://sampleserver6.arcgisonline.com/arcgis/rest/services/PoolPermits/FeatureServer/0";
    var queryTask = new QueryTask(new System.Uri(poolPermitUrl));
    var queryFilter = new Query(mapPoint);
    queryFilter.OutFields.Add("apn");
    queryFilter.OutFields.Add("address");

    Notice that the QueryTask constructor takes an argument that specifies the URI for the service to query. The Query object defines the spatial and/or attribute criteria (the where clause) for the query. The previous code uses the map point to do a spatial search using the default spatial relationship, which is SpatialRelationship.Intersects. Since you need to display the APN and address values for the feature, those fields must be added to the OutFields collection, as shown in the previous code example.

  9. Add the following code to execute the query. If a result is found, its APN and address values are displayed in the UI.

    var queryResult = await queryTask.ExecuteAsync(queryFilter);
    if (queryResult.FeatureSet.Features.Count > 0)
    {
      var resultGraphic = queryResult.FeatureSet.Features[0] as Graphic;
      ApnTextBlock.Text = resultGraphic.Attributes["apn"].ToString();
      AddressTextBlock.Text = resultGraphic.Attributes["address"].ToString();
    }

  10. Run your app. Zoom in to a part of the map displaying pool permit features. Click the Get Parcel Info button, then click one of the features in the map to display its APN and address values. Click the button again, and try a neighboring parcel that is not currently displayed in the map. You'll see information for these locations as well.

    Clicking the map to get parcel information

In this tutorial, you learned how to access, filter, and display data from an ArcGIS feature service. As you can see, feature layers give you flexibility to modify the content and appearance of feature service data for use in your app. To learn more, take a look at the many samples available that illustrate the use of feature layers.

Related topics