Convert from Raster to Vector

Liz Sanderson
Liz Sanderson
  • Updated

Introduction

In this tutorial, you will learn how to convert raster data into polygons using the RasterToPolygonCoercer transformer.

Data Source

The source dataset is a GeoTIFF of the urban and park areas in the City of Vancouver. 

RasterSource.png

Step-by-step Instructions

In this scenario, you want to convert a 1m raster of urban and park areas into a city boundary polygon stored in KML format.

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 VancouverParks.tif dataset, which is available for download from the Files section of this article. Then open the parameters. 

Geotiff.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 the dataset's name. Click OK twice to finish adding the reader. 

TiffParams.png

3. Create Polygons

Click on the VancouverParks reader feature type to select it.  Then add a RasterToPolygonCoercer transformer to the canvas by typing “RasterToPolygonCoercer” to bring up the list of FME Transformers in the Quick Add Search. Select the RasterToPolygonCoercer from the list of Transformers by double-clicking or by using the arrow keys and the Enter key to add it. 

QuickAdd.png

Connection.png

The RasterToPolygonCoercer creates polygons from input raster features. One polygon is output for each contiguous area of pixels with the same value in the input raster. We can accept the default parameters. 

4. Inspect New Polygon

Enable Data Caching (formerly Feature Caching) by clicking on the arrow next to the Run button and selecting Enable Feature Caching. Click Run to run the workspace to the RasterToPolygonCoercer. 

FeatureCaching.png

After the workspace finishes running, click the green magnifying glass on the RasterToPolygonCoercer to open the data in Data Preview (formerly Visual Preview). 

ViewCache.png

In Visual Preview, we can see that the RasterToPolygonCoercer created the _label attribute, which represents the band values within that polygon (in this case, R, G, B, and A). In the original dataset, there are three classes: urban, park, and background. Although the dataset appears to be clipped to the land boundary, the background cells still have values (0, 0, 0, 0) but are transparent. Since the background cells still had values, the RasterToPolygonCoercer converted them to polygons.

VP1.png

5. Remove the Background

Add a Tester to the canvas and connect it to the RasterToPolygonCoercer. In the parameters, set the Left Value to _label and the Operator to =. Since we have been running the workspace up to this point with feature caching, we can select the cached value for _Label instead of typing it manually. 

Click on the drop-down arrow for the Right Value, expand Cached Values, then select the 0,0,0,0 value. 

Tester.png

6. Smooth the Polygon Edges

If we were to run the workspace and inspect the output right now, we would notice that the polygon is very jagged as it follows the outline of the raster cells, as shown in the screenshot below.

NoGeneralize.png

To avoid this, we need to smooth the lines by reducing the coordinate density by removing vertices. 

Add a Generalizer to the canvas and connect it to the Tester's Failed output port. These are all the non-background polygons. 

GenConnect.png

In the Generalizer parameters, we will use the default Douglas (Generalize) Algorithm, but set the Generalization Tolerance to 10. 

Generalizer.png

7. Write to OGC Google KML

With the vector polygons created, the data can now be written out to a vector format. For this example, add an OGC/Google KML writer to the canvas. Browse to the Output folder and name the dataset ParkPolygons.kml. 

Writer.png

Connect the VancouverParks writer feature type to the Generalizer output port. 

CompleteWorkspace.png

8. Run Workspace

Run the workspace. The output dataset can be viewed in either Visual Preview or in Google Earth. To open the data in Google Earth, click on the VancouverParks writer feature type to open the mini toolbar, then click on Open Containing Folder. 

OpenContaining.png

Double-click on the dataset in the file browser to open Google Earth. Note that Google Earth needs to be installed. Otherwise, open the data in Data Preview. 

GoogleEarth.png

Data Attribution

The data used here 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?

We're sorry to hear that.

Please tell us why.

As of January 14th, 2026, comments on knowledge base articles have been closed. To make sure questions don’t get missed and to enable more community support, we’ve moved discussions to the FME Community. If you have a question or a comment about this article, please create a new post or create a support ticket.