Following on from my ramblings in the "Collapse Clump/Sieve Original Value back to DN value" article I realized that it would be helpful to be able to perform a Join operation of an external table (or another Raster) of attribute information to a commonly identifiable field in a Raster Attribute Table.
For example, consider this thematic image which is the result of performing a Clump and Sieve operation (to remove small contiguous groupings of class values). The Original_Value field is present to identify the original DN values of the thematic image that was Clumped, but we have no idea what classes those numbers represent. Nor do we have standardised colors for each Original Value - just random colors based on the clump DN value.
|2D View showing the image sieved_no_attributes.img and its associated attribute fields|
But I do have a couple of Table files which represent the original Class_Names and Color attributes:
|Contents of class_names.tbl and class_colors.tbl|
So what we want to do is perform a Join using, effectively, the row number of the Tables as the attribute to relate to the Original_Value field. I.e. we want all occurrences of Original_Value = 0 in the raster image to be associated with row 0, Class_Names = Unclassified, Color = Black; all occurrences of Original_Value = 1 to be associated with row 1, Class_Names = Highway, Color = Dark Grey; etc.
The Spatial Model to perform this operation looks like this:
After running the Spatial Model the input thematic image and its associated attribute values look like this:
The model as provided assumes that the input thematic raster is the result of a Clump operation and therefore has an Original_Value field which is going to be used as the primary Match Attribute for the Join. However the model can be easily modified if a different attribute is to be used for the Match Attribute.
The model also expects two separate input tables, one representing a Names field and the other the associated Colors for those named classes. As such the two Tables should have the same number of rows and the number of rows corresponds to the unique occurrences of the Match Attribute. The model could be easily modified to take more (or fewer) Tables, but all should have the same number of rows. Rather than external Table files the tables could be read from another input Raster if desired.
The model is designed to add the Joined attribute fields to the Input Thematic image file, not to output a new raster. Again, the model could be easily modified to create a new output raster file, with the Joined attributes, if the user does not wish to modify the input image.
Input Thematic: The filename of the input raster image to be updated with Joined attributes. The raster should include an Original_Value field which is used as the Match attribute when performing the Join. Note that this is a Spatial Model that modifies the input data so do not run it as-is if you do not wish the original image to be modified.
Input Names Table: A .tbl ascii file consisting of class names, one name per row. The table should have as many rows as there are unique values of the Match Attribute. In the case of the example data there are 17 name strings corresponding to 17 unique values present in Original_Value.
Input Color Table: A .tbl ascii file consisting of color definitions, one name per row. The table should have as many rows as there are unique values of the Match Attribute