Module gplately.spatial
This sub-module contains spatial tools for calculating distances on the Earth.
Functions
def cartesian_distance(lon1, lon2, lat1, lat2, degrees=True, k=1, return_neighbours=False)
def geocentric_radius(lat, degrees=True)
-
Calculates the latitude-dependent radius of an ellipsoid Earth.
Parameters
lat
:float
- The geodetic latitude at which to calculate the Earth's radius
degrees
:bool
, default=True
- Specify whether the given latitude is in degrees.
Returns
earth_radius
:float
- The Earth's geocentric radius (in metres) at the given geodetic latitude.
def great_circle_distance(lon1, lon2, lat1, lat2, degrees=True, k=1, return_neighbours=False)
def haversine_distance(lon1, lon2, lat1, lat2, degrees=True)
-
Computes the Haversine distance (the shortest distance on the surface of an ideal spherical Earth) between two points given their latitudes and longitudes.
Sources
https://en.wikipedia.org/wiki/Haversine_formula https://stackoverflow.com/questions/639695/how-to-convert-latitude-or-longitude-to-meters
Parameters
lon1
,lon2
:float
- Longitudes of both points
lat1
,lat2
:float
- Latitudes of both points
Returns
d
:float
- The Haversine distance in metres.
Notes
Default behaviour assumes values in degrees; for radians specify degrees=False
def lonlat2xyz(lon, lat, degrees=True)
-
Convert lon / lat (radians) for spherical triangulation into Cartesian (x,y,z) coordinates on the unit sphere.
Parameters
lon
,lat
:lists
- Longitudes and latitudes of feature points in radians.
Returns
xs
,ys
,zs
:lists
- Cartesian coordinates of each feature point in all 3 dimensions.
def xyz2lonlat(x, y, z, validate=False, degrees=True)
-
Converts Cartesian (x,y,z) representation of points (on the unit sphere) for spherical triangulation into lon / lat (radians).
Note: No check is made here that (x,y,z) are unit vectors - it is assumed.
Parameters
x
,y
,z
:lists
- Cartesian coordinates of each feature point in all 3 dimensions.
Returns
lon
,lat
:lists
- Longitudes and latitudes of feature points in radians.
Notes
No check is made here that (x,y,z) are unit vectors, unless validate=True is specified