Showing results for 
Search instead for 
Do you mean 

Relate a Table of values to a Raster Attribute

by Technical Evangelist on ‎12-18-2019 08:46 AM - edited on ‎02-24-2020 04:45 AM by Community Manager (116 Views)

Download model and sample data

Description:

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
No_Classes_Image.PNG

 

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
Tables.PNG

 

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:

 

relate_attributes_v16_6_0.gmdx
Join_Attributes_Model.PNG

After running the Spatial Model the input thematic image and its associated attribute values look like this:

 
Join_Attributes_Results.PNG

 

Data Requirements and Assumptions

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 parameters:

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

 

Join_Attributes_Dialog.PNG

   

Example data:

sieved_no_attributes.img – A single-band thematic image produced from a landcover classification which has been run through a Clump and Sieve operation (to remove small clusters of contiguous pixels with the same class value. The Clumping process converts a limited number of original class DN values to a large number of sequential clump DN values. As such, there is an Original_Value attribute field which defines the relationship of each clump back to the original landcover class value.

class_names.tbl – An ascii file (created originally via the Table File Output operator) denoting the landcover class names that are to be Joined into the thematic image.

class_colors.tbl – An ascii file (created originally via the Table File Output operator) denoting the landcover class colors that are to be Joined into the thematic image.

Courses
Contributors