Creating A KML Spatial File Using Google Maps For Tableau

Blog | March 8, 2018 | By Vijai Narasimha

Guide to Creating KML Spatial Files for Tableau with Google Maps

Harnessing Google Maps Data: Generating KML Files for Tableau Visualizations

Step-by-Step Tutorial: Using Google Maps to Create KML Spatial Files for Tableau

Geo mapping is such a powerful technique in studying the topography and understanding the geographic locations better with the existing data or to put it better, data can be well interpreted or appreciated with geographic visualizations (The question we are trying to answer is: Does Geography influence our data or drive business decisions?).

Geo mapping has wide applications – Aviation datasets to map airport-passenger traffic, Regional retail market Sales, University data to plot School-Student ratios, Agriculture data to interpret water and vegetation, Census data to represent demographics, Mobile communication data sets to track subscribers and local networks etc.

Understanding KML Files and Their Role in Tableau Mapping

Preparing Google Maps Data for Conversion to KML Format

Exporting KML Files from Google Maps for Tableau Integration

Importing and Utilizing KML Spatial Files in Tableau for Geospatial Analysis

With Tableau’s instant geocoding, it is very easy to build visually rich interactive maps for fields that have a specified geographic role.

For most of the developers, Spatial data for Geo mapping is a big requirement. Spatial data sets offer something that regular fields on Tableau cannot offer. For example – Lines and Polygons. These cannot be automatically shown on Tableau without the support of Point Oder, Path and Polygon data.

With Tableau 10.2, a new native spatial data connector was introduced. Most of the developers had a big sigh of relief as it made their jobs a little easy. The Spatial connector can be used to access KPI files, ESRI Shape files, Map-Info tables and GeoJSON files.

In this blog, we will be discussing the creation of a KML (Keyhole Markup Language) file using Google maps as a base. For this example, we will be creating points, lines to show the path from Point A to Point B and we will also be creating shapes as polygons to show a small area of coverage. Eventually this file will be used in Tableau to show Points or Lines or Polygons using the Geometry aggregation. But there is a small caveat. Tableau at this point (10.5) will not be able to represent Points and Lines and Polygons together. We may expect them in the near future. To show line and polygon together, we need to extract the Latitude and Longitude which will be discussed in a different blog.

Introduction to KML Files: What They Are and How They Work in Tableau

Converting Google Maps Data: Essential Steps for KML File Creation

Leveraging Tableau’s Mapping Capabilities: Enhancing Visualization with KML Spatial Files

Advanced Techniques: Tips for Optimizing KML File Usage in Tableau

1) First, we need to login to My Maps on google. It is a free service offered by Google to create customized maps: https://www.google.com/maps/d/

We need a Gmail account to access My Maps. Once we login, we can access all the maps previously created if any and create a new ones.

2) Create a new map. For this example, to keep it simple, the focus will be on New York City area. We shall create a some points, lines and polygons.

3) We will give a name for the Map and the layer.

Also, we need to focus on some of the available map features.

The features are self-explanatory. The map offers Undo and Redo options; Pan option to move the map; Add markers to get specific point of interest (Eg: Statue of Liberty, World Trade Center); Add Line of Polygons to draw lines or shapes; Add directions between data points; Find Distance between data points.

All of these can be achieved in the same layer. We are using 3 layers for a better understanding.

If we have data saved elsewhere, we can import the data points here.

4) Starting with Points of Interest layer. Using the Add marker tool to select some points and providing a name and description if needed. (World Trade Center, Charging Bull, Empire State Building and Times Square)

5) Now focusing on Lines – Paths layer. Starting with a single click. Every Point on the path is a single click. At the finish, we need to double click. Every point selected will have a Latitude and Longitude generated internally. (Empire State Building to Rockefeller Center, World Trade Center to New York Stock Exchange, Grand Central Terminal to Central Park Zoo)

6) Now focusing on Polygons – Shapes layer. Starting with the single click, when the line converges back to the same starting point, it will complete the polygon. Every point selected will have a Latitude and Longitude internally. (John F Kennedy Airport area and LaGuardia Airport area)

7) Once the layers are ready, we need to download the individual layers of the Map. We are going for a .KML (Keyhole Markup Language) local file. If nothing is unchecked, we get a KMZ file which acts like a ZIP file. But Tableau cannot open a KMZ file directly.

8) Time to use them in Tableau as Spatial local file connection. I have downloaded the entire map to show the difference. Starting with the entire map.

As mentioned before, Tableau does not allow multiple layers.

At the same time, Tableau does not allow for Mixed Geometries in the same layer to be used.

9) So, we need to bring them individually. Bringing them together as a dataset will be discussed as a different blog as it needs data repair.

We can notice that when Tableau reads spatial files, it recognizes the Geometry field with a Geographic role which is required for mapping.

The Geometry field has an aggregation called Collect.

Also the Description column is empty because nothing was entered when the Layers were created.

10) Finally, creating a Dashboard to show all together.

About the Author
A BI Analyst and Tableau trainer working for USEReady since 2015. Well versed in Data Analysis, ETL and Dashboard building across different business domains.
Vijai NarasimhaSenior Business Intelligence Analyst | USEReady