Spatial Functions

This article introduces spatial functions and their uses in Tableau. It also demonstrates how to create a spatial calculation using an example.

Why use spatial functions

Spatial functions allow you to perform advanced spatial analysis and combine spatial files with data in other formats like text files or spreadsheets. For example, you might have a spatial file of city council districts, and a text file containing latitude and longitude coordinates of reported potholes. You can use a spatial calculation when creating your data source to join these files and analyze which district takes the longest to repair potholes.

The visualization might look something like this:

You can also use spatial functions to create a line that connects two data points for origin-destination maps. For example, you might have a spreadsheet of bikeshare data that tells you where cyclists began and ended their trips. The visualization might look something like this:

List of spatial functions in Tableau

Function Syntax Definition
MakeLine MakeLine(geometry1,geometry2) Generates a line mark between two points; useful for building origin-destination maps.
MakePoint MakePoint(coordinatesX, coordinatesY) Converts data from latitude and longitude columns and converts them into spatial objects.

Use a spatial calculation

Create a spatial data source using MakePoint

You can use MakePoint to spatially-enable a data source so that it can be joined with a spatial file using a spatial join. To use MakePoint, your data must contain latitude and longitude coordinates.

  1. Open Tableau and connect to a spatial data source. Under Connections, click Add to add a second, non-spatial data source.

    The two data sources are added to the canvas.

  2. Click the Join icon.
  3. In the Join dialog box that appears, do the following:
    • Select a join type.
    • Under Data Source, select a spatial field from your spatial file to join by. Spatial fields have a globe icon next to them.
  4. For the non-spatial data source, select Create Join Calculation as the join clause.

    The calculation might look something like this:

    MAKEPOINT(Latitude,Longitude)

  5. After adding the spatial function to your text file, select the Intersects join clause operator to create a data source for spatial analysis.
  6. When finished, close the Join dialog box.

For more information on spatial joins, see Join Spatial Files in Tableau

Create a visualization using MakeLine

In Tableau Desktop, download the Flight Path workbook from Tableau Public, available here.

  1. Navigate to a new worksheet.
  2. Select Analysis > Create Calculated Field.
  3. In the calculation that opens, do the following:
    • Name the calculated field Flight Paths
    • Enter the following formula

    MAKELINE(MAKEPOINT([Lat],[Long]),MAKEPOINT([Dest Lat],[Dest Lng]))

    This formula takes latitude and longitude coordinates from your origin and destination cities and turns them into geographic points for spatial analysis. Those coordinates are used to build to two-point lines between origin and destination.

  4. When finished, click OK.
  5. The new calculated field appears under Dimensions in the Data pane. Just like your other fields, you can use it in one or more visualizations.

  6. From the Data pane, double-click Flight Paths to add it to your visualization, which should automatically render as a map.
  7. The calculation automatically produces curved geodesic lines when the lines span longer expanses of the globe.

 

 

Thanks for your feedback! There was an error submitting your feedback. Try again or send us a message.