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.
You can also create a line that connects two data points for origin-destination maps. For example, you might have a spreadsheet of public transportation data that tells you where commuters began and ended their trips. You can use a spatial calculation to see what paths commuters are taking.
List of spatial functions in Tableau
Function |
Syntax |
Description |
AREA | AREA(Spatial Polygon, "units") |
Returns the total surface area of a spatial polygon. Supported unit names: meters ("meters," "metres" "m"), kilometers ("kilometers," "kilometres," "km"), miles ("miles" or "mi"), feet ("feet," "ft"). |
BUFFER | BUFFER(Spatial Point, distance, "units")
|
Returns a polygon shape with a radius determined by the distance and unit values defined in the calculation. Note: The Buffer calculation will only work with a Point spatial object. BUFFER supports the same unit names as the DISTANCE function. |
DISTANCE |
DISTANCE(<Spatial Point1>,<Spatial Point2>,"<units>")
|
Returns distance measurement between two points in a specified unit. Supported unit names: meters ("meters," "metres" "m"), kilometers ("kilometers," "kilometres," "km"), miles ("miles" or "mi"), feet ("feet," "ft"). This function can only be created with a live connection and will continue to work when a data source is converted to an extract. Example:
|
INTERSECTS | INTERSECTS (<geometry1>,<geometry2>) |
Returns a Boolean (True/False) indicating if two geometries overlap in space. Supported combinations: point/polygon, line/polygon, and polygon/polygon. |
MAKELINE | MAKELINE(<Spatial Point1>,<Spatial Point2>)
|
Generates a line mark between two points; useful for building origin-destination maps. Examples:
|
MAKEPOINT | MAKEPOINT(<latitude>, <longitude>)
|
Converts data from latitude and longitude columns into spatial objects. You can use MAKEPOINT to spatially-enable a data source so that it can be joined with a spatial file using a spatial join. For more information, see Join Spatial Files in Tableau . To use MAKEPOINT, your data must contain latitude and longitude coordinates. Example:
|
MAKEPOINT(X,Y, SRID) |
|
Converts data from projected geographic coordinates into spatial objects. SRID is a spatial reference identifier that uses ESPG reference system codes to specify coordinate systems. If SRID is not specified, WGS84 is assumed and parameters are treated as latitude/longitude in degrees. This function can only be created with a live connection and will continue to work when a data source is converted to an extract. Example:
|
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.
- 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.
Tip: To get the Join dialog box to appear, double-click (control click on Mac) a data source on the canvas.
-
Drag the non-spatial data source onto the Join dialog box.
- Click the Join icon.
- 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.
- For the non-spatial data source, select Create Join Calculation as the join clause.
The calculation should look something like this:
MAKEPOINT(Latitude,Longitude)
- Seleck OK.
-
Select the Intersects join clause operator to create a data source for spatial analysis.
- 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(Link opens in a new window).
- Navigate to a new worksheet.
- Select Analysis > Create Calculated Field.
- In the calculation that opens, do the following:
- Name the calculated field Flight Paths
- Enter the following formula
- When finished, click OK.
- From the Data pane, double-click Flight Paths to add it to your visualization, which should automatically render as a map.
MAKELINE(MAKEPOINT([Lat],[Lng]),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.
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.
The calculation automatically produces curved geodesic lines when the lines span longer expanses of the globe.
Visualize an area with BUFFER
In Tableau Desktop, download the Flight Path workbook from Tableau Public, available here(Link opens in a new window).
- Navigate to a new worksheet.
- Right-click the Data pane and select Create Parameter.
- In the Parameter dialog that opens, set the options below:
- Name the parameter Buffer Distance
- Set the Data Type to Integer
- Set Allowable values to Range
- Set the Minimum range to 100, the Maximum range to 1000, and the step size to 100.
- When finished, click OK.
- Select Analysis > Create Calculated Field.
- In the calculation that opens, do the following:
- Name the calculated field Buffer
- Enter the following formula
- When finished, click OK.
- From the Data pane, double-click Buffer to add it to your visualization, which should automatically render as a map.
- Drag Destination to the Color panel on the Marks card to complete the visualization.
This parameter allows us to customize the radius of our buffer, ranging from 100 to 1000 miles. Right-click the parameter and select Show Parameter.
BUFFER(MAKEPOINT([Dest Lat],[Dest Lng]),[Buffer Distance],"miles")
The BUFFER calculation takes point spatial data and converts it into shapes with a radius in miles determined by the Buffer Distance parameter.
Note: Because BUFFER can only be used with point spatial data, we're converting the latitude and longitude data into a point with Makepoint, as demonstrated in the previous example.
The new calculated field appears in the Data pane. Just like your other fields, you can use it in one or more visualizations.
Note: If your view does not look like the image above, make sure that the Mark type is set to Map and not Circle. For more information on Marks type, see Change the Type of Mark in the View.