Hello
I'd like to add several raster files (format: .ecw) from one folder with several subfolders to my mxd-file. It works fine with the following code:
workspace = r"C:\Workspace" #Workspace ... ... ... #Code ... import arcpy, os ... ... mxd = arcpy.mapping.MapDocument("CURRENT") ... df = arcpy.mapping.ListDataFrames(mxd, "*")[0] ... ... walk = arcpy.da.Walk(workspace) ... ... for dirpath, dirnames, filenames in walk: ... for filename in filenames: ... arcpy.mapping.AddLayer(df, arcpy.mapping.Layer(os.path.join(dirpath, filename)))
The Problem is, that after adding them like this, they appear with a symbology "stretched values along a color ramp" but they should be drawn as "RGB composite".
Can someone help me?
Solved! Go to Solution.
I got it to work by adding the ECWs, then updating the stretched layer using a template RGB .lyr file:
import os workspace = r"C:\Temp\Test" #Workspace rgb_lyr = arcpy.mapping.Layer(r"C:\Temp\rgb.lyr") mxd = arcpy.mapping.MapDocument("CURRENT") df = mxd.activeDataFrame walk = arcpy.da.Walk(workspace) for dirpath, dirnames, filenames in walk: for filename in filenames: print os.path.join(dirpath, filename) lyr = arcpy.mapping.Layer(os.path.join(dirpath, filename)) arcpy.mapping.AddLayer(df, lyr) updateLayer = arcpy.mapping.ListLayers(mxd, lyr.name, df)[0] arcpy.mapping.UpdateLayer(df, updateLayer, rgb_lyr)
You could also use replaceDatasource on the template layer:
import os workspace = r"C:\Temp\Test" #Workspace rgb_lyr = r"C:\Temp\rgb.lyr" mxd = arcpy.mapping.MapDocument("CURRENT") df = mxd.activeDataFrame walk = arcpy.da.Walk(workspace) for dirpath, dirnames, filenames in walk: for filename in filenames: lyr = arcpy.mapping.Layer(rgb_lyr) lyr.replaceDataSource (dirpath, 'RASTER_WORKSPACE', filename) lyr.name = filename arcpy.mapping.AddLayer(df, lyr)
I can find nothing but read-only properties Layer—Help | ArcGIS for Desktop in the arcpy.mapping module. I presume that is because histograms and band statistics are required for multiband rasters. All other references to rasters and symbology refer to setting a raster's symbology to an existing layer file (lyr) which isn't going to work in your case
http: //desktop.arcgis.com/en/arcmap/latest/analyze/arcpy-mapping/layer-class.htm
Thanks for your help.
I can't open the Link. May you post it again?
Would that mean that there's a option I could set?
I don't mind setting the symbology afterwords but I couln't figure a way to do so.
I copied the link as text above
Timothy Hales check my link above... I just copied and pasted the url and this error keeps appearing. I have seen this before
I thought it may be the dash, but this URL works:
http://desktop.arcgis.com/en/arcmap/latest/analyze/arcpy-classes/cursor.htm
However I noticed the URLs with two dashes do not:
http://desktop.arcgis.com/en/arcmap/latest/analyze/arcpy-mapping/styleitem-class.htm
I have an open case with Jive Software to determine the issue. Thanks for letting me know!
so does this mean that there's no solution for my problem?
If you managed to get through to the link by a manual search on the topic, you would see that there is no arcpy access to that particular symbology probably because it is dependent on other things which may not exist. The rest of the discussion was directed toward the failure of a direct link to the help files not working.
To return to your issue... can you set the symbology to what you want manually? is not, does pyramids/histograms help do it manually?
Hi Silvan,
Have you considered starting with a Raster Mosaic?
Yes, I can set the symbology manually. But I'll have to do so for about 100 Rasters, which really sucks. And I'll have to do it at least once a year.
I tried to use a Raster Catalog. But this enlarged the Data (from 8G to 130G) and was extremely slow.
I can't create a MosaicDataset because I run on basic licence.
Ok, I solved it diffrently:
I made a Batch-Script:
for /R C:/Path %%f in (*.ec*) do copy %%f C:/Path2/
So now I copy all the files from the folder with those many subfolders to one single folder.
It works fine. The only sad thing is that I now do have two folders with all those images... but still much better than doing all this manually...
If someone knows about an other method without copying the files, I would still be interested in the solution.