Search code examples
pythonpython-3.xgeolocationgis

How to find all coordinates efficiently between two geo points/locations with certain interval using python


I want to calculate all geo coordinates between two geo points(lat/long) on earth. I would like to have a python solution for this problem.

Note: I don't want the distance I need coordinates between two points to simulate a person on the map to move him from one point to another on the map that's why I need all coordinates to show a smooth lifelike movement.


Solution

  • This is more of a geometry problem than a python problem.

    The following formula gives you all the points (x,y) between points (x1,y1) and (x2,y2):

    y = (y1-y2)/(x1-x2) * (x - x1) + y1      for x in [x1, x2]
    

    so if you want a simple python code (not the smoothest increment possible):

    # your geo points
    x1, y1 = 0, 0
    x2, y2 = 1, 1
    # the increment step (higher = faster)
    STEP = 0.004
    
    if x1 > x2:           # x2 must be the bigger one here
        x1, x2 = x2, x1
        y1, y2 = y2, y1
    
    for i in range(int((x2-x1)/STEP) + 1):
        x = x1 + i*STEP
        y = (y1-y2)/(x1-x2) * (x - x1) + y1
        do_something(x, y)