KNOWLEDGE BASE

Plotting Two Sets of Latitude and Longitude on a Map


Published: 22 Jan 2013
Last modified date: 30 Oct 2023

Question

How to plot two sets of latitude and longitude coordinates. 

NOTE: The sets of latitude and longitude data need to be in different tables in the same data source.

Environment

Tableau Desktop

Answer

Open a workbook and connect to data

  1. Compare the structures from the two data sources to determine any differences in the field names and types.
  2. Open Tableau Desktop and connect to the data source.
  3. Note: For Excel and text file data sources, the Custom SQL option is available only in workbooks that were created before Tableau Desktop 8.2 or when using Tableau Desktop on Windows with the legacy connection. To connect to Excel or text files using the legacy connection, connect to the file, and in the Open dialogue box, click the Open drop-down menu, and then select Open with Legacy Connection.
  4. Select New Custom SQL.
  5. Write a UNION query that creates a common set of fields between the two data tables, such as in the following example:

    SELECT [MapPoints1$].[Location_Name] AS [Location_Name],
    [MapPoints1$].[Latitude] AS [Latitude],
    [MapPoints1$].[Longitude] AS [Longitude],
    [MapPoints1$].[Type] AS [Type],
    "A" as [Source]
    FROM [MapPoints1$]
    UNION
    SELECT
    [MapPoints2$].[Location_Place] AS [Location_Name],
    [MapPoints2$].[Latitude] AS [Latitude],
    [MapPoints2$].[Longitude] AS [Longitude],
    [MapPoints2$].[TypeOfPlace] AS [Type],
    "B" as [Source]
    FROM [MapPoints2$]

  6. Click OK.
  7. In the Data Connection dialogue box, select Connect live or Import all data.

Create the map view

  1. Drag [Longitude] (not [Longitude (generated])] to the Columns shelf.
  2. Drag [Latitude] (not [Latitude (generated)]) to the Rows shelf.
  3. Drag [Location_Name] to Label on the Marks card.
  4. Drag [Type] to Colour.

Additional information

The field [Source] may be used to differentiate between the two original data tables in the data connection. 



Discuss this article... Feedback Forum
Did this article resolve the issue?