2
2
from pystac .errors import STACTypeError
3
3
from typing import Any , Dict , Iterator , List , Optional , Collection , Iterable , Union
4
4
5
- import pystac
5
+ from pystac .item import Item
6
+ from pystac .stac_io import StacIO
7
+ from pystac .stac_object import STACObjectType
6
8
from pystac .utils import make_absolute_href , is_absolute_href
7
9
from pystac .serialization .identify import identify_stac_object_type
8
10
9
11
10
- ItemLike = Union [pystac . Item , Dict [str , Any ]]
12
+ ItemLike = Union [Item , Dict [str , Any ]]
11
13
12
14
13
- class ItemCollection (Collection [pystac . Item ]):
15
+ class ItemCollection (Collection [Item ]):
14
16
"""Implementation of a GeoJSON FeatureCollection whose features are all STAC
15
17
Items.
16
18
@@ -70,7 +72,7 @@ class ItemCollection(Collection[pystac.Item]):
70
72
# If an item is present in both ItemCollections it will only be added once
71
73
"""
72
74
73
- items : List [pystac . Item ]
75
+ items : List [Item ]
74
76
"""List of :class:`pystac.Item` instances contained in this ``ItemCollection``."""
75
77
76
78
extra_fields : Dict [str , Any ]
@@ -83,20 +85,20 @@ def __init__(
83
85
extra_fields : Optional [Dict [str , Any ]] = None ,
84
86
clone_items : bool = False ,
85
87
):
86
- def map_item (item_or_dict : ItemLike ) -> pystac . Item :
88
+ def map_item (item_or_dict : ItemLike ) -> Item :
87
89
# Converts dicts to pystac.Items and clones if necessary
88
- if isinstance (item_or_dict , pystac . Item ):
90
+ if isinstance (item_or_dict , Item ):
89
91
return item_or_dict .clone () if clone_items else item_or_dict
90
92
else :
91
- return pystac . Item .from_dict (item_or_dict )
93
+ return Item .from_dict (item_or_dict )
92
94
93
95
self .items = list (map (map_item , items ))
94
96
self .extra_fields = extra_fields or {}
95
97
96
- def __getitem__ (self , idx : int ) -> pystac . Item :
98
+ def __getitem__ (self , idx : int ) -> Item :
97
99
return self .items [idx ]
98
100
99
- def __iter__ (self ) -> Iterator [pystac . Item ]:
101
+ def __iter__ (self ) -> Iterator [Item ]:
100
102
return iter (self .items )
101
103
102
104
def __len__ (self ) -> int :
@@ -151,25 +153,23 @@ def from_dict(
151
153
raise STACTypeError ("Dict is not a valid ItemCollection" )
152
154
153
155
items = [
154
- pystac . Item .from_dict (item , preserve_dict = preserve_dict )
156
+ Item .from_dict (item , preserve_dict = preserve_dict )
155
157
for item in d .get ("features" , [])
156
158
]
157
159
extra_fields = {k : v for k , v in d .items () if k not in ("features" , "type" )}
158
160
159
161
return cls (items = items , extra_fields = extra_fields )
160
162
161
163
@classmethod
162
- def from_file (
163
- cls , href : str , stac_io : Optional [pystac .StacIO ] = None
164
- ) -> "ItemCollection" :
164
+ def from_file (cls , href : str , stac_io : Optional [StacIO ] = None ) -> "ItemCollection" :
165
165
"""Reads a :class:`ItemCollection` from a JSON file.
166
166
167
167
Arguments:
168
168
href : Path to the file.
169
169
stac_io : A :class:`~pystac.StacIO` instance to use for file I/O
170
170
"""
171
171
if stac_io is None :
172
- stac_io = pystac . StacIO .default ()
172
+ stac_io = StacIO .default ()
173
173
174
174
if not is_absolute_href (href ):
175
175
href = make_absolute_href (href )
@@ -181,7 +181,7 @@ def from_file(
181
181
def save_object (
182
182
self ,
183
183
dest_href : str ,
184
- stac_io : Optional [pystac . StacIO ] = None ,
184
+ stac_io : Optional [StacIO ] = None ,
185
185
) -> None :
186
186
"""Saves this instance to the ``dest_href`` location.
187
187
@@ -191,7 +191,7 @@ def save_object(
191
191
will use the default instance.
192
192
"""
193
193
if stac_io is None :
194
- stac_io = pystac . StacIO .default ()
194
+ stac_io = StacIO .default ()
195
195
196
196
stac_io .save_json (dest_href , self .to_dict ())
197
197
@@ -217,6 +217,6 @@ def is_item_collection(d: Dict[str, Any]) -> bool:
217
217
# Prior to STAC 0.9 ItemCollections did not have a stac_version field and could
218
218
# only be identified by the fact that all of their 'features' are STAC Items.
219
219
return all (
220
- identify_stac_object_type (feature ) == pystac . STACObjectType .ITEM
220
+ identify_stac_object_type (feature ) == STACObjectType .ITEM
221
221
for feature in d .get ("features" , [])
222
222
)
0 commit comments