Skip To Content ArcGIS for Developers Sign In Dashboard

ArcGIS Runtime SDK for Qt

Read a GeoPackage

Sample Viewer View Sample on GitHub

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

  1. Create a GeoPackage object using the path the local geoPackage.
  2. Connect to the GeoPackage.loadStatusChanged signal.
  3. Load the geoPackage geoPackage.load(), then iterate through the available rasters, exposed by geopackage.geoPackageRasters.
    • For each raster, create a raster layer then add it to the map.
  4. Iterate through available feature tables, exposed by geopackage.geoPackageFeatureTables.
    • For each feature table, create a feature layer then add it to the map.

Relevant API

  • GeoPackage
  • GeoPackage.loadStatusChanged
  • GeoPackage.geoPackageFeatureTables
  • GeoPackage.geoPackageRasters
  • GeoPackageFeatureTable
  • GeoPackageRaster

Offline data

Read more about how to set up the sample's offline data here.

Link Local Location
AuroraCO.gpkg <userhome>/ArcGIS/Runtime/Data/gpkg/AuroraCO.gpkg

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 liquour 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

import QtQuick 2.6
import Esri.ArcGISRuntime 100.9
import Esri.ArcGISExtras 1.1

Rectangle {
    id: rootRectangle
    clip: true
    width: 800
    height: 600

    readonly property string dataPath: System.userHomePath + "/ArcGIS/Runtime/Data/gpkg/"

    MapView {
        id: mapView
        anchors.fill: parent

        Map {
            id: map
            initialViewpoint: vc
            BasemapTopographic {}
        }

        ViewpointCenter {
            id: vc
            center: Point {
                x: -104.8319
                y: 39.7294
                spatialReference: SpatialReference {
                    wkid: 4326
                }
            }

            targetScale: 500000
        }
    }

    // Load and read the GeoPackage
    GeoPackage {
        id: gpkg
        path: dataPath + "AuroraCO.gpkg"

        // Initial check to see if GeoPackage is loaded and not empty
        onLoadStatusChanged: {
            if (loadStatus !== Enums.LoadStatusLoaded)
                return;

            if (!gpkg.geoPackageRasters.length > 0 && !gpkg.geoPackageFeatureTables.length > 0)
                return;

            // For each raster, create a raster layer and add the layer to the map
            for (let k = 0; k < gpkg.geoPackageRasters.length; k++){
                const raster = gpkg.geoPackageRasters[k];
                const rasterLayer = ArcGISRuntimeEnvironment.createObject("RasterLayer", {raster: raster}, gpkg);
                rasterLayer.opacity = 0.55;
                map.operationalLayers.append(rasterLayer);
            }

            // For each feature table, create a feature layer and add the layer to the map
            for (let i = 0; i < gpkg.geoPackageFeatureTables.length; i++){
                const featureLayer = ArcGISRuntimeEnvironment.createObject("FeatureLayer", {featureTable: gpkg.geoPackageFeatureTables[i]}, gpkg);
                map.operationalLayers.append(featureLayer);
            }
        }

        Component.onCompleted: load()
    }
}