Select to view content in your preferred language

AddLayerToGroup

892
2
01-07-2019 11:35 AM
GabrielMarcus1
Frequent Contributor

I have a script that produces several raster layers (10-20) from a netCDF. 

When I use addLayerToGroup to add the rasters to a group, the layers are duplicated into the group, rather than placed into the group without duplication. According to the docs onliine "The addLayerToGroup method is the only way to add a layer or collection of layers to an existing, empty group layer in a layer file."   

Questions:

1) How can I select just the layers that weren't added to the group for deletion?

2) Is there a way to go about creating a MakeNetCDFRasterLayer that doesn't add the layer to the contents pane?

Why can't we create a blank group layer using arcpy? It would seem easy to do so and this is desired, since I see StackExchange posts going back to 2011 complaining about this missing feature. 

 

Thanks!

Gabe

Tags (2)
2 Replies
nsidaniel
Regular Contributor

I know this post is a few years old, but I wanted to revive it.

Does anyone know a way to add layers to a group without duplicating them?

In the unlikely event that @GabrielMarcus1 is still wondering how to make a group layer, here you go: m.createGroupLayer()

And here's how I like to use m.createGroupLayer() in context

if arcpy.Exists("YourGroupLayer") == False:
    m.createGroupLayer("YourGroupLayer")

lyr_to_move = "yourlayer"
    for lyr in m.listLayers(lyr_to_move):
        groupLayer = "YourGroupLayer"
        lyr =  m.listLayers(lyr_to_move)[0]
        mapGroupLayer = m.listLayers(groupLayer)[0]
        m.addLayerToGroup(mapGroupLayer, lyr)

 

0 Kudos
nsidaniel
Regular Contributor

So this might fix the layer duplication issue, I haven't tried it yet:

https://support.esri.com/en-us/bug/the-addlayertogroup-python-function-adds-the-layer-redu-bug-00011...

0 Kudos