I would like to calculate a point based on direction and distance using GeoDjango or GeoPy.
For example, If I have a point that is (-24680.1613, 6708860.65389) I would like to find out a point 1KM North, 1KM East, 1KM Sourh and 1KM west using Vincenty distance formula.
I closest thing I can find is a "destination" function in distance.py (https://code.google.com/p/geopy/source/browse/trunk/geopy/distance.py?r=105). Although I cannot find this documented anywhere and I'm yet to figure out how to use it.
Any help is much appreciated.
Edit 2
Okay, there is an out-of-the-box solution with geopy, it is just not well-documented:
The output is
48 52m 0.0s N, 2 21m 0.0s E
(orPoint(48.861992239749355, 2.349, 0.0)
).A bearing of 90 degrees corresponds to East, 180 degrees is South, and so on.
Older answers:
A simple solution would be:
However, I am not sure if that serves your purposes in all generality.
Okay, seriously, you can get started using geopy. First of all, you need to define your starting point in a coordinate system known to geopy. At the first glance, it seems that you cannot just "add" a certain distance into a certain direction. The reason, I think, is that calculation of the distance is a problem without simple inverse solution. Or how would we invert the
measure
function defined in https://code.google.com/p/geopy/source/browse/trunk/geopy/distance.py#217?Hence, you might want to take an iterative approach.
As stated here: https://stackoverflow.com/a/9078861/145400 you can calculate the distance between two given points like that:
For going north by one kilometer you would iteratively change the latitude into a positive direction and check against the distance. You can automate this approach using a simple iterative solver from e.g. SciPy: just find the root of
geopy.distance.distance().km - 1
via one of the optimizers listed in http://docs.scipy.org/doc/scipy/reference/optimize.html#root-finding.I think it is clear that you go south by changing the latitude into a negative direction, and west and east by changing the longitude.
I have no experience with such geo calculations, this iterative approach only makes sense if there is no simple direct way for "going north" by a certain distance.
Edit: an example implementation of my proposal:
Output:
I had to deal with adding meters to longitude and latitude.
Here's what I did, inspired by this source :