Skip to content

Commit 7c0690b

Browse files
committed
scripts for building arcticdem index files
1 parent 40b59d7 commit 7c0690b

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#
2+
# Build index file (catalog) of ArcticDem hosted on AWS
3+
import geopandas as gpd
4+
import numpy as np
5+
import pandas as pd
6+
import pystac
7+
8+
9+
###############################################################################
10+
# MAIN
11+
###############################################################################
12+
13+
if __name__ == '__main__':
14+
15+
# catalog_stac = 'https://pgc-opendata-dems.s3.us-west-2.amazonaws.com/pgc-data-stac.json'
16+
# cat = pystac.read_file(catalog_stac)
17+
# arcticdem_collection = cat.get_child('arcticdem')
18+
# mosaic_collection = arcticdem_collection.get_child('arcticdem-mosaics')
19+
20+
collection_stac = 'https://pgc-opendata-dems.s3.us-west-2.amazonaws.com/arcticdem/strips/s2s041/2m.json'
21+
col = pystac.read_file(collection_stac)
22+
23+
catalog_links = []
24+
collection_links = []
25+
item_list = []
26+
27+
for link in col.links:
28+
if link.rel == pystac.RelType.CHILD:
29+
collection_links.append(link)
30+
31+
print(f"Number of collection links: {len(collection_links)}")
32+
cnt = 0
33+
34+
for link in collection_links:
35+
cnt += 1
36+
if cnt % 100 == 0:
37+
print(f"working collection links: {cnt}")
38+
39+
if link.rel == pystac.RelType.CHILD:
40+
sub_cat = pystac.read_file(link.target)
41+
42+
for _link in sub_cat.links:
43+
if _link.rel == pystac.RelType.CHILD:
44+
catalog_links.append(_link)
45+
46+
47+
print(f"Number of catalog links: {len(catalog_links)}")
48+
cnt = 0
49+
50+
for link in catalog_links:
51+
cnt += 1
52+
if cnt % 100 == 0:
53+
print(f"working catalog links: {cnt}")
54+
55+
subcat = pystac.read_file(link)
56+
57+
for _link in subcat.links:
58+
if _link.rel == pystac.RelType.CHILD:
59+
item = pystac.read_file(_link.target)
60+
item_list.append(item)
61+
62+
print(f"Number of features: {len(item_list)}")
63+
64+
# Geopandas ignores list-valued keys when opening, so this moves asset hrefs to properties for convenience
65+
for item in item_list:
66+
item.clear_links()
67+
asset_hrefs = pd.DataFrame(
68+
item.to_dict()['assets']).T['href'].to_dict()
69+
item.properties.update(asset_hrefs)
70+
71+
items = pystac.ItemCollection(item_list)
72+
items.save_object('/data/ArcticDem/strips.geojson')

0 commit comments

Comments
 (0)