Raster Handling in KML

Liz Sanderson
Liz Sanderson
  • Updated

FME Version

  • FME 2021.1

Introduction

FME can write georeferenced raster features directly to a KML (or KMZ) dataset. FME is also able to write 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 able to supply 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 will cause a single KMZ file to be created containing both a header document (doc.kml) and a sub-folder 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 completely 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 Navigation Pane in FME Workbench. There are three raster handling modes, Write, Copy, and Relative.
 

Regionating Raster Data

Raster data can be regionated, or split into sections, using the Generate Super-Overlays parameter. Regionating data – particularly rasters – can make it easier to control and faster to load in Google Earth.
 

Raster Output Format

The Raster Output Format parameter allows a user to change the type of raster being written to the KML dataset; the four options are JPEG, TIFF, PNG, or GIF. In general terms, a 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

Opacity in a raster dataset can be set using the KMLPropertySetter.

 

Source

sourcedem.png

DEM-Full.dem in Data Inspector

 

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 can be downloaded from the Files section of this article. 
DEMReader.png

Note: This particular dataset has a coordinate system attached, so we do not need to manually set it. If you are reading in a raster that does not have a coordinate system, you will need to manually set it using the CoordinateSystemSetter. 
 
2. Change Raster Interpretation
Add a RasterInterprecationCoercer to the canvas and connect it to the CDED reader feature type. In the parameters, set the Destination Interpretation Type to Gray8. This is an interpretation that is compatible with the TIFF format, which is the default raster output format that is specified in the KML writer advanced parameters. Other destination interpretation types may be used, as long as they are compatible with the raster output format specified (tiff, png, jpeg, gif). 
RasterInterp.png

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. 
PropertySetter.png

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 will cause a single KMZ file to be created containing both a header document (doc.kml) and a sub-folder containing the raster image(s). Then change the Feature Type Definition to Automatic and click OK. 
KMLWriter.png

Note: If you want to change the output raster type, click on 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. 
Parameters.png
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.
Output.png
Elevation.kmz in Google Earth

 

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.