Skip To Content ArcGIS for Developers Sign In Dashboard

ArcGIS Runtime SDK for .NET

Raster layer (GeoPackage)

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

Open a GeoPackage, obtain a raster from the package, and display the table as a RasterLayer.


How to use the sample

Run the sample.

How it works

  1. Create a GeoPackage by passing the path to a .gpkg file stored locally on the device.
  2. Load the GeoPackage with .LoadAsync().
  3. Wait for the package to load.
  4. Create a RasterLayer by obtaining the first Raster in the list of .GeoPackageRasters, and passing that Raster to the RasterLayer.
  5. Finally, add the RasterLayer the Map's operational layers.

Relevant API

  • GeoPackage
  • GeoPackageRaster
  • RasterLayer

Offline data

This sample downloads the following items from ArcGIS Online automatically:

  • - GeoPackage with datasets that cover Aurora Colorado: Public art (points), Bike trails (lines), and Subdivisions (polygons), Airport noise (raster), Buildings (raster).
  • - GeoPackage with datasets that cover Aurora Colorado: Public art (points), Bike trails (lines), and Subdivisions (polygons), Airport noise (raster), Buildings (raster).


Layers, OGC, container, geopackage, package, raster

Sample Code

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns=""
    <esriUI:MapView x:Name="MyMapView"/>
// 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:
// 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 System.Linq;
using Xamarin.Forms;

namespace ArcGISRuntime.Samples.RasterLayerGeoPackage
        "Raster layer (GeoPackage)",
        "This sample demonstrates how to open a GeoPackage and show a GeoPackage raster in a raster layer.",
        "The GeoPackage will be downloaded from an ArcGIS Online portal automatically.")]
    public partial class RasterLayerGeoPackage : ContentPage
        public RasterLayerGeoPackage()

            // Read data from the GeoPackage

        private async void Initialize()
            // Create a new map
            MyMapView.Map = new Map(Basemap.CreateLightGrayCanvas());

            // Get the full path
            string geoPackagePath = GetGeoPackagePath();

                // Open the GeoPackage
                GeoPackage myGeoPackage = await GeoPackage.OpenAsync(geoPackagePath);

                // Read the raster images and get the first one
                Raster gpkgRaster = myGeoPackage.GeoPackageRasters.FirstOrDefault();

                // Make sure an image was found in the package
                if (gpkgRaster == null) { return; }

                // Create a layer to show the raster
                RasterLayer newLayer = new RasterLayer(gpkgRaster);
                await newLayer.LoadAsync();

                // Set the viewpoint
                await MyMapView.SetViewpointAsync(new Viewpoint(newLayer.FullExtent));

                // Add the image as a raster layer to the map (with default symbology)
            catch (Exception e)
                await Application.Current.MainPage.DisplayAlert("Error", e.ToString(), "OK");

        private static string GetGeoPackagePath()

            return DataManager.GetDataFolder("68ec42517cdd439e81b036210483e8e7", "AuroraCO.gpkg");