Raster symbology from attribute table

787
1
Jump to solution
07-15-2013 03:10 PM
ThomasLaxson
New Contributor III
I apologize in advance for the verbose post:

I am trying to symbolize raster data, not based on the value, but based on another field in the raster attribute table. I've created a .lyr file, and, in order to easily script the map production, I am simply replacing the data source (I need to create nationwide maps of more than 1000 30-meter raster datasets). However, when the raster values (from the value field, not from the symbology field) exceed those that were in the raster from which the .lyr was created, then that portion of the raster will not draw at all. In theory, one could work around this problem by creating the .lyr file from the raster that has the greatest number of values...Unfortunately, the value field and the field of interest have an arbitrary and inconsistent relationship; value 1346 in one raster may refer to code 3 in one raster's attribute table, but it may refer to code 2 in another raster. So, when I replace the data source, even though ArcMap says that it is symbolizing on my field of interest, the symbols don't match the underlying data. For example, a pixel that is actually code 1 is symbolized as if it were code 4. It seems as if ArcMap gives the appearance of setting symbology by field B, when behind the scenes it is actually basing the symbology on the original relationship of the value field to field B. Is that as clear as mud?

Using UpdateLayer() or ApplySymbologyFromLayer() does not resolve the above issues. Should these work in this situation?

All of the work-arounds that I can think of require incredibly long processing periods (or ArcObjects). At the rate that I am observing, running lookup() on each raster (in order to set the field on which I'd like to symbolize as the value field) would take about 6 months...and I actually want to do this for two different fields, so it would take a year. That's not feasible, and I might as well do it manually.  My only other option seems to be getting a 10.1 license and trying UniqueValuesSymbology to reset the symbology field; however, given that nothing else has worked as expected, I don't know if it's worth the time/money to try what may be another dead end.

Can anyone think of any other ways to address this?

Thanks.

Thomas
0 Kudos
1 Solution

Accepted Solutions
ThomasLaxson
New Contributor III
Even though I was setting the symbology by an attribute field that shared a consistent structure (i.e., type, precision, etc.) among all the rasters, inconsistency in the pixel depth of the value fields was throwing off the symbology. Solutions:

Quickest processing: Create a layer file unique to each pixel type; as each raster is brought in, describe the raster and identify the pixel type; based on the layer's pixel type, select the appropriate .lyr file for assigning symbology.

Quickest script-writing: Copy all the rasters with the pixel type explicitly set to a common (maximum) size.


Here's the relevant portion of code that I used for the first option, with variable names adapted for clarity:

lyrDict = {'U16':'mylayer_u16.lyr', 'S16':'mylayer_s16.lyr', 'U8':'mylayer_u8.lyr'}  d = arcpy.Describe(rast) symLayer = arcpy.mapping.Layer(os.path.join(lyrDir, lyrDict[d.pixelType]))  myLayer = arcpy.mapping.Layer(rast) arcpy.mapping.AddLayer(myDF, myLayer)  myLyr = arcpy.mapping.ListLayers(mxd, '', dfSpecies)[0] arcpy.ApplySymbologyFromLayer_management(myLyr, symLayer)

View solution in original post

0 Kudos
1 Reply
ThomasLaxson
New Contributor III
Even though I was setting the symbology by an attribute field that shared a consistent structure (i.e., type, precision, etc.) among all the rasters, inconsistency in the pixel depth of the value fields was throwing off the symbology. Solutions:

Quickest processing: Create a layer file unique to each pixel type; as each raster is brought in, describe the raster and identify the pixel type; based on the layer's pixel type, select the appropriate .lyr file for assigning symbology.

Quickest script-writing: Copy all the rasters with the pixel type explicitly set to a common (maximum) size.


Here's the relevant portion of code that I used for the first option, with variable names adapted for clarity:

lyrDict = {'U16':'mylayer_u16.lyr', 'S16':'mylayer_s16.lyr', 'U8':'mylayer_u8.lyr'}  d = arcpy.Describe(rast) symLayer = arcpy.mapping.Layer(os.path.join(lyrDir, lyrDict[d.pixelType]))  myLayer = arcpy.mapping.Layer(rast) arcpy.mapping.AddLayer(myDF, myLayer)  myLyr = arcpy.mapping.ListLayers(mxd, '', dfSpecies)[0] arcpy.ApplySymbologyFromLayer_management(myLyr, symLayer)
0 Kudos