Jim Dehner 

 Tableau Visionary and Ambassador

Tableau How to’s,  Use Cases, and Forums Questions

Hey #DataFam

Let’s Talk

Open for

Post Links

Spatial Parameters

Working with spatial data is fun!   Everyone likes maps, and letting the user change their viz by selecting geo points and shapes in a parameter increases the experience. So how is it done?


Note:  (I want to thank Ambassador Don Wise for this collaboration.  His work on the connections and the spatial parameter logic made this possible)


1 What is Spatial Data –

 

Let's start by agreeing on what is (and what is not) spatial data. You create maps all the time by dragging fields like state or city to the canvas—right? The points or shapes you create use the Longitudes and Latitudes generated by Tableau. They make a great visualization, but they are now what we mean when we say spatial data.

Spatial data includes points, lines, and polygons that are contained in Shape Files, KML, GeoJSON,  Ersi files, and other Geodatabases  – you get the idea.   They are data file types that need to be uploaded into Tableau before you can create maps or use spatial parameters.


2 Using  Spatial files

 

We’ll start by loading a Shape for Art locations in Nashville (note: you can often find these type of files by searching for Spatial Files at aa data.gov site – I found these at https://data.nashville.gov/  )

Open a new workbook and connect to a Spatial file on the connection tab.



When loaded the data may look something like this which has a long and lat field (real data) and a Geometry field – here Points – The file I downloaded specifically contained “point” data. Other files, as we will see later can contain other “shapes” like Linestrings, polygons, etc. so search for the data source that contains the type of shape you plan to use in the viz.



Once the data is loaded, it can be used directly as it is to create a map. Simply Drag and Drop the Geometry field to the canvas.



Ok, that was easy – now let's add a second spatial file.


3 Multiples Spatial Files

 

You may be familiar with the “share bike” concept – pick up a bike at a “station” use it and return it to any other location in the grid.  The second file contains the national shared bike station locations which I am adding as a separate new data source.



It is a Point-shaped file, similar to the art locations.  During uploading, I used Data Source filters to only bring in data for Nashville.


 

4 Using spatial parameters on intersecting points

 

Maps from the individual datasets can be viewed by dragging and dropping their Geometry fields to the canvas.

First the Art map.



Then the Bike Station map



Easy enough but not what we needed. 


I would like to use share bikes to tour the street art around Nashville so I want to see the art close by bike stations where I can drop off a bike.


For that, we need to create 2 parameters and some calculations.


There are no locations (longs and lats) that are identical in the 2 data sets so we need to create a buffer around the individual points and determine where the art and bike station buffers intersect. 


We each have our view on what an acceptable distance is to walk we can create a parameter – Buffer Radius – which will be used in determining the buffer size.



Next, we create calculations in the individual dataset to buffer the art points and bike station points separately.

Art buffer



And similarly in the bike data set



While the formulas are similar it is important that they are created in separate datasets using the Art or Bike Geometry and they are given the same name – simply Buffer


One more parameter to add – the Spatial Parameter –  will be used to capture the longs and lats of the “Selected” points from the Bike Station layer on the map.  Wait longs and lats are possible from several points on the map – is that even possible with a parameter?


Yes, but we need one more parameter first.  Spatial parameters are global like all other parameters so we only need one and the values will be available to each data set.  Unlike other parameters, the "Values" will be empty at setup.  Not to worry they will be loaded by using a Parameter Action and selecting points from the map.  The values will be the longs and lats of the selected points and yes there will be many (not limited to one)

The setup is similar to other parameters.  Start by giving it a Name like Spatial Parameter and then select Spatial from the dropdown.  Then OK –



Spatial parameters are different and will collect the longs and lats from the selected geo shapes on a map layer.  Selecting the 5 marks using a lasso



Can be used to find the “near Art points” to each of the stations



Cool, but we still need to add a parameter action and a filter.  First the parameter action:



We are selecting marks from the Map to change the Spatial Parameter value. It is very important to select the correct geo field (which layer) on the map as the source for the marks.  Our user will select a bike station to drop off the bike so we want a bike station layer from the map.  We need to select the BUFFERED Bike Station layer (so we have all the geometry within the radius and not just a single point.



Now we need a filter to filter out the unselected point and I plan to use Intersect – it is a spatial calculation that returns a T/F – based on the selected geometry from the parameter and the buffered Art Geometry – Simple enough, but there is a very important twist – we can just put the parameter values directly into Intersect –   It has to come from a calculation that results in a Geo field –


The parameter values are global (like any parameter) but we need to use them in the Art data set – the calculation is:



Then the Intersect formula is done in the Art data set.



It is the intersection of the Buffered Art Point data and the Select Spatial field we just created


I know that is exhausting, but we are finally ready to create the viz.


There are 4 layers in the map – the top layer (1) is the selected data – it comes from the Art Data Set and uses the Art Geometry (not buffered) and will place a purple * shape on the layer.



The second layer is from the Bike data set – it is a filled map that generates circles on the map using the Buffered Bike Station location.



The third layer is from the Bike Data and a filled map that will plot as points – and is original (not buffered) Bike Station locations.



The fourth layer is from the Art data set and is the unbuffered Art locations – (I decided to hide them in the end).



I also added a simple text chart to the dashboard and filtered the Intersection TF so it would list the Art that is near the Bike Station(s) selected – the radius parameter allows the more adventurous art enthusiasts to increase the buffer zone.


 

5 Intersect shapes and points

 

Here we will look at finding the NYC Starbucks locations that are near subway lines.  The process is the same with just a couple of changes – I will not go into extensive detail (but you can download the workbook)


There are 2 files – the Starbucks locations are in a shape file as Points and the Subway lines are in a separate shape file as LineStrings.  I used side-by-side maps for the selection of the subway lines and the presentation of the nearby Starbucks location (It was just a cleaner result).  The rest of the process was the same:


The Starbucks data included the long and lat which I converted to a Geospatial field called 


Points using Makepoint  – it was used as one of the layers in the Starbucks map.



The Spatial Parameter is set to accept All Values.



The spatial parameter and a parameter to set the radius are used to create the buffer zone in the Starbucks data set.

 

buffer([selected spatial shape],[Radius around selected points],"mi")

 

In the Subway data set, I used Makepoint again to create a POINTS geo field. 



Then use the spatial parameter values and a value from the parameter to define the buffer around the subway line.



It took several tries and a lot of help from Don Wise – to figure out the parameter action – it turned out to be this.



From the Subway side-by-side map select any Subway line (click on any point on the link)  and all the parameter values will collect all the values from the buffered subway geo field.



The last calculation uses Intersect to identify the Starbucks location near the select line.



The finished viz looks like this.



Setting up and using Spatial Parameters was challenging but the results are worth the effort.  


Hope this helps you when you explore Spatial Parameters


The workbook can be downloaded at Link to Workbook


Jim

Leave a Reply

Your email address will not be published. Required fields are marked *