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
object using the path the local geoPackage. - Connect to the
GeoPackage::doneLoading
signal. - Load the geoPackage
geoPackage::load()
, then iterate through the available rasters, exposed bygeopackage::geoPackageRasters
.- For each raster, create a raster layer using
new Rasterlayer(geopackageRaster)
, then add it to the map.
- For each raster, create a raster layer using
- Iterate through available feature tables, exposed by
geopackage::geoPackageFeatureTables
.- For each feature table, create a feature layer using
new FeatureLayer(geopackageFeatureTable)
, then add it to the map.
- For each feature table, create a feature layer using
Relevant API
- GeoPackage
- GeoPackage::doneLoading
- 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
// [WriteFile Name=ReadGeoPackage, Category=Maps]
// [Legal]
// Copyright 2018 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.
// [Legal]
#ifdef PCH_BUILD
#include "pch.hpp"
#endif // PCH_BUILD
#include "ReadGeoPackage.h"
#include "Map.h"
#include "Layer.h"
#include "GeoPackage.h"
#include "RasterLayer.h"
#include "MapQuickView.h"
#include "FeatureTable.h"
#include "FeatureLayer.h"
#include "GeoPackageRaster.h"
#include "GeoPackageFeatureTable.h"
#include <QDir>
#include <QtCore/qglobal.h>
#ifdef Q_OS_IOS
#include <QStandardPaths>
#endif // Q_OS_IOS
using namespace Esri::ArcGISRuntime;
// helper method to get cross platform data path
namespace
{
QString defaultDataPath()
{
QString dataPath;
#ifdef Q_OS_ANDROID
dataPath = "/sdcard";
#elif defined Q_OS_IOS
dataPath = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
#else
dataPath = QDir::homePath();
#endif
return dataPath;
}
} // namespace
ReadGeoPackage::ReadGeoPackage(QQuickItem* parent /* = nullptr */):
QQuickItem(parent),
m_dataPath(defaultDataPath() + "/ArcGIS/Runtime/Data")
{
}
void ReadGeoPackage::init()
{
// Register the map view for QML
qmlRegisterType<MapQuickView>("Esri.Samples", 1, 0, "MapView");
qmlRegisterType<ReadGeoPackage>("Esri.Samples", 1, 0, "ReadGeoPackageSample");
}
void ReadGeoPackage::componentComplete()
{
QQuickItem::componentComplete();
// find QML MapView component
m_mapView = findChild<MapQuickView*>("mapView");
// Create a map using the topographic basemap
m_map = new Map(BasemapStyle::ArcGISTopographic, this);
// Set map to map view
m_mapView->setMap(m_map);
// Create the initial view area
const Viewpoint initialViewpoint(39.7294, -104.8319, 500000);
m_mapView->setViewpoint(initialViewpoint);
// Initialize the read operation
readGeoPackage();
}
// Read the GeoPackage and create lists for the names and layer data
void ReadGeoPackage::readGeoPackage()
{
// Load the GeoPackage at the beginning
GeoPackage* auroraGpkg = new GeoPackage(m_dataPath + "/gpkg/AuroraCO.gpkg", this);
// Make sure there are no errors in loading the GeoPackage before interacting with it
connect(auroraGpkg, &GeoPackage::doneLoading, this, [auroraGpkg, this](Error error)
{
if (error.isEmpty())
{
// For each raster, create a raster layer and add the layer to the map
const auto rasters = auroraGpkg->geoPackageRasters();
for (GeoPackageRaster* rasterItm : rasters)
{
RasterLayer* rasterLyr = new RasterLayer(rasterItm, this);
rasterLyr->setOpacity(0.55f);
m_map->operationalLayers()->append(rasterLyr);
}
// For each feature table, create a feature layer and add the layer to the map
const auto tables = auroraGpkg->geoPackageFeatureTables();
for (GeoPackageFeatureTable* featureTbl : tables)
{
FeatureLayer* layer = new FeatureLayer(featureTbl, this);
m_map->operationalLayers()->append(layer);
}
}
});
auroraGpkg->load();
}