acdc.database.saa_distance

Taken from: # https://stackoverflow.com/questions/43440813/shortest-great-circle-distance-between-a-point-and-a-polygon-on-a-sphere-globe

Functions

Distance3dPointTo3dCoords

Calculate the closest distance between a latitude-longitude query point and a shapely polygon defined by latitude-longitude points using only spherical mathematics, modified from Distance3dPointTo3dPolygon.

Distance3dPointTo3dPolygon

Calculate the closest distance between a latitude-longitude query point and a shapely polygon defined by latitude-longitude points using only spherical mathematics.

DistanceToGCArc

Calculate the distance from a query point to the nearest point on a Great Circle Arc :param lat1: Latitude of start of arc in degrees :type lat1: float :param lon1: Longtiude of start of arc in degrees :type lon1: float :param lat2: Latitude of end of arc in degrees :type lat2: float :param lon2: Longtiude of end of arc in degrees :type lon2: float :param plat: Latitude of query point in degrees :type plat: float :param plon: Longitude of query point in degrees :type plon: float

Haversine

Calculate the Great Circle distance on Earth between two latitude-longitude points :param lat1: Latitude of Point 1 in degrees :type lat1: float :param lon1: Longtiude of Point 1 in degrees :type lon1: float :param lat2: Latitude of Point 2 in degrees :type lat2: float :param lon2: Longtiude of Point 2 in degrees :type lon2: float

LatLonToXYZ

Convert a latitude-longitude pair to 3D-Cartesian coordinates.

NearestPointOnGC

Calculate the location of the nearest point on a Great Circle to a query point :param lat1: Latitude of start of arc in degrees :type lat1: float :param lon1: Longtiude of start of arc in degrees :type lon1: float :param lat2: Latitude of end of arc in degrees :type lat2: float :param lon2: Longtiude of end of arc in degrees :type lon2: float :param plat: Latitude of query point in degrees :type plat: float :param plon: Longitude of query point in degrees :type plon: float

Pairwise

Iterate through an itertable returning adjacent pairs.

XYZtoLatLon

Convert 3D-Cartesian coordinates to a latitude-longitude pair.

saa_distance

Wrapper to calculate distance to polygon (defined in latitude-longitude space) for a series of points.

saa_distance_shapely

Wrapper to calculate distance to shapely geometry (defined in latitude-longitude space) for a series of points.

Distance3dPointTo3dCoords(lat, lon, polylat, polylon)[source]

Calculate the closest distance between a latitude-longitude query point and a shapely polygon defined by latitude-longitude points using only spherical mathematics, modified from Distance3dPointTo3dPolygon.

Parameters:
  • lat (float) – Latitude of query point in degrees

  • lon (float) – Longitude of query point in degrees

  • polylat (array) – Latitude borders polygon

  • polylon (array) – Longitude borders polygon

  • geom (shapely geometry) – A shapely geometry whose points are in latitude-longitude space

Returns:

dist (float) – The minimum distance in kilometres between the polygon and the query point.

Distance3dPointTo3dPolygon(lat, lon, geom)[source]

Calculate the closest distance between a latitude-longitude query point and a shapely polygon defined by latitude-longitude points using only spherical mathematics.

Parameters:
  • lat (float) – Latitude of query point in degrees

  • lon (float) – Longitude of query point in degrees

  • geom (shapely geometry) – A shapely geometry whose points are in latitude-longitude space

Returns:

dist (float) – The minimum distance in kilometres between the polygon and the query point.

DistanceToGCArc(alat, alon, blat, blon, plat, plon)[source]

Calculate the distance from a query point to the nearest point on a Great Circle Arc :param lat1: Latitude of start of arc in degrees :type lat1: float :param lon1: Longtiude of start of arc in degrees :type lon1: float :param lat2: Latitude of end of arc in degrees :type lat2: float :param lon2: Longtiude of end of arc in degrees :type lon2: float :param plat: Latitude of query point in degrees :type plat: float :param plon: Longitude of query point in degrees :type plon: float

Returns:

float – The distance in kilometres from the query point to the great circle arc

Haversine(lat1, lon1, lat2, lon2)[source]

Calculate the Great Circle distance on Earth between two latitude-longitude points :param lat1: Latitude of Point 1 in degrees :type lat1: float :param lon1: Longtiude of Point 1 in degrees :type lon1: float :param lat2: Latitude of Point 2 in degrees :type lat2: float :param lon2: Longtiude of Point 2 in degrees :type lon2: float

Returns:

float – Distance between the two points in kilometres

LatLonToXYZ(lat, lon, radius)[source]

Convert a latitude-longitude pair to 3D-Cartesian coordinates.

Parameters:
  • lat (float) – Latitude in degrees

  • lon (float) – Longitude in degrees

  • radius (float) – Radius in arbitrary units

Returns:

tuple – x,y,z coordinates in arbitrary units

NearestPointOnGC(alat1, alon1, alat2, alon2, plat, plon)[source]

Calculate the location of the nearest point on a Great Circle to a query point :param lat1: Latitude of start of arc in degrees :type lat1: float :param lon1: Longtiude of start of arc in degrees :type lon1: float :param lat2: Latitude of end of arc in degrees :type lat2: float :param lon2: Longtiude of end of arc in degrees :type lon2: float :param plat: Latitude of query point in degrees :type plat: float :param plon: Longitude of query point in degrees :type plon: float

Returns:

tuple – A (lat,lon) pair in degrees of the closest point

Pairwise(iterable)[source]

Iterate through an itertable returning adjacent pairs.

Parameters:

iterable (array-like) – An iterable

Returns:

tuple – Pairs of sequential, adjacent entries from the iterable

XYZtoLatLon(x, y, z)[source]

Convert 3D-Cartesian coordinates to a latitude-longitude pair.

Parameters:
  • x (float) – x-coordinate in arbitrary units

  • y (float) – y-coordinate in arbitrary units

  • z (float) – z-coordinate in arbitrary units

Returns:

tuple – lat,lon pair in degrees

saa_distance(lat, lon, poly_lat, poly_lon)[source]

Wrapper to calculate distance to polygon (defined in latitude-longitude space) for a series of points.

Parameters:
  • lat (float) – Latitude of query point in degrees

  • lon (float) – Longitude of query point in degrees

  • polylat (array) – Latitude borders polygon

  • polylon (array) – Longitude borders polygon

Returns:

dist (float) – The minimum distance in kilometres between the polygon and the query point.

saa_distance_shapely(lat, lon, geom)[source]

Wrapper to calculate distance to shapely geometry (defined in latitude-longitude space) for a series of points.

Parameters:
  • lat (float) – Latitude of query point in degrees

  • lon (float) – Longitude of query point in degrees

  • geom (shapely geometry) – A shapely geometry whose points are in latitude-longitude space

Returns:

dist (float) – The minimum distance in kilometres between the polygon and the query point.