LayerFactory.CreateMosiacLayer returns null for Landsat URL

11-16-2021 07:12 PM
Occasional Contributor III

When I run this code with 2.9, it prints: "null layer" then "ImageServiceLayer".

I was expecting to get a MosaicLayer.  Am I doing something wrong?

var uri = new Uri(@"");
var map = MapView.Active.Map;
await QueuedTask.Run(() =>
    var layer = LayerFactory.Instance.CreateMosaicLayer(uri, map,0,"landsat");
    if (layer == null)
        Debug.Print("null layer");
    var layer2 = MapView.Active.Map.Layers[0];


Tags (2)
0 Kudos
3 Replies
Esri Regular Contributor


I have used ArcGIS Pro sample   code to load ImageServiceLayer.

                // Create a url pointing to the source. In this case it is a url to an image service 
                // which will result in an image service layer being created.
                string dataSoureUrl = @"";
                // Note: A url can also point to  
                // 1.) An image on disk or an in a file geodatabase. e.g. string dataSoureUrl = @"C:\temp\a.tif"; This results in a raster layer.
                // 2.) A mosaic dataset in a file gdb e.g. string dataSoureUrl = @"c:\temp\mygdb.gdb\MyMosaicDataset"; This results in a mosaic layer.
                // 3.) A raster or mosaic dataset in an enterprise geodatabase.

                // Create an ImageServiceLayer object to hold the new layer.
                ImageServiceLayer rasterLayer = null;

                // The layer has to be created on the Main CIM Thread (MCT).
                await QueuedTask.Run(() =>
                    // Create a layer based on the url. In this case the layer we are creating is an image service layer.
                    rasterLayer = (ImageServiceLayer)LayerFactory.Instance.CreateLayer(new Uri(dataSoureUrl), myMap);

                    // Check if it is created.
                    if (rasterLayer == null)
                        ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Failed to create layer for url:" + dataSoureUrl); 
                    // Validate the colorizer to see if the layer is colorized correctly.
                    if (!(rasterLayer.GetColorizer() is CIMRasterRGBColorizer))
                        ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Colorizer does not match for layer created from url: " + dataSoureUrl); 

After you can try to check rasterLayer is MosaicLayer and if it is trus cast rasterLayer to MosaicLayer

0 Kudos
Occasional Contributor III

@GKmieliauskas thanks for responding!

Unfortunately, when I run your code with the Landsat Url, I get a ImageServiceLayer, and not a MosaicLayer.

The properties for the resulting layer say there are 3 bands...


And yet the metadata says it has 9 bands ....


Other properties in the metadata suggest I should be able to create a mosaiclayer from it, e.g. MaxMosaicImageCount, AllowedMosaicMethods, AvailableMosaicMethods, etc.

Is there a sample anywhere showing how to create a MosaicLayer from a Landsat Imagery URL?

0 Kudos
Esri Regular Contributor


You can MosaicRule on ImageServiceLayer:


                    // Get the mosaic rule of the image service.
                    CIMMosaicRule mosaicRule = imageServiceLayer.GetMosaicRule();
                    // Set the mosaic method to be Center.
                    mosaicRule.MosaicMethod = RasterMosaicMethod.Center;
                    // Update the image service with the changed mosaic rule.


I have tried and it works.

Another one thing I have found  in 

Similarly, an image service layer that is part of a mosaic layer can be distinguished from other image service layers by using the ImageMosaicSubLayer class. You could try to investigate ImageMosaicSubLayer functionality


0 Kudos