Add rasters and feature tables from a geopackage to a map.
Use case
The OGC GeoPackage specification defines an open standard for sharing raster and vector data. You may want to use GeoPackage files to support file-based sharing of geographic data.
How to use the sample
When the sample loads, the feature tables and rasters from the GeoPackage will be shown on the map.
How it works
- Create a GeoPackage from a named bundle resource using
AGSGeoPackage.init(name:)
. - Load the GeoPackage using
AGSGeoPackage.load(completion:)
. - Iterate through available rasters, exposed by
AGSGeoPackage.geoPackageRasters
.- For each raster, create an
AGSRasterLayer
object and add it to the map.
- For each raster, create an
- Iterate through available feature tables, exposed by
AGSGeoPackage.geoPackageFeatureTables
.- For each feature table, create an
AGSFeatureLayer
object and add it to the map.
- For each feature table, create an
Relevant API
- AGSGeoPackage
- AGSGeoPackage.geoPackageFeatureTables
- AGSGeoPackage.geoPackageRasters
- AGSGeoPackageFeatureTable
- AGSGeoPackageRaster
Offline data
The Aurora Colorado GeoPackage holds datasets that cover Aurora, Colorado.
About the data
This sample features a GeoPackage with datasets that cover Aurora, Colorado: Public art (points), Bike trails (lines), Subdivisions (polygons), Airport noise (raster), and liquor license density (raster).
Additional information
GeoPackage uses a single SQLite file (.gpkg) that conforms to the OGC GeoPackage Standard. You can create a GeoPackage file (.gpkg) from your own data using the create a SQLite Database tool in ArcGIS Pro.
Tags
container, GeoPackage, layer, map, OGC, package, raster, table
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 ReadGeopackageViewController: UIViewController, UIPopoverPresentationControllerDelegate {
@IBOutlet weak var mapView: AGSMapView! {
didSet {
mapView.map = makeMap()
mapView.setViewpoint(AGSViewpoint(latitude: 39.7294, longitude: -104.8319, scale: 288895.277144))
}
}
func makeMap() -> AGSMap {
// Instantiate a map.
let map = AGSMap(basemapStyle: .arcGISStreets)
// Create a geopackage from a named bundle resource.
let 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
}
// Create feature layers for each feature table in the geopackage.
let featureLayers = geoPackage.geoPackageFeatureTables.map { AGSFeatureLayer(featureTable: $0) }
// Create raster layers for each raster in the geopackage.
let rasterLayers = geoPackage.geoPackageRasters.map { raster -> AGSLayer in
let rasterLayer = AGSRasterLayer(raster: raster)
// make it semi-transparent so it doesn't obscure the contents under it
rasterLayer.opacity = 0.55
return rasterLayer
}
// Add the arrays of feature and raster layers to the map.
map.operationalLayers.addObjects(from: rasterLayers)
map.operationalLayers.addObjects(from: featureLayers)
}
return map
}
override func viewDidLoad() {
super.viewDidLoad()
// Add the source code button item to the right of navigation bar.
(self.navigationItem.rightBarButtonItem as! SourceCodeBarButtonItem).filenames = ["ReadGeopackageViewController"]
}
}