Files
Introduction
FME can write georeferenced raster features directly to a KML (or KMZ) dataset. FME is also capable of writing a combination of vector and raster features to the same output file. The Google KML writer works with raster features sent to the writer (as opposed to copying the original source) and carries out proper raster reprojection, rather than doing a vector reproject on the raster’s bounding box.
Overview
The KML format supports raster features, and FME is equally capable of supplying data using that structure. This demo will translate and transform a raster DEM into KML.
Writing Raster Data as KML or KMZ?
In most instances, you will want to write your raster data to a KMZ output file. You do this by simply specifying KMZ as the output extension to use. By default, writing data to a file with a KMZ extension creates a single KMZ file that contains both a header document (doc.kml) and a subfolder containing the raster image(s). When the file extension is set to KML, then the output is somewhat different. The KML file itself is the header document. It contains pointers to the raster image(s), which are stored in a separate folder called 'images'.
KML Parameters for Rasters
Raster Handling Mode
The Raster Handling Mode is an advanced writer parameter found in the Google KML Writer parameters or the Navigation Pane in FME Workbench. Three raster handling modes are available: Write, Copy, and Relative.
Regionating Raster Data
You can regionate, or split into sections, raster data using the Generate Super-Overlays parameter. Regionating data – particularly rasters – can make it easier to control and load faster in Google Earth.
Raster Output Format
The Raster Output Format parameter lets users select the raster type written to the KML dataset, with four options: JPEG, TIFF, PNG, or GIF. In general, TIFF output provides better quality but at the cost of larger file sizes. This parameter has no effect unless the Raster Handling Mode is set to “write”.
Opacity
You can set opacity in a raster dataset using the KMLPropertySetter.
Source
Step-by-step Instructions
1. Read in Digital Elevation Model (DEM)
Open a blank workspace in FME Workbench. Add a Canadian Digital Elevation Data (CDED) reader and browse to the dem-full..dem dataset, which you can download from the Files section of this article.
This dataset has an attached coordinate system, so we don't need to set it manually. If you are reading in a raster without a coordinate system, you will need to set it manually using the CoordinateSystemSetter.
2. Change Raster Interpretation
Add a RasterInterpretationCoercer to the canvas and connect it to the CDED reader feature type. In the parameters, set the Destination Interpretation Type to Gray8. This interpretation is compatible with the TIFF format, which is the default raster output format specified in the KML writer's advanced parameters. You can use other destination interpretation types, as long as they match the specified raster output format (tiff, png, jpeg, gif).
3. Set Raster Opacity
Next, add a KMLPropertySetter to the canvas and connect it to the RasterInterpretationCoercer. Change the Geometry Type to Raster, then set the Raster Opacity to 0.7. If you’d like to change other properties, such as the Navigator Tree Name or what is displayed in the Description Balloon, you can change them now.
4. Write to OGC/Google KML
Add an OGC/Google KML writer to the canvas and browse to a location to save the dataset; name the dataset Elevation.kmz. Remember, we are writing to a .kmz because the KMZ extension creates a single KMZ file containing both a header document (doc.kml) and a subfolder containing the raster image(s). Then change the Feature Type Definition to Automatic and click OK.
To change the output raster type, click Parameters, then expand the Advanced section. Scroll down to the Raster Output Format and select either tiff, png, jpeg, or gif from the drop-down.
In the Feature Type dialog, change the Feature Type Name to Elevation and then click OK. Connect the Elevation writer feature type to the KMLPropertySetter.
4. Run the Workspace and View Results in Google Earth
Run the workspace, then view the output in Google Earth. Notice how the underlying Google Earth background is partly visible under the KMZ raster.
Data Attribution
The data used in this tutorial comes from open data made available by the Government of Canada. It contains information licensed under the Open Government License - Canada.