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 analyse 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.

Spatial functions available in Tableau

AREA

SyntaxAREA(Spatial Polygon, 'units')
OutputNumber
DefinitionReturns the total surface area of a <spatial polygon>.
Example
AREA([Geometry], 'feet')
Notes

Supported unit names (must be in quotation marks in the calculation, such as 'miles'):

  • metres: meters, metres, m
  • kilometres: kilometers, kilometres, km
  • miles: miles, mi
  • feet: feet, ft

BUFFER

SyntaxBUFFER(Spatial Point, distance, 'units')

BUFFER(Linestring, distance, 'units')

  • metres: meters, metres, m
  • kilometres: kilometers, kilometres, km
  • miles: miles, mi
  • feet: feet, ft
OutputGeometry
Definition

For spatial points, returns a polygon shape centred over a <spatial point>, with a radius determined by the <distance> and <unit> values.

For linestrings, computes the polygons formed by including all points within the radius distance from the linestring.

Example
BUFFER([Spatial Point Geometry], 25, 'mi')
BUFFER(MAKEPOINT(47.59, -122.32), 3, 'km')
BUFFER(MAKELINE(MAKEPOINT(0, 20),MAKEPOINT (30, 30)),20,'km'))
Notes

Supported unit names (must be in quotation marks in the calculation, such as 'miles'):

  • metres: meters, metres, m
  • kilometres: kilometers, kilometres, km
  • miles: miles, mi
  • feet: feet, ft

DIFFERENCE

SyntaxDIFFERENCE(Spatial, Spatial)
OutputSpatial Polygon
DefinitionComputes the portions of regions remaining when all regions in the second argument are carved out of the first argument in areas that overlap. Discards regions from the second argument in areas that don't overlap.
Example
DIFFERENCE(Spatial Polygon1, Spatial Polygon2)
Notes

Supports spatial polygons and multipolygons, not spatial points or lines.

DISTANCE

SyntaxDISTANCE(SpatialPoint1, SpatialPoint2, 'units')
OutputNumber
DefinitionReturns the distance measurement between two points in the specified <unit>.
Example
DISTANCE([Origin Point],[Destination Point], 'km')
Notes

Supported unit names (must be in quotation marks in the calculation, such as 'miles'):

  • metres: meters, metres, m
  • kilometres: kilometers, kilometres, km
  • miles: miles, mi
  • feet: feet, ft
Database limitationsThis function can only be created with a live connection but will continue to work if the data source is converted to an extract.

INTERSECTION

SyntaxINTERSECTION (spatial, spatial)
OutputPolygon
DefinitionComputes and returns the portions of regions in the second argument that overlap regions in the first argument.
ExampleINTERSECTION (Spatial Polygon1, Spatial Polygon2)
NotesSupports spatial polygons and multipolygons, not spatial points or lines.

INTERSECTS

SyntaxINTERSECTS (geometry1, geometry2)
OutputBoolean
DefinitionReturns true or false indicating whether two geometries overlap in space.
NotesSupported combinations: point/polygon, line/polygon and polygon/polygon.

MAKELINE

SyntaxMAKELINE(SpatialPoint1, SpatialPoint2)
OutputGeometry (line)
DefinitionGenerates a line mark between two points
Example
MAKELINE(MAKEPOINT(47.59, -122.32), MAKEPOINT(48.5, -123.1))
NotesUseful for building origin-destination maps.

MAKEPOINT

SyntaxMAKEPOINT(latitude, longitude, [SRID])
OutputGeometry (point)
Definition

Converts data from <latitude> and <longitude> columns into spatial objects.

If the optional <SRID> argument is added, the inputs can be other projected geographic coordinates.

Example
MAKEPOINT(48.5, -123.1)
MAKEPOINT([AirportLatitude], [AirportLongitude])
MAKEPOINT([Xcoord],[Ycoord], 3493)
Notes

MAKEPOINT can't use the automatically generated latitude and longitude fields. The data source must contain the coordinates natively.

SRID is a spatial reference identifier that uses ESPG reference system codes(Link opens in a new window) to specify coordinate systems. If SRID is not specified, WGS84 is assumed and parameters are treated as latitude/longitude in degrees.

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.

LENGTH

SyntaxLENGTH(geometry, 'units')
OutputNumber
DefinitionReturns the geodetic path length of the line string or strings in the <geometry> using the given <units>.
Example
LENGTH([Spatial], 'metres')
NotesThe result is <NaN> if the geometry argument has no linestrings, though other elements are permitted.

OUTLINE

SyntaxOUTLINE(spatial polygon)
OutputGeometry
DefinitionConverts a polygon geometry into linestrings.
Notes

Useful for creating a separate layer for an outline that can be styled differently than the fill.

Supports polygons within multipolygons.

SHAPETYPE

SyntaxSHAPETYPE(geometry)
OutputString
DefinitionReturns a string describing the structure of the spatial <geometry>, such as Empty, Point, MultiPoint, LineString, MultiLinestring, Polygon, MultiPolygon, Mixed and unsupported.
Example
SHAPETYPE(MAKEPOINT(48.5, -123.1)) = "Point"

SYMDIFFERENCE

SyntaxSYMDIFFERENCE(spatial, spatial)
OutputGeometry
DefinitionComputes any portions of regions from the second argument that overlap regions in the first argument and discards from both. Returns the remaining portions of regions from both arguments.
Example

SYMDIFFERENCE(Spatial Polygon1, Spatial Polygon2)

VALIDATE

SyntaxVALIDATE(spatial geometry)
OutputGeometry
DefinitionConfirms topological correctness of the geometry in your spatial value. If the value cannot be used for analysis due to problems such as a polygon’s perimeter intersecting itself, then the result will be a null. If the geometry is correct, the result will be the original geometry.
Example

UNION(VALIDATE([Geometry]))

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.
  2. 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.

  3. Drag the non-spatial data source onto the Join dialog box.

  4. Click on the Join icon.
  5. 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.
  6. For the non-spatial data source, select Create Join Calculation as the join clause.

    The calculation should look something like this:

    MAKEPOINT(Latitude,Longitude)

  7. Select OK.
  8. Select the Intersects join clause operator to create a data source for spatial analysis.

  9. When finished, close the Join dialog box.

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

Create a visualisation using MAKELINE

In Tableau Desktop, download the Flight Path workbook from Tableau Public, available here(Link opens in a new window).

  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],[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.

  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 visualisations.

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

Visualise an area with BUFFER

In Tableau Desktop, download the Flight Path workbook from Tableau Public, available here(Link opens in a new window).

  1. Navigate to a new worksheet.
  2. Right-click on the Data pane and select Create Parameter.
  3. 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.

  4. When finished, click OK.
  5. This parameter allows us to customise the radius of our buffer, ranging from 100 to 1000 miles. Right-click the parameter and select Show Parameter.

  6. Select Analysis > Create Calculated Field.
  7. In the calculation that opens, do the following:
    • Name the calculated field Buffer
    • Enter the following formula

    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.

  8. When finished, click OK.
  9. The new calculated field appears in the Data pane. Just like your other fields, you can use it in one or more visualisations.

  10. From the Data pane, double-click on Buffer to add it to your visualisation, which should automatically be rendered as a map.
  11. Drag Destination to the Colour panel on the Marks card to complete the visualisation.

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.

Thanks for your feedback!Your feedback has been successfully submitted. Thank you!