Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 36 additions & 35 deletions pymeos/pymeos/boxes/stbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,14 @@ def _get_box(self, other: Union[Geometry, STBox, Temporal, Time], allow_space_on

# ------------------------- Constructors ----------------------------------
def __init__(self, string: Optional[str] = None, *,
xmin: Optional[Union[str, float]] = None, xmax: Optional[Union[str, float]] = None,
ymin: Optional[Union[str, float]] = None, ymax: Optional[Union[str, float]] = None,
zmin: Optional[Union[str, float]] = None, zmax: Optional[Union[str, float]] = None,
tmin: Optional[Union[str, datetime]] = None, tmax: Optional[Union[str, datetime]] = None,
xmin: Optional[Union[str, float]] = None,
xmax: Optional[Union[str, float]] = None,
ymin: Optional[Union[str, float]] = None,
ymax: Optional[Union[str, float]] = None,
zmin: Optional[Union[str, float]] = None,
zmax: Optional[Union[str, float]] = None,
tmin: Optional[Union[str, datetime]] = None,
tmax: Optional[Union[str, datetime]] = None,
tmin_inc: bool = True, tmax_inc: bool = True,
geodetic: bool = False, srid: Optional[int] = None,
_inner=None):
Expand Down Expand Up @@ -171,14 +175,13 @@ def from_time(time: Time) -> STBox:
timestamp_to_stbox, timestampset_to_stbox, period_to_stbox, periodset_to_stbox
"""
if isinstance(time, datetime):
result = (datetime, datetime)
result = timestamp_to_stbox(datetime_to_timestamptz(time))
elif isinstance(time, TimestampSet):
result = (time.start_timestamp(), time.end_timestamp())
result = timestampset_to_stbox(time._inner)
elif isinstance(time, Period):
result = (time.lower, time.upper, time.lower_inc, time.upper_inc)
result = period_to_stbox(time._inner)
elif isinstance(time, PeriodSet):
result = (time.start_period().lower, time.end_period().upper,
time.start_period().lower_inc, time.end_period().upper_inc)
result = periodset_to_stbox(time._inner)
else:
raise TypeError(f'Operation not supported with type {time.__class__}')
return STBox(_inner=result)
Expand Down Expand Up @@ -226,15 +229,16 @@ def from_tpoint(temporal: TPoint) -> STBox:
return STBox(_inner=tpoint_to_stbox(temporal._inner))

@staticmethod
def from_expanding_bounding_box(value: Union[Geometry, TPoint, STBox], expansion: float,
geodetic: Optional[bool] = False) -> STBox:
def from_expanding_bounding_box(value: Union[Geometry, TPoint, STBox],
expansion: float, geodetic: Optional[bool] = False) -> STBox:
"""
Returns a `STBox` from a `Geometry`, `TPoint` or `STBox` instance, expanding its bounding box by the given amount.

Args:
value: A `Geometry`, `TPoint` or `STBox` instance.
expansion: The amount to expand the bounding box.
geodetic: Whether to create a geodetic or geometric `STBox`. Only used when value is a `Geometry` instance.
geodetic: Whether to create a geodetic or geometric `STBox`.
Only used when value is a `Geometry` instance.

Returns:
A new :class:`STBox` instance.
Expand Down Expand Up @@ -536,7 +540,7 @@ def set_srid(self, value: int) -> STBox:
return STBox(_inner=stbox_set_srid(self._inner, value))

# ------------------------- Transformations -------------------------------
def expand(self, other: Union[int, float, timedelta]) -> STBox:
def expand(self, other: Union[int, float, timedelta, STBox]) -> STBox:
"""
Expands ``self`` with `other`.
If `other` is a :class:`int` or a :class:`float`, the result is equal to ``self`` but with the spatial dimensions
Expand All @@ -556,6 +560,9 @@ def expand(self, other: Union[int, float, timedelta]) -> STBox:
result = stbox_expand_space(self._inner, float(other))
elif isinstance(other, timedelta):
result = stbox_expand_time(self._inner, timedelta_to_interval(other))
elif isinstance(other, STBox):
result = stbox_copy(self._inner)
stbox_expand(other._inner, result)
else:
raise TypeError(f'Operation not supported with type {other.__class__}')
return STBox(_inner=result)
Expand Down Expand Up @@ -596,7 +603,8 @@ def tscale(self, duration: timedelta) -> STBox:
"""
return self.shift_tscale(duration=duration)

def shift_tscale(self, shift: Optional[timedelta] = None, duration: Optional[timedelta] = None) -> STBox:
def shift_tscale(self, shift: Optional[timedelta] = None,
duration: Optional[timedelta] = None) -> STBox:
"""
Returns a new `STBox` with the time dimension shifted by `shift` and with duration `duration`.

Expand Down Expand Up @@ -641,16 +649,15 @@ def round(self, maxdd : int = 0) -> STBox:
return STBox(_inner=new_inner)

# ------------------------- Set Operations --------------------------------
def union(self, other: STBox, strict: bool = True) -> STBox:
def union(self, other: STBox, strict: Optional[bool] = True) -> STBox:
"""
Returns the smallest spatio-temporal box that contains both ``self`` and `other`.
Returns the union of `self` with `other`. Fails if the union is not contiguous.

Args:
other: The other :class:`STBox` to union with ``self``.
strict: If ``True``, the union will fail if the boxes are not overlapping.
other: spatiotemporal box to merge with

Returns:
A new :class:`STBox` instance.
A :class:`STBox` instance.

MEOS Functions:
union_stbox_stbox
Expand All @@ -659,32 +666,29 @@ def union(self, other: STBox, strict: bool = True) -> STBox:

def __add__(self, other):
"""
Returns the non-strict union of ``self`` and `other`.
Returns the union of `self` with `other`. Fails if the union is not contiguous.

Args:
other: The spatiotemporal object to union with ``self``.
other: spatiotemporal box to merge with

Returns:
An :class:`STBox` with the union of ``self`` and ``other``.
A :class:`STBox` instance.

MEOS Functions:
union_stbox_stbox

See Also:
:meth:`STBox.union`
"""
return self.union(other, strict=False)
return self.union(other)

# TODO: Check returning None for empty intersection is the desired behaviour
def intersection(self, other: STBox) -> Optional[STBox]:
"""
Returns the intersection of ``self`` and `other`.
Returns the intersection of `self` with `other`.

Args:
other: The other :class:`STBox` to intersect with ``self``.
other: temporal object to merge with

Returns:
A new :class:`STBox` instance or ``None`` if the intersection is empty.
A :class:`STBox` instance if the instersection is not empty, `None` otherwise.

MEOS Functions:
intersection_stbox_stbox
Expand All @@ -694,19 +698,16 @@ def intersection(self, other: STBox) -> Optional[STBox]:

def __mul__(self, other):
"""
Returns the intersection of ``self`` and `other`.
Returns the intersection of `self` with `other`.

Args:
other: The spatiotemporal object to intersect with ``self``.
other: temporal object to merge with

Returns:
An :class:`STBox` with the intersection of ``self`` and ``other``.
A :class:`STBox` instance if the instersection is not empty, `None` otherwise.

MEOS Functions:
intersection_stbox_stbox

See Also:
:meth:`STBox.intersection`
"""
return self.intersection(other)

Expand Down
Loading