11from __future__ import annotations
22
3+ import copy
34import datetime
45import warnings
56from typing import Any , Sequence
67
78from typing_extensions import Self
89
910from .constants import DEFAULT_BBOX , DEFAULT_INTERVAL
11+ from .decorators import v2_deprecated
1012from .errors import StacWarning
1113from .types import PermissiveBbox , PermissiveInterval
1214
@@ -54,7 +56,19 @@ def from_dict(cls: type[Self], d: dict[str, Any]) -> Self:
5456 """Creates a new spatial extent from a dictionary."""
5557 return cls (** d )
5658
57- def __init__ (self , bbox : PermissiveBbox | None = None ):
59+ @classmethod
60+ @v2_deprecated ("Use the constructor instead" )
61+ def from_coordinates (
62+ cls : type [Self ],
63+ coordinates : list [Any ],
64+ extra_fields : dict [str , Any ] | None = None ,
65+ ) -> Self :
66+ if extra_fields :
67+ return cls (coordinates , ** extra_fields )
68+ else :
69+ return cls (coordinates )
70+
71+ def __init__ (self , bbox : PermissiveBbox | None = None , ** kwargs : Any ):
5872 """Creates a new spatial extent."""
5973 self .bbox : Sequence [Sequence [float | int ]]
6074 if bbox is None or len (bbox ) == 0 :
@@ -63,10 +77,13 @@ def __init__(self, bbox: PermissiveBbox | None = None):
6377 self .bbox = bbox # type: ignore
6478 else :
6579 self .bbox = [bbox ] # type: ignore
80+ self .extra_fields = kwargs
6681
6782 def to_dict (self ) -> dict [str , Any ]:
6883 """Converts this spatial extent to a dictionary."""
69- return {"bbox" : self .bbox }
84+ d = copy .deepcopy (self .extra_fields )
85+ d ["bbox" ] = self .bbox
86+ return d
7087
7188
7289class TemporalExtent :
@@ -77,6 +94,11 @@ def from_dict(cls: type[Self], d: dict[str, Any]) -> Self:
7794 """Creates a new temporal extent from a dictionary."""
7895 return cls (** d )
7996
97+ @classmethod
98+ def from_now (cls : type [Self ]) -> Self :
99+ """Creates a new temporal extent that starts now and has no end time."""
100+ return cls ([[datetime .datetime .now (tz = datetime .timezone .utc ), None ]])
101+
80102 def __init__ (
81103 self ,
82104 interval : PermissiveInterval | None = None ,
0 commit comments