The world’s leading publication for data science, AI, and ML professionals.

Underrated Combined Functionalities of Tableau – Point, LineString & Polygon Mapping

Geospatial Analytics in Tableau – Working with no need for geocoding/basemap services + Rendering mixed geometry types in a single setting

Having finished 1 of my spatial analytics projects, I was all ready to present my findings in Tableau but faced the unconventional problem of having absolutely no Internet access. As most of us usually take the in-built geocoding and basemap services in Tableau for granted, this had brought on more complications than I had initially expected.

Image by Author | A map rendered in Tableau by a spatial data file | Showcasing the distribution of citizens (65&Over) in Singapore by Planning Areas
Image by Author | A map rendered in Tableau by a spatial data file | Showcasing the distribution of citizens (65&Over) in Singapore by Planning Areas

Basically when Internet accessibility is not available, the above map rendered becomes like this instead –

Image by Author | A map rendered in Tableau by a spatial data file without internet connection - All geocoding & basemap services are unavailable.
Image by Author | A map rendered in Tableau by a spatial data file without internet connection – All geocoding & basemap services are unavailable.

So ouch… Clearly, this has some devastating impacts. What was even more devastating was the appalling lack of in-depth tutorials for rendering spatial data without its in-built map functionalities. So I proceeded to do some exploration on my own and mainly, there were 2 issues I had to resolve to get my project done:

  1. Ensuring the map polygons of Singapore are rendered proportionately and to scale.
  2. Display the missing basemap details – highways, street names etc. since they are no longer automatically shown in the background.

Addressing Issue 1 – Plotting map polygons and render its actual proportions

Based on the above context, all I had to work with was a spatial data file in GeoJSON format (for this tutorial’s sake I have uploaded a sample onto my GitHub at sg_planning_areas_2020_elderly_distribution.geojson) and proceeded to study it.

Fundamentally, a GeoJSON FeatureCollection object is a JSON object which contains all the necessary coordinates (latitudes and longitudes) to render its geometric shapes onto any map. As such, I decided to leverage on this information to churn out the geometric shapes using "Polygon" instead of "Map". This would require a data format easily interpreted by Tableau – in which case the format I settled on was a CSV file:

Image by Author | To render geometries with "Polygon" instead of "Map" in Tableau, the GeoJSON data must first be transformed into CSV format.
Image by Author | To render geometries with "Polygon" instead of "Map" in Tableau, the GeoJSON data must first be transformed into CSV format.

Fortunately, there is a tool I have created right here at https://tableau-data-utility.onrender.com/ to speed up the process.

Image by Author | GeoJSON file is uploaded at https://tableau-data-utility.onrender.com/ to generate CSV output file | "Export CSV Output" is then selected to save CSV file
Image by Author | GeoJSON file is uploaded at https://tableau-data-utility.onrender.com/ to generate CSV output file | "Export CSV Output" is then selected to save CSV file

Basically, it’s a browser-based application tool I had created with all instructions and required information for implementation. All I needed to do now was upload the above GeoJSON file, export the transformed output by selecting "Generate CSV Output" and render it in Tableau with "Polygon":

Image by Author | Fields generated in the CSV file are used to render the map polygons in Tableau - Not dependent on any geocoding services
Image by Author | Fields generated in the CSV file are used to render the map polygons in Tableau – Not dependent on any geocoding services

Then magic happens! Issue 1 has been resolved— The map polygons are now rendered in its correct proportions without the need for geocoding services.

Image by Author | (Left) Map polygons rendered with "Map" | (Right) Map polygons rendered with "Polygon"
Image by Author | (Left) Map polygons rendered with "Map" | (Right) Map polygons rendered with "Polygon"

However, with issue 1 resolved, the second issue quickly took its place—which is the lack of a basemap , **** leading us directly to issue 2.

Addressing Issue 2 – Plotting the Basemap layer of Spatial Data rendered in Tableau

At first glance, while this may not seem like a big deal at first, it soon became problematic when I was tasked to investigate and optimise various transportation routes around the island:

Image by Author | Showcasing the various transportation routes which can be taken from an origin to destination | The above example displays 2 possible routes which can be taken via driving in Singapore from Tiong Bahru Market to Vivo City
Image by Author | Showcasing the various transportation routes which can be taken from an origin to destination | The above example displays 2 possible routes which can be taken via driving in Singapore from Tiong Bahru Market to Vivo City

