fairdm.utils.location.coverage#

The smallest box that holds the locations of a set of records.

Module Contents#

Classes#

Coverage

A box in WGS 84 degrees. A box across the 180th meridian has west greater than east.

Functions#

spatial_coverage

Return the smallest box holding every location in the given querysets.

API#

class Coverage#

Bases: typing.NamedTuple

A box in WGS 84 degrees. A box across the 180th meridian has west greater than east.

Attributes: west: The western bound, a longitude. south: The southern bound, a latitude. east: The eastern bound, a longitude. north: The northern bound, a latitude.

west: float#

None

south: float#

None

east: float#

None

north: float#

None

spatial_coverage(*querysets_and_fields)#

Return the smallest box holding every location in the given querysets.

Each queryset is read twice, as longitudes in -180 to 180 and as longitudes in 0 to 360, and the narrower of the two boxes is kept. Locations on both sides of the 180th meridian therefore give a narrow box with west greater than east, as DataCite writes it, and not one that spans the globe.

Args: *querysets_and_fields: (queryset, field) pairs, field naming a point column or a point annotation on the queryset.

Returns: The Coverage, or None when nothing in the querysets is located.

Example: python     spatial_coverage(         (dataset.samples.all(), "location"),         (dataset.measurements.with_effective_location(None), "effective_location"),     )