Skip To Content ArcGIS for Developers Sign In Dashboard

ArcGIS Runtime SDK for .NET

Read a GeoPackage

This code sample is available for these platforms:
View Sample on GitHub

Add rasters and feature tables from GeoPackages to a map.

screenshot

Use case

GeoPackage is an open standard for sharing raster and vector data. You may want to use GeoPackage 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. Open the GeoPackage using GeoPackage.OpenAsync(path).
  2. Iterate through available rasters exposed by geopackage.GeoPackageRasters.
    • For each raster, create a raster layer using new Rasterlayer(geopackageRaster), then add it to the map.
  3. 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.

Relevant API

  • GeoPackage
  • GeoPackageRaster
  • GeoPackage.GeoPackageRasters
  • GeoPackageFeatureTable
  • GeoPackage.GeoPackageFeatureTables

Offline data

Find this item on ArcGIS Online.

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 Buildings (raster).

Tags

GeoPackage, Maps, Rasters, Layers, Tables, OGC, package, container

Sample Code

<UserControl
    x:Class="ArcGISRuntime.UWP.Samples.ReadGeoPackage.ReadGeoPackage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:esriUI="using:Esri.ArcGISRuntime.UI.Controls">
    <Grid>
        <esriUI:MapView x:Name="MyMapView" />
    </Grid>
</UserControl>
// 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.

using System;
using ArcGISRuntime.Samples.Managers;
using Esri.ArcGISRuntime.Data;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Rasters;
using Windows.UI.Popups;

namespace ArcGISRuntime.UWP.Samples.ReadGeoPackage
{
    [ArcGISRuntime.Samples.Shared.Attributes.Sample(
        "Read a GeoPackage",
        "Data",
        "Add rasters and feature tables from GeoPackages to a map.",
        "When the sample loads, the feature tables and rasters from the GeoPackage will be shown on the map.")]
    [ArcGISRuntime.Samples.Shared.Attributes.OfflineData("68ec42517cdd439e81b036210483e8e7")]
    public partial class ReadGeoPackage
    {
        public ReadGeoPackage()
        {
            InitializeComponent();
            Initialize();
        }

        private async void Initialize()
        {
            // Create a new map centered on Aurora Colorado.
            MyMapView.Map = new Map(BasemapType.Streets, 39.7294, -104.73, 11);

            // Get the full path to the GeoPackage on the device.
            string myGeoPackagePath = DataManager.GetDataFolder("68ec42517cdd439e81b036210483e8e7", "AuroraCO.gpkg");

            try
            {
                // Open the GeoPackage.
                GeoPackage myGeoPackage = await GeoPackage.OpenAsync(myGeoPackagePath);

                // Loop through each GeoPackageRaster.
                foreach (GeoPackageRaster oneGeoPackageRaster in myGeoPackage.GeoPackageRasters)
                {
                    // Create a RasterLayer from the GeoPackageRaster.
                    RasterLayer myRasterLayer = new RasterLayer(oneGeoPackageRaster)
                    {
                        // Set the opacity on the RasterLayer to partially visible.
                        Opacity = 0.55
                    };

                    // Add the raster layer to the map.
                    MyMapView.Map.OperationalLayers.Add(myRasterLayer);
                }

                // Loop through each GeoPackageFeatureTable.
                foreach (GeoPackageFeatureTable oneGeoPackageFeatureTable in myGeoPackage.GeoPackageFeatureTables)
                {
                    // Create a FeatureLayer from the GeoPackageFeatureLayer.
                    FeatureLayer myFeatureLayer = new FeatureLayer(oneGeoPackageFeatureTable);

                    // Add the layer to the map.
                    MyMapView.Map.OperationalLayers.Add(myFeatureLayer);
                }
            }
            catch (Exception e)
            {
                await new MessageDialog(e.ToString(), "Error").ShowAsync();
            }
        }
    }
}