Display a raster contained in a 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
- Create and load an
AGSGeoPackage
, specifying the URL to the local .gpkg file. - When it is done loading, get the
AGSGeoPackageRaster
s from the geopackage. - Construct an
AGSRasterLayer
with the geopackage raster you want to use. - 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
// 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))
}
}