def features_in_bounding_box()

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


def features_in_bounding_box(data: list, bbox: dict) -> list:
    """
    Filter for extracting features only in a bounding box

    :param data: the features list to be checked
    :type data: list

    :param bbox: Bounding box coordinates

        Example::
            >>> {
            ...     'west': 'BOUNDARY_FROM_WEST',
            ...     'south': 'BOUNDARY_FROM_SOUTH',
            ...     'east': 'BOUNDARY_FROM_EAST',
            ...     'north': 'BOUNDARY_FROM_NORTH'
            ... }

    :type bbox: dict

    :return: Features that only exist within the bounding box selected for the given features list
        provided in the BBox functon
    :rtype: list
    """

    # define an empty geojson as output
    output = []

    # For each feature in the filtered_data
    for feature in data:

        # If feature exists in bounding box
        if (
            feature["geometry"]["coordinates"][0] < bbox["east"]
            and feature["geometry"]["coordinates"][0] > bbox["west"]
        ) and (
            feature["geometry"]["coordinates"][1] > bbox["south"]
            and feature["geometry"]["coordinates"][1] < bbox["north"]
        ):
            # Append feature to the output
            output.append(feature)

    return output