Hexagon Geospatial
MENU

Spatial Modeler Tutorials

Learn more about our products, find answers, get the latest updates, and connect with other Hexagon Geospatial product users, or get support from our professional service team.
Showing results for 
Search instead for 
Do you mean 

Attach Standardised Class Names and Colors

by Technical Evangelist ‎01-15-2019 07:50 AM - edited ‎01-16-2019 05:10 AM (82 Views)

Download models

Description:

When producing thematic raster outputs, assigning a consistent set of DN value to color assignments (as well as other attributes, such as class names) is vital to providing interpretability of the displayed results. This can be performed interactively in ERDAS IMAGINE using the Raster Attribute CellArray. However if you have multiple images to apply consistent attribution to it's far more efficient to perform this task as part of a Spatial Model.

 

The landcover crop attribute names, and their corresponding colors, used in this example are those discussed in this USDA / University of Wisconsin article:

 

https://www.sco.wisc.edu/2012/04/25/133-map-categories-how-the-us-department-of-agriculture-solved-a...

 

Consider the screenshot below. In the left 2D View is a thematic map of cropland classes with a default grey-scale color ramp applied to the DN values and no saved attributes. What we really want is the version shown on the right (and the legend shown in the Contents panel) which has a standardized set of cropland class names and colors associated with it.

 

colortable_results.png

 

Attach to New File

 The first Spatial Model provided (cropland_colors_float_v16_5_0.gmdx) takes an existing thematic image file, associates standard class names and colors with it, and writes out a new thematic image file.

 

This exact Spatial Model generally wouldn't be performed since it is costly in disk space. It represents a Spatial Model snippet that you would normally embed into a larger spatial model that is creating a thematic output. Use of the Attach Attributes operator is especially useful since it enables a Preview of the model results, with colors applied, without needing to write an output file. 

 

 cropland_colors_float_v16_5_0.gmdx
attribute_model1.PNG

 

How does it work?

 There are essentially three different attributes we want to attach using this Spatial Model: Class_Names, Colors and Opacity (for each color, mainly to set the Background class, DN 0, to fully transparent).

 

To do this we need a single Create Column(s) operator. Right click on the default operator and select Add Port twice so that you have the necessary inputs for three sets of attributes in total. Generally we'd feed this using Custom Table Input operators, but....

 

The article referenced above provides the DN value to attribute mappings as an Excel spreadsheet with the color values broken out into three separate columns representing the Red, Green and Blue components of each color. To make use of color data presented in this way three three Custom Table Input operators are added. Each one is defined as having 256 entries (because the output data in this instance is 8-bit) of Float datatype. Each color component column is then copied from Excel and pasted into the Table Source dialog of the appropriate operator. Here's part of the table comprising the Red component of each color:

 

Red.png

 

Once Custom Tables Inputs have been populated in this way for red, green and blue components, those three tables are fed into a Color operator which combines then into a single Table of type Color.

 

That Color Table is then fed into the Create Column(s) operator to create an attribute column called Color with datatype Color.

 

Class Names could be directly copied from the Excel spreadsheet and pasted into a Custom Tables Input again with 256 entries but this time defined as datatype String. That StringTable is then fed into the Create Column(s) operator to create an attribute column called Class_Names with datatype String.

 

Names.png

 

Finally, opacity values were defined by adding a Custom Tables Input with 256 entries, defined as Float. This time there were no values to copy from an Excel spreadsheet. Instead it as assumed that the Background class (DN value 0) should be transparent (opacity 0.0) while all other classes should be opaque (opacity 1.0). So in the Custom Tables Input operator's Table Source dialog, New Value as set to 1.0 and the From Below button clicked to set all entries to 1.0. Then the first row was manually edited to 0.0, to look like this:

 

Opacity.png

 

This table is then fed into the Create Column(s) operator to create an attribute column called Opacity with datatype Float.

 

Depending on the data depth of the thematic data you are dealing with you may need less (or more) rows in your Tables. But in general, when creating Attribute Columns, you'll need the same number of rows in each Table. 

 

Also note that Color and Opacity are specially named attribute fields - the 2D View will automatically use attributes named this way to style the raster data when displayed. Class_Names is also a unique attribute name which will be used to populate the legend in the Contents panel (but is customizable via a Preference).

 

The Attach Attributes operator then (funnily enough) attaches the attribute columns to the input raster stream. The raster stream can then be Previewed or fed to  Raster Output file.

 

If adding this snippet to a larger model of your own design you may wish to ensure the raster stream you are attaching the attribute columns to is thematic by using a Set Thematicity operator.

 

Attach to Existing File

 The second Spatial Model (cropland_colors_float_update_v16_5_0.gmdx) works in a very similar fashion except that it is designed to update an existing thematic raster file with the attributes. I.e. it does not create a new output file, it instead modifies the existing file (and therefore assumes that the input file is writeable).

 

 cropland_colors_float_update_v16_5_0.gmdx
attribute_model2.PNG

 

This Spatial Model is slightly different in that I consolidated the Input colors into a Custom Table Input operator (which helps if you want to see the colors of the colors before applying them). This is simply an alternate way of inputting colors. 

 

Colors.png

 

Custom Color Chooser

 Also included in the Zip file is a custom Color Library file (Cropland_Colors.clb). This can be copied to a user's .imagine1650\colors directory, or to <IMAGINE_HOME>\etc\colors if all users of ERDAS IMAGINE should have access. The color palette defined for the USDA Cropland Data Layer will then be available to choose colors from.

 

cropland_colors.png

 

A color library like this can be used to select colors for Annotation polygon fill, line colors, vector styling, etc.

 

 

Courses
Contributors