Skip to content
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

feat: add implementation for haversine distance for geo-coordinates #69

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

sumsamvoi
Copy link

In this PR, I have added the implementation for calculating haversine distance between geo coordinates in kilometers. This is useful if you are working with latitude and longitudes. The original implementation only calculates euclidean distances.

@paulmach
Copy link
Owner

Thank you, but this is already implemented in the orb/geo package where all "geo" type functions are located. Flat/euclidean stuff is located in orb/planar. https://github.com/paulmach/orb/blob/master/geo/distance.go#L26

For the "distance from" stuff. I'm not sure that's accurate for points+lines on a sphere. I would have to think about but I assume you'd need some more trig functions in there.

@sumsamvoi
Copy link
Author

Thank you, but this is already implemented in the orb/geo package where all "geo" type functions are located. Flat/euclidean stuff is located in orb/planar. https://github.com/paulmach/orb/blob/master/geo/distance.go#L26

For the "distance from" stuff. I'm not sure that's accurate for points+lines on a sphere. I would have to think about but I assume you'd need some more trig functions in there.

Thank you for the comment. Basically, my use case here was the distance from stuff. That was missing in the current implementation. I wanted to calculate distance(actual distance on earth) from a geographical location to a geometery. The current implementation was only calculating planar distances in that context. And yes you are right, maybe i should have added it in the orb/geo package and use the existing "geo distance" method from there, but i figured, since you have all the "distance from" implementation inside planar package so i might as well add it there.

On your point about how accurate that is, from the benchmark testing I did, it is almost identical to what postGIS calculates. Basically, we moved some logic from db layer (which was using postGIS) into code using your lib and benchmarked the results from both implementations, and they were almost identical. We are already using the forked repo i created in production. But having said that, its probably better to be safe and double check the implementation and validate it thoroughly. For now, we are using the forked repo (https://github.com/sumsamvoi/orb). But once we finalize this PR, we can start using this one again in our services.

@sumsamvoi
Copy link
Author

@paulmach Made some changes to this, moved all the geo calculations in the geo package and started using the existing "DistanceHaversine" function for calculating the distance between points on earth. Please give further directions of what needs to done to move forward with this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants