Skip to content

duboviy/dist

Repository files navigation

logo dist

by Eugene Duboviy

Build Status Codacy Badge Code Health PyPI Open Source Love PRs & Issues Welcome Awesome

Python/C API extension module that computes distance between two coordinates on the world map.

Why?

As more and more apps are using maps, the more demand for geolocation capabilities increase. Geolocation is about the reporting of your location to other users, as well as associating real-world locations (such as landmarks) to your location. This repo helps to accurately calculate the distance between two locations and presents a time efficient practical solution, that is almost 3 times faster than similar fast pure python implementation.

Installation

python setup.py install

Or using alternative command:

pip install https://github.com/duboviy/dist/archive/master.zip

Input and output data

The dist function accepts four float parameters:

  • lat1, lon1: The Latitude and Longitude of point 1 (in decimal degrees)
  • lat2, lon2: The Latitude and Longitude of point 2 (in decimal degrees)

The unit of measurement in which result is calculated is kilometers. [float]

Usage

>>> import dist
>>> dist.compute(10.1, 12.1, 10.1, 10.1)
218.933532715

Performance / speed comparison

This Python/C API Extension module is in ~ 3 times faster than similar fast pure python implementation. You can use performance test to compare speed with fast pure python implementation, just run nose test runner:

>>> nosetests
ext_time: 2.46785402298 pure_py_time: 7.49713611603

Python Versions

Checked under following Python versions:

  • 2.6
  • 2.7
  • 3.3
  • 3.4
  • 3.5
  • 3.6

What does it use inside? What kind of formula implementation is used?

Module accounts the curvature of the Earth when calculating large distances on the world map. If the Earth were flat, calculating the distance between two points would be very simple as for a straight line. The Haversine formula is used in current implementation, it includes a constant that represents the radius of the Earth. The Haversine formula is not 100% accurate because the Earth is not a perfect sphere. However, the Haversine gives a good enough approximation for most applications that use geolocation.

License

MIT licensed library. See LICENSE.txt for details.

Contributing

If you have suggestions for improving the dist, please open an issue or pull request on GitHub.

Badges

forthebadge forthebadge forthebadge forthebadge

forthebadge forthebadge forthebadge forthebadge

Open Source Love

forthebadge


About

🗺️ Python/C API extension module that computes distance between two coordinates on the world map

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published