Creating a KML ScreenOverlay or Watermark

Liz Sanderson
Liz Sanderson
  • Updated

FME Version

  • FME 2021.2

Introduction

Screen overlays are used to place icons or images onto the Google Earth canvas. In FME, there are two methods for building a ScreenOverlay element. It is possible to either (1) use the Watermark parameters of the KML Writer, or (2) to set values of the KML icon and screenXY elements for a ScreenOverlay feature in a workspace. Both methods will be demonstrated in this article.
If you are interested in learning more about the KML ScreenOverlay element, please visit the Google Developers KML Reference.
 

Step-by-step Instructions

Part 1: Prepare BikePath Data

1. Add a Shapefile Reader
Open FME Workbench. In a blank workspace, add an Esri Shapefile reader to the canvas. Browse to the Data folder which can be downloaded from the Files section on this article. Select all BikePath datasets (BikePath_L.shp, BikePath_M.shp, and BikePath_S.shp). Then change the Workflow Options to Single Merged Feature Type, and click OK to add the reader.  
ShapeReader.png
 
2. Join BikePath Lines
The BikePath lines are fragmented for each block, let’s join them together so that they are single lines per PathName. Add a LineCombiner to the canvas and connect it to the <All> reader feature type. In the parameters, click on the ellipsis for Combine On Attributes and select all. 
LineCombiner.png
 
3. Reproject Data
Google Earth and the OGC KML format only accepts coordinate system in latitude and longitude. Add a CsmapReprojector to the canvas and connect it to the Line output port on the LineCombiner. In the parameters, set the Destination Coordinate System to LL84, then click OK. 
Reprojector.png
 
4. Style KML
Next, we need to style the KML output. Add a KMLStyler to the canvas and connect it to the CsmapReprojector. In the parameters, set the Color to Red (255, 0, 0), then expand Line Style and set the Line Width to 2.0. 
KMLStyler.png
 
5. Set KML Properties
One final step before we can write the BikePaths_L dataset out to KML, is to set the Navigation Tree name. Add a KMLPropertySetter to the canvas and connect it to the KMLStyler. In the parameters, set the Name to PathName, then click OK. 
KMLPropSeter.png

Part 2a: Write Watermark to KML Using the Writer Parameters

The data is ready to be written out, in this example, we will use the KML writer parameters to set the watermark. This method is quick and easy to add a watermark if you are not particular as to where the watermark will appear. Using this method the watermark will always appear in the bottom left corner of Google Earth. If you would like to control where the watermark is placed, see Part 2b
 
6. Add an OGC/Google KML Writer
Now the BikePaths watermark is ready to be written out to KML. Add an OGC/Google KML writer to the canvas. Browse to a location to save the dataset and name it BikePath_Watermark.kml. Change teh Feature Type Definition to Automatic then open the parameters. 
WatermarkWriter.png
 
In the Parameters, set the Watermark Name to FME Logo, then set the Watermark Snippet Text to FME Rocks!, finally set the Watermark Overlay Icon to one of the following:
If your workspace is saved in the same root folder as the data downloaded from this article 

images\fme.png

Otherwise, use a direct path such as:

C:\Users\<username>\Documents\KML\KMLWatermark\images\fme.png

WatermarkParams.png

 
Click OK twice to finish adding the writer. In the Feature Type dialog, change the Feature Type Name to BikePaths_Watermark, then click OK. Connect the writer feature type to the KMLPropertySetter. 
If you forgot to set up the Watermark parameters while setting up the writer or you need to change something after the writer has been added, you can modify the parameters in the Navigator pane. 
NavigatorPane.png
 
7. Run Workspace and View the Output in Google Earth
Run the workspace, then open the containing folder and view the output in Google Earth
OpenFolder.png
WatermarkGE.png

 

Part 2b: Set the Position of the ScreenOverlay

In this example, we will use an AttributeCreator to set the position and file location of the ScreenOverlay element. Once we’ve created these attributes we will write the BikePaths and the Logo out separately. 

If you were following along with Part 2a, disable the BikePath_Watermark writer as we will not be using it for this example. (Right-click on writer > Disable) 

8. Create Attributes
Continuing in the workspace from Part 1, add a Creator and an AttributeCreator to the canvas. Connect the AttributeCreator to the Creator, then open the AttributeCreator parameters. 
AttributeCreator.png

We will now specify a number of attributes to manipulate the position of the logo, as well as define the logo path and name. See the screenxy and icon documentation for more information. In the AttributeCreator parameters, create the following attributes:

Attribute Name Value
kml_screenxy_y 0.65
kml_screenxy_x 0.65
kml_screenxy_xunits fraction
kml_screenxy_yunits fraction
kml_icon_href image\fme.png
kml_name FME Logo

AttributeCreatorParams.png
Note: If your workspace is saved in the same root folder as the data downloaded from this article the kml_icon_href path can be: 

images\fme.png

Otherwise, use a direct path such as:

C:\Users\<username>\Documents\KML\KMLWatermark\images\fme.png



9. Add ScreenOverlay Writers
Add an OGC/Google KML writer to the canvas and browse to a location to save the data. Name the file BikePaths_ScreenOverlay.kml. Change the Feature Type Definition to Copy from Reader and click OK. 
OverlayWriter.png
Note that if you were following along with Part 2a, you will need to open the writer parameters and clear the values for the Watermark. (You can also do this in the Navigator pane). 

In the Feature Type dialog, change the Feature Type Name to ScreenOverlay then click OK. Connect the ScreenOverlay writer feature type to the AttributeCreator. 
ScreenOverlayConnection.png

Next, add a second writer feature type. On the top menu bar go to Writers > Add Feature Type. 
AddFT.png

In the Feature Type dialog, change the Feature Type Name to Bike Paths, and then double-check that the Writer is the BikePath_ScreenOverlay. Then click OK.
OverlayBPWriter.png

Connect the BikePaths writer feature type to the KMLPropertySetter that was set up in Part 1. 
Part2bConnections.png

10. Run Workspace and View Output in Google Earth
Run the workspace, then open the containing folder and view the output in Google Earth
OverlayGE.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?

Comments

0 comments

Please sign in to leave a comment.