Label Google Earth Polygons

Liz Sanderson
Liz Sanderson
  • Updated

FME Version

  • FME 2021.1

Introduction

In addition to labeling points in KML, it is possible to label other geometries, such as polygons. To draw an icon and label in Google Earth, a point and a Placemark are necessary. If a dataset has polygon geometries, it is necessary to create a point aggregated with each polygon, for icon and label display. The point element is used for the icon and label location. If only labels are desired, in the KMLStyler an icon scale of 0 will cause Google Earth to display the label, but no icon.
 

Step-by-step Instructions

1. Add a MapInfo TAB Reader
Open FME Workbench and start a blank workspace. Add a MapInfo TAB (MITAB) reader to the canvas and browse to the Parks.tab dataset available from the Files section on this article. 

MapInfoReader.png

2. Reproject the Data
If you inspect the Parks.tab dataset in Visual Preview, you’ll see that the coordinate system is UTM83-10. Google Earth only accepts data in latitude and longitude systems, so we will need to reproject. 
VPUTM83.png

Add a CsmapReprojector transformer to the canvas and connect it to the Parks reader feature type. In the parameters, set the Destination Coordinate System to LL84 and then click OK. CSMap.png

3. Create a Polygon ID
Next, we will need to create a unique polygon id for each of the polygons. This will be used to aggregate points and polygons. Add a Counter to the canvas and connect it to the CsmapReprojector. In the parameters, change the Count Output Attribute to Polygon_ID.
PolygonID.png

4. Create Center Point
Now we need to create a point in the middle of the polygon to which we will attach the label, to do this, we will use the CenterPointReplacer transformer. Add a CenterPointReplacer to the canvas and connect it to the Counter. We can accept the defaults for this transformer. 
If you have irregularly shaped polygons, the point may be outside of the polygon. To ensure that the point is within it, you can change the Mode of the CenterPointReplacer to Any Inside Point. 
 
5. Aggregate Polygons and Points
With the points created, we need to aggregate them with the polygons. Add an Aggregator to the canvas and connect it to both the Counter and the CenterPointReplacer. 
AggregateConnection.png

In the Aggregator parameters, enable Group Processing, then set the Group By to Polygon_ID. 
Aggregator.png

6. Set Navigation Tree Name
In Google Earth, each of the features has a name in the side navigation tree, which can be set. Add a KMLPropertySetter to the canvas and connect it to the Aggregator. In the parameters, set the Name to the ParkName attribute, then set Include Attribute Table to No. 

KMLPropSetter.png

7. Style the KML 
One final step before we write out the data is to style how the labels will look. Add a KMLStyler to the canvas and connect it to the KMLPropertySetter. In the parameters, expand the Icon section, then set the Scale to 0. A scale of 0 will cause Google Earth to display the icon label, but not the icon itself. Now expand the Label section and set the Label Style Scale to 0.5. Then click OK. The displayed label will be whatever attribute or value you assign to the Name parameter in the KMLPropertySetter. 

Note: If you wish to have an icon, leave the Icon Scale to 0.8, then select an icon from the ellipsis next to Name in the Icon section. 
KMLStyler.png

8. Add an OGC / Google KML Writer
Add an OGC / Google KML writer to the canvas then browse to a location to save the KML and name it VancouverParks.kml. Set the Feature Definition to Automatic and then click OK. 

Writer.png

In the Feature Type dialog, change the Feature Type Name to Parks and click OK. Connect the Parks writer feature type to the KMLStyler. 
ParksConnection.png

9. Run the Workspace and View Output
Run the workspace, then view the output in Google Earth. 
GoogleEarth.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.