Coercing Rasters - Creating Points and Polygons from Rasters

Liz Sanderson
Liz Sanderson
  • Updated

FME Version

  • FME 2018.x

Introduction

The RasterToPolygonCoercer transformer vectorizes data by converting each cell into a polygon feature. This is suitable for thematic mapping as polygons with similar values can be dissolved together to produce larger areas.

The RasterCellCoercer transformer vectorizes raster data by converting each cell into either a point feature or polygon feature. In point mode, it is more suitable for working with DEM data than for aerial photos or other images as point features can then be used in transformers such as the SurfaceModeller. In polygon mode, it is similar to the RasterToPolygonCoercer.

 

Step-by-step Instructions

1. Read in a Digital Elevation Model (DEM)

In a blank workspace read in the PortMoody.dem using the Canadian Digital Elevation Data (CDED) Reader. This DEM contains ocean, mountains, and urbanized areas.

portmoody-clipped.png

DEM of Port Moody, British Columbia

 

2. Resample the Raster

Next, add a RasterResampler transformer. This transformer is used for testing the workspace and can be removed before production if desired. The RasterResampler resamples the raster reducing the size which helps the translation process faster.

 

In the RasterResampler parameters, ensure that the Size Specification is set to RowsColumns. For the row and column size, a user parameter will be used to quickly change the cell size at runtime. Click the drop-down arrow next to Number of Columns (cells) > Users Parameters > Create User Parameter. In the Add/Edit User Parameter dialog set the following parameters:

  • Name: CellSize
  • Prompt: Number of Cells:
  • Default Value: 100
  • Published: Yes
  • Optional: Yes

Click OK to create the parameter. Apply the parameter to Number of Rows (cells) by using the drop-down menu and selecting the CellSize parameter.

rasterresampler.png

RasterResampler parameters, CellSize user parameter created.

 

3. Add the RasterToPolygonCoercer

This example will be using polygons, so it makes sense to use the RasterToPolygonCoercertransformer instead of the RasterCellCoercer, as it is faster. Add a RasterToPolygonCoercer to the canvas and connect it to the RasterResampler. In the parameters, rename the Label Attribute to _z. The Label Attribute will take the values from the raster bands and convert it to a comma-separated list. This raster only has one band, we will only get one value, which in this case will be the elevation because it is a DEM.

 

4. Group layers

Merging polygons by their original elevation has the drawback that not many adjacent polygons may have the same values. It would be much more logical - and more in line with a layer-shaded map - to group features at 10ft intervals.

withoutgrouping.png

Without grouping the layers, the cells are not related to each other to create elevations. (Viewed by using the Group By option in the Inspector mentioned in Step 5)

 

To do this, add an ExpressionEvaluator to the canvas and in the parameters set the expression to:

(int((@Value(_z)/10)))

 

This expression divides the actual elevation (_z) by ten and rounds the value off to an integer. By doing so, it effectively creates 10ft bands of elevation across the data.

 

5. Inspect output

Add an Inspector transformer, and connect it to the ExpressionEvaulator. In the Inspector parameters, set the Group By to _result. This will set a different color to each of the _result values.

elevations.png

Elevations can now be distinguished

 

6. Dissolve boundaries

Now we can see distinct patterns of elevation, but we can remove the cell boundaries for elevations with the same value. Add a Dissolver transformer to the canvas and connect it between the ExpressionEvaluator and the Inspector using the Area output port. In the parameters set the Group By to _result. Rerun the translation to see the elevations.

completedworkspace.png

Final workspace

finaloutput.png

Final output with the cell boundaries dissolved, with a cell size of 100

 

Try running the workspace with Run with Prompt enabled and set the cell size to different values anywhere between 1 and 1201. A lower cell size will be less detail but will run faster; a higher cell size will have greater detail but will run significantly slower.

50cells.png1201cells.png

A cell size of 50 and a cell size of 1201 set using the CellSize user parameter

 

RasterCellCoercer

The RasterCellCoercer transformer can be used similarly to the RasterToPolygonCoercer, except that it works better for creating points. When using this transformer a CoordinateExtractor should be used before the ExpressionEvaulator and Dissolver transformers to extract the elevation from the raster bands.

 

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.