Author avatar

Deepika Singh

Use Custom Geocoding in Tableau

Deepika Singh

  • Aug 10, 2020
  • 8 Min read
  • 4,259 Views
  • Aug 10, 2020
  • 8 Min read
  • 4,259 Views
Data
Data Analytics
Business Intelligence
Tableau

Introduction

Custom geocoding is a technique used to assign latitude and longitude coordinates to locations so Tableau can plot them accurately on a map. Geocoding is of great use for many industries, including transportation and logistics companies. These businesses often divide customers into geographical zones for sales, delivery, marketing, and customer service perspectives. Geocoding is also used for analytical policing purposes in which intelligence agencies keep tabs on crime sensitive locations using geographical coordinates.

In this guide, you will learn how to do custom geocoding in Tableau.

Data

To incorporate geocoding in Tableau, you need data containing a list of geographic data points, for example, any country with its corresponding states, cities, or counties. You also need the respective coordinates, that is, latitude and longitude.

In this guide, you will use two fictitious datasets. The first, named Florida Small Towns, consists of 15 records with variables City and Description.

The second dataset, named Florida Latitude and Longitude, consists of 15 records with five variables: Country, City, State, Latitude, and Longitude.

Getting Started

The first step is to load the data into Tableau. To begin, open the Tableau desktop and look at the Connect pane.

cg1

Select More from the To a File option.

cg2

The above step will create an option for you to select the file from your system location. Now, drag the Florida Small Towns file into the canvas.

cg4

The lower half of the canvas provides the data grid, which can be used to view the data.

cg5

Exploring Data

The next step is to open the sheet. You can see below that the variable City is in the Dimensions part of the pane, while the coordinates, the latitude and longitude, are in the Measures section.

cg6

Drag City into the Detail card of the Marks pane. This should automatically plot the detected latitude and longitude in the view. Another option is to drag Longitude into the Columns shelf and Latitude in the Rows shelf.

cg8

You would expect the locations to be plotted, but that’s not the case, as seen above. This is also highlighted with the message "15 unknown," shown at the extreme right bottom in the view. To understand this further, go to the Map menu in the toolbar section and select Edit Locations.

cg9

That will generate the following tab.

cg10

In the above output, you can see that the Country/Region selected is India. This is incorrect as we are looking for locations in Florida. You will have to fix this.

Fixing Issues with Maps

To fix the incorrect location, select the drop-down option, select United States, and click OK.

cg11

This will reduce the unknown locations from 15 to five. Go back to the Edit Locations option as explained above, and check for places where Tableau is not able to plot. This is shown below.

c11

The output above shows that the locations Stuart, Waldo, and Williston are Ambiguous, while the other two locations, Lebanon Station and Matlacha, are not recognized by Tableau.

There are two methods to fix this.

  1. Manually enter latitude and longitude details. This is feasible in scenarios where few corrections are required.
  1. Import a CSV file with all the names of cities along with their latitudes and longitudes. This is feasible in scenarios where several missing coordinates are present.

Let's look at each of these solutions. For manual entry, go back to the Edit Locations option. Next, click on Enter a Latitude and Longitude option, as shown below.

c121

cg122

Enter the correct coordinates as shown below and click OK.

cg123

Post the above correction. There are now four locations that are unknown. You can correct these manually, but you will have to use the second approach of importing the CSV file with the correct coordinates.

To implement this, create a new sheet and go to the Map option in the toolbar. Select the option Geocoding, followed by Import Custom Geocoding.

cg14

Next, browse the CSV file containing the coordinates of latitude and longitude in your system. This data is in the file named Florida Latitude and Longitude, which was discussed in the beginning.

cg15

The following output is displayed while the file is loaded.

cg16

Once the file is loaded, drag the City column into the Detail card of the Marks pane.

cg0

You can see that the final output above has all the locations with zero unknowns.