All IT Courses 50% Off
Tableau Tutorials

Spatial Files in Tableau

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:

All IT Courses 50% Off
  1. Navigate to the folder containing your spatial data and select the spatial file you want to connect.
  2. Select Open.
https://help.tableau.com/current/pro/desktop/en-us/Img/examples_spatial_file1.png

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.

https://help.tableau.com/current/pro/desktop/en-us/Img/maps_sql10.png

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

  1. Open the Tableau Desktop and connect to Microsoft SQL Server.
  2. On the Data Source page, drag New Custom SQL onto the canvas.
  3. 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:

https://help.tableau.com/current/pro/desktop/en-us/Img/maps_sql3.png

Step 2: Build the map

  1. Navigate to a new worksheet.
  2. 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.

https://help.tableau.com/current/pro/desktop/en-us/Img/maps_sql4.png
  1. Drag a dimension to Label on the Marks card. In this example, the School Name is used.
  2. 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.

https://help.tableau.com/current/pro/desktop/en-us/Img/maps_sql5.png
  1. 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.
  2. Select Analysis > Create Calculated field.
  3. 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.
  1. When finished, click on, OK.
  2. 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.

https://help.tableau.com/current/pro/desktop/en-us/Img/maps_sql6.png
  1. 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.

  1. Drag the same dimension from the Data pane to Color on the Marks card.

In this instance, each park is now assigned a color.

https://help.tableau.com/current/pro/desktop/en-us/Img/maps_sql7.png
  1. 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.

https://help.tableau.com/current/pro/desktop/en-us/Img/maps_sql8.png
  1. 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.

https://help.tableau.com/current/pro/desktop/en-us/Img/maps_sql9.png

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.

  1. Open the Tableau and connect to the first spatial data source.
  2. Under Connections, click Add.
  3. In the menu, Add a Data Source, connect to the second data source.

The two data sources are now added to the canvas.

https://help.tableau.com/current/pro/desktop/en-us/Img/spatial_join1.png
  1. Click on the Join icon.
  2. 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.
https://help.tableau.com/current/pro/desktop/en-us/Img/spatial_join2.png
  1. When it is finished, close the Join dialog box.

You are now ready to analyze your spatial data.

https://help.tableau.com/current/pro/desktop/en-us/Img/maps_spatial_analysis.png
Facebook Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Articles

Check Also
Close
Back to top button
H2kinfosys Free Demo Online Training