The Tableau 2020.4 release comes fully-loaded with tons of great features, including several key updates to boost your geospatial analysis. In particular, the new multiple marks layers feature lets you add an unlimited number of layers to the map. This means you can visualize multiple sets of location data in context of one another, and there’s no need for external tools to build custom background maps.
Introduction of the dashboard and the data
For one of my clients I use spatial analysis a lot.
Over a year ago I need to create a dashboard which included events of armed violence in an area, and an overview of these events in its country.
The data is available from the incredible ACLED project.
The Armed Conflict Location & Event Data Project, a non-governmental organization specializing in disaggregated conflict data collection, analysis, and crisis mapping.
The ‘old’ way: spatial calculations in PostgreSQL/PostGIS
To build the dashboards I had in mind I needed a visualization which included several spatial elements: a central point, a range around that point, several locations inside that range, and last but not least: a ‘made up’ point to stretch the map so I could fit in another map, on top of the other map. Without this point Tableau would always centre the circle – while I wanted some room for another sheet.
The range around Tripolis (the city on the map) is visualized by a circle. To be able to fit the complete map of Libya on the same background I needed to create a ‘virtual’ point on the right of the map (the small dot on the right)
I managed to do this – but only by preparing the data inside the data source. I used the underlying PostgreSQL database – which has amazing spatial capabilities, especially in combination with the PostGIS extension.
To visualize both the circle, the locations inside that circle and the virtual point I created a spatial “multi-polygon” inside PostgreSQL which includes both the circle and the virtual point. It was quite a challenge to create this object – the circle for example is not a line, but the difference between to circles…
Switching between geometry and geography data types I created the final spatial object after quite some time (the PostgreSQL-query can be found as a Gist on GitHub).
In Tableau Desktop I used the dual-axis method to show the data on a map: the multi-polygon (circle + right dot) on one axis, and the events on the other on the other. It worked out well – I was proud I succeeded – but it was not ideal; the underlying SQL query was hard to maintain,the ranges needed to be defined in the query, and creating the necessary extract for all the requested locations was heavy on the database server.
Tableau 2020.4+: Drag and drop multiple map layers, (do not) zoom to extend, Hide layers & disable selection
The new ‘unlimited’ map layers in 2020.4 is a real improvement and time saver the way spatial analysis can be done, and how you create dashboards with maps.
Instead of only two axis it is now possible to use as many spatial objects on a map as you want, without hacks or creating spatial objects in the back-end.
And that’s not the only improvement: you can now instruct Tableau to ignore the spatial object on zoom, hide a layer without losing context, and to disable selecting objects on a map.
My original visualization – using the spatial calculations in PostgreSQL – could benefit from all 4 new features.
Multiple map layers using drag and drop
I used four spatial fields in my visualization (no spatial prepping was needed!)
Using my data set I created these formulas:
the corresponding country of the city, to be able to view the borders
ISO3 code of country; turned Geographic Role of the field to : Country/Region
- [city spatial point]
reference point for the range of events
* created with
MAKEPOINT([latitude city],[longitude city])
- [city spatial buffer]
a range of 10km round the city
* BUFFER([city spatial point],10,’km’)
(I used a parameter in my final visualisation to change the diameter)
- [city shift point]
a point ‘west’ from the city, 4 x the radius of the buffer, to make space on the map for an extra map on top of it
* The most challenging one, since the calculation relative to longitude (“horizontal”) depends on latitude (“vertical”) location on earth. Using PI and the radius of the earth (6.378.137 m) I came up with this Tableau calculation:
MAKEPOINT( [latitude], [longitude] + (10*1000 * 4 / 6378137) * (180 / PI()) / cos([latitude] * PI()/180) )
(10*1000 == 10 kilometers)
When I calculated the distance between this shift-point and the original point I got the exact right figure back – so Tableau is probably using the same kind of metrics under the hood as well…
- [acled event point]
ACLED event points: same calculation like city-point: MAKEPOINT([latitude event point],[longitude event point])
Combining these was really easy by dragging and dropping the fields onto the sheet.
Feature: (Do not) Zoom to Extend
Another exciting feature (albeit small) of the new map layers is the ability to turn off the standard behaviour of zooming out to the largest polygon on the map. Now you can visualize underlying borders (countries, regions, custom areas) without having to show these fully
Feature: Hide Layers
If we ware so happy with multiple layers – why do you want to hide these?
Hiding a layer can be useful for example with the ‘zoom to extend’. Sometimes you want to visualize an area without zooming (see previous) – but other times you want to zoom out without visualizing the underlying data. In my case, I needed a virtual / helper point to stretch my map – and now I can drag this spatial point onto a layer, disable the selection, hide it – but still zoom to this point, so the area keeps visible.
Feature: Disable selection
And at least as important as the feature above is the option ‘disable selection’, especially when using multiple layers on top of each other.
If selection is enabled, you have to click exactly on the underlying points to make the tooltip or action work – otherwise it will select the full polygon or buffer – very ugly:
When disabled you can’t select the object – and therefore you can only select the objects you want to be selected!. This small feature is a very big improvement on the usability of spatial buffers and polygons!
Second visualisation: country view
For my visualisation I needed (or wanted) to show an overview of all ACLED events in the country of the sellected city. On the sheet I used four map-layers:
- the country (with add to zoom extend enabled)
- the spatial buffer of the city to show which area is on the map below
- twice the ACLED events: once as ‘Density’ – which show the intensity of locations in a certain area of the map
- and once as circle – to show the individual data points.
This sheet is incorporated in the visualisation on a dashboard, with the country-data on top of the city-view. To create a shadow-like effect, place a blank container element between the city- and country view, and change the colour to 50% black for some transparency.
Take a look a the final interactive visualisation on Tableau Public: