ApplySymbologyFromLayer Not Working for Raster Mosaic Dataset

3915
8
01-07-2014 08:30 AM
JonathanMulder
New Contributor III
I am thoroughly flummoxed with this issue!

I've created a set of daily surfaces representing groundwater levels.  I want to step through them in time (i.e., make them time-enabled).  I found a good site ( http://esriaustraliatechblog.wordpress.com/2011/08/18/time-enabled-rasters/ ) that essentially said to create a raster mosaic dataset, add all my daily surfaces, and create a field that represents the date.  That works great!

Now, I want to color-ramp the mosaic dataset.  I'm able to do that and have saved it as a layer file.

The code below crashes when I try to apply the saved layer file to my surface raster mosaic dataset, saying

"ERROR 000968: The symbol layer does not match the input layer

Ultimately, I'll want to re-classify the raster because different datasets will have different min/max values.

Any ideas?

Jon Mulder

import arcpy
import arcpy.mapping
import datetime
import os

##Reference the Current map document.
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
GeoDatabaseNameAndLocation = "G:\Documents\GIS\HydstraData\HydstraMeasurementsDeep\Contours_Daily_20130601_20130605.gdb"
LayerFileNameAndLocation_WSE_Surface = "G:\Documents\GIS\HydstraData\Template_WSE_Surface.lyr"
arcpy.AddMessage(LayerFileNameAndLocation_WSE_Surface)
CurrentSurface = os.path.join(GeoDatabaseNameAndLocation,"WSE_RasterMosaicDataset")
arcpy.AddMessage(CurrentSurface)
Surface_lyr = arcpy.mapping.Layer(CurrentSurface)
arcpy.mapping.AddLayer(df, Surface_lyr, "BOTTOM")
arcpy.ApplySymbologyFromLayer_management(Surface_lyr,LayerFileNameAndLocation_WSE_Surface)



=====Error Message======================================
Executing: AddRaster
Start Time: Tue Jan 07 10:22:53 2014
Running script AddRaster...
G:\Documents\GIS\HydstraData\Template_WSE_Surface.lyr
G:\Documents\GIS\HydstraData\HydstraMeasurementsDeep\Contours_Daily_20130601_20130605.gdb\WSE_RasterMosaicDataset

Traceback (most recent call last):
  File "G:\Documents\GIS\HydstraData\AddRasterMosaicToCurrentMap_20140107.py", line 16, in <module>
    arcpy.ApplySymbologyFromLayer_management(Surface_lyr,LayerFileNameAndLocation_WSE_Surface)
  File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\management.py", line 5754, in ApplySymbologyFromLayer
    raise e
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000968: The symbol layer does not match the input layer
Failed to execute (ApplySymbologyFromLayer).


Failed to execute (AddRaster).
Failed at Tue Jan 07 10:22:58 2014 (Elapsed Time: 4.64 seconds)
Tags (2)
0 Kudos
8 Replies
T__WayneWhitley
Frequent Contributor
Probably don't want ApplySymbology in this case.... UpdateLayer and Reclassify sounds more like it, see the code samples at the bottom of the page (RasterClassifiedSymbology examples) here:

http://resources.arcgis.com/en/help/main/10.2/index.html#//00s30000005p000000
0 Kudos
JakeSkinner
Esri Esteemed Contributor
One thing to note is that when you are adding the mosaic dataset to your MXD using the 'AddLayer' function, you are adding it as a raster layer.   Therefore, be sure you create your layer file from a raster layer and not the mosaic dataset itself.  If not, an error will occur when trying to run the 'UpdateLayer' function.  Try the following steps:

1.  Run the Make Raster Layer tool on the mosaic dataset
2.  Change the symbology and then create the layer file from the raster layer added to ArcMap
3.  Execute the following code:

mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
GeoDatabaseNameAndLocation = r"G:\Documents\GIS\HydstraData\HydstraMeasurementsDeep\Contours_Daily_20130601_20130605.gdb"
LayerFileNameAndLocation_WSE_Surface = r"G:\Documents\GIS\HydstraData\Template_WSE_Surface.lyr"
arcpy.AddMessage(LayerFileNameAndLocation_WSE_Surface)
CurrentSurface = os.path.join(GeoDatabaseNameAndLocation,"WSE_RasterMosaicDataset")
arcpy.AddMessage(CurrentSurface)
Surface_lyr = arcpy.mapping.Layer(CurrentSurface)
arcpy.mapping.AddLayer(df, Surface_lyr, "BOTTOM")
updateLayer = arcpy.mapping.ListLayers(mxd, "WSE_RasterMosaicDataset", df)[0]
sourceLayer = arcpy.mapping.Layer(LayerFileNameAndLocation_WSE_Surface)
arcpy.mapping.UpdateLayer(df, updateLayer, sourceLayer)
0 Kudos
JonathanMulder
New Contributor III
Thank you for your inputs, Wayne and JSkinn3.  Howver, I'm still muddling through this...  My methodolgy currently is:


  • Identify the template layer file ("Template_WSE_Surface.lyr") that contains the symbolization.

  • Replace the DataSource in the template layer file.


That works fine and my raster mosaic dataset comes in fine with the Boundary, Footprint, and Image.  BUT, the Green-Red color ramping doesn't come across from my template layer; it's just grey-scale.  So, I tried the UpdateLayer method to bring in the symbolization.  But I get the following error: "ValueError: LayerObject: Unexpected error".

BTW JSkinn3, I didn't quite understand your methodolgy.  My rasters all cover the same extent; they are time-sensitive and my ultimate goal is to step through them with the Time Slider.  I tried your process (if I understood it correctly), and it only brought in the Image and not the Boundary nor Footprint.  I need the Footprint because that hold my Date/Time field for the Time Slider.

Jon Mulder

import arcpy
import arcpy.mapping
import datetime
import os

##Reference the Current map document.
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
GeoDatabaseNameAndLocation = r"G:\Documents\GIS\HydstraData\HydstraMeasurementsDeep\Contours_Daily_20130630_20130705.gdb"
LayerFileNameAndLocation_WSE_Surface = r"G:\Documents\GIS\HydstraData\Template_WSE_Surface.lyr"
arcpy.AddMessage(LayerFileNameAndLocation_WSE_Surface)
CurrentSurface = os.path.join(GeoDatabaseNameAndLocation,"WSE_RasterMosaicDataset")
arcpy.AddMessage(CurrentSurface)
Surface_lyr = arcpy.mapping.Layer(LayerFileNameAndLocation_WSE_Surface)
Surface_lyr.replaceDataSource(GeoDatabaseNameAndLocation,"FILEGDB_WORKSPACE")
Surface_lyr = arcpy.mapping.ListLayers(mxd, "WSE_RasterMosaicDataset", df)[0]
SourceLayer = arcpy.mapping.Layer(r"G:\Documents\GIS\HydstraData\Template_WSE_Surface.lyr")
arcpy.AddMessage(Surface_lyr)
arcpy.AddMessage(SourceLayer)
arcpy.mapping.UpdateLayer(df,Surface_lyr,SourceLayer,True)
arcpy.mapping.AddLayer(df, Surface_lyr, "BOTTOM")


===Script Feedback=============================================
Executing: AddRaster
Start Time: Wed Jan 08 09:48:34 2014
Running script AddRaster...
G:\Documents\GIS\HydstraData\Template_WSE_Surface.lyr
G:\Documents\GIS\HydstraData\HydstraMeasurementsDeep\Contours_Daily_20130630_20130705.gdb\WSE_RasterMosaicDataset
WSE_RasterMosaicDataset
WSE_RasterMosaicDataset

Traceback (most recent call last):
  File "G:\Documents\GIS\HydstraData\AddRasterMosaicToCurrentMap_20140107.py", line 20, in <module>
    arcpy.mapping.UpdateLayer(df,Surface_lyr,SourceLayer,True)
  File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\utils.py", line 181, in fn_
    return fn(*args, **kw)
  File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\mapping.py", line 1878, in UpdateLayer
    tl._update(rl, symbology_only)
ValueError: LayerObject: Unexpected error

Failed to execute (AddRaster).
Failed at Wed Jan 08 09:48:35 2014 (Elapsed Time: 1.31 seconds)
0 Kudos
JonathanMulder
New Contributor III
I'm still trying to get this to work and have rem'd out some lines of the code to do some "bench-testing". In the following code, I'm just simply adding a layer file of the Raster Mosaic Dataset. The saved lyr file does have "Graduated Colors". But when I test for "GRADUATED_COLORS", I get back the error "The attribute 'symbologyType' is not supported on this instance of Layer."Is this because I'm not drilling into the Raster Mosaic Dataset and not explicitly addressing the Image layer of the Dataset?
When a Raster Mosaic Dataset is added to a map, it comes across almost like a "group" comprised of Boundary, Footprint, and Image. How can I test the Image portion of the layer for "GRADUATED_COLORS"?

