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.
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: log.write(filepath) newlayer = arcpy.mapping.Layer(filepath) arcpy.mapping.AddLayerToGroup(df, lyr, newlayer) lyr.save()
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) AssertionError 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.