KML Style Range & Display Order

Liz Sanderson
Liz Sanderson
  • Updated

FME Version

  • FME 2021.1


Style KML using attributes, including unique styles by feature, and set the display order of features. The styling in this example includes classifying features into color ranges and extruding 3D features.
This demo maps fabricated pollution values from monitored facilities, with zipcode boundaries in the background.

Symbology & Style Range

Symbology in KML is controlled by a tag called Style. Style is defined in a workspace using the KMLStyler transformer.
Style can apply to a group of features, or to individual features. The KMLStyler transformer has a parameter to control this. It is called Allow Unique Styles Per Feature. When all features are given the same style, then this parameter should be set to No and there will only be a single Style section.

Display Order

There is no particular parameter or tag in KML by which to order features one above the other. However, the display order in Google Earth can be controlled by the elevation of the feature. Features with higher elevation will appear above features with a lower elevation. Therefore, strict handling of the Z coordinate, plus the use of an altitude mode relative to the ground, can be used to control the display order of features.

Step-by-step Instructions

1. Add Zipcode Data
In FME Workbench, start with a blank workspace. Add MapInfo (MID/MIF) reader to the canvas and browse the zipcode_boundaries.mif dataset. 

2. Style Zipcode Data
Now let’s style the zipcode data as it will be used as a backdrop to the pollution data. Add a KMLStyler transformer to the canvas and connect it to the zipcode_boundaries reader. In the parameters, set Allow Unique Styles Per Feature to No, then set the Fill Color to green and the Fill Opacity to 0.5. 

3. Set Navigation Tree Parameters
Add a KMLPropertySetter to the canvas and connect it to the KMLStyler. We are going to set up the display name for the navigation tree in Google Earth. Open the parameters, and set the Navigation Tree Name to zipcode, then click OK. 

4. Write Out to KML
Let’s write out the zipcode_boundaries to KML. Add an OGC/Google KML writer to the canvas, browse to a location to save the data, and name the file Pollution.kml. Leave the Feature Type Definition to Copy from Reader, as we will be using the same base dataset for both of our KML.

5. Read in Monitoring Location Addresses
We have a facility monitoring dataset that is monitored by the Environment Protection Agency (EPA). We will randomly generate pollution levels for these sites and then we will use this information to create a 3D visualization of pollution levels. 
Add an OGC GML reader to the canvas and browse to the EPAMonitoredFacilities.gml dataset, then click OK. 

In the Select Feature Types dialog, unselect all feature types except HouseAddress, then click the ellipsis next to Add to writers, and select “Pollution [OGCKML]”, this will also add a writer feature type for HouseAddress.  After adding the reader, remove the connection line between the HouseAddress reader and writer feature types, as we will add it back in later.

6. Generate Pollution Levels
Now we need to generate the pollution levels, add a RandomNumberGenerator to the canvas and connect it to the HouseAddress reader feature type. Set the following parameters:

  • Minimum Value: 1
  • Maximum Value: 10
  • Decimal Places: 2
  • Result Attribute: DailyPollutionLevels


7. Set Range
Based on the randomly generated pollution level, we can set the output color. Add an AttributeRangeMapper to the canvas and connect it to the RandomNumberGenerator. In the parameters, set the Source Attribute to DailyPollutionLevels, then the Output Attribute to featurecolor. Next, set the following for Range Lookup Table:

From To Output Value
1 4 1,1,0
4 7 1,0.5,0
7 10 1,0,0


8. Buffer Points into Polygons
Using the Bufferer we will convert the facility points into polygons which we can then color. Add a Bufferer to the canvas and connect it to the AttributeRangeMapper. In the parameters, set the Buffer Distance and both the End Cap and Corner Styles to Round. 

9. Style Facility Locations
Add another KMLStyler to the canvas and connect it to the Bufferer. In the parameters, leave Allow Unique Styles Per Feature set to Yes, this will allow us to color each facility separately. Now click on the drop-down arrow next to Fill Color and select the featurecolor attribute. Change the Fill Opacity to 0.7 and click ok.


10. Extrude Monitoring Facilities Based on Pollution Level
Add a 3DExtruder to the canvas and connect it to the KMLStyler_2. In the parameters set the Elevation to:


This will make elevation relative to pollution and will also cause the monitoring facilities to appear above the zipcode boundaries, as features with a higher elevation will appear above features with a lower elevation.

11. Set the KML Properties
One final step before we write out the facilities to KML, we need to set up the properties. Add a KMLPropertySetter to the canvas and connect it to the 3DForcer. In the parameters, set the Name to FacilityName, then set Altitude Mode to Relative to Ground. Finally, set Extude to Yes, this will ensure that our data will be in 3D. 


12. Connect and Rename Writer
Connect the KMLPropertySetter_2 to the HouseAddress writer feature type. Then in the writer parameters, change the Feature Type Name to FacilityAddresses, then click OK. 


13. Run Workspace and View Output
Run the workspace then view the output in Google Earth. Note that the pollution monitoring facility data appears above the zipcode boundaries and the monitoring facilities are extruded based on the pollution level.


Data Attribution

The data used here originates from data made available by the Government of Austin, Texas. It contains information available to the public domain. 

Was this article helpful?



Please sign in to leave a comment.