AnsweredAssumed Answered

Exception with Color_ramp Raster Function (WPF/v100.4)

Question asked by keith.gemeinhart on Aug 16, 2019
Latest reply on Aug 17, 2019 by keith.gemeinhart

I'm trying to implement a raster function, starting with the code in the Raster Layer Raster Function sample. The sample uses Hillshade. I can get that to work, but I'm getting an exception with the Color_ramp function. I have not investigated this with v100.5, but I did check the release notes and don't see anything related.

 

I'm using the json for Color_ramp function listed on Add raster data—ArcGIS Runtime SDK for .NET | ArcGIS for Developers . I'm getting an exception in the RasterFunction.FromJson() method. The exception is

 

"invalid start of field name - expecting \"": } : 1158

 

If I add some random spaces in the json string, the 1158 number in the exception changes, so I'm thinking that is possibly the location in the string where the problem is.

 

Stack trace is:

   at Esri.ArcGISRuntime.ArcGISException.HandleCoreError(CoreError error, Boolean throwException)
   at RuntimeCoreNet.GeneratedWrappers.Interop.CheckError(IntPtr errorHandle, Boolean throwOnFailure, GCHandle wrapperHandle)
   at RuntimeCoreNet.GeneratedWrappers.CoreRasterFunction.FromJSON(String jSON)
   at Esri.ArcGISRuntime.Rasters.RasterFunction.FromJson(String json)

 

Here is my code. I added a line to parse the json to make sure it was valid json syntax, and that works OK.

 

string colorRamp =
@"{
  ""raster_function"":{""type"":""Color_ramp_function""},
  ""raster_function_arguments"":
  {
    ""resizable"":{""bool"":false,""type"":""Raster_function_variable""},
    ""color_ramp"":
    {
      ""color_ramp"":
      {
        ""ramps"":
        [
         {""to_color"":[0,255,0],""from_color"":[0,191,191],""num_colors"":3932,""type"":""Algorithmic_color_ramp"",""algorithmic_type"":""hsv""},
         {""to_color"":[255,255,0],""from_color"":[0,255,0],""num_colors"":3932,""type"":""Algorithmic_color_ramp"",""algorithmic_type"":""hsv""},
         {""to_color"":[255,127,0],""from_color"":[255,255,0],""num_colors"":3932,""type"":""Algorithmic_color_ramp"",""algorithmic_type"":""hsv""},
         {""to_color"":[191,127,63],""from_color"":[255,127,0],""num_colors"":3932,""type"":""Algorithmic_color_ramp"",""algorithmic_type"":""hsv""},
         {""to_color"":[20,20,20],""from_color"":[191,127,63],""num_colors"":3935,""type"":""Algorithmic_color_ramp"",""algorithmic_type"":""hsv""}
        ],
        ""type"":""Multipart_color_ramp""
      },
      ""type"":""Raster_function_variable""
    },
    ""raster"":{""name"":""raster"",""is_raster"":true,""type"":""Raster_function_variable""},
    ""type"":""Raster_function_arguments"",
  },
  ""type"":""Raster_function_template"",
}"
;

var json = colorRamp;
try
{
    JObject rss = JObject.Parse(json);
    RasterFunction myRasterFunction = RasterFunction.FromJson(json);

}
catch (Exception e)
{
    Console.WriteLine(e);
}

Outcomes