I have previously written about how we continue to add new features to Tableau and this means that we can develop better solutions to previously difficult problems. I’d like to present another example of this – where we want to plot points and polygons together on a single Tableau map. In an earlier blog post, I had shown how we could present points and polygons together in Tableau. However in Tableau 10.1 and earlier it was a complex process that required significant data preparation.
In Tableau 10.2 we are introducing a spatial file connector that will make it much easier to plot polygons and points together. You can now simply present your polygon data to Tableau in an ESRI shapefile, KML or MapInfo file format:
and Tableau can directly plot the polygons:
Note that this is a much less complex viz structure than in earlier versions of Tableau. We are not using a vertex list anymore – we simply double-click on the new Geometry object (the globe field in the Measures section) and Tableau takes care of the rest. Note that in the above viz we have the (generated) latitude and longitude fields on the row/column shelves and the COLLECT(Geometry) measure on the details shelf.
When we want to overlay points on this polygon map, we simply need to have our point data also presented in a spatial file format. For this example, I had raw lat/lon data in a CSV and using Alteryx I converted it to a spatial object. I also used some of Alteryx’s spatial matching features to tag each location with the nameof the SA3 region in which it is contained (it will become clear later why this was done):
Once again we can simply connect to the resulting shapefile:
and plot the points on the map – note the layout of the viz is the same as for the polygon map above with the (generated) lat/lon fields and the COLLECT(Geometry) field on details:
To combine the two spatial data sets we can use the new cross-data-source join feature introduced in Tableau 10 to join the two shapefiles:
Starting with the previous polygon map, we can CTRL-drag the longitude field on the column shelf to duplicate the map and swap the COLLECT(Geometry) field on the detail shelf of the second map to show the Geometry field from the point location data source. Set the mark type to a red circle and you will see the following:
If we make the map a dual axis map, we now have points and polygons shown together. Yay! This is a much simpler (and more useful) solution compared to the previous approach.
Finally, because both data sets have the SA3 name we can use this to highlight both a polygon and the set of points therein, allowing for interactions that previously were not easy to do:
So thanks, Tableau development team, for adding these new capabilities and making old, complex techniques obsolete.
You can download the workbook and data for this example here.
Pingback: Points and Polygons | The Last Data Bender
Great work as always 🙂 I think this would really help my current situation, but can I get some more info on the Alteryx workflow ? (although I’m trying to solve it myself right now as well).
I got it working for my situation, thanks again 🙂 🙂
This is brilliant, great new addition. Map layers are awesome.
Pingback: How to geocode thousands of addresses and make a Tableau custom polygon + point map, with a little help from FME » Tableau Picasso
Wow – no more fake maps in the background just to get dual axis lat/longs on the same map. Love it!
You can actually just drag a second set of coords onto the row/col shelves and choose a different mark type (e.g. shape) to get the filled polygon map and shapes in one graph. No need for the additional data transformation.
Hi Chris,
Thanks for your comment however I’m not sure what you mean by “drag a second set of coords onto the row/col shelves”. In 10.2 the spatial field is represented by the geometry field and you can’t drag that to the row/col shelves – only to the detail shelf. It is used in conjunction with the generated lat/lon fields.
You can duplicate the lat/lon fields on the row/col shelves and then associate them with different geometry fields – that’s what I’ve done in this example. The data prep was simply to get the SA boundary data and the volunteer data correlated so they could be joined (because we don’t currently support unioning spatial files directly in Tableau).
I hope this clarifies.
Cheers,
Alan
Alan, this is great but I’m having trouble overlaying some data from excel – looking to add some population data at SA2 level, along with some specific location points as well. I have joined a KML file (from the ABS) with an SHP file (which I generated through an online converter that has 21 places marked, with an SA2 field that enabled the join). This follows your logic and appears to work. Things get a little funky when I try to add an excel spreadsheet of ABS population data that also has an SA2 name field. I can’t seem to get the union/join/blend right. Can you provide some guidance? Ideally I am trying to view population data when I select a specific location and drag a radius out – and I also have other uses for the SA2 location data.
Hi Andrew,
I’d really need to see the data and understand what you are trying to do. You can send me a direct email to aeldridge at Tableau dot com and I’d be happy to take a look.
Cheers,
Alan
Thanks Alan, I will do that, but my primary issue was that I was trying to join when I should have been blending my excel data (ABS data). I have resolved this, but I have another query so I will hit you up direct with that one. Thanks so much for this information though. It really opens up a lot of potential.
Hi Alan,
This is an amazing and helpful tool that is going to work well for some of my dasboards going forward. I have a question though around sizing and colouring the points that are overlaid on the map. When I attempt to resize using the slider on the shelf containing my point geometry there is no change. When I bring another measure in to size by, most of the points disappear.
Hi Kevin,
Thanks for the kind feedback. For your question – have you made sure you have changed the mark type from “filled map” to “circle”? For the point data, because the GEOMETRY field is a single point it will plot as a small circle when the mark type is “filled map” but you can’t resize this. You need to explicitly make the mark a circle or shape type.
Let me know if this fixes your issue.
Cheers,
Alan
Was wondering how you would go about randomly distributing specific points within a given polygon? I’ve downloaded a census boundary shapefile with population race data at the block level and need to distribute the given points randomly within a specified polygon. For example, at a specific block level I might have 20 Asian, 40 White, 60 African American etc. How would I go about plotting 20 specific points for the Asian variable within that set polygon? Any help is appreciated. Thanks.
Hi Gabe, why do you want to randomly place them within the shapefile? What does this achieve from an analytic perspective? My concern is that this could take away from the analytic accuracy of the viz as the viewer might think the random locations are actual data. Wouldn’t it be better to either a) just colour the boundary as a choropleth or b) place a single sized marker at the centroid of the polygon? This would preserve the analytic accuracy of the viz (i.e. the number you are showing is accurate the area, not specific points) and still communicate the same information.
If you are dead set on doing this, the only approach I can think of would be some form of jittering around the polygon centroid, but you aren’t guaranteed that the points will be inside the polygon if you are dealing with complex polygon shapes (e.g. LGAs, postcodes… these all can be concave topologies, or could potentially have enclaves/holes within the outer hull).
Your only certain path would be to prepare the data upstream of Tableau using some kind of GIS/spatial ETL package.
Hope this helps.
Cheers,
Alan
Hey Alan, thanks for the reply. I’m trying to mirror this map by University of Virginia (http://demographics.virginia.edu/DotMap/) as a proof of concept for work with the goal of utilizing different variables (income distribution etc.).
Hi Gabe, unless you generate the data point upstream from Tableau there’s no way to do this completely within the Tableau layer. However, even if you did, I suspect it would perform very slowly as you’d be plotting 1 dot per person and the population of WA is ~2.6 million. I’m not sure this is something that Tableau will be a good fit for.
Hi Alan can we also use this feature to plot the tower sector files ? and link KPIs to that sector as you have shown in one your other posts ?
Hi Ashhad,
Not really – the sector polygons are manufactured and use explicit lat/lon data for each point. A polygon from a shapefile doesn’t – you’ll notice that it uses generated lat/lon values like our internal geocoding. Unfortunately you can’t combine them on the row/column shelves so this approach wouldn’t be possible. You’d need to have the sectors as shapefile data to do this.
Cheers,
Alan
Hi Alan
Great article, thanks. The link to the workbook and data appears broken. Would it be possible to get a copy of the Alteryx workflow?
Thanks
Henry
I just checked the link and it seems to be working – https://www.dropbox.com/s/hspa39l8bwrhryc/Join%20Example.zip?dl=0
I don’t have the Alteryx workbook anymore – sorry. But it should be trivial for you to create it as it’s just taking lat/lon, turning it into a point, and then using a spatial match to see which polygon contains it.
Cheers,
Alan
Hi. I can’t seem to find the Alteryx converter that will convert my .csv with lat/long into a shapefile. Can you please share that link? Thanks!
Hi! Thanks for the post! I’d like to know if there’s a way to add a THIRD axis to the map. I specifically need to plot a polygon shape (that represents markets), points (that represents suppliers) and then a heat-map (that represents consumer density). Is there a way to add the 3 on the same view? Thanks for the support!
Hi Fernando,
Currently, there is no easy way to do this as it would require three different marks – the points, the polygon and the density map. You can only have two marks on a chart as each is bound to an axis and you can only have two axes. I guess you could use transparent backgrounds (a recent feature) and stack the maps on top of each other (like I did in my last blog post) but that is very difficult to do reliably and only allows you to interact with the highest layer.
There was work underway to enhance the ability for maps to have multiple marks – essentially creating layers – but I don’t know what the timeline for this is. You’d need to ask Tableau.
Hope this is helpful.
Cheers,
Alan
Pingback: How to geocode thousands of addresses and make a Tableau custom polygon + point map, with a little help from FME - Vizable Insights