Changing Raster Values by Geographic Feature

Liz Sanderson
Liz Sanderson
  • Updated

FME Version

  • FME 2022.0

Introduction

In this tutorial, you will learn how to select an area and change the values of raster cells by overlaying a polygon onto a raster dataset. This can be easily accomplished in FME using the MapnikRasterizer, an existing raster dataset, and point, line, or polygon features.

preview.png

 

Step-by-step Instructions

In this scenario, you will reclassify raster cells based on areas where park polygons overlay urban cells. This will change the band values from [Band 0: 0], [Band 1: 0], [Band 2: 0], [Band 3: 255] to [Band 0: 0], [Band 1: 255], [Band 2: 0], [Band 3: 255] where park polygons overlay raster cells in the VancouverLand dataset.

Sources
The first source dataset is a GeoTIFF of the land area in the City of Vancouver.
TiffSource.png

The second source dataset is a MapInfo TAB dataset of all the parks in the City of Vancouver. 
ParkSource.png

1. Create a New Workspace
Open FME Workbench and create a blank workspace. 
NewWorkspace.png
 
2. Add a GeoTIFF Reader
Add a GeoTIFF reader to the canvas by clicking on the Reader button on the top menu bar or by going to Readers > Add Reader. In the Add Reader dialog, select GeoTIFF as the Format, then for Dataset browse to the VancouverLand.tif dataset which is available for download from the Files section on this article. Then open the parameters. 
GeotiffReader.png

In the parameters, change the Feature Type Name(s) to From File Name(s), so that when we add the reader, we can see what the dataset is called. Click OK twice to finish adding the reader. 
ReaderParam.png
 
3. Add a MapInfo TAB Reader
Next, add a MapInfo TAB (MITAB) reader to the canvas. Browse to the Parks.tab dataset, then click OK to finish adding the reader. 
MapinfoTab.png
 
4. Add a MapnikRasterizer Transformer
The MapnikRasterizer allows you to convert point, line, and polygon features onto a new or existing raster by dividing features into groups called layers. For more information see the MapnikRasterizer Documentation.

Select the VancouverLand and Parks reader feature types by clicking and dragging a box around them, then type “MapnikRasterizer” to bring up the list of FME Transformers in the Quick Add Search. Select the MapnikRasterizer from the list of transformers by double-clicking or by using the arrow keys and the Enter key to add it to the canvas. This will automatically connect the VancouverLand and Parks reader feature types to the MapnikRasterizer.
QuickAdd.png


The MapnikRasterizer creates the input ports alphabetically, which results in crossed connection lines. To uncross the lines, right-click on the Parks port and select Move Down. 
 
MoveDown.png
 
 Uncrossed.png

Once the MapnikRasterizer has been added, double-click the MapnikRasterizer to open the parameters. 
Notice how the two connections are listed in the Rendering Rules; however, they are set as Line symbols. Since you are classifying raster values by park polygons, you need to change the symbolizers for both of the Rendering Rules.
Change the Symbolizer of the VancouverLand Rendering Rule to Raster and Parks to Polygon. Typically you want the Symbolizer to match the geometry of the features that are ported into the MapnikRasterizer.
Mapnik1.png
Ensure the Rendering Rules are ordered with the VancouverLand raster above the Parks polygons otherwise, the urban cells will be created on top of the park cells. The urban cells need to be classified first, followed by the park cells, so they appear on the output raster. You can adjust the ordering of the rendering rules using the move up/down arrows below the Rendering Rules box.

 
5. Edit the Park Cell Style
Still in the MapnikRasterizer, click on the Edit button for the Parks row to modify the polygon parameters. In the Polygon Parameters dialog, set the Color to Green (0,1,0). Then expand the Smoothing section and set Gamma to 0. Click OK to confirm the polygon parameters. 
Polygon.png
Smoothing is used to control whether the output will have to follow Boolean or Fuzzy logic. A Smoothing Gamma value of 1 uses Fuzzy logic which is useful for areas with movement or uncertainty such as a shoreline. Alternatively, a Smoothing Gamma value of 0 uses Boolean logic which is useful when you want to classify cells with 100% certainty. This exercise will use Boolean Logic so cells will be classified as either urban or park - this will prevent cells from being classified as 20% park and 80% urban.

 

Fuzzy Logic

Boolean Logic



6. Set the Raster Properties
The last step in the MapnikRasterizer is to set the Raster Properties. First, we need to define the cell size for the raster. In the Raster Properties section of the MapnikRasterizer, change the Resolution Specification to Cell Spacing, then give Cell Spacing a value of 1. 
The Cell Spacing parameter specifies the width of the output raster cells, measured in ground units. Note: smaller cells provide greater resolution, however, they typically take longer to load when viewing large extents (i.e. a cell spacing of 1 will take longer to load than 5) and also have large file sizes.
Finally, expand the Background section and set the Color Alpha Value to 0. This will effectively remove the background cells by making them transparent since you are only interested in creating raster cells for areas that are either urban or park in this exercise. For more information on adding alpha bands to remove cells, see the Setting NoData and Adding Alpha Bands to Remove Black Borders article.
CellSpacing.png

7. Add a GeoTIFF Writer
Add a GeoTIFF writer to the canvas, similarly to how a reader is added. Then click on the Dataset ellipsis and navigate to the Output folder. Change the Raster File Definition to Automatic, then click OK to open the Writer Feature Type dialog.
Writer.png 
 
In the Writer Feature Type dialog, set the Raster File Name to VancouverReclass, then click OK to finish adding the writer. 
WriterParams.png
 
8. Run the Workspace
Connect the VancouverReclass writer feature type to the MapnikRasterizer Raster output port. 
Workspace.png

Run the workspace by clicking on the Run button on the top toolbar, or by using Run > Run Workspace on the top menu bar. 
Run.png
 
After running the workspace, the new raster will be created. You can view the raster by selecting the writer feature type to open the popup menu and clicking on the View Written Data button.  
ViewWrittenData.png

In Visual Preview, you’ll see the raster with the park cells classified using the Raster Bands (Band 0-3) and the black urban areas.
VP.png

 

Data Attribution

Data used in this tutorial originates from open data made available by the City of Vancouver, British Columbia. It contains information licensed under the Open Government License - Vancouver.

Was this article helpful?

Comments

0 comments

Please sign in to leave a comment.