Raster layer (geopackage)

View on GitHubSample viewer app

Display a raster contained in a GeoPackage.

Raster layer (geopackage)

Use case

GeoPackages are designed to simplify file management and transfer. They can store raster files (as well as other types of data). An end-user wishing to transfer rasters from ArcGIS Pro or between runtime apps, might need to import raster files from GeoPackages into their map to view and analyze the data.

How to use the sample

When the sample starts, a raster will be loaded from a GeoPackage and displayed in the map view. Pan and zoom to explore.

How it works

  1. Create and load an AGSGeoPackage, specifying the URL to the local .gpkg file.
  2. When it is done loading, get the AGSGeoPackageRasters from the geopackage.
  3. Construct an AGSRasterLayer with the geopackage raster you want to use.
  4. Add the raster layer to the map.

Relevant API

  • AGSGeoPackage
  • AGSGeoPackageRaster
  • AGSRasterLayer

About the data

The Aurora Colorado GeoPackage holds datasets that cover Aurora, Colorado. The raster that is opened and displayed shows airport noise levels.

Tags

container, data, image, import, layer, OGC, package, raster, visualization

Sample Code

RasterLayerGPKGViewController.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
53
54
// 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 RasterLayerGPKGViewController: 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 = ["RasterLayerGPKGViewController"]

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

        // 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 raster from the geopackage to the map.
            if let raster = self?.geoPackage?.geoPackageRasters.first {
                let rasterLayer = AGSRasterLayer(raster: raster)
                // make it semi-transparent so it doesn't obscure the contents under it
                rasterLayer.opacity = 0.55
                map.operationalLayers.add(rasterLayer)
            }
        }

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

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

You can no longer sign into this site. Go to your ArcGIS portal or the ArcGIS Location Platform dashboard to perform management tasks.

Your ArcGIS portal

Create, manage, and access API keys and OAuth 2.0 developer credentials, hosted layers, and data services.

Your ArcGIS Location Platform dashboard

Manage billing, monitor service usage, and access additional resources.

Learn more about these changes in the What's new in Esri Developers June 2024 blog post.

Close