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.
<SPAN class="keyword token">string</SPAN> colorRamp <SPAN class="operator token">=</SPAN>
<SPAN class="string token">@"{
""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"",
}"</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">var</SPAN> json <SPAN class="operator token">=</SPAN> colorRamp<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">try</SPAN>
<SPAN class="punctuation token">{</SPAN>
JObject rss <SPAN class="operator token">=</SPAN> JObject<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Parse</SPAN><SPAN class="punctuation token">(</SPAN>json<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
RasterFunction myRasterFunction <SPAN class="operator token">=</SPAN> RasterFunction<SPAN class="punctuation token">.</SPAN><SPAN class="token function">FromJson</SPAN><SPAN class="punctuation token">(</SPAN>json<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="keyword token">catch</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="token class-name">Exception</SPAN> e<SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
Console<SPAN class="punctuation token">.</SPAN><SPAN class="token function">WriteLine</SPAN><SPAN class="punctuation token">(</SPAN>e<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>