Elevation Zoning Scenario - Reclassify Rasters Using the RasterExpressionEvaluator

Liz Sanderson
Liz Sanderson
  • Updated

FME Version

  • FME 2018.x

Introduction

This scenario combines a numeric DEM raster and a color RGB raster to determine elevation zones. These elevation zones are used to determine how to prepare your car for winter. If you live in a red zone, you will need winter tires from October until May, but if you live in a green zone, you should be fine with all-season tires.

Keep in mind that this is a fictional scenario and you should not base your winter preparations on this article. Please consult your local government transportation agency for winter preparedness guidelines for your area.

 

Step-by-step Instructions

1. Read in DEM and reproject

In a blank workspace, add a Canadian Digital Elevation Data (CDED) reader to the canvas and browse to the PortMoody.dem dataset.

Once the reader is added to the canvas, add a Reprojector transformer. In the parameters, set the Destination Coordinate System to LL84.

readdem.png

Read in the DEM and reproject to LL84

 

2. Read in the PNG Map

Next, add a PNG (Portable Network Graphics) reader to the canvas and browse to the Reference_Map.png dataset. Inspect the dataset and ensure that the Coordinate System is set to LL84, if the coordinate system is undefined, the world file is missing. Ensure that the Reference_Map.wld file is in the same folder as the Reference_Map.png.

 

3. Extract raster attributes

We will need to use the attributes of the reference map throughout the workspace, so we will need to extract them. Add a RasterPropertyExtractor transformer to the canvas and connect it to the PNGRASTER Feature Type. There are no parameters to set for this transformer.

 

4. Clip DEM to reference map

Using the Clipper transformer, we will clip the DEM of Port Moody to the reference map. Add a Clipper to the canvas and connect the Output port of the RasterPropertyExtractor to the Clipper input port and the Reprojected output port on the Reprojector to the Clippee input port. The default parameters are used.

clipper.png

Connect the RasterPropertyExtractor to the Clipper input port and the Reprojector to the Clippee

 

5. Join features

We will use the FeatureJoiner transformer to join the attributes of the two features but first we will need to create an attribute to merge on. Add an AttributeCreator transformer to the canvas and connect it to the Output port on the RasterPropertyExtractor. Create a new Attribute called _merged and give it a Value of 1.

 

Duplicate the AttributeCreator by right clicking on it and selecting Duplicate or highlighting it and using the keyboard shortcut CTRL-D. Connect the duplicate AttributeCreator to the Inside output port on the Clipper.

duplicate.png

Duplicate the completed AttributeCreator transformer

 

Now that we have attributes to merge on, add a FeatureJoiner to the canvas. Connect the Right input port on the FeatureJoiner to the first AttributeCreator, which is connected to the RasterPropertyExtrator. Then connect the Left input port to the other AttributeCreator. In the parameters, set the Join Mode to Left, then set the Join On to _merge for both Left and Right.

featurejoiner.png

FeatureJoiner parameters; set the Join Mode to Left and set both Left and Right to _merged

joinerworkflow.png

Connect the first AttributeCreator to the Right input port and the second to the Left on the FeatureJoiner

 

6. Create and then fetch height parameter

When we run the workspace, we want the user to be able to pick the height of the elevation zones. To do this, we will create a User Parameter.

In the Navigator pane, right-click on User Parameters then select Create User Parameter. In the Add/Edit User Parameter dialog change it to match:

Type: Number
Name: ZoneHeight
Published: Checked
Optional: Checked
Prompt: Elevation Zone Height
Attribute Assignment: Default
Default Value: 50
Configuration:  
Lower Limit Greater than or equal to value
Value 20
Upper Limit Less than or equal to value
Value 100
Decimal places of precision 0


zoneheightparam.png

Create the ZoneHeight User Parameter

 

Next, we will need to fetch the parameter and put it into our workflow. Add a ParameterFetcher transformer to the canvas and connect it to the Joined output port on the FeatureJoiner. In the parameters set the Parameter Name to ZoneHeight and the Target Attribute to _height.

parameterfetcher.png

ParameterFetcher parameters; set the Parameter Name to ZoneHeight and the Target Attribute to _height

 

7. Resample Raster

Next, we want to resample the DEM with the dimension of the PNG so we will be able to use the RasterExpressionEvaluator on both later on.

Add a RasterResampler transformer to the canvas and connect it to the ParameterFetcher. In the parameters, set the Size Specification to RowsColumns and then set the Number of Columns (cells) to _num_columns and set the Number of Rows (cells) to _num_rows. These attributes come from the PNG and were exposed when we used the RasterPropertyExtractor.

 

8. Remove NoData

Rasters that contain NoData does not allow for logical operations using the RasterExpressionEvaluator; it will cause the translation to fail, so we will need to remove them. Add a RasterBandNoDataRemover transformer to the canvas and connect it to the RasterResampler. There are no parameters to set for this transformer; it will automatically remove bands that contain NoData.

rasterbandnodataremoverworkflow.png

Connect the FeatureJoiner Joined output port to the ParameterFetcher, then connect the RasterResampler and the RasterBandNodataRemover

 

9. Classify DEM for elevation

Now that the data is clean we can classify the DEM to set the elevation zone. Add a RasterExpressionEvaluator transformer to the canvas and connect it to the RasterBandNodataRemover. In the parameters, append _DEM to the Transformer Name, then ensure that the Mode is set to One Raster. Under Band Expressions set the following:

Interpretation: UInt8

Expression:

if(A[0]==0,0,A[0]/A:_height+1)

demrasterexpression.png

RasterExpressionEvaluator parameters for the DEM

 

This equation breaks down to:

If elevation = 0 then leave it as 0

If the elevation is between 1 and 50, set it to 1

If the elevation is between 51 and 100, set it to 2

If the elevation is between 101 and 150, set it to 3 and so on.

classifieddemoutput.png

Output of the RasterExpressionEvaluator_DEM with the classified elevation zones

 

10. Classify PNG as grayscale background

We will now classify the PNG to make it a grayscale image but leave the ocean blue since it won’t be colored with our elevation zones. Since this is an RGB raster, the equation will be a bit more complicated. Add another RasterExpressionEvaluator to the canvas and connect it to the PNG Feature Type. In the parameters, append _PNG to the Transformer Name then ensure that the Mode is set to One Raster. For the Band Expressions set the following:

 

Interpretation: Red8

Expression:

if(A[0]==153 && A[1]==179 && A[2]==204, A[0], 0.2989*A[0] + 0.5870*A[1] + 0.1140*A[2])

 

Interpretation: Green8

Expression:

if(A[0]==153 && A[1]==179 && A[2]==204, A[1], 0.2989*A[0] + 0.5870*A[1] + 0.1140*A[2])

 

Interpretation: Blue8

Expression:

if(A[0]==153 && A[1]==179 && A[2]==204, A[2], 0.2989*A[0] + 0.5870*A[1] + 0.1140*A[2])

 

pngrasterexpression.png

RasterExpressionEvaluator parameters for the PNG

 

These equations break down to:

If Red8=153, Green8=179, and Blue8=204 ignore it, which leave the ocean blue

Then change the remaining colors to grayscale

Output of the RasterExpressionEvaluator_PNG with the raster as a grayscale except the ocean

 

11. Reclassify to create elevation zones

Finally, we can reclassify both of the rasters together to create the elevation zones. Add a RasterExpressionEvaluator to the canvas and in the parameters set the Mode to Two Rasters, and click OK. Connect the RasterExpressionEvaluator_PNG to the A input port and then connect the RasterExpressionEvaluator_DEM to the RasterBandNodataRemover to the B input port. In the parameters set the following for the Band Expressions:

 

Interpretation: Red8

Expression:

if(B[0]<=2, A[0], if(B[0]==3 || B[0]==4, A[0]*1.1, if(B[0]==5 || B[0]==6, A[0]*1.3, A[0]*1.5)))

 

Interpretation: Green8

Expression:

if(B[0]==0 || B[0]==5 || B[0]==6, A[1], if(B[0]==1 || B[0]==2, A[1]*1.3, if(B[0]>=7, A[1]/1.1, A[1]*1.1)))

 

Interpretation: Blue8

Expression:

A[2]

 

elevationrasterexpression.png

RasterExpressionEvaluator parameters for creating the color elevation zones

 

These equations break down to:

For DEM zones 1 and 2 increase the value of the green band (which makes it greener)

For DEM zones 3 and 4 increase the value of the red and green band (which makes it yellower)

For DEM zones 4 and over increase the value of the red band (which makes it redder)

 

12. Inspect output

Add an Inspector transformer to the Result output port on the third RasterExpresionEvaluator or write out to your preferred raster format. Enable Run with Prompt to set the Elevation Zone Height parameter. Inspect the results, and you should see the elevation zones overlaid on the raster map.

Final output; various elevations with green being the lowest and red being the highest elevation.

 

Additional Resources

Simple Examples Using the RasterExpressionEvaluator

TransformerCombining Rasters with the RasterExpressionEvaluator

Using Conditions with the RasterExpressionEvaluator Transformer

 

Data Attribution

Data used in this tutorial originates from open data made available by the Government of Canada. It contains information licensed under the Open Government Licence - Canada.

 

 

Was this article helpful?

Comments

0 comments

Please sign in to leave a comment.