Feature layer (geopackage)

View on GitHub
Sample viewer app

Display features from a local GeoPackage.

Feature layer (geopackage)

Use case

A GeoPackage is an OGC standard, making it useful when your project requires an open source data format or when other, non-ArcGIS systems may be creating the data. Accessing data from a local GeoPackage 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 GeoPackage when conducting signage inspections in rural areas with poor network coverage.

How to use the sample

Pan and zoom around the map. View the data loaded from the geopackage.

How it works

  1. Create an AGSGeoPackage using the provided local resource, AuroraCO.
  2. Load the AGSGeoPackage with AGSGeoPackage.load(completion:).
  3. When it's done loading, get the first feature layer from the AGSGeoPackages array of AGSGeoPackageFeatureTables.
  4. Create an AGSFeatureLayer for the first AGSFeatureTable.
  5. Add it to the map's array of operationalLayers.

Relevant API

  • AGSFeatureLayer
  • AGSGeoPackage
  • AGSGeoPackageFeatureTable
  • AGSMap

Offline data

This sample uses the Aurora, Colorado GeoPackage. It is downloaded from ArcGIS Online automatically.

About the data

The map shows point locations of public art installations in Aurora, Colorado.

Tags

feature table, geopackage, gpkg, OGC, package, standards

Sample Code

FeatureLayerGPKGViewController.swift
                                                    
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
// Copyright 2017 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.

import ArcGIS

class FeatureLayerGPKGViewController: UIViewController {
    @IBOutlet weak var mapView: AGSMapView!

    var geoPackage: AGSGeoPackage?

    override func viewDidLoad() {
        super.viewDidLoad()

        // add the source code button item to the right of navigation bar
        (self.navigationItem.rightBarButtonItem as! SourceCodeBarButtonItem).filenames = ["FeatureLayerGPKGViewController"]

        // Instantiate a map.
        let map = AGSMap(basemapStyle: .arcGISLightGrayBase)

        // Display the map in the map view.
        mapView.map = map
        mapView.setViewpoint(AGSViewpoint(latitude: 39.7294, longitude: -104.8319, scale: 577790.554289))

        // Create a geopackage from a named bundle resource.
        geoPackage = AGSGeoPackage(name: "AuroraCO")

        // Load the geopackage.
        geoPackage?.load { [weak self] error in
            guard error == nil else {
                self?.presentAlert(message: "Error opening Geopackage: \(error!.localizedDescription)")
                return
            }

            // Add the first feature layer from the geopackage to the map.
            if let featureTable = self?.geoPackage?.geoPackageFeatureTables.first {
                let featureLayer = AGSFeatureLayer(featureTable: featureTable)
                map.operationalLayers.add(featureLayer)
            }
        }
    }
}

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