How to Convert Google KML to Esri Shapefile

Liz Sanderson
Liz Sanderson
  • Updated

FME Version

  • FME 2019.x

Introduction

In this tutorial we will translate Google KML (*.kml) data, representing neighborhood areas, to Esri shapefile (*.shp) format. Our goal will be to create an Esri shapefile of neighborhoods, and to calculate the percent increase in population between 2001 and 2011.

 

The VancouverNeighborhoods.kml Google Earth file contains area features representing neighborhoods, along with accompanying attribute information including population data.

 

Video

This video was created with FME version 2016.0. Some of the steps might be slightly different, but the overall process is the same for newer versions of FME.

 

Step-By-Step Instructions

1. Inspect the Data in FME

The first step is to inspect the VancouverNeighborhoods.kml file. Open a blank FME Workspace and add a new reader. In the reader dialog, type in GoogleKML, then browse to the VancouverNeighborhoods.kml file. Click OK to add the reader to the canvas.

reader.png

 

In the Select Feature Types dialog, click the Select All box to unselect all of the feature types and then select the Neighborhoods feature type.

selectft.png

 

Now to view the data, click on the Neighborhood reader feature type on the canvas to open the popup menu. Then on the popup menu click the View Source Data button to view the data in the Visual Preview Window.

readerpopup.png

In the Visual Preview window (or FME Data Inspector), click the drop-down in the table window and select Neighborhoods to view the Neighborhoods attributes. Take note of the length of the attribute names, since we are planning on writing out to Esri shapefile we will need to shorten the attribute names to only 10 characters.

visualpreview.png

 

Note: This step can also be completed in FME Data Inspector for versions previous to FME 2019. Just be sure to add the Google KML reader to FME Workbench after inspecting the data.

 

2. Set the Output (Writer) Format to Esri Shapefile

Next, we need to add a writer to the canvas. Click on the Add Writer and in the Add Writer dialog box, for the Format, select Esri Shapefile. Then for Dataset, browse to a folder to save the shapefile and then click OK to add the writer.

writer.png

 

3. Clean up Attribute Names

To shorten the attribute names we will need to use an AttributeManager transformer. Add an AttributeManager transformer to the canvas and connect the input port to the Neighborhoods reader feature type and the output to the Neighborhoods writer feature type.

attributemanworkflow.png

 

Open the AttributeManager parameters and change the following Output Attributes:

Input Attribute

Output Attribute

NeighborhoodID

NeighID

NeighborhoodName

NeighName

NeighborhoodURL

NeighURL

TotalPopulation2001

Pop2001

TotalPopulation2011

Pop2011

attributemanager.png

 

4. Update Writer Properties

Now that we have renamed the attributes, we need to reflect the name change in the writer. Open the writer feature type parameters and switch to the User Attributes tab. In this tab, we can see that the attributes are not the same as the ones we just renamed in the AttributeManager. To easily fix this, switch the Attribute Definition to Automatic and it will automatically update to the attributes we renamed. Click OK to accept the new attribute names.

writerparams.png

 

5. Calculate Population Increase

The final step before we run the translation is to calculate the population increase; we will do this with an ExpressionEvaluator transformer. Add an ExpressionEvaluator to the canvas and connect it between the AttributeManager and the writer feature type.

expressionworkflow.png

 

In the ExpressionEvaluator parameters, set the New Attribute name to PopChange. Then in the Arithmetic Expression window set the expression to:

((@Value(Pop2011)-@Value(Pop2001))/@Value(Pop2001))*100

 

This expression calculates the percent increase between 2001 and 2011 populations. It does this by taking the absolute value of the difference and divides it by the original value - the resulting decimal is then converted to a percent.

expressioneval.png

 

Since we set the writer feature type definition to Automatic, the PopChange attribute will automatically be added to the writer. This can be confirmed by expanding the Neighborhoods writer feature type to view the attributes.

writerattributes.png

 

6. Run the Workspace

The workspace is now ready to be run. Run the workspace by clicking on the green play button.

 

7. View the Output Dataset

To view the output dataset, click on the Neighborhoods writer feature type to open the popup menu. Then click on the View Output Data button.

writerpopup.png

 

The attributes have been renamed and we now have a PopChange column containing the population change data as a percent.

output.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.