I want to create a group layer (or similar) of many raster files that only display when I tick them. They must not all be displaying when I make the layer, or my standard office entry level machine will crash.

I will need to recreate this "layer" as files are moved around and new ones are found on the network.

So I am after tricks for

  • a quick way to get them all into one "layer"
  • but with each raster being unticked/not showing so my machine does not crash

I have collected the list of 100 odd raster file paths in a text file. Can I easily turn this into some kind of text file that imports into ArcMap and it displays the list of grids without any being ticked to display? A text file with something wrapped around each file address, such as XML?

It does not matter if it converts into the ESRI binary format of a layer file. Making a large layer without dragging and dropping images is more important.

Added 10/9/2020

Follow Michael Stimson suggestion, I tried the following

import arcpy

mxd_path = arcpy.GetParameterAsText(0)
mxd = arcpy.mapping.MapDocument(mxd_path)

text = arcpy.GetParameterAsText(1)

layer_path = arcpy.GetParameterAsText(2)
lyr = arcpy.mapping.Layer(layer_path)

df = arcpy.mapping.ListDataFrames(mxd)

log = open(text + ".log", "w")

f = open(text, "r").readlines()
for filepath in f:
    newlayer = arcpy.mapping.Layer(filepath)
    arcpy.mapping.AddLayerToGroup(df, lyr, newlayer)


The only failure is AddLayerToGroup. The UNC network address successfully creates a layer and I even isolated to check the lyr.save line works by itself.


Traceback (most recent call last):
  File "K:\Tim K\Program Resources\ArcGIS\Arcgis10.1\GridsToLayer.py", line 22, in <module>
    arcpy.mapping.AddLayerToGroup(df, lyr, newlayer)
  File "c:\program files (x86)\arcgis\desktop10.6\arcpy\arcpy\utils.py", line 182, in fn_
    return fn(*args, **kw)
  File "c:\program files (x86)\arcgis\desktop10.6\arcpy\arcpy\mapping.py", line 87, in AddLayerToGroup
    assert isinstance(data_frame, DataFrame)

Failed to execute (GridsToLayer).

I suspect the problem is in the AddLayerToGroup help where it states the layer I want to add to the group layer must be "a layer file on disk or a layer file in a map document". That would mean copying the raster files to new disk location and converting each into layer. I was hoping to simply reference where they are now. That location may change a bit each week a few files pass through a QA/QC "process" by others.

It looks like I want an unmanaged Raster Catalog, which references files instead of copying to a gdb. But, can it reference a workspace for every raster?

Turns out yes, but its not displaying the rasters, just polygons where they are located.

See answer below - changed to making an mxd of rasters.

  • Have you tried a mosaic dataset? Does your raster have pyramids/overviews to make them render alot faster, maybe your machine wont crash then? – BERA Sep 9 '20 at 7:03
  • 1
    Are you comfortable with python? This can easily be achieved by creating a group layer in ArcCatalog then adding the rasters as layers resources.arcgis.com/en/help/main/10.2/index.html#//… into the group, turning their visibility off (visible is on by default). You could do this in model builder if you're not comfortable with python but it's a little more difficult to explain what the ovals and rectangles are actually doing and it's a bit more difficult to use the existing paths consumed as a text file. – Michael Stimson Sep 9 '20 at 7:15
  • 1
    Are you aware that you can pause drawing by pressing F9? desktop.arcgis.com/en/arcmap/10.3/map/working-with-arcmap/… If you are creating a document from very large rasters or vector layers and you don't want ArcMap to refresh with each little modification in the TOC pausing the drawing helps while you're getting organized then F9 to turn drawing back on when you're ready. – Michael Stimson Sep 9 '20 at 7:21
  • @Michael Stimson Yes I am very comfortable with python. I will explore your suggestion. – user24007 Sep 9 '20 at 23:08
  • @BERA I will experiment with the Mosaic idea later. A networked geodatabase others can connect to might a reasonable answer too. – user24007 Sep 10 '20 at 0:57

After a bit of poking around I found there is no way to create a new group layer in arcpy which comes with a suggested workaround. Neither can ArcMap drawing be paused from arcpy which is a bit of a disappointment.

It is possible to load layers as not visible with python, reading the data paths from a text file:

import os, sys, arcpy

FileOfPaths= r'E:\Testing\DataPaths.txt'
OpenDoc    = arcpy.mapping.MapDocument('CURRENT') # reference to the current document
FocusFrame = OpenDoc.activeDataFrame              # and the active data frame

with open(FileOfPaths,'r') as InFile:
    for Line in InFile:
        NewLay         = arcpy.mapping.Layer(Line) # data path makes new layer
        NewLay.visible = False
        NewLay.name    = os.path.splitext( os.path.basename(Line) )[0] # the name for this data source
        #arcpy.mapping.AddLayerToGroup(FocusFrame,NewGL,NewLay)# use this if you have a group layer 
        arcpy.mapping.AddLayer(FocusFrame,NewLay)# use this if you don't
        del NewLay

As the layer object exists prior to being added you can toggle the visible off and even change symbology before the layer is added to the map then delete the reference before making a new one otherwise arcpy might think you want to modify the first added layer by each subsequent layer and you'll only have the last layer.

The code expects to be run from within ArcMap, either with the python console or as a script tool but would work equally well if you want to add your layers to an existing map document without opening it, just change OpenDoc = arcpy.mapping.MapDocument('CURRENT') to OpenDoc = arcpy.mapping.MapDocument(r'c:\full\path\to\yourMapDocument.mxd') then you can shell ArcMap to open the focus document.. as the existing document isn't open it wont redraw.

  • Thank you again. Worked like a charm. I only had to add a try/except for network addresses creating exceptions. – user24007 Sep 10 '20 at 23:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.