Skip To Content ArcGIS for Developers Sign In Dashboard

ArcGIS Runtime SDK for .NET

Feature layer (geodatabase)

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

Display features from a local geodatabase.

screenshot

Use case

Useful for applications which consume data maintained by a local source (e.g. a geodatabase) on the device running the application.

How it works

  1. Create a geodatabase using the provided local resource, new Geodatabase(geodatabaseResourceUrl).
  2. Wait for geodatabase to load.
  3. Get the 'Trailheads' GeodatabaseFeatureTable from the geodatabase, Geodatabase.GeodatabaseFeatureTable(tableName).
  4. Create feature layer using the table from above, new FeatureLayer(geodatabaseFeatureTable).
  5. Add feature layer to Map with Map.OperationalLayers.Add(featureLayer).

Relevant API

  • FeatureLayer
  • Geodatabase
  • GeodatabaseFeatureTable

Offline data

This sample downloads the following items from ArcGIS Online automatically:

Additional information

One of the ArcGIS Runtime data set types that can be accessed via the local storage (i.e. hard drive, flash drive, micro SD card, USB stick, etc.) of the device is a mobile geodatabase. One of the primary advantages of the mobile geodatabase is that it allows users to access feature data in their map without having to be connected to the internet. A mobile geodatabase can be provisioned for use in an ArcGIS Runtime application by ArcMap. The following provide some helpful tips on how to create a mobile geodatabase file:

In ArcMap, choose File > Share As > ArcGIS Runtime Content from the menu items to create the .geodatabase file (see the document: http://desktop.arcgis.com/en/arcmap/latest/map/working-with-arcmap/creating-arcgis-runtime-content.htm).

Note: You could also use the 'Services Pattern' and access the Geodatabase class via a Feature Service served up via ArcGIS Online or ArcGIS Enterprise. Instead of using the Geodatabase class to access the .geodatabase file on disk, you would use GeodatabaseSyncTask point to a Uri instead. For more information review the document: https://developers.arcgis.com/net/latest/wpf/guide/create-an-offline-layer.htm.

Tags

geodatabase, mobile, offline

Sample Code

<UserControl 
    x:Class="ArcGISRuntime.UWP.Samples.FeatureLayerGeodatabase.FeatureLayerGeodatabase"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:esriUI="using:Esri.ArcGISRuntime.UI.Controls" >
    <esriUI:MapView x:Name="MyMapView" />
</UserControl>
// Copyright 2018 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: http://www.apache.org/licenses/LICENSE-2.0
//
// 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 System;
using Windows.UI.Popups;
using Esri.ArcGISRuntime.Mapping;
using ArcGISRuntime.Samples.Managers;
using Esri.ArcGISRuntime.Data;

namespace ArcGISRuntime.UWP.Samples.FeatureLayerGeodatabase
{
    [ArcGISRuntime.Samples.Shared.Attributes.Sample(
        "Feature layer (geodatabase)",
        "Data",
        "This sample demonstrates how to consume an Esri .geodatabase file (aka. mobile geodatabase) by using a FeatureLayer and a GeodatabaseFeatureTable.",
        "The mobile geodatabase (.geodatabase file) will be downloaded from an ArcGIS Online portal automatically from the Url: https://www.arcgis.com/home/item.html?id=2b0f9e17105847809dfeb04e3cad69e0.",
        "")]
    [ArcGISRuntime.Samples.Shared.Attributes.OfflineData("2b0f9e17105847809dfeb04e3cad69e0")]
    public partial class FeatureLayerGeodatabase
    {
        public FeatureLayerGeodatabase()
        {
            InitializeComponent();

            // Open a mobile geodatabase (.geodatabase file) stored locally and add it to the map as a feature layer.
            Initialize();
        }

        private async void Initialize()
        {
            // Create a new map to display in the map view with a streets basemap.
            MyMapView.Map = new Map(Basemap.CreateStreets());

            // Get the path to the downloaded mobile geodatabase (.geodatabase file).
            string mobileGeodatabaseFilePath = GetMobileGeodatabasePath();

            try
            {
                // Open the mobile geodatabase.
                Geodatabase mobileGeodatabase = await Geodatabase.OpenAsync(mobileGeodatabaseFilePath);

                // Get the 'Trailheads' geodatabase feature table from the mobile geodatabase.
                GeodatabaseFeatureTable trailheadsGeodatabaseFeatureTable = mobileGeodatabase.GeodatabaseFeatureTable("Trailheads");

                // Asynchronously load the 'Trailheads' geodatabase feature table.
                await trailheadsGeodatabaseFeatureTable.LoadAsync();

                // Create a feature layer based on the geodatabase feature table.
                FeatureLayer trailheadsFeatureLayer = new FeatureLayer(trailheadsGeodatabaseFeatureTable);

                // Add the feature layer to the operations layers collection of the map.
                MyMapView.Map.OperationalLayers.Add(trailheadsFeatureLayer);

                // Zoom the map to the extent of the feature layer.
                await MyMapView.SetViewpointGeometryAsync(trailheadsFeatureLayer.FullExtent, 50);
            }
            catch (Exception e)
            {
                await new MessageDialog(e.ToString(), "Error").ShowAsync();
            }
        }

        private static string GetMobileGeodatabasePath()
        {
            // Use samples viewer's DataManager helper class to get the path of the downloaded dataset on disk.
            // NOTE: The url for the actual data is: https://www.arcgis.com/home/item.html?id=2b0f9e17105847809dfeb04e3cad69e0.
            return DataManager.GetDataFolder("2b0f9e17105847809dfeb04e3cad69e0", "LA_Trails.geodatabase");
        }
    }
}