Creating KML Folders By Feature Type Fanout

Liz Sanderson
Liz Sanderson
  • Updated

FME Version

Introduction

KML Folders define the nested tree structure in the Google Earth Places pane (as shown below). This tree control helps organize data presentation to the user so they can turn on and off layers of interest. It also helps group features together so the user isn’t presented with a list of thousands of features. For example, instead of a hundred different zoning types, you might want to organize your zone features into zone categories such as commercial, residential, industrial, transportation, and open space.

kml-folders-example1.png

KML Folders: Approaches in FME

FME allows you to create KML folder structures in two ways:

  1. The feature type fanout approach (this tutorial)
  2. Through the use of KML_IDs (the next tutorial)

These two approaches are intended for use in KML and not KMZ (which is a zipped KML file). In this example, we will be focusing on the feature type fanout approach. Using Vancouver’s Skytrain stations from a CSV, and Vancouver zones from a MapInfo file, we will create a KML that groups stations together by zones. This is a great way to organize features in the Google Earth legend, especially if you have lots of features that can be aggregated in a logical manner.
 

Step-by-step Instructions

1. Read Source Datasets
In a blank FME workspace, add a Comma Separated Value (CSV) reader to the canvas and browse to the rapid_transit_stations.csv dataset. Set the Coordinate System to UTM83-10, then open the Parameters. 
CSVReader.png
 
In the parameters, change the Feature Type Name(s) to From File Name(s), then change the Attribute Definition to Manual. Now we need to set the attribute types so that FME will create points from our data. Set x to x_coordinate, and y to y_coordinate, then click OK twice to add the reader. 
CSVParams.png
 
Next, add a MapInfo Tab (MITAB) reader to the canvas and browse to the Zones.tab dataset that is available for download from the Files section on this article. We can accept the default parameters. 
MitabReader.png
 
2. Overlay Train Stations on Zones
Next, we will use the PointOnAreaOverlayer to merge the ZoneCategory attributes from the Zones dataset, onto the station points. Add a PointOnAreaOverlayer transformer to the canvas. Connect the rapid_train_stations reader feature type to the Point input port, then connect the Zones reader feature type to the Area input port. 
POAOConnections.png

In the PointOnAreaOverlayer parameters, expand the Attribute Accumulation section, then enable Merge Attributes. 
POAOParams.png
 
3. Clip Stations to Zones
If you inspected the data at any point, you may have noticed that the zones don’t cover all of the train stations, so now we will clip our stations to the zone areas. Add a Clipper to the canvas, then connect the Zones reader feature type to the Clipper input port. Next, connect the Point output port on the PointOnAreaOverlayer to the Clippee input port on the Clipper. 
ClipperConnection.png
If you don’t like that your connection lines are crossed, you can change the order of the ports on the Clipper. Right-click on the Clipper port and select Move Down. 
Reorder.png

 
Note that if you are looking for a quick way to make folders, you can skip to step 7 where we add the writer and connect it directly to the Inside output port on the Clipper. 
 
4. Clean Up Attributes
Both the PointOnAreaOverlayer and the Clipper create attributes we don’t need. Add an AttributeManager to the Inside output port on the Clipper. In the parameters, rename STATION to Station, then remove _overlaps and _clipped. 
AttributeManager.png
 
5. Filter Zones For Styling
Taking a quick glance at our stations and zone data in the visual preview, we can see that our train stations only fall into three zones out of 7 possible ones: Commercial, Development, and Light Industrial. 
VP.png
 
We will filter these out so that we can apply different styles to the output later. Add a TestFilter to the canvas and connect it to the AttributeManager. In the parameters, create the following tests: 

  Test Condition Output Port
If ZoneCategory = Commercial Commercial
Else If ZoneCategory = Comprehensive Development Development
Else <All Other Conditions Light Industrial

TestFilter.png


If you ran the workspace with Feature Caching Enabled before this step, and you are using 2020.1 or newer, you can take advanced of the TestFilter being data-aware. This means when you go to type in the attribute value for the test condition, the attribute value will appear without needing to type it out in full, or you can select it from the drop-down menu. 
DataAware.png

 
 
6. Style KML
We will have three KML folders: Commercial, Comprehensive Development, and Light Industrial, when we set our fanout to ZoneCategory. This step is simply for visualization so we can tell the points apart quickly. Add a KMLStyler to each of the output ports on the TestFilter, there should be three in total. 
ConnectKMLStylers.png
In the first KMLStyler, expand the Icon section, then set the Icon Name to gme/gx_rail, then set the Color to purple. Repeat this step for the other two KMLStylers, selecting blue and yellow as the colors. 
KMLStyler.png
 
7. Write out to OGC/Google KML Using Feature Type Fanout
Our data is ready to be written out. Add an OGC/Google KML writer to the canvas and browse to a location to save the dataset. Name the file KMLFolders_Fanout.kml and set the Feature Type Definition to Automatic. 
KMLWriter.png

In the Feature Type dialog, click OK to accept the default. Then connect the writer feature type to all three KMLStylers. Once it is connected, reopen the parameters. 
WriterConnection.png
 
In the writer feature type parameters, click on the drop-down next to Feature Type Name and select the ZoneCategory attribute. 
WriterParams.png

8. Run the Workspace and View the Output in Google Earth
Run the workspace, then open the containing folder and view the output in Google Earth
GoogleEarth.png
 
In the Navigation Tree you will see the individual folders that we created with the feature type fanout. 
FolderStructure.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.