In order to draw a route whether straight or curved it was necessary to have two records for each origin/destination country combination. The first one for the start and the second one for the end. In this case, number 1 is the starting point and number 2 is the end.

See the result below :

Now the dataset is ready for Tableau! After I had loaded the data, I had to create some new calculations.

Just follow me step by step.

3.step

How to get the curved lines depicting the routes?

I had to calculate the Quadratic Brezier curve which starts at t = 0 and ends at t = 1. It is useful, especially when fitting together a string of Brezier curves, to allow an arbitrary parameter interval: t0 ≤ t ≤ t1

This is the formula:

Let’s go to create the Brezier value which starts at 1 and end at 100.

4.step

Next step is to generate the Brezier Value of 100 points varying from 0 to 100. It was done by creating a bin. Set the size to 1. These points define the all the points of the lines.

IIF([Path Order] = 1,1,100)

5.step

Now I calculated the ’t’ value based on the Index field. Since the ’t’ should be t0 ≤ t ≤ t1 therefore, I had to subtract 1 and then divided by 100.

([Index]-1)/100

6.step

The next step is to calculate the new latitude/longitude radians fields. Those are required to get the distance between two points on the map.

Newlat1 Radians

RADIANS(WINDOW_MIN(min([Origin Latitude]),FIRST(),FIRST()))

Newlat1 Radians

RADIANS(window_min(min([Target Latitude]),LAST(),LAST()))

Newlon1 Radians

RADIANS(window_min(min([Origin Longitude]),FIRST(),FIRST()))

Newlon2 Radians

RADIANS(window_min(min([Target Longitude]),LAST(),LAST()))

7.step

Using the long/lang radians field I was able to get the distance.Since the surface of a sphere is curved, finding the distance between the origin and the destination countries along that surface will require some non-Euclidean geometry. The haversine formula calculates the great – circle distance between longitude/latitude points assuming a spherical earth. Vincenty’s formula takes into account that the earth is not perfectly spherical, by calculating the ellipsoidal distance between two points on the surface of a spheroid

Now I was able to convert back the previously calculated fields to lat/long.

lat= atan2(z,sqrt(x*x+y*y)) lon = atan2(y, x)

◊◊ These formulas in Tableau ◊◊

Newlat

atan2([z],sqrt(power([x],2)+power([y],2)))

Newlon

atan2([y],[x])

10.step

So by now, I’ve had the new long and lat coordinates, but to be able to draw the curved lines I had to generate the degrees. I promise this is the last step.

Newlong Degress

case [Index]

when 1 then window_min((avg([Origin Longitude])),FIRST(),FIRST())

when 100 then window_min((avg([Target Longitude])),LAST(),LAST())

else degrees([Newlon])

end

Newlat Degress

case [Index]

when 1 then window_min((avg([Origin Latitude])),FIRST(),FIRST())

when 100 then window_min((avg([Target Latitude])),LAST(),LAST())

else degrees([Newlat])

end

We are close to the end. Let’s go and create the curved lines.

FINAL STEPS

Set the Geographical role of the ‘Newlong Degrees’ to Longitude and the ‘Newlat Degrees’ field to Latitude.

Set the Mark type to line.

Add the ‘Path’ to the Detail shelf and the ‘Brezier Value(bin)’ to the Path.

Add the ‘Newlong Degrees’ to the Columns and ‘Newlat Degrees’ field to the Rows.

Set the Tableau Calculations in the Degrees field using Specific Dimensions, select ‘Path’ and ‘Bezier Value’, use the Deepest level and restarting from every ‘Path’.

And VOILÁ! 🙂

Final thoughts

Be sure you set everything and used the bin field in the Path shelf in order to avoid getting not continuous lines. Otherwise, don’t worry because Tableau has the best community and if you just get stuck somewhere a clever guy will help you. 🙂

Comments (6)

March 13, 2017 by Adolfo

Adolfo

Hi Ivett,

Thanks for this great tutorial! I have a problem though, I want to make my lines with a different thickness depending on a variable value but when I drag this variable to my size card I just got circles of different sizes at the end of my lines! Also how did you make to get transparent background in the Country labels in your map? Thanks.

Ivett Kovács

Helene

I’m really impressed with your writing skills as well as with the layout
on your weblog. Is this a paid them or did you customize it
yourself? Anyway keep up the nice quality writing, it iss rare to see a great
blog like this one these days.