Thanks,
Jon Mulder

import arcpy
import arcpy.mapping
import datetime
import os

##Reference the Current map document.
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
GeoDatabaseNameAndLocation = r"G:\Documents\GIS\HydstraData\HydstraMeasurementsDeep\Contours_Daily_20130630_20130705.gdb"
LayerFileNameAndLocation_WSE_Surface = r"G:\Documents\GIS\HydstraData\Template_WSE_Surface.lyr"
arcpy.AddMessage(LayerFileNameAndLocation_WSE_Surface)
CurrentSurface = os.path.join(GeoDatabaseNameAndLocation,"WSE_RasterMosaicDataset")
arcpy.AddMessage(CurrentSurface)
Surface_lyr = arcpy.mapping.Layer(LayerFileNameAndLocation_WSE_Surface)
##Surface_lyr.replaceDataSource(GeoDatabaseNameAndLocation,"FILEGDB_WORKSPACE")
##Surface_lyr = arcpy.mapping.ListLayers(mxd, "WSE_RasterMosaicDataset", df)[0]
##SourceLayer = arcpy.mapping.Layer(r"G:\Documents\GIS\HydstraData\Template_WSE_Surface.lyr")
arcpy.AddMessage(Surface_lyr)
##arcpy.AddMessage(SourceLayer)
##arcpy.mapping.UpdateLayer(df,Surface_lyr,SourceLayer,True)
arcpy.mapping.AddLayer(df, Surface_lyr, "BOTTOM")
##arcpy.mapping.layer.save()

if Surface_lyr.symbologyType == "GRADUATED_COLORS":
    arcpy.AddMessage("GRADUATED_COLORS are supported.")
else:    
    arcpy.AddMessage("GRADUATED_COLORS are NOT supported.")
0 Kudos
T__WayneWhitley
Frequent Contributor
I may have missed this, but have you tried using Make Raster Layer using your mosaic dataset as input, then saving that output to a layer file to use when replacing the layer in the TOC of your map (via UpdateLayer, if I'm following)?

This is per Jake's instructions in the previous post; I'll leave it to you to test if you haven't already.  Here's the doc and I'm guessing the data type for a mosaic is as in the documentation, a 'composite geodataset':

http://resources.arcgis.com/en/help/main/10.2/index.html#//00170000006t000000



Wayne
0 Kudos
JonathanMulder
New Contributor III
Thanks Wayne, I gave that a try.

When I used the Make Raster Tool, my Red-Green color ramped Mosaic Dataset was saved as grey-scale color ramp.  So, I modified the color ramp of the newly created layer file to Red-Green.  Finally, I SAVED the in-memory layer file to a lyr on disk.

I looked at the lyr in ArcCatalog, and this is the datasource (which seems rather odd!):

Data Type:  File System Raster
Folder:  C:\Users\mulder\AppData\Local\Temp\arcF6F\
Raster:  x40372eb8_2a96_4484_8419_83ecd66908f6y0.afr

So I tried to Change Datasource and navigated into my GeoDatabase and tried to click on the Raster Mosaic Dataset, but it won't accept it.  I tried to set datasource to a single raster and that did take.

Jon Mulder

PS   Can I send you a sample geodatabase and the relvany lyr files?
0 Kudos
T__WayneWhitley
Frequent Contributor
Yes I'm interested...
If you can, clip the source rasters and mosaic, whatever you have, just to give me a sample (if you don't mind) along with the relative-sourced lyr files and an mxd, maybe your py files, and if you would please just zip it into a single root folder (makes it easier to send back to you).

....then later, when all's done, I want to see the project, if that's okay with you!  I've never done or even seen the time-slider stuff, lol, just read about it!

Wayne


PS- Curious about this, is there the ability to export a gif or some sort of media animation file from the time-enabled data frame, or at least with enough 'snapshots' in time to assimilate into some sort of animation?   hmmm...get to that later.
0 Kudos
T__WayneWhitley
Frequent Contributor
...sorry I did not see this - you should perhaps try the Make Mosaic Layer tool, which accepts an input mosaic dataset:

http://resources.arcgis.com/en/help/main/10.2/index.html#/Make_Mosaic_Layer/0017000000vm000000/
0 Kudos