Clearly, while the outline of a country/state/province can be easily inferred from its map polygons, transportation routes represented by (Multi)Point and (Multi)LineString are not so apparent without a detailed map layer as its basemap as seen above. The sample data used to render the above can be found at my GitHub: sg_tiong_bahru_mkt_to_vivo_city.geojson. Using the same tool, the GeoJSON file has now been converted into CSV format (sg_tiong_bahru_mkt_to_vivo_city.csv).

Image by Author | Screenshot of the tool I deployed at https://tableau-data-utility.onrender.com/ to output CSV files for Tableau from JSON files uploaded by users
Image by Author | Screenshot of the tool I deployed at https://tableau-data-utility.onrender.com/ to output CSV files for Tableau from JSON files uploaded by users

Hence, this then brings us to a simple yet extremely useful and convenient functionality available on the application – the ability to export out the background map image for Tableau:

Image by Author | Showcasing the functionality of the web app to export map as a background image
Image by Author | Showcasing the functionality of the web app to export map as a background image

There are a few particular sub-functionalities to note here:

1. Choice of basemap can be changed – By default, the basemap from OpenStreetMap (OSM) is used. However, users are able to change the basemap by entering a valid basemap URL as shown below:

Image by Author | (Left) Uses default basemap | (Right) Uses an alternative map service i.e. OneMap - Note that the user's input must be leafletJS compatible - XYZ Basemap Tile Service a.k.a. Slippy Map
Image by Author | (Left) Uses default basemap | (Right) Uses an alternative map service i.e. OneMap – Note that the user’s input must be leafletJS compatible – XYZ Basemap Tile Service a.k.a. Slippy Map

2. Automated display and updates of the map bounds – Right below the map, there is a table of coordinates which are auto-updated when the map is zoomed or moved.

Image by Author | These coordinates correspond to the exact coordinates in Tableau when plotting the background image as a basemap
Image by Author | These coordinates correspond to the exact coordinates in Tableau when plotting the background image as a basemap

Hence, to export the appropriate map image for the transportation route – it is essential to ensure that both zoom level and bounds of the map captured in the map’s viewing port includes the desired boundaries of your geometry shapes. This eventually leads us to:

Image by Author | Exported map image and coordinates rendered are input directly into Tableau
Image by Author | Exported map image and coordinates rendered are input directly into Tableau
Image by Author | (Left) Route without basemap | (Right) Route with imported map image | Clearly, with details of the map layer displayed, the origin-destination route above shows viewers which roads, streets, buildings, facilities etc. are nearby, providing more context for further spatial analysis
Image by Author | (Left) Route without basemap | (Right) Route with imported map image | Clearly, with details of the map layer displayed, the origin-destination route above shows viewers which roads, streets, buildings, facilities etc. are nearby, providing more context for further spatial analysis

As such, issue 2 (missing basemap details) is now resolved.

Finally, although I could end the article at this point, but I would also like to share 1 other revelation I gained from this— Plotting mixed geometry types via a combination of standard functionalities in Tableau ("Polygon" and "Line").


Bonus Discovery – Plotting Mixed Geometry Types in Tableau from a single CSV file

Despite the claimed limitations of Tableau being unable to

connect to mixed geometry types

My exploration of the already existing functionalities of Tableau says otherwise. Tableau does already have the innate functionalities to render mixed geometry types which I shall prove using this spatial file which is created via merging the 2 previous GeoJSON files (actual file is in my GitHub) . The same steps are repeated – GeoJSON is transformed to CSV output and basemap image is exported via the tool at https://tableau-data-utility.onrender.com/, which gives us:

Image by Author | Showcasing the plotting of mixed geometry types with "Polygon" and "Line" functionalities in Tableau | Both polygons and transportation routes are rendered in the same view
Image by Author | Showcasing the plotting of mixed geometry types with "Polygon" and "Line" functionalities in Tableau | Both polygons and transportation routes are rendered in the same view

A note of caution would be to take a closer look at the "Marks" panel because each mandatory field has been specifically suffixed with either "(points+lines)" or "(polygons)". This is meant to differentiate which fields should be rendered by "Line" – i.e. (points+lines) and which fields should be rendered by "Polygon" – i.e. (polygon) (and yes, the tool I deployed does generate the fields based on geometry type).

In a nut shell, my attempt at rendering spatial datasets in Tableau via alternative means have shown me further visualisation possibilities using the existing multiple functionalities present. Hope you guys found this useful and feel free to use the tool at https://tableau-data-utility.onrender.com/ to generate your required datasets!

P.S. The previous Tableau tutorial I have published on rendering datasets for network graphs uses the tool deployed on the same site at https://tableau-data-utility.onrender.com/. Do check it out if you wish to plot network graphs with minimal effort in Tableau. Thanks for reading!


Related Articles