KML Pathway Tutorial
KML Pathway Tutorial
KML Pathway Tutorial
Copyright
© 1994 – 2012 Safe Software Inc. All rights are reserved.
Revisions
Every effort has been made to ensure the accuracy of this document. Safe Software Inc. regrets any
errors and omissions that may occur and would appreciate being informed of any errors found. Safe
Software Inc. will correct any such errors and omissions in a subsequent version, as feasible. Please
contact us at:
Safe Software Inc.
Suite 2017, 7445 – 132nd Street
Surrey, BC
Canada
V3W1J8
www.safe.com
Safe Software Inc. assumes no responsibility for any errors in this document or their consequences, and
reserves the right to make improvements and changes to this document without notice.
Trademarks
FME is a registered trademark of Safe Software Inc.
All brand or product names mentioned herein may be trademarks or registered trademarks of their
respective holders and should be noted as such.
Documentation Information
Document Name: FME Desktop KML Pathway Tutorial
Version: FME 2012
Updated: October 2011
FME Desktop KML Tutorial
Using KML
Introduction....................................................................................................................................... 4
KML Pathway ........................................................................................................................................... 4
FME Version ............................................................................................................................................ 4
Sample Data ............................................................................................................................................ 4
Introduction to FME .......................................................................................................................... 5
What is FME? .......................................................................................................................................... 5
KML Basics ...................................................................................................................................... 6
What is KML? .......................................................................................................................................... 6
KML and FME .......................................................................................................................................... 7
Reading KML Data ........................................................................................................................... 8
Exercise 1: Read KML Data ..................................................................................................................... 8
Exercise 2: Translate KML with FME Workbench .................................................................................. 10
Writing KML Data ........................................................................................................................... 13
KML Writing Requirements .................................................................................................................... 13
Exercise 3: Translate to KML with FME Workbench .............................................................................. 14
KML Data Transformation .............................................................................................................. 16
Exercise 4: Style KML Data with FME Workbench ................................................................................ 16
Exercise 5: Add a Point Dataset ............................................................................................................ 19
Exercise 6: Regionate KML Data with FME Workbench ........................................................................ 22
Exercise 7: Create 3D KML Data with FME Workbench ........................................................................ 24
What’s Next? .................................................................................................................................. 27
Next Step ............................................................................................................................................... 27
Introduction Page 3
FME Desktop KML Tutorial
Introduction
KML Pathway
This tutorial is an introduction to using
KML data with FME. It is the first part of
the FME Training KML Pathway.
FME Version
This tutorial specifically covers the use of FME Desktop® 2012 edition. Older versions of FME
may not have some of the functionality described in this tutorial.
Sample Data
The sample data required to carry out the examples in this document can be obtained from:
http://www.safe.com/fmedata
Introduction Page 4
FME Desktop KML Tutorial
Introduction to FME
What is FME?
FME is a spatial data transformation platform that helps
organizations more easily overcome a range of spatial data
interoperability challenges. It is available in both desktop and
server solutions.
With Data Transformation, the output from an FME process can be tailored to match a required
structure, and can even be greater than the sum of the inputs.
The key FME Desktop application is FME Workbench, an intuitive point and click interface for
graphically defining translations and transformations as a flow of data.
FME Quick Translator is an application for carrying out basic, non-customized translations.
KML Basics
If you are new to KML data, then here are some basic facts and
information
What is KML?
KML stands for Keyhole Markup Language. It is an XML-based format (or language if you prefer)
intended to store data for use within the Google Earth™ and Google Maps™ applications.
The name “Keyhole” comes from the name of the original developers of the KML format and
Google Earth product.
KMZ is an alternate form for a KML format dataset. A KMZ dataset is simply a KML dataset
compressed by a ZIP type program and renamed with a new file extension. KMZ is most
frequently used as a means to store a set of raster images; the KMZ (zip) folder stores the raster
files (as JPEG or GeoTIFF) plus a KML file that references them.
Google Maps is also a KML browser, but – at the time of writing – only supports a subset of KML.
There are other KML viewers, but for this module we will stick to using Google Earth.
Like HTML, KML has tags that affect how specific features are displayed. Since KML stores data
of a spatial nature – whereas HTML tends to be non-spatial information – the tags are those that
relate to spatial data symbology; for example, line styles, point symbols and area fill colors.
After cleaning up the data (by removing various style tags), a sample KML dataset looks like this:
<Placemark id="kml_1">
<name>Safe Software HQ</name>
<description><![CDATA[Safe Software's HQ]]></description>
<Style>
<IconStyle>
<scale>0.8</scale>
<Icon>
<href>images/C2.png</href>
</Icon>
</IconStyle>
</Style>
<Point>
<coordinates>-132,45,0 </coordinates>
</Point>
</Placemark>
For example, if the FME dataset name is planning and the feature type name is ROADS, then the
output would be a KML file called planning.kml containing a section beginning:
<Folder id="kml_ft_ROADS">
Data sent to the KML writer must be tagged with a coordinate system – either from within the
source data or using a CoordinateSystemSetter transformer. Then FME will automatically convert
the data to LL84.
When the data is untagged, and FME is unable to ascertain the source coordinate system, the
translation will be terminated.
FME’s support for KML includes the ability to read KML datasets
and to convert them into other GIS data formats
FME’s ability to read KML datasets includes all of the spatial components, but also items like
document properties, folders, and timestamp attributes.
1. Start FME Universal Viewer. Select Start > All Programs > FME Desktop 2012 >
FME Universal Viewer from the Windows Start menu.
2. Select File > Open Dataset from the menu bar to open the dataset selection dialog.
Now that there is some data open in the FME Universal Viewer, it can be queried.
The feature is queried and the information window of the FME Universal Viewer shows the results
of the query:
1. Start FME Workbench. In the Start tab, choose the option to Generate workspace.
Reader
Format: Google Earth KML
Dataset: C:\FMEData\Data\Properties\Properties.kml
Writer
Format: MapInfo TAB (MFAL)
Dataset: C:\FMEData\Output\TutorialOutput
Press the Clear All button to deselect all types. Place a check mark next to the
LandParcels feature type in order to select it for translation. Click OK.
5. A workspace will now be created. Click the expand icon on each feature type object, in
order to reveal the attributes being translated. The workspace will now look like this:
6. Run the translation. Click the green play button to start the translation.
The translation will now run. It may take one or two minutes to complete. A dialog and log
message may warn of “Unexpected Input”, but it is not really unexpected, since we turned
off several feature types in step 4. Therefore the warning can be ignored.
7. To inspect the output, right-click on the writer feature type and choose the option Inspect.
The FME Universal Viewer will start up, and a pre-filled dialog will be displayed:
Click OK. The newly created MapInfo dataset will be opened and can be inspected to
prove the translation functioned correctly.
FME allows users to translate other spatial datasets into the KML
format widely used in today’s society
Writing a basic KML dataset, with no concern about complex node types or feature styling, is as
simple as choosing KML as the output format and running the translation. Where there is styling
(symbology) present on the source data, FME will attempt to preserve it when writing KML output.
KML requires all features to be three-dimensional; if necessary FME will force compliance to
this rule by setting a Z value (third dimension) of zero on all two-dimensional features.
All nodes must have a unique ID. By default FME uses the format attribute kml_id, but if this
is unset then FME will automatically create an id number in order to comply with this rule.
As noted, KML requires all features to be held in the LL84 coordinate system.
FME will automatically convert your data to LL84 provided that it knows the source coordinate
system used. If it cannot deduce this information, and you do not provide it in the dataset
parameters, then the translation will be stopped with an error.
KML or KMZ?
FME’s KML writer provides the capability to write the output data as either a KML or a KMZ
dataset. The type of dataset created depends upon the file extension you provide within the
output dataset name; for example, name your output myData.kml to create an uncompressed
dataset, or myData.kmz to create it in compressed form.
1. Start FME Workbench. In the Start tab choose the option to Generate workspace.
Reader
Format: MapInfo TAB (MFAL)
Dataset: C:\FMEData\Data\Parks\city_parks.tab
Writer
Format: Google Earth KML
Dataset: C:\FMEData\Output\TutorialOutput\Parks.kml
There are no available parameters for the KML writer at this point, so go ahead and click
OK.
3. Run the translation. Click the green play button to start the translation.
The translation will now run and will be completed in a few seconds.
4. Inspect the output. To locate the output folder, right-click on the writer feature type.
Choose the option Open Containing Folder.
5. Windows Explorer will now open and display the correct location for the
output dataset.
Right-click the file Parks.kml and choose Open with > Google Earth.
KML format supports tags that define the style and symbology of the features within a dataset.
In FME these tags can be set using a series of writer parameters and KML-specific transformers.
1. Start FME Workbench. Open, or re-create, the workspace from the previous exercise.
2. Place the KMLStyler transformer. Click on the connection between the reader and writer
feature types. Type the characters KML. A list of KML-related transformers will appear.
Select KMLStyler from the list. A KMLStyler transformer will be added between the reader
and writer.
3. Click on the yellow parameters button on the KMLStyler to open up the parameters dialog
for this transformer.
To set a fill color for the parks, click on the browse button to the right of the Fill Color field:
4. Back in the KMLStyler parameters dialog, click on the browse button to the right of the
Color field, and set the Color value for the polygon outline to black or to the same green
as the fill color.
Click OK.
6. Back in Google Earth, choose the File > Revert menu item (or right-click the object in the
“Places” window and choose Revert) to reload the data.
The park features will now all be the same shade of semi-transparent green, with a
common border color.
8. Open the parameters dialog for the KMLPropertySetter. Fill in these fields:
Name: click the button to select Set To Attribute Value > name
Summary: A park in the city of Interopolis
1. In FME Workbench, open or continue with the workspace from the previous exercise.
2. Click Readers > Add Reader on the menu bar. When the Add Reader dialog opens, fill
in these fields:
Reader
Format: MapInfo MIF/MID
Dataset: C:\FMEData\Data\BirdSociety\BirdNestPoints.mif
4. Right-click the BirdNestPoints reader feature type, and choose Duplicate (On Writer).
Delete the connection that will automatically be created, and connect the
KMLPropertySetter transformer to the new writer feature type.
5. Click on the yellow parameters button on KMLStyler to open up the parameters dialog.
To set an icon for the bird nests, click on the browse button to the right of the Name field.
In the icon-picker dialog, choose icon C2 and click OK.
NB: An image URL can be entered into the name field instead of picking an FME icon.
For example, try http://fme.ly/nest with an icon scale of 1.0
6. Set the properties for these bird nest features. Click on the red parameters button on the
KMLPropertySetter to open up its parameters dialog. Fill in these fields:
8. Problem! Google opens the data in the center of the Atlantic Ocean. There must be a
problem with the bird nest coordinate system.
In the Navigator windows, locate the Coordinate System parameter for the
BirdNestPoints reader. Double-click the parameter. When prompted enter a coordinate
system of TX83-CF and click OK.
1. Start FME Workbench. Open or recreate the workspace from the previous exercise.
3. Click on the red parameters button on the KMLRegionSetter. Fill in these fields:
You will now see that city parks appear and disappear as you zoom in and out.
NB: It’s better to set an explicit bounding box for point features and not use the option to
calculate it. That’s because point features produce an infinitely small bounding box and
would never show in the output. The numbers above cover a good area of the data.
You will now see that bird nests also appear as you zoom in and out, but because
Maximum Display Size = -1, will never disappear because you have zoomed in too close.
1. Start FME Workbench. In the Start tab choose the option to Generate workspace.
Reader
Format: Esri Geodatabase (File Geodatabase API)
Dataset: C:\FMEData\Data\Properties\Buildings.gdb
Writer
Format: Google Earth KML
Dataset: C:\FMEData\Output\TutorialOutput\Buildings.kml
3. Click on the connection between the reader and writer feature types.
Type the characters 3DF. Select 3DForcer from the list of transformers.
4. Open up the parameters dialog for the 3DForcer transformer. This transformer gives a Z
value to the coordinates of 2D features.
Select the attribute Elevation as the source for the Z values. This attribute contains a
building height for each feature.
5. Place a KMLPropertySetter transformer between the 3DForcer and the writer feature type.
Change the view aspect and you will now see three-dimensional building features.
NB: This 3D forcing technique can be used in many scenarios, even for thematic mapping
data such as earthquake intensity:
What’s Next?
Next Step
The next step in the FME KML Pathway
is to take a basic FME Desktop training
course, in preparation for the full FME
KML Training Course.
Further information on all training options is available on the Safe Software web site at
www.safe.com/training
Many other resources for FME Desktop technical information can be located through the
FMEpedia knowledgebase at http://fmepedia.safe.com