-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
haversine raises an exception above 180 degrees latitude #49
Comments
Maybe you can normalize values by converting them to the relevant numbers. For example, convert 270 degrees to -90, convert 720 to 0 etc. |
Also, the limits of |
Hi @uri-rodberg , Thanks for opening the issue. |
Hi @jdeniau, OK, I'll try. How do you want me to fix this? Do you want me to convert the input to a specific range? And what range of values do you expect the input to be? For example, you can define |
Hi, I read on Google the ranges of latitude and longitude:
Now, I would like to know if you receive input beyond this range, what do you want to do? I think maybe it makes sense to raise an exception if the latitude is below -90 or above 90, but convert the longitude to the required range by adding or subtracting 360 multiplied by the relevant integer. But I'm not sure. Maybe raise an exception anyway? Or convert the latitude too? In theory you can add or subtract 360 for the latitude too, and if it's not between -90 and 90, reverse the location (add 180 degrees to the longitude). But I'm not sure what's the correct thing to do. What do you think? |
A conversion to a range seems to work fine, but be I do not work with haversine a lot, so I might not choose the best option. @MuellerSeb , @merschformann , may I ask for your opinion another time ? (And please tell me if you don't want to be notified anymore ! 😃 ) |
All fine. 🤗 I tried to wrap my head around it by replaying the example given by @uri-rodberg :
When not "normalizing" the points are London: (-51.5072, 179.8724)
Other: (231.5072, -0.1276) which indeed causes a When "normalizing" the points to [-90,90] and [-180,180] the points are London: (-51.5072, 179.87239999999997)
Other: (51.50720000000001, -0.12760000000000105) and the distance is However, this is where discussions may start and I am not fully certain that I have sufficient knowledge about expectations of the GIS community (and who else uses this library) to have a good recommendation. It seems to me there are at least three options though:
I added the code I wrote for testing to #52 just in case we want option 1. I am not certain this is the right way though. Some more feedback would be recommended, I think. |
Hi @merschformann, I think you have a mistake. London is That being said, I think maybe it makes more sense to raise an exception if lat1 is not in the range -90 to 90, and then you can optionally assign Another option is to define a setting that will determine if to normalize the latitude and longitude, or raise an exception. |
@uri-rodberg : I think I misunderstood your problematic case due to the way I intuitively normalized. And my choice of variable names was poor too. 😅 So, I think we are getting to the same discussion of what is the correct way of normalizing. Simply "normalizing" latitude to [-90,90] like I did may indeed be confusing when thinking about the full circle. Your strategy seems a bit complicated to me too, but it may well be the way to go. Maybe we can have some further opinions? Let me update #52 anyway to accommodate my improved understanding. |
Hi @merschformann, Just to emphasize why calculating |
I understand now why you propose to throw an exception only for latitude and normalize longitude 😄 It seems that longitude out of bounds is an error and should throw. For the latitude, I like consistency, so I would suggest to throw an exception too, but if having a "weird" latitude is a thing that happen, we can normalize it. As you prefer. |
Regarding the normalization: I noticed that too. The way @uri-rodberg proposes probably makes sense. The one I intuitively used certainly leads to unexpected results on the user side. Personally, I would suggest throwing an exception for non-proper lat/lons and accepting an optional Edit: I also updated #52. Maybe this is what we want? |
Fixed by #52 |
Hi,
I defined London as
(51.5072, -0.1276)
, and then I had 3 methods to define the other side of the earth from London:Then I tried to check the distance between each point, and the distance to London. When I defined the other side of the earth from London as
(51.5072 + 180.0, -0.1276)
, haversine raises an exception when I check its distance to(51.5072 * -1.0, -0.1276 + 180.0)
(which should be 0). You have a problem with angles above 180 degrees. I know latitude and longitude shouldn't usually be above 180 degrees (actually latitude should be from -90 to 90 degrees), but it would be nice if haversine would be able to handle other degrees too while converting them to the relevant degree (51.5072 - 180.0
and51.5072 + 180.0
should be the same degree).Notice that
51.5072 - 180.0
is-128.4928
and it works, even though it's below-90
degrees (it's just a way to define the point on the other side of the earth).The text was updated successfully, but these errors were encountered: