holoviz / geoviews

Simple, concise geographical visualization in Python
http://geoviews.org
BSD 3-Clause "New" or "Revised" License
577 stars 75 forks source link

Great-circle paths #38

Open jbednar opened 7 years ago

jbednar commented 7 years ago

HLine and VLine will always be straight in screen coordinates, but it's important to be able to draw paths between two points that follow the great-circle path that one would need to travel in the real world. Such paths can already be plotted using the latest geoviews master (thanks @philippjfr!):

image

though it would be nice to increase the number of points to make smoother curves. Philipp also had a suggestion for exposing the coordinate transformations for when you want to work with them explicitly:


path = gv.Path([[(132, -0.08), (43.17, 51.53)]], crs=crs.Geodetic())
mercator_path = GeoConversion(path, crs=crs.GOOGLE_MERCATOR)

This all sounds good, but there are some other things that would help when working with great-circle paths. First, if there is a function in cartopy or proj4 for computing a great-circle distance between two points, it would be great to show that in an example in a GeoViews tutorial, along with the above example of plotting paths. Second, if there is not currently such a function, Philipp has some code of his own for computing it, and it would be good to add that to GeoViews so that people can work naturally with great-circle paths.

philippjfr commented 7 years ago

This little function computes a great-circle path at any required density:

import pyproj

def get_circle_path(start, end, sampling=1000):
    sx, sy = start
    ex, ey = end
    g = pyproj.Geod(ellps='WGS84')
    (az12, az21, dist) = g.inv(sx, sy, ex, ey)
    lonlats = g.npts(sx, sy, ex, ey,
                     1 + int(dist / sampling))
    return lonlats

We should add this as an option on the existing gv.operation.project_shape function.

jbednar commented 7 years ago

Sounds good. Can we use it to have meaningful lon, lat coordinates shown on the axes by drawing a grid with lines starting at each axis?

ea42gh commented 7 years ago

get_circle_path should add start and end to lonlats