traffic/core/flight.py
def clip(
        self, shape: Union[ShapelyMixin, base.BaseGeometry]
    ) -> Optional["Flight"]:
        """Clips the trajectory to a given shape.

        For a shapely Geometry, the first time of entry and the last time of
        exit are first computed before returning the part of the trajectory
        between the two timestamps.

        Most of the time, aircraft do not repeatedly come out and in an
        airspace, but computation errors may sometimes give this impression.
        As a consequence, the clipped trajectory may have points outside the
        shape.

        .. warning::
            Altitudes are not taken into account.

        """
        list_coords = list(self.xy_time)
        if len(list_coords) < 2:
            return None

        linestring = LineString(list_coords)
        if not isinstance(shape, base.BaseGeometry):
            shape = shape.shape

        intersection = linestring.intersection(shape)

        if intersection.is_empty:
            return None

        if isinstance(intersection, Point):
            return None

        if isinstance(intersection, LineString):
            time_list = list(
                datetime.fromtimestamp(t, timezone.utc)
                for t in np.stack(intersection.coords)[:, 2]
            )
            return self.between(min(time_list), max(time_list))

        def _clip_generator() -> Iterable[Tuple[datetime, datetime]]:
            for segment in intersection:
                times: List[datetime] = list(
                    datetime.fromtimestamp(t, timezone.utc)
                    for t in np.stack(segment.coords)[:, 2]
                )
                yield min(times), max(times)

        times: List[Tuple[datetime, datetime]] = list(_clip_generator())
        clipped_flight = self.between(
            min(t for t, _ in times), max(t for _, t in times)
        )

        if clipped_flight is None:
            return None

        if clipped_flight.shape is None:
            return None

        return clipped_flight
Clips the trajectory to a given shape.

        For a shapely Geometry, the first time of entry and the last time of
        exit are first computed before returning the part of the trajectory
        between the two timestamps.

        Most of the time, aircraft do not repeatedly come out and in an
        airspace, but computation errors may sometimes give this impression.
        As a consequence, the clipped trajectory may have points outside the
        shape.

        .. warning::
            Altitudes are not taken into account.

        
Clips the trajectory to a given shape.
For a shapely Geometry, the first time of entry and the last time of
exit are first computed before returning the part of the trajectory
between the two timestamps.

Most of the time, aircraft do not repeatedly come out and in an
airspace, but computation errors may sometimes give this impression.
As a consequence, the clipped trajectory may have points outside the
shape.

:
Altitudes are not taken into account.
Clips the trajectory to a given shape . For a shapely Geometry the first time of entry and the last time of exit are first computed before returning the part of the trajectory between the two timestamps . Most of the time aircraft do not repeatedly come out and in an airspace but computation errors may sometimes give this impression . As a consequence the clipped trajectory may have points outside the shape . : Altitudes are not taken into account .
def clip(
        self, shape: Union[ShapelyMixin, base.BaseGeometry]
    ) -> Optional["Flight"]:
        list_coords = list(self.xy_time)
        if len(list_coords) < 2:
            return None
        linestring = LineString(list_coords)
        if not isinstance(shape, base.BaseGeometry):
            shape = shape.shape
        intersection = linestring.intersection(shape)
        if intersection.is_empty:
            return None
        if isinstance(intersection, Point):
            return None
        if isinstance(intersection, LineString):
            time_list = list(
                datetime.fromtimestamp(t, timezone.utc)
                for t in np.stack(intersection.coords)[:, 2]
            )
            return self.between(min(time_list), max(time_list))
        def _clip_generator() -> Iterable[Tuple[datetime, datetime]]:
            for segment in intersection:
                times: List[datetime] = list(
                    datetime.fromtimestamp(t, timezone.utc)
                    for t in np.stack(segment.coords)[:, 2]
                )
                yield min(times), max(times)
        times: List[Tuple[datetime, datetime]] = list(_clip_generator())
        clipped_flight = self.between(
            min(t for t, _ in times), max(t for _, t in times)
        )
        if clipped_flight is None:
            return None
        if clipped_flight.shape is None:
            return None
        return clipped_flight
def clip ( self , shape : Union [ ShapelyMixin , base . BaseGeometry ] ) -> Optional [ "Flight" ] : list_coords = list ( self . xy_time ) if len ( list_coords ) < 2 : return None linestring = LineString ( list_coords ) if not isinstance ( shape , base . BaseGeometry ) : shape = shape . shape intersection = linestring . intersection ( shape ) if intersection . is_empty : return None if isinstance ( intersection , Point ) : return None if isinstance ( intersection , LineString ) : time_list = list ( datetime . fromtimestamp ( t , timezone . utc ) for t in np . stack ( intersection . coords ) [ : , 2 ] ) return self . between ( min ( time_list ) , max ( time_list ) ) def _clip_generator ( ) -> Iterable [ Tuple [ datetime , datetime ] ] : for segment in intersection : times : List [ datetime ] = list ( datetime . fromtimestamp ( t , timezone . utc ) for t in np . stack ( segment . coords ) [ : , 2 ] ) yield min ( times ) , max ( times ) times : List [ Tuple [ datetime , datetime ] ] = list ( _clip_generator ( ) ) clipped_flight = self . between ( min ( t for t , _ in times ) , max ( t for _ , t in times ) ) if clipped_flight is None : return None if clipped_flight . shape is None : return None return clipped_flight
Clips the trajectory to a given shape.
Clips the trajectory to a given shape .
"""Clips the trajectory to a given shape.

        For a shapely Geometry, the first time of entry and the last time of
        exit are first computed before returning the part of the trajectory
        between the two timestamps.

        Most of the time, aircraft do not repeatedly come out and in an
        airspace, but computation errors may sometimes give this impression.
        As a consequence, the clipped trajectory may have points outside the
        shape.

        .. warning::
            Altitudes are not taken into account.

        """
self
shape
Union[ShapelyMixin, base.BaseGeometry]