Feature layer (geodatabase)

View inAndroidUWPiOSView on GitHub

Display features from a local geodatabase.

Image of feature layer geodatabase

Use case

Accessing data from a local geodatabase is useful when working in an environment that has an inconsistent internet connection or that does not have an internet connection at all. For example, a department of transportation field worker might source map data from a local geodatabase when conducting signage inspections in rural areas with poor network coverage.

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

Additional information

One of the ArcGIS Runtime data set types that can be accessed via the local storage of the device (i.e. hard drive, flash drive, micro SD card, USB stick, etc.) is a mobile geodatabase. 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 to point to a Uri instead.

Tags

geodatabase, mobile, offline

Sample Code

FeatureLayerGeodatabase.cs
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// 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 ArcGISRuntime.Samples.Managers;
using Esri.ArcGISRuntime.Data;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.UI.Controls;
using Foundation;
using UIKit;

namespace ArcGISRuntime.Samples.FeatureLayerGeodatabase
{
    [Register("FeatureLayerGeodatabase")]
    [ArcGISRuntime.Samples.Shared.Attributes.OfflineData("2b0f9e17105847809dfeb04e3cad69e0")]
    [ArcGISRuntime.Samples.Shared.Attributes.Sample(
        name: "Feature layer (geodatabase)",
        category: "Data",
        description: "Display features from a local geodatabase.",
        instructions: "",
        tags: new[] { "geodatabase", "mobile", "offline" })]
    public class FeatureLayerGeodatabase : UIViewController
    {
        // Hold references to UI controls.
        private MapView _myMapView;

        public FeatureLayerGeodatabase()
        {
            Title = "Feature layer (geodatabase)";
        }

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

            // Get the path to the downloaded mobile geodatabase (.geodatabase file).
            string mobileGeodatabaseFilePath = DataManager.GetDataFolder("2b0f9e17105847809dfeb04e3cad69e0", "LA_Trails.geodatabase");

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

                // Get the 'Trailheads' geodatabase feature table from the mobile geodatabase.
                GeodatabaseFeatureTable trailheadsGeodatabaseFeatureTable = mobileGeodatabase.GetGeodatabaseFeatureTable("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)
            {
                new UIAlertView("Error", e.ToString(), (IUIAlertViewDelegate) null, "OK", null).Show();
            }
        }

        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            Initialize();
        }

        public override void LoadView()
        {
            // Create the views.
            _myMapView = new MapView();
            _myMapView.TranslatesAutoresizingMaskIntoConstraints = false;

            View = new UIView() { BackgroundColor = ApplicationTheme.BackgroundColor };

            // Add the views.
            View.AddSubviews(_myMapView);

            // Lay out the views.
            NSLayoutConstraint.ActivateConstraints(new[]
            {
                _myMapView.TopAnchor.ConstraintEqualTo(View.SafeAreaLayoutGuide.TopAnchor),
                _myMapView.BottomAnchor.ConstraintEqualTo(View.BottomAnchor),
                _myMapView.LeadingAnchor.ConstraintEqualTo(View.LeadingAnchor),
                _myMapView.TrailingAnchor.ConstraintEqualTo(View.TrailingAnchor)
            });
        }
    }
}

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.