this might be an absolute basic question, but how do I add a raster to an active map so that it is listed in the table of content and visible in the map?
I managed to create an empty map, which is then under MapView.Active.Map. when I try to add a simple .tif raster to this map, I fail. I tried various code snippets, but none works for me. the .tif rasterfile is currently in my local directory.
https://github.com/esri/arcgis-pro-sdk/wiki/ProSnippets-Raster I found this code snippet (Open raster dataset in a folder), which works as it doesnot raise an error. But it doesn't add the created raster to the map either. So I'm guessing that I need to add it specifically.
https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/topic11851.html the docu suggests a RemoveLayer method. but I cannot find a addRaster or addLayer method. how is this done??
https://github.com/Esri/arcgis-pro-sdk-community-samples/tree/master/Map-Authoring/AddRasterLayer I also found this example, but I really don't see/get where they are adding the raster..
thanks for any help
Solved! Go to Solution.
Hi,
Take a look at the ArcGIS Pro SDK API reference
string url = @"C:\Images\Italy.tif";
await QueuedTask.Run(() =>
{
// Create a raster layer using a path to an image.
// Note: You can create a raster layer from a url, project item, or data connection.
rasterLayer = LayerFactory.Instance.CreateLayer(new Uri(url), aMap) as RasterLayer;
});
Or modify sample from your last link
// The layer has to be created on the Main CIM Thread (MCT).
string url = @"C:\Images\Italy.tif";
RasterLayer rasterLayer = null;
await QueuedTask.Run(() =>
{
// Create a layer based on the url. In this case the layer we are creating is an image service layer.
var layerParams = new LayerCreationParams(new Uri(url));
rasterLayer = LayerFactory.Instance.CreateLayer<RasterLayer>(layerParams, myMap);
// Check if it is created.
if (rasterLayer == null)
{
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Failed to create layer for url:" + dataSoureUrl);
return;
}
});
Hi,
Take a look at the ArcGIS Pro SDK API reference
string url = @"C:\Images\Italy.tif";
await QueuedTask.Run(() =>
{
// Create a raster layer using a path to an image.
// Note: You can create a raster layer from a url, project item, or data connection.
rasterLayer = LayerFactory.Instance.CreateLayer(new Uri(url), aMap) as RasterLayer;
});
Or modify sample from your last link
// The layer has to be created on the Main CIM Thread (MCT).
string url = @"C:\Images\Italy.tif";
RasterLayer rasterLayer = null;
await QueuedTask.Run(() =>
{
// Create a layer based on the url. In this case the layer we are creating is an image service layer.
var layerParams = new LayerCreationParams(new Uri(url));
rasterLayer = LayerFactory.Instance.CreateLayer<RasterLayer>(layerParams, myMap);
// Check if it is created.
if (rasterLayer == null)
{
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Failed to create layer for url:" + dataSoureUrl);
return;
}
});