Download notebook (.ipynb)

Geodesic lines on livemap: geodesic parameter#

With geodesic=True, geom_segment() and geom_path() draw a geodesic: the shortest path between two points on Earth’s surface. Coordinates are expected in WGS84 longitude/latitude.

This parameter is supported by geom_segment() and geom_path() only when they are used with geom_livemap(). The default is geodesic=False.

import pandas as pd

from lets_plot import *
LetsPlot.setup_html()
LetsPlot.set(maptiles_lets_plot(theme='dark'))

Default: no geodesic#

(ggplot()
  + geom_livemap()
  + geom_segment(x=-122.25165, y=37.464958,
                 xend=139.4130, yend=35.4122,
                 color='white', size=1))

Segment with geodesic=True#

With geodesic=True, the segment follows the shortest path on Earth’s surface.

(ggplot()
  + geom_livemap()
  + geom_segment(x=-122.25165, y=37.464958,
                 xend=139.4130, yend=35.4122,
                 color='white', size=1,
                 geodesic=True))               # <----

geom_path() with geodesic=True#

data = {
    'city': ['New York', 'San-Francisco', 'Tokyo'],
    'lon': [-73.935242, -122.25165, 139.4130],
    'lat': [40.730610, 37.464958, 35.4122],
}

(ggplot(data)
  + geom_livemap()
  + geom_path(aes(x='lon', y='lat'),
              color='white', size=1, linetype="dotted")
  + geom_path(aes(x='lon', y='lat'),
              color='white', size=1,
              geodesic=True))         # <----

Comparing default, geodesic=True, and flat=True#

See the flat parameter example for how to keep line segments straight after projection.

route = {
    'lon': [-73.7997, -149.9002],
    'lat': [40.6408, 61.2180],
}

(ggplot(route, aes(x='lon', y='lat'))
  + geom_livemap()
  + geom_path(color='white', size=1, manual_key=layer_key("default"))
  + geom_path(color='aquamarine', size=1, flat=True, manual_key=layer_key("flat=True"))
  + geom_path(color='coral', size=1, geodesic=True, manual_key=layer_key("geodesic=True"))
  + theme(legend_position=[.11, .35],
          legend_text=element_text(color='white'),
          legend_background=element_rect(fill='#141414')))