Select to view content in your preferred language

LoadError: {"A null pointer: Invalid raster function"} While applying raster functions to an image service

121
0
12-27-2024 02:22 AM
KayalvizhiK
Emerging Contributor
public static async Task<Raster> ApplyRasterForService(string rasterID, string theJSON_String, Raster currentRaster = null)
        {
            //RasterLayer rasterLayer = null;
            Raster raster = null;
            try
            {
                if (rasterID.Contains("Layout"))
                {
                    rasterID = rasterID.Replace("_Layout", "");
                }
                if (MainWindow.Instance.ImageDetails3D.ContainsKey(rasterID))
                {
                    List<object> details = MainWindow.Instance.ImageDetails3D[rasterID];
                    int objectID = (int)details[0];
                    string sensorName = (string)details[1];
                    string imageurl = (string)details[2];
                    string sceneid = (string)details[3];
                    ImageServiceRaster imageServiceRaster = new ImageServiceRaster(new Uri(imageurl));
                    await imageServiceRaster.LoadAsync();
                    if (imageServiceRaster.LoadStatus == Esri.ArcGISRuntime.LoadStatus.Loaded)
                    {
                        MosaicRule mosaicrule = new MosaicRule
                        {
                            MosaicMethod = MosaicMethod.LockRaster,
                            LockRasterIds = { objectID },
                            MosaicOperation = MosaicOperation.Max
                        };
                        imageServiceRaster.MosaicRule = mosaicrule;
                        //RasterLayer SelectedRasterLayer = new RasterLayer(imageServiceRaster);
                        //SelectedRasterLayer.Id = sceneid;
                        //SelectedRasterLayer.Name = sensorName;
                        //string Url = SelectedRasterLayer.Raster.Path;
                        //await SelectedRasterLayer.LoadAsync();
                        RasterFunction myRasterFunction = RasterFunction.FromJson(theJSON_String);
                        RasterFunctionArguments myRasterFunctionArguments = myRasterFunction.Arguments;
                        ReadOnlyCollection<string> myRasterNames = (ReadOnlyCollection<string>)myRasterFunctionArguments.GetRasterNames();
                        if (myRasterNames.Count == 0)
                        {
                            
                        }
                        else
                        {
                            if (currentRaster != null)
                            {
                                myRasterFunctionArguments.SetRaster((string)myRasterNames[0], currentRaster);
                            }
                            else
                                myRasterFunctionArguments.SetRaster((string)myRasterNames[0], imageServiceRaster);
                        }
 
                        raster = new Raster(myRasterFunction);
 
                        await raster.LoadAsync();
 
                        //rasterLayer = new RasterLayer(raster);
 
                        //await rasterLayer.LoadAsync();
                    }
                }
            }
            catch (Exception ex)
            {
 
            }
            return raster;
        }
 string theJSON_String =
                            @"{
                        ""raster_function_arguments"":
                        {
                          ""band_ids"":{ ""int_array"":" + bandIds + @",""type"":""Raster_function_variable""},
                          ""missing_band_action"":{ ""int"":""0"",""type"":""Raster_function_variable""},
                          ""type"":""Raster_function_arguments"",
                          ""raster"":{ ""name"":""$$"",""is_raster"":true,""type"":""Raster_function_variable""},
                          ""nbits"":{ ""int"":8,""type"":""Raster_function_variable""}
                        },
                      ""raster_function"":{ ""type"":""Extractband_function""},
                      ""type"":""Raster_function_template""
                    }";
 
While loading raster, I am getting an exception of LoadError: {"A null pointer: Invalid raster function"}
 
What am I missing? 
0 Kudos
0 Replies