'GeoDjango: Move a coordinate a fixed distance in a given direction (e.g. move a point east by one mile)

Given a Point (django.contrib.gis.geos.Point) how do I find another point 1 mile east from that Point object?

(A) ---[ 1 mile ]---> (B)

My failed attempts:

  • I've considered trying to go hardcode the 1 mile east point but due to the curvature of the earth. The miles per degree change.

  • Copius googling on SO and Geo Info Exchange. I assume I cannot find the terminology?


  • Python 3.6
  • Django 1.11


Solution 1:[1]

You can accomplish this using the Geod class of pyproj.

from pyproj import Geod
geoid = Geod(ellps='WGS84')

def add_distance(lat, lng, az, dist):
    lng_new, lat_new, return_az = geoid.fwd(lon, lat, az, dist)
    return lat_new, lng_new
  • lng: starting longitude
  • lat: starting latitude
  • az: azimuth, the direction of movement
  • dist: distance in meters

So for your specific question, you could do the following:

from django.contrib.gis.geos import Point

def move_point_mile_east(point):
    dist = 1609.34
    lat, lng = add_distance(point.y, point.x, 90, dist)
    return Point(lng, lat)

Solution 2:[2]

Please note there appears to be a typo in the answer by roob above. In the definition of the add_distance function the argument lng is used, but then in the body of that function the variable lon is used. These need to be the same, of course.

Otherwise it's an excellent answer. Thank you.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 allan