@@ -93,22 +93,30 @@ def query(
93
93
return result .featurescollection
94
94
95
95
@staticmethod
96
- def query_by_id (id_ : Union [str , List [str ]]):
96
+ def query_by_id (scene_id : Union [str , List [str ]], collection : str = None ):
97
97
"""
98
98
Search a product by id
99
99
100
100
Args:
101
- id_: One or more scene's id
101
+ scene_id: One or more scene's id
102
+ collection: Collection's name
102
103
Returns:
103
104
dict: Dict with GeoJSON-like format
104
105
"""
105
106
search = Search ()
106
107
108
+ if not scene_id :
109
+ raise Exception ("Especify an id" )
110
+ elif not collection :
111
+ raise Exception ("Especify a collection" )
112
+
107
113
# search() method only works with a list of ids.
108
- if type (id_ ) is not list :
109
- search .ids ([id_ ])
114
+ if type (scene_id ) is not list :
115
+ search .ids ([scene_id ])
110
116
else :
111
- search .ids (id_ )
117
+ search .ids (scene_id )
118
+
119
+ search .collections (collection )
112
120
113
121
result = search ()
114
122
return result .featurescollection
@@ -180,7 +188,7 @@ def __download_gdf(
180
188
mkdir (new_path )
181
189
outdir = new_path
182
190
183
- products_query = self .query_by_id (str (index ))
191
+ products_query = self .query_by_id (str (index ), row . collection )
184
192
products_query = ItemCollection (products_query ).items ()
185
193
for product in products_query :
186
194
for band in bands :
@@ -249,6 +257,18 @@ def to_geodataframe(products: Dict, crs: str = "EPSG:4326"):
249
257
Returns:
250
258
GeoDataFrame
251
259
"""
252
- return GeoDataFrame .from_features (products , crs = crs ).set_index (
253
- json_normalize (products ["features" ])["id" ].values
254
- )
260
+ items = [feat for feat in ItemCollection (products ).items ()]
261
+
262
+ for item in items :
263
+ item_metadata = {}
264
+ item_metadata .update (id = item .id )
265
+ item_metadata .update (bbox = item .bbox )
266
+ item_metadata .update (collection = item .collection )
267
+
268
+ for index , feature in enumerate (products .get ("features" )):
269
+ if feature ["id" ] == item .id :
270
+ products .get ("features" )[index ].get ("properties" ).update (
271
+ ** item_metadata
272
+ )
273
+
274
+ return GeoDataFrame .from_features (products , crs = crs ).set_index ("id" )
0 commit comments