Select to view content in your preferred language

Problems Adding Raster to GeoPackage

06-02-2023 10:30 AM
New Contributor II

I'm trying to create a GeoPackage that contains a raster image using .NET and C#.  I was able to do something similar in Python but can't seem to get it to work in C#.  Here's the simplified code:

      private Task BuildExport ()
         string output = @"C:\Data\GeoPackage.gpkg";

         return QueuedTask.Run(() =>
            if (SelectedMapFeatures == null) return;

               var parameters = Geoprocessing.MakeValueArray(output, "GEOPACKAGE");
               var result = Geoprocessing.ExecuteToolAsync("management.CreateSQLiteDatabase", parameters, null, null, null, GPExecuteToolFlags.None);

               foreach (var map in SelectedMapFeatures)
                  foreach (var feature in map.Value)
                     parameters = Geoprocessing.MakeValueArray(feature.Raster, output, feature.Name, "Tiled", null);
                     result = Geoprocessing.ExecuteToolAsync("conversion.AddRasterToGeoPackage", parameters, null, null, null, GPExecuteToolFlags.None);
            catch (Exception ex)
               Debug.WriteLine(ex.ToString(), Assembly.GetExecutingAssembly().FullName);

The GeoPackage is created just fine but adding the raster fails.  An exception is thrown on line 18 of the MakeValueArray for the first parameter:

TAKInterface, Version=, Culture=neutral, PublicKeyToken=null: System.InvalidOperationException: convert unsupported type
at ArcGIS.Desktop.GeoProcessing.ObjectToValueConverter.to_string(CoreObjectsBase b, Object& oref)
at ArcGIS.Desktop.GeoProcessing.ObjectToValueConverter.ToString(Object o, Object& oref)
at ArcGIS.Desktop.Core.Geoprocessing.Geoprocessing.MakeValueArray(Object[] args)
at TAKInterface.TAKExporterDockPaneViewModel.<>c__DisplayClass26_0.<BuildExport>b__0() in C:\Users\...

The type for feature.Raster is RasterValue.  I've tried using feature.Raster.GetRasterDataset() with the same error.

So, the question I have, is how do I get my raster into my GeoPackage?



0 Kudos
1 Reply
Esri Regular Contributor


The first parameter of "conversion.AddRasterToGeoPackage" is RasterLayer. See documentation:

Add Raster to GeoPackage (Conversion)—ArcGIS Pro | Documentation

So you need to add raster to map and then pass result RasterLayer to geoprocessing.

0 Kudos