Spherical math

detroit.geo_area(obj: dict[str, Any]) float

Returns the spherical area of the specified GeoJSON object in steradians. This is the spherical equivalent of GeoPath.area.

Parameters:

obj (GeoJSON) – GeoJSON object

Returns:

Spherical area

Return type:

float

detroit.geo_bounds(obj: dict[str, Any]) tuple[tuple[float, float], tuple[float, float]]

Returns the spherical bounding box for the specified GeoJSON object. The bounding box is represented by a two-dimensional array: [[left, bottom], [right, top]], where left is the minimum longitude, bottom is the minimum latitude, right is maximum longitude, and top is the maximum latitude. All coordinates are given in degrees. (Note that in projected planar coordinates, the minimum latitude is typically the maximum y-value, and the maximum latitude is typically the minimum y-value.) This is the spherical equivalent of GeoPath.bounds.

Parameters:

obj (GeoJSON) – GeoJSON object

Returns:

Spherical bounding box

Return type:

tuple[Point2D, Point2D]

detroit.geo_centroid(obj: dict[str, Any]) tuple[float, float]

Returns the spherical centroid of the specified GeoJSON object. This is the spherical equivalent of GeoPath.centroid.

Parameters:

obj (GeoJSON) – GeoJSON object

Returns:

Spherical centroid

Return type:

Point2D

detroit.geo_distance(a: tuple[float, float], b: tuple[float, float]) float

Returns the great-arc distance in radians between the two points a and b. Each point must be specified as a two-element array [longitude, latitude] in degrees. This is the spherical equivalent of GeoPath.measure given a LineString of two points.

Parameters:
  • a (Point2D) – 2D point

  • b (Point2D) – 2D point

Returns:

Distance

Return type:

float

detroit.geo_length(obj: dict[str, Any]) float

Returns the great-arc length of the specified GeoJSON object in radians. For polygons, returns the perimeter of the exterior ring plus that of any interior rings. This is the spherical equivalent of GeoPath.measure.

Parameters:

obj (GeoJSON) – GeoJSON object

Returns:

Great-arc length

Return type:

float

detroit.geo_interpolate(a: tuple[float, float], b: tuple[float, float]) Interpolate

Returns an interpolator function given two points a and b. Each point must be specified as a two-element array [longitude, latitude] in degrees. The returned interpolator function takes a single argument t, where t is a number ranging from 0 to 1; a value of 0 returns the point a, while a value of 1 returns the point b. Intermediate values interpolate from a to b along the great arc that passes through both a and b. If a and b are antipodes, an arbitrary great arc is chosen.

Parameters:
  • a (Point2D) – 2D point

  • b (Point2D) – 2D point

Returns:

Interpolate function

Return type:

Interpolate

detroit.geo_contains(obj: dict[str, Any], point: tuple[float, float]) bool

Returns True if and only if the specified GeoJSON object contains the specified point, or False if the object does not contain the point. The point must be specified as a two-element array [longitude, latitude] in degrees. For Point and MultiPoint geometries, an exact test is used; for a Sphere, true is always returned; for other geometries, an epsilon threshold is applied.

Parameters:
  • obj (GeoJSON) – GeoJSON object

  • point (Point2D) – 2D point

Returns:

True if the GeoJSON object contains the point else False

Return type:

bool

detroit.geo_rotation(rotate: tuple[float, float] | tuple[float, float, float]) Rotation

Returns a rotation function for the given angles, which must be a two- or three-element array of numbers \([\lambda, \phi, \gamma]\) specifying the rotation angles in degrees about each spherical axis. (These correspond to yaw, pitch and roll). If the rotation angle \(\gamma\) is omitted, it defaults to 0.

Parameters:

rotate (tuple[float, float] | tuple[float, float, float]) – Rotation parameters \([\lambda, \phi, \gamma]\)

Returns:

Rotation callable object

Return type:

Rotation

class detroit.geo.rotation.Rotation(rotate: tuple[float, float] | tuple[float, float, float])

Rotation class

__call__(coordinates: tuple[float, float]) tuple[float, float]

Rotates a 2D point

Parameters:

coordinates (Point2D) – 2D point

Returns:

Rotated 2D point

Return type:

Point2D

invert(coordinates: tuple[float, float]) tuple[float, float]

Invert transformation.

Parameters:

coordinates (Point2D) – 2D point

Returns:

Inverted 2D point

Return type:

Point2D