question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Distance calculation takes (y, x) instead of (x, y)

See original GitHub issue

So the issue is that distance caluclation (vincenty and great_circle) take arguments in the form of ((y, x), (y, x)) instead of ((x, y), (x, y)). The convention followed by Geopy is consistent with the idea of (Latitude, Longitude), but is not conversant with Shapely or Fiona’s idea of the same. Shapely and Fiona will return (x, y), or (Longitude, Latitude), and I think Geopy should accept that format as default. Perhaps have a Boolean switch that takes the other format. For example, the following pseudocode:

def vincenty(p1, p2, xy=True):
    if xy:
        p1 = reversed(p1)
        p2 = reversed(p2)
    # And the rest of the algorithm as usual.

IMHO, this would save a considerable amount of headache. Most answers on Stack Exchange are also oblivious to this (eg: http://gis.stackexchange.com/questions/4022/looking-for-a-pythonic-way-to-calculate-the-length-of-a-wkt-linestring).

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
KostyaEsmukovcommented, May 8, 2018

Closed by #282 which introduced the aforementioned lonlat function.

Feel free to bump if this solution does not seem complete.

0reactions
KostyaEsmukovcommented, May 10, 2018

Python is also famous for preferring to have a single way of doing one thing 😃.

The reason why I decided to not introduce latlon is that I believe it would be confusing to the API users: what’s the difference between that and constructing the Point instance directly? The order of coordinates is the same. So which one to choose?

The (latitude, longitude) order is spread around the library anyways, this won’t go away. So I believe it’s OK to assume the lat, lon order when the order is not explicitly specified by code (like lonlat). Especially considering that this order is documented and is constant across the library.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is the formula for finding distance? - StudyPug
Key things to remember when calculating for distance is: 1) Do not mismatch your x and y values. Ensure that you've matched them...
Read more >
Distance between point & line (video) - Khan Academy
The distance from a point to a line is the shortest distance between the point ... In the formula, the line is represented...
Read more >
Three-Dimensional Coordinate Systems
The distance between two points P1 = (x1,y1) and P2 = (x2,y2) in the xy-plane is given by the distance formula, d(P1,P2) =...
Read more >
Method for calculating distance between all points in a ...
At the moment I can calculate the distance between two points using: length = sqrt((x1 - x2)^2 ...
Read more >
Math: how do I write a formula for the distance between (x,y ...
= (x, x^8) on the graph of y = x^8 and the point (2,8), we'll need to utilize the distance formula which is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found