In Tableau Desktop, you can also connect to the following spatial file types: Shapefiles, GeoJSON files, KML (Keyhole Markup Language) files, MapInfo tables, TopoJSON files, and Esri File Geodatabases. You can then create a point, line, or polygon maps using the data in those files.
Before you can connect to the spatial files, make sure to include all the following files in the same directory:
- Esri shapefiles: This folder must contain .shp, .shx, .dbf, and .prj files as well as .zip files of the Esri shapefile.
- Esri File Geodatabases: This folder must contain the File Geodatabase’s .gdb or the .zip of the File Geodatabases’s .gdb.
- MapInfo tables: This folder must contain .TAB, .DAT, .MAP, and .ID or .MID and .MIF files.
- KML files: This folder must contain the .kml file.
- GeoJSON files: This folder must contain the .geojson file.
- TopoJSON files: This folder must contain the .json or .topojson file.
In Tableau Desktop: click on the New Data Source icon and select Spatial file.
In Tableau Online or Tableau Server: Select Create > Workbook. Select the Files tab.
Then perform the following:
- Navigate to the folder containing your spatial data and select the spatial file you want to connect.
- Select Open.
How to build a map from Microsoft SQL Server spatial data?
The below example demonstrates how to create a map that shows schools within 600 meters of parks in Seattle, Washington.
This example will be using a Microsoft SQL Server connection to a database called TestSpatial. The below tables from this database are used:
- seattleelementaryschools
- allseattleparks
Step 1: Connect
- Open the Tableau Desktop and connect to Microsoft SQL Server.
- On the Data Source page, drag New Custom SQL onto the canvas.
- Type or paste a query into the dialog box Edit Custom SQL that appears.
For this instance, the following query is used:
SELECT S.[common nam] as SchoolName, P.[common nam] as ParkName, S.geom.STBuffer(<Parameters.Radius>) as school_geom, P.geom as park_geom FROM TestSpatial.dbo.seattleelementaryschools S LEFT JOIN TestSpatial.dbo.allseattleparks P on S.geom.STBuffer(<Parameters.Radius>).STIntersects(P.geom) = 1
The result of this query will be:
Step 2: Build the map
- Navigate to a new worksheet.
- In the Data pane, double-click on a spatial field.
In this instance, school_geom is used. It is automatically added to Detail on the Marks card when it is double-clicked, and a map view gets created.
- Drag a dimension to Label on the Marks card. In this example, the School Name is used.
- On the Rows shelf, control-click and drag Latitude to the right. This will copy the field.
A duplicate map will appear below the first map and the Marks card updates with two Latitude tabs. The top tab is for the map on the top, and the bottom tab is for the map on the bottom.
- On the Marks card, click on the bottom Latitude tab, and remove the fields by dragging them back to the Data pane. The bottom map updates to a blank map.
- Select Analysis > Create Calculated field.
- In the Calculation editor that opens, perform the following:
- Name the calculated field. In this instance, the calculated field is named Intersection.
- Enter a RAWSQL formula. This instance uses the given formula:
RAWSQL_SPATIAL(“Select %1.STIntersection(%2.STBuffer(200))”,[school_geom], [park_geom])
- This formula will return unique spatial data based on the intersection of two values.
- When finished, click on, OK.
- Select Analysis, and then clear Aggregate Measures.
Drag the new calculated field to Detail on the Marks card.
The bottom map will update with new marks.
- Drag one dimension from the data pane to Detail on the Marks card. This will disaggregate the marks.
In this instance, the dimension, ParkName, is used.
- Drag the same dimension from the Data pane to Color on the Marks card.
In this instance, each park is now assigned a color.
- On the Rows shelf, right-click the Latitude (generated) field on the right and select Dual Axis.
The maps are now combined, and the data is layered.
- Format the map.
In this instance, the following formatting is applied:
- The School Name marks are colored in gray.
- The School Name mark labels are colored in orange.
- The map background style is then set to Dark.
- The Streets and the Highways layer is shown on the background map.
The map is finished now.
How to join Spatial Files in Tableau?
You can now join two spatial files together or use a spatial calculation for joining a spatial file with non-spatial data, including latitude and longitude fields.
- Open the Tableau and connect to the first spatial data source.
- Under Connections, click Add.
- In the menu, Add a Data Source, connect to the second data source.
The two data sources are now added to the canvas.
- Click on the Join icon.
- In the dialog box Join that appears, perform the following:
- Select a join type.
- Under Data Source, select the spatial field to join by. Spatial fields consist of a globe icon next to them.
- For the secondary data source, select another spatial field. If your secondary data source is not a spatial file and contains latitude and longitude fields, select Create Join Calculation as the join clause so that the data can be used in a spatial join.
- Click on the = sign and then select Intersects from the drop-down menu. You can only intersect two spatial fields.
- When it is finished, close the Join dialog box.
You are now ready to analyze your spatial data.