def haversine_dist()

in src/mapillary/utils/filter.py [0:0]


def haversine_dist(data: dict, radius: float, coords: list, unit: str = "m") -> list:
    """
    Returns features that are only in the radius specified using the Haversine distance, from
    the haversine package

    :param data: The data to be filtered
    :type data: dict

    :param radius: Radius for coordinates to fall into
    :type radius: float

    :param coords: The input coordinates (long, lat)
    :type coords: list

    :param unit: Either 'ft', 'km', 'm', 'mi', 'nmi', see here https://pypi.org/project/haversine/
    :type unit: str

    :return: A feature list
    :rtype: list
    """

    # Define an empty list
    output = []

    # Go through the features
    for feature in data:

        # If the calculated haversince distance is less than the radius ...
        if (
            haversine.haversine(coords, feature["geometry"]["coordinates"], unit=unit)
            < radius
        ):
            # ... append to the output
            output.append(feature)

    # Return the output
    return output