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.
Iterate through available feature tables, exposed by AGSGeoPackage.geoPackageFeatureTables.
For each feature table, create an AGSFeatureLayer object and add it to the map.
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.
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
// 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
classReadGeopackageViewController: UIViewController, UIPopoverPresentationControllerDelegate{
@IBOutletweakvar mapView: AGSMapView! {
didSet {
mapView.map = makeMap()
mapView.setViewpoint(AGSViewpoint(latitude: 39.7294, longitude: -104.8319, scale: 288895.277144))
}
}
funcmakeMap() -> 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 { [weakself] error inguard error ==nilelse {
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 -> AGSLayerinlet rasterLayer =AGSRasterLayer(raster: raster)
// make it semi-transparent so it doesn't obscure the contents under it rasterLayer.opacity =0.55return rasterLayer
}
// Add the arrays of feature and raster layers to the map. map.operationalLayers.addObjects(from: rasterLayers)
map.operationalLayers.addObjects(from: featureLayers)
}
return map
}
overridefuncviewDidLoad() {
super.viewDidLoad()
// Add the source code button item to the right of navigation bar. (self.navigationItem.rightBarButtonItem as!SourceCodeBarButtonItem).filenames = ["ReadGeopackageViewController"]
}
}