Select to view content in your preferred language

Create a BasicRasterLayer in memory

796
5
Jump to solution
10-16-2022 01:17 PM
JeromeHaaland
Regular Contributor

Is there a way to create a BasicRasterLayer and hold it in memory to be used as an intermediate in a raster calculation?

The code below is slightly modified from:

https://github.com/Esri/arcgis-pro-sdk/wiki/ProSnippets-MapAuthoring#create-a-raster-layer

The container needs to be "memory" instead of MapView.Active.Map

BasicRasterLayer rasterLayer = null;
            await QueuedTask.Run(() =>
            {
                rasterLayer = LayerFactory.Instance.CreateLayer<BasicRasterLayer>(rasterLayerCreationParams, MapView.Active.Map);                
            });    

 

0 Kudos
1 Solution

Accepted Solutions
JeromeHaaland
Regular Contributor

Ken,

After researching this a bit more.  It is simple to remove the layer added to the ToC.

The Create Raster Dataset does meet my needs.

MapView.Active.Map.RemoveLayer(layerToRemove);

 

View solution in original post

0 Kudos
5 Replies
KenBuja
MVP Esteemed Contributor

Instead of using CreateLayer, which assumes you want to add it to the map (since a member of the ArcGIS.Desktop.Mapping Namespace), try using the GeoProcessing tool Create Raster Dataset. For the path you can use the "memory" workspace (but not "in_memory" as noted here).

0 Kudos
JeromeHaaland
Regular Contributor

Ken,

Thanks for your reply. 

This does create a raster in memory... but also adds the layer to the ToC by default... and there does not appear to be a setting that prevents the layer from being added to the ToC.  Thus, a person has to go through and manually remove the layer from the ToC.

Close to fitting the need... but not quit.

0 Kudos
KenBuja
MVP Esteemed Contributor

You can set whether the result of a Geoprocessing tool gets added to the map (if that's not already set in the Geoprocessing options in Pro). One of the members of the ExecuteToolAsync method is the GPExecuteToolFlags enumeration. You can use AddToHistory or None so it won't be added to the map. This is an example where I'm creating a feature class but not adding it to the map.

IGPResult result = await Geoprocessing.ExecuteToolAsync("management.CreateFeatureclass", Geoprocessing.MakeValueArray(arguments.ToArray()), null, null, null, GPExecuteToolFlags.None);
0 Kudos
JeromeHaaland
Regular Contributor

I see this works too.  Thanks

0 Kudos
JeromeHaaland
Regular Contributor

Ken,

After researching this a bit more.  It is simple to remove the layer added to the ToC.

The Create Raster Dataset does meet my needs.

MapView.Active.Map.RemoveLayer(layerToRemove);

 

0 Kudos