Skip to main content

A collection of functions to calculate attributes of the great circle

Project description

Great Circle Calculator

This is a collection of equations and formulas that I've been using across many projects to compute various distances using great circle calculations. The formulas here were adapted into python for my use from here and here.
Because I've been using these equations across several projects, I decided to upload this to PyPI for ease of keeping updated and distribution. Feel free to clone, fork, or modify the code as needed. I believe there are more robust packages out there. One example is geodesy.
But I figured I could use the python practice.

Any questions, feel free to get in touch.

How to install

I still haven't uploaded it to the PyPI as of this writing. But you can either download/clone the package to your computer or download it via pip install (someday).

How to use

Right now, there aren't that many functions to go over, but I'll outline them here.

Library great_circle_calculator

distance_between_points(p1, p2, unit='meters', haversine=False): This function computes the distance between two points in the unit given in the unit parameter.
It will calculate the distance using the law of cosines unless the user specifies haversine to be true. :param p1: tuple point of (lon, lat) :param p2: tuple point of (lon, lat) :param unit: unit of measurement. List can be found in constants.eligible_units :param haversine: False (default) uses law of cosines, True uses haversine :return: Distance between p1 and p2 in the units specified.

bearing_at_p1(p1, p2): This function computes the bearing (i.e. course) at p1 given a destination of p2. Use in conjunction with midpoint() and intermediate_point() to find the course along the route. Use bearing_at_p2(*) to find the bearing at the endpoint :param p1: tuple point of (lon, lat) :param p2: tuple point of (lon, lat) :return: Course, in degrees

bearing_at_p2(p1, p2): This function computes the bearing (i.e. course) at p2 given a starting point of p1. Use in conjunction with midpoint() and intermediate_point() to find the course along the route. Use bearing_at_p1(*) to find the bearing at the endpoint :param p1: tuple point of (lon, lat) :param p2: tuple point of (lon, lat) :return: Course, in degrees

midpoint(p1, p2): This is the half-way point along a great circle path between the two points. :param p1: tuple point of (lon, lat) :param p2: tuple point of (lon, lat) :return: point (lon, lat)

intermediate_point(p1, p2, fraction=0.5): This function calculates the intermediate point along the course laid out by p1 to p2. fraction is the fraction of the distance between p1 and p2, where 0 is p1, 0.5 is equivalent to midpoint(*), and 1 is p2. :param p1: tuple point of (lon, lat) :param p2: tuple point of (lon, lat) :param fraction: the fraction of the distance along the path. :return: point (lon, lat)

point_given_start_and_bearing(p1, course, distance, unit='meters'): Given a start point, initial bearing, and distance, this will calculate the destina­tion point and final bearing travelling along a (shortest distance) great circle arc. :param p1: tuple point of (lon, lat) :param course: Course, in degrees :param distance: a length in unit :param unit: unit of measurement. List can be found in constants.eligible_units :return: point (lon, lat)

Library compass

This lets me call something like Compass.east so I can get 90deg. I thought it helped with code readability at first, kept it because it might be useful...

Library _constants

This was created for two purposes:

  1. To easily store the radius of the earth in various units

  2. To simplify the code in the program so I don't have to call math.* each time I want sin, cos, etc.

To see the available units, call _constants.eligible_units and a list of the units that are available will be given.

Libraries __conversion and __error_checking

Private libraries that convert (__conversion.py) values between radians and degrees as the default option for python's math package is radians.

The error checking library (__error_checking.py) is something I want to work on. I use regular cartesian convention when passing points, i.e. (lon, lat) or (x, y). So if you try to pass a point which is in (lat, lon) and it doesn't pass the sanity check, such as lat > 90 and lon <= 90, it will, right now, swap the coordinates. Not sure if that's the best for everyone, but I am mostly working on projects where the lon is (approximately) > 90

And finally:

Last updated Jan 8, 2018. Hit me up here for questions and critiques.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

great_circle_calculator-1.0.0.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

great_circle_calculator-1.0.0-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file great_circle_calculator-1.0.0.tar.gz.

File metadata

  • Download URL: great_circle_calculator-1.0.0.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.0 CPython/3.7.2

File hashes

Hashes for great_circle_calculator-1.0.0.tar.gz
Algorithm Hash digest
SHA256 7ea63a077cb1ec5511707e29e8e592dc5d8d2b4c7203cf7c33cd1ed63a83cedd
MD5 5f13f5e69d939973645726cac4f2cf40
BLAKE2b-256 5b28c676bf9db87929ed49a7dd420e32ef18780052674f3c2fcefd9a212a2a92

See more details on using hashes here.

File details

Details for the file great_circle_calculator-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: great_circle_calculator-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.0 CPython/3.7.2

File hashes

Hashes for great_circle_calculator-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5d5a626252a3e07bef874214eed45dea7b2b0573d7f9448b462a92759186081b
MD5 a443f956a12d8458bc7aa2314c5984de
BLAKE2b-256 1f792fa8b47e540d284a4defca1ea9d76f0c4b8a986510a013271b6589ee0de3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page