def create_catalog_command(destination, source, id, quiet): """Creates a relative published 3DEP catalog in DESTINATION. If SOURCE is not provided, will use the metadata in AWS. SOURCE is expected to be a directory tree mirroring the structure on USGS, so it is best created using `stac threedep download-metadata`. """ base_ids = id # not sure how to rename arguments in click collections = {} items = {} for product in PRODUCTS: items[product] = [] if base_ids: ids = base_ids else: ids = utils.fetch_ids(product) for id in ids: item = stac.create_item_from_product_and_id( product, id, source) items[product].append(item) if not quiet: print(item.id) extent = Extent.from_items(items[product]) if product == "1": title = "1 arc-second" description = "USGS 3DEP 1 arc-second DEMs" elif product == "13": title = "1/3 arc-second" description = "USGS 3DEP 1/3 arc-second DEMs" else: raise NotImplementedError collection = Collection( id=f"{USGS_3DEP_ID}-{product}", title=title, keywords=["USGS", "3DEP", "NED", "DEM", "elevation"], providers=[USGS_PROVIDER], description=description, extent=extent, license="PDDL-1.0") collections[product] = collection catalog = Catalog(id=USGS_3DEP_ID, description=DESCRIPTION, title="USGS 3DEP DEMs", catalog_type=CatalogType.RELATIVE_PUBLISHED) for product, collection in collections.items(): catalog.add_child(collection) collection.add_items(items[product]) catalog.generate_subcatalogs("${threedep:region}") catalog.normalize_hrefs(destination) catalog.save() catalog.validate()
def test_from_items(self) -> None: item1 = Item( id="test-item-1", geometry=ARBITRARY_GEOM, bbox=[-10, -20, 0, -10], datetime=datetime(2000, 2, 1, 12, 0, 0, 0, tzinfo=tz.UTC), properties={}, ) item2 = Item( id="test-item-2", geometry=ARBITRARY_GEOM, bbox=[0, -9, 10, 1], datetime=None, properties={ "start_datetime": datetime_to_str( datetime(2000, 1, 1, 12, 0, 0, 0, tzinfo=tz.UTC)), "end_datetime": datetime_to_str( datetime(2000, 7, 1, 12, 0, 0, 0, tzinfo=tz.UTC)), }, ) item3 = Item( id="test-item-2", geometry=ARBITRARY_GEOM, bbox=[-5, -20, 5, 0], datetime=None, properties={ "start_datetime": datetime_to_str( datetime(2000, 12, 1, 12, 0, 0, 0, tzinfo=tz.UTC)), "end_datetime": datetime_to_str( datetime(2001, 1, 1, 12, 0, 0, 0, tzinfo=tz.UTC), ), }, ) extent = Extent.from_items([item1, item2, item3]) self.assertEqual(len(extent.spatial.bboxes), 1) self.assertEqual(extent.spatial.bboxes[0], [-10, -20, 10, 1]) self.assertEqual(len(extent.temporal.intervals), 1) interval = extent.temporal.intervals[0] self.assertEqual(interval[0], datetime(2000, 1, 1, 12, 0, 0, 0, tzinfo=tz.UTC)) self.assertEqual(interval[1], datetime(2001, 1, 1, 12, 0, 0, 0, tzinfo=tz.UTC))
def test_from_items(self): item1 = Item(id='test-item-1', geometry=RANDOM_GEOM, bbox=[-10, -20, 0, -10], datetime=datetime(2000, 2, 1, 12, 0, 0, 0, tzinfo=tz.UTC), properties={}) item2 = Item(id='test-item-2', geometry=RANDOM_GEOM, bbox=[0, -9, 10, 1], datetime=None, properties={ 'start_datetime': datetime_to_str( datetime(2000, 1, 1, 12, 0, 0, 0, tzinfo=tz.UTC)), 'end_datetime': datetime_to_str( datetime(2000, 7, 1, 12, 0, 0, 0, tzinfo=tz.UTC)) }) item3 = Item(id='test-item-2', geometry=RANDOM_GEOM, bbox=[-5, -20, 5, 0], datetime=None, properties={ 'start_datetime': datetime_to_str( datetime(2000, 12, 1, 12, 0, 0, 0, tzinfo=tz.UTC)), 'end_datetime': datetime_to_str( datetime(2001, 1, 1, 12, 0, 0, 0, tzinfo=tz.UTC), ) }) extent = Extent.from_items([item1, item2, item3]) self.assertEqual(len(extent.spatial.bboxes), 1) self.assertEqual(extent.spatial.bboxes[0], [-10, -20, 10, 1]) self.assertEqual(len(extent.temporal.intervals), 1) interval = extent.temporal.intervals[0] self.assertEqual(interval[0], datetime(2000, 1, 1, 12, 0, 0, 0, tzinfo=tz.UTC)) self.assertEqual(interval[1], datetime(2001, 1, 1, 12, 0, 0, 0, tzinfo=tz.UTC))