Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 633
Stefan Collier Avatar asked Dec 12 '25 17:12

Stefan Collier


1 Answers

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)
like image 152
roob Avatar answered Dec 15 '25 07:12

roob



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!