KML Style Range & Display Order

Liz Sanderson
Liz Sanderson
  • Updated

Introduction

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 specific parameter or tag in KML that allows features to be ordered one above the other. However, the display order in Google Earth can be controlled by the elevation of the feature. Features with higher elevations will appear above those with lower elevations. 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 a MapInfo (MID/MIF) reader to the canvas and browse the zipcode_boundaries.mif dataset. 

MifReader.png

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. 

KMLStyler.png

3. Set Navigation Tree Parameters

Add a KMLPropertySetter to the canvas and connect it to the KMLStyler. We will 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. 

KMLPropSetter.png

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.

KMLWriter.png

5. Read in Monitoring Location Addresses

We have a facility monitoring dataset that is monitored by the Environmental Protection Agency (EPA). We will randomly generate pollution levels for these sites and then use this information to create a 3D visualization of the pollution levels. 

Add an OGC GML reader to the canvas and browse to the EPAMonitoredFacilities.gml dataset, then click OK. 

GMLReader.png

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 re-add it later.

FeatureTypes.png

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

RandomNumberGenerator.png

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

AttributeRangeMapper.png

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. 

Bufferer.png

9. Style Facility Locations

Add another KMLStyler to the canvas and connect it to the Bufferer. In the parameters, set Allow Unique Styles Per Feature 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.

KMLStyler2.png

10. Extrude Monitoring Facilities Based on Pollution Level

Add a 3DForcer to the canvas and connect it to the KMLStyler_2. In the parameters set the Elevation to:

@Value(DailyPollutionLevel)*500

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.

3DForcer.png

11. Set the KML Properties

One final step before we write out the facilities to KML| is to et 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. 

KMLPropSetter2.png

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. 

FacilityWriter.png

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.

GoogleEarthOutput.png

Data Attribution

The data used in this article originates from open data made available by the City of Austin, Texas. It contains data licensed under the Public Domain Dedication License, as provided by the City of Austin.

Was this article helpful?

We're sorry to hear that.

Please tell us why.

As of January 14th, 2026, comments on knowledge base articles have been closed. To make sure questions don’t get missed and to enable more community support, we’ve moved discussions to the FME Community. If you have a question or a comment about this article, please create a new post or create a support ticket.