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(@"https://landsat2.arcgis.com/arcgis/rest/services/Landsat/MS/ImageServer");
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];
Debug.Print(layer2.GetType().Name);
});
Hi,
I have used ArcGIS Pro sample https://github.com/Esri/arcgis-pro-sdk-community-samples/tree/master/Map-Authoring/AddRasterLayer 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 = @"http://imagery.arcgisonline.com/arcgis/services/LandsatGLS/GLS2010_Enhanced/ImageServer";
// 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);
return;
}
// 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
@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?
Hi,
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.
imageService.SetMosaicRule(mosaicRule);
I have tried and it works.
Another one thing I have found in https://github.com/Esri/arcgis-pro-sdk/wiki/ProConcepts-Map-Authoring#working-with-mosaic-layers
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