Skip to content

Commit

Permalink
added get items function
Browse files Browse the repository at this point in the history
  • Loading branch information
Corey White committed Sep 19, 2023
1 parent 0a151f9 commit 18326d5
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 15 deletions.
62 changes: 47 additions & 15 deletions src/temporal/t.stac.import/t.stac.import.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,16 @@ def validate_collections_option(client, collections=[]):
boolean: Returns true if the collection is avaliable.
"""
avaliable_collections = client.get_collections()
if collections in avaliable_collections:
avaliable_collections_ids = [c.id for c in list(avaliable_collections)]

gs.warning(_(f"Avaliable Collections: {avaliable_collections_ids}"))

if collections in avaliable_collections_ids:
return True
gs.warning(_("The specified collections do not exisit."))

for collection in avaliable_collections:
gs.warning(_(f"{collection} collection found"))
for collection in collections:
if collection not in avaliable_collections_ids:
gs.warning(_(f"{collection} collection not found"))

return False

Expand Down Expand Up @@ -301,15 +305,40 @@ def get_collection_items(client, collection_name):
# gs.message(_(i.id))


def import_items(
items,
region_params=None,
reprojection=None,
output=None,
strds_output=None,
method=None,
resolution=None,
memory=None,
):
"""Import items"""
for item in items:
gs.message(_(f"Item: {item.id}"))
gs.message(_(f"Spatial Extent: {item.geometry}"))
gs.message(_(f"Temporal Extent: {item.datetime}"))
gs.message(_(f"Assets: {item.assets}"))
gs.message(_(f"Links: {item.links}"))
gs.message(_(f"Properties: {item.properties}"))
gs.message(_(f"Collection ID: {item.collection_id}"))


def main():
"""Main function"""

client_url = options["url"]
ids = options["ids"] # optional
collections = options["collections"] # Maybe limit to one?
limit = options["limit"] # optional
max_items = options["max_items"] # optional
limit = int(options["limit"]) # optional
max_items = int(options["max_items"]) # optional
bbox = options["bbox"] # optional

# if bbox:
# bbox = [float(i) for i in bbox.strip("[]").split(",")]

intersects = options["intersects"] # optional
datetime = options["datetime"] # optional
query = options["query"] # optional
Expand All @@ -331,19 +360,22 @@ def main():
return None

if validate_collections_option(client, collections):
items = search_stac_api(
items_search = search_stac_api(
client=client,
ids=ids,
collections=collections,
limit=limit,
max_items=max_items,
bbox=bbox,
intersects=intersects,
datetime=datetime,
query=query,
filter=filter,
filter_lang=filter_lang,
# bbox=[-72.5, 40.5, -72.0, 41.0],
# intersects=intersects,
# datetime=datetime,
# query=query,
# filter=filter,
# filter_lang=filter_lang,
)
print(items)
gs.message(_("Import Items..."))
import_items(list(items_search.items()))

# if reprojection:


if __name__ == "__main__":
Expand Down
11 changes: 11 additions & 0 deletions src/temporal/t.stac.import/testsuite/test_t_stac_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,17 @@ def test_validate_collection(self):
isValid = in_stac_lib.validate_collections_option(client)
self.assertFalse(isValid)

def test_import_asset(self):
"""
Tests importing STAC asset
"""
self.assertModule(
"t.stac.import",
url=EARTH_SEARCH_API_URL,
collections=["naip"],
bbox="-72.5,40.5,-72,41",
)


if __name__ == "__main__":
test()

0 comments on commit 18326d5

Please sign in to comment.