7

Geospatial Analysis with Map Layers – datavis.blog

 3 years ago
source link: https://datavis.blog/2021/02/28/geospatial-analysis-with-map-layers/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Geospatial Analysis with Map Layers

In version 2020.4, Tableau added the Map Layers feature, which I gave an overview of in an earlier blog post. This post will explore this functionality further with the goal of bringing different sources of geospatial data together in a dashboard to support decision making.

The example use case we’ll look at is to find an Airbnb in London within range of a user-selected target destination and also with an electrical vehicle charging point in range of the selected Airbnb. The following filters will be available:

  • Airbnb: Price range per night and the property type (room, entire home etc.)
  • EV Charging Point: The connection type (Tesla, Combo, 3 pin etc.)

Data Sources

Three data sources will be used with each one being shown on a separate map layer:

  1. Airbnb locations in London.  Source
  2. EV Charging Points.  Source
  3. Target Locations – custom list of six latitude / longitude pairs for six locations in London

Map Layers from Spatial Calculations

In addition to the three map layers above, further map layers are added to show spatial fields generated from calculations:

  1. Target Buffer – this fixed size buffer is used to highlight the selected target location on the map
  2. Target Buffer Range – a buffer around the selected target location with a user-specified radius, within which Airbnb locations will be considered ‘in range’
  3. Charging Point Buffer – a buffer around the selected Airbnb with a user-specified radius, within which charging points will be considered ‘in range’
  4. Line – Airbnb to Target – this line clearly shows the connection from the target location to the selected Airbnb and is also used to show the distance between the two points in a tooltip
  5. Line – Airbnb to Charging Points – this layer shows a line from the selected Airbnb to all charging points within the user-defined range

Application Flow

The flow of user actions is as per the help instructions, shown below in a series of help overlay images. Click the right arrow to navigate through the steps:

Combining Data Sources

In the current (2020.4) release, all sources of spatial data used on map layers in the same map must be combined into one data source. So it is not possible to have two data sources in the data pane, as below, and then drag spatial fields from each to create new layers on the same map:

Instead, the two sources must be combined and there are two options for this:

  • Union the data source, if they have a similar data structure
  • Join the data source using a full outer join with a join condition of 1=2

I have used a join as this maintains all the original field names from each data source.

Let’s consider the join of the two main data sources in this use case: Airbnb locations and Charging Point locations. In Tableau, the join is set up as follows using join calculations on both sides (1 = 2):

This will, of course, not join any rows but because I’m using a full outer join, all rows from each source will be maintained and they will show on separate rows with all source columns intact. A diagram of the result is below:

(Note, “S1 Lat” and “S2 Lat” are shorthand for ‘source one’ and ‘source two’. These are not the actual field names in the files)

Data from the Airbnb file will be in the top left, with all columns to the right having null values. Data from the Charging Points file will be in the lower right with all fields on the left being null.

Having all those nulls is not a problem. When you create a spatial object using one of Tableau’s spatial functions (MakePoint, MakeLine, Buffer or Distance), if the source fields are null, the output of the spatial function will be null and no object will be created on that row. So you can effectively perform operations on the original field names of the source files.

Filtering a Combined Data Source

Joining the data sources in this way does create an issue. If a filter is applied to one of the fields in one source, all the rows from the other source will be filtered out. For example, say you want to filter the price range of Airbnbs to the £100 to £149 range.  This will filter out all rows for the other Airbnbs of different price ranges as expected:

The problem is that it also filters out all rows containing the charging data (from what was the second data source):

Using Sets to Store Filter Criteria

To resolve this, a set can be used to store the filter options and then the Airbnb marks can be drawn conditionally, based on if their values are in the set (or sets for multiple filter conditions). This method does not filter out any rows so the separate layer that is working with charging point data is unaffected.

The flow is as follows for the price filter:

  1. Select a price range(s) in the dashboard
  2. That selection updates the Price Range Set using a set action
  3. If an Airbnb is in the Price Range Set then draw a point
  4. Else return Null (i.e. don’t draw points for other Airbnbs)

Conditionally Create Spatial Points

Here’s the MakePoint calculation that draws the Airbnb points based on if the filter criteria are met:

Similar logic is used for creating the Charging Points:

Adding Lines and Distance

To emphasise the connection between the target location and the selected Airbnb, I added a line between these two points. Similarly, lines were added between the selected Airbnb and all charging points in range (determined using another parameter).

Below is the calculation to create the line between the target location and the selected Airbnb.  The condition at the start is so that the line only shows if a target selection has been made:

A Distance calculation is used to determine the distance between the target location and all Airbnbs. This enables the Airbnbs to be filtered to show only those ‘in range’ if desired and also to show a count of the number of Airbnbs in range that meet the criteria selected.

All Map Layers

Below are all the marks cards making up the layers of the visualisation along with the type of spatial calculations used to create the marks for each layer:

Resetting the View

To allow the user to easily start a new search with a different target location, I created a “Start Over” button and styled this to have the same format as the Download PDF button:

This is a worksheet with an empty string calculation and a SUM(0) calculation on the Detail shelf. When the button is clicked a series of parameter actions pass these values to different parameters, which impacts the calculations that conditionally draw the marks in the view so that those calculations now return Null values and no marks are drawn other than the target locations.

Below are the parameter actions triggered in the dashboard when the Start Over button is selected:

11-clear-actions.png

Example Use of Dashboard

The below animation shows an example of searching for an Airbnb within 2.5km of Wembley Stadium with a Type 1 EV Charging Point within 1km of the selected Airbnb:

Summary

Being able to overlay different sources of spatial data in this way, and combining that with the built in spatial calculations that Tableau provides, enables a variety of spatial analyses. The above example could be expanded to include, for example, crime data, locations of restaurants, tourist sites etc. or any other spatial data relevant to the decision making process being designed for.

You can interact with the workbook on Tableau Public here.

Marc Reid
Twitter | LinkedIn | Tableau Public


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK