Exception when creating a RasterFunction from JSON file

366
1
08-11-2022 04:07 AM
cfrob
by
New Contributor II

Hello,

I basically want to load some raster data (from GeoTIFF file) and then transform it via a Raster Function.

I created the Raster Function Template in ArcGISPro and then exported it in JSON format.
(Actually exported as XML and then converted to JSON via the Python console using arcpy.management.ConvertRasterFunctionTemplate as I found no way to directly export as JSON).

Now, in the code, when I want to create a RasterFunction instance from the JSON file I always get an Exception saying

Esri.ArcGISRuntime.ArcGISRuntimeException: JSON object key not found.

The documentation of the Runtime SDK (for any language) is vague at best.

When I look at a sample I noticed that the keys in the JSON use snake_case whereas the export from ArcGISPro uses camelCase (or PascalCase).

The sample I'm referring to:
https://github.com/Esri/arcgis-runtime-samples-dotnet/blob/main/src/WPF/ArcGISRuntime.WPF.Viewer/Sam...

I would be grateful for any hint on how to successfully load a Raster Function Template exported from ArcGISPro.

I attached the JSON file with the Raster Function.

I'm using ArcGIS Runtime 100.14.1 and ArcGISPro 3.0

Regards,
Christian

 

0 Kudos
1 Reply
cfrob
by
New Contributor II

I did some experiments based on the sample mentioned in the original post:

If I take the Raster Function from the sample as a JSON string and create a RasterFunction instance from that string, it works.

var rftJson = await File.ReadAllTextAsync(@"D:\temp\online_sample.rft.json");
var rasterFunction = RasterFunction.FromJson(rftJson);

 

If I instead try to create the RasterFunction instance directly from the file, it fails.

var rasterFunction = new RasterFunction(@"D:\temp\online_sample.rft.json");

 

Only this time with a different exception:

System.ArgumentException: Invalid argument: Failed to read 599 bytes from D:\temp\online_sample.rft.json

I attached the json file I used but with extension .txt as attatching files with .json extension wasn't possible.

Regards,
Christian

 

0 Kudos