Friday, September 9, 2016

Creating Custom Tableau Maps from existing ShapeFile using QGIS

*** The newer versions of Tableau 10.2 and above supports reading Geospatial files directly. This article is only valid for older versions ***

For those who don't know Tableau and QGIS, here is quick introduction.

Tableau Software is an American computer software company headquartered in Seattle, Washington. It produces a family of interactive data visualization products focused on business intelligence. Tableau can help anyone see and understand their data. Connect to almost any database, drag and drop to create visualizations, and share with a click.

QGIS is a cross-platform free and open-source desktop geographic information system (GIS) application that provides data viewing, editing, and analysis. QGIS is a user friendly Open Source Geographic Information System (GIS) licensed under the GNU General Public License.

The Link between Tableau and QGIS

Tableau is a data driven software (it rely heavily on data to create maps and chart visualizations). With this in mind, we can generate datasets in QGIS to be utilized in Tableau. And that exactly what we are going to learn in this post to be able to create custom tableau maps and charts.

Creating Custom Nigerian LGA Maps

Tableau has excellent build-in geographic dataset for the Nigeria (such as state boundary, cities, roads/streets...etc.), but it doesn't contain local government area (LGA) boundaries. The country that has its geographic dataset very well covered is the United States (US) and most European state.

Since Tableau allows us to create our own custom map elements from Points, Lines or Polygons, we will create a custom LGA polygon boundaries map of Kaduna state. Polygons can be created from a file that contains the points (Longitude and Latitude) that make up the vertexes of each polygon boundary, and the order in which to draw them.

Kaduna state consists of twenty-three (23) Local Government Areas (LGA) as follow:- Birni-Gwari, Chikun, Giwa, Igabi, Ikara, Jaba, Jema’a, Kachia, Kaduna North, Kaduna South, Kagarko, Kajuru, Kaura, Kauru, Kubau, Kudan, Lere, Makarfi, Sabon-Gari, Sanga, Soba, Zango-Kataf, and Zaria.

So we are going to have twenty-three (23) different polygons to deal with and each polygon will definitely consist of series of connected points forming the vertexes (point where two edges meet).

Explore ShapeFile in QGIS

Now lets open the Kaduna state LGA shapefile in QGIS and convert the boundary polygons edges  into nodes. So that we can generate the coordinates of all the nodes forming the edges of the LGA boundary polygons.

Lets extract nodes from the ShapeFile. Select the LGA shapefile in the Layers panel then: Go to Vector menu >> Geometry Tools >> Extract nodes

Save the Shapefile to a new name. I've called it "LGA-nodes", selecting "Open output file after runing algorithm" Once it's done, the dialogue box will close.

The new Geometry file will now appear in the Layers pane and on the map view, it will appeared with many series of connected points forming the vertexes (point where two edges meet) defining the boundary of each LGA as seen above.

To export the nodes attributes into a .CSV file, select the Nodes layer (that generated by LGA-nodes) in the Layers panel then: Right Click on it and select "Save As…" with the following settings:-
Format = Comma Separated Value, Choose Name for CSV, CRS = WGS 84. Layer options should default to the correct settings, but check against screen shot below that you have Geometry AS_XY

The above action will result in a CSV file which contains Longitude/Latitude and other attributes columns for the extent of each LGA. Your csv will look different since you are using a different dataset.

Getting the CSV file into a Tableau Format

So we need to keep some required columns to be able to plot the geometry in Tableau.

Tableau needs a plot order for each polygon. The plot order include the follow columns in csv file (Longitude, Latitude, name, PolygonID, and Path_Sequence) any other column is optional for plotting custom map elements in Tableau. We need to keep these columns (X, Y, ID_2, NAME_2) and add a number sequence column.

So remove all other columns and keep just (X, Y, ID_2,  and NAME_2) columns.

Now, open the CSV file and edit as follow:-
~ Rename X and Y fields to "Longitude" and "Latitude", and
~ Rename ID_2 and NAME_2 fields to "PolygonID" and "LGA_name"
~ Add a 'number Sequence' (0,1,2,3...) column and name it "Path_Sequence". The Polygon Nodes are in the correct order so you just need to auto fill the "Path_Sequence" cell.

Once the csv file is prepared, it is fairly straight forward to create custom polygons in Tableau.

Plotting Custom LGA Polygons in Tableau

~ Load in the csv file into Tableau and go to sheet1

~ Convert ‘Path Sequence’ to Dimension
Just drag and drop this column in the dimension pane.

~ Add Longitude to Columns, Latitude to Rows

~ Change the Mark type from "Automatic" to "Polygon"
~ Add "Polygon ID" into Detail Pane and "Path Sequence" into Path Pane 
~ Add "LGA Name" into Color Pane

This will result in a custom polygons added to Tableau mapping capability. This procedure is applicable to any geographic element (polygon, line or point) that is not publicly covered and made available by tableau map server.

That is it. If you have any question or comment drop it below.

Thanks for reading.


  1. Hi Umar, this is very impressive. Thanks a lot. I am trying to create similar coordinates for all the LGAs of all states in Nigeria. Could you please kindly give a guide or help me out. I really appreciate your efforts. Thanks

    1. Hi Christopher,
      If you understood the process above, then it is fairly the same approach for other states.

      The concept explained in the blog post above can be extended to cover for all the 37 states according.

      I hope that helps.

  2. Umar, do you now have the complete LGA geo-data for Nigeria? Thanks


    1. Hi Aziz,
      Yes, I have the complete 700+ LGA geo-data for Nigeria.

  3. Hello Umar,
    Could you kindly share your viz on the geo-data in a format that I could import into tableau. Thanks.

    1. OK, I will find time to share it. Thanks


    1. Yes Mr. ABDULMUJIB
      My email and phone number are: and 08039508010. You are welcome