FME Version
Files
-
- 90 KB
- Download
Introduction
In this tutorial, you will learn how to convert raster data into polygons using the RasterToPolygonCoercer transformer.
Step-by-step Instructions
In this scenario, you want to convert a 1m raster of urban and park areas into a city boundary polygon that will be stored in the KML format.
Source
The source dataset is a GeoTIFF of the urban and park areas in the City of Vancouver.
1. Create a New Workspace
Open FME Workbench and create a blank workspace.
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 on this article. Then open the parameters.
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.
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.
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 Feature Caching, by going clicking on the arrow next to the Run button and selecting Enable Feature Caching. Click Run to run the workspace to the RasterToPolygonCoercer.
After the workspace has finished running, click on the green magnifying glass on the RasterToPolygonCoercer to open the data in Visual Preview.
In Visual Preview, we can see that the RasterToPolygonCoercer created the _label attribute which represents the band values covered by that polygon (in this case R, G, B, A). In the original dataset, there are three classified cell values: 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 have been made transparent. Since the background cells still have values, they made into polygons by the RasterToPolygonCoercer.
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 ran the workspace up to this point using feature caching, we can select the cached value for _Label instead of typing in the value manually.
Click on the drop-down arrow for the Right Value, expand Cached Values then select the 0,0,0,0 value.
6. Smooth the Polygon Edges
If we were to run the workspace and inspect the output right now, we would notice the polygon is very jagged as it follows the outline of the raster cells, similar to the screenshot provided below.
To avoid this, we need to smooth the lines by reducing the density of coordinates by removing vertices.
Add a Generalizer to the canvas and connect it to the Failed output port on the Tester. These are all the polygons that are not background.
In the Generalizer parameters, we will use the default Douglas (Generalize) Algorithm, but set the Generalization Tolerance to 10.
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.
Connect the VancouverParks writer feature type to the Generalizer output port.
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 popup menu, then click on Open Containing Folder.
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 Visual Preview.
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.
Comments
0 comments
Please sign in to leave a comment.