pygeofun

Geographic Functions: geodesics and rhumblines, orthodromes and loxodromes


Keywords
geodesic, rhumb, line, loxodrome, orthodrome, distance, azimuth
License
MIT
Install
pip install pygeofun==0.0.14

Documentation

GeoFun

Library for doing geographic calculations like distance, azimuth and position determination for geodesics and rhumb lines, orthodromes and loxodromes, respectively.

This version makes use of GeographicLib for doing most of the calculations.

This is a C++ package that uses pybind11 to wrap the C++ version of GeographicLib, which makes it faster (~100x) than the pure python version of geographiclib.

Compare:

Installing

pip install pygeofun should work without needing to compile anything on Windows, Linux (x86_64, aarch64) and MacOS 13 (x86_64) for python versions 3.9 - 3.12. For other platforms you might need to build the C++ parts. Wheel contributions for other platforms are very welcome.

Building

  • Get poetry if you don't have it
  • Check out the source code: git clone https://github.com/jrversteegh/geofun.git --recurse-submodules
  • Execute poetry build to build the package or poetry install to get a virtual environment to work in. Both require a working modern C++ compiler. GCC 9.4 and MSVC 14.3 were tested. Others may work.

Examples

Some operator abuse was used to mark the difference between geodesic and mercator based operations. + and - are addition and subtraction in the mercator projection (loxodromes) and * and / are addition and subtraction on geodesics (orthodromes). If you object to this, you’re probably right. Any suggestions for a better way are quite welcome.

Another example. Flying from Kennedy Airport to Amsterdam Schiphol Airport and splitting both a great circle and a rhumbline route into segments:

Classes

Position
  • latitude
  • longitude

Position(latitude: int, longitude: int) -> Position Position in arc seconds.

Position(latitude: float, longitude: float) -> Position Position in arc degrees.

Position(position: str) -> Position Position parsed from string.

Vector
  • azimuth
  • length

Vector(azimuth: float, length: float) -> Vector Polar vector in arc degrees and meters.

Point
  • x
  • y

Point(x: float, y: float) -> Point Point on locally flat coordinate system, x pointing north, y pointing east.

Many operators will work on classes like:

  • Point + Point, adds x and y coordinates of points
  • Point + Vector, offsets point by vector
  • Position + Vector, offsets position by vector along loxodrome
  • Position * Vector, offsets position by vector along orthodrome
  • Position - Position, get loxodromic vector from position to position
  • Position / Position, get orthodromic vector from position to position

Functions

get_version() -> str

Get the library version

geodesic_direct(latitude: float, longitude: float, azimuth: float, distance: float) -> tuple

Get position and final azimuth after moving distance along great circle with starting azimuth

geodesic_inverse(latitude1: float, longitude1: float, latitude2: float, longitude2: float) -> tuple

Get starting azimuth, distance and ending azimuth of great circle between positions

rhumb_direct(latitude: float, longitude: float, azimuth: float, distance: float) -> tuple

Get position and final azimuth after moving distance from starting position at fixed azimuth/along rhumb line

rhumb_inverse(latitude1: float, longitude1: float, latitude2: float, longitude2: float) -> tuple

Get rhumb line azimuth, distance and final azimuth between positions

angle_diff(arg0: numpy.ndarray[numpy.float64], arg1: numpy.ndarray[numpy.float64]) -> object

Signed difference between to angles

angle_mod(arg0: numpy.ndarray[numpy.float64]) -> object

Return angle bound to [0.0, 360.0>

angle_mod_signed(arg0: numpy.ndarray[numpy.float64]) -> object

Return angle bound to [-180.0, 180.0>