Skip to content

Commit 14f13a6

Browse files
committed
initial version of script building geojson index file from mosaic arcticdem on aws
1 parent 95f586b commit 14f13a6

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

utils/build_arctic_dem_index.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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/mosaics/v3.0/2m.json'
21+
col = pystac.read_file(collection_stac)
22+
23+
catalog_links = []
24+
item_list = []
25+
26+
for link in col.links:
27+
if link.rel == pystac.RelType.CHILD:
28+
catalog_links.append(link.target)
29+
30+
print(f"Number of tiles: {len(catalog_links)}")
31+
32+
cnt = 0
33+
34+
for link in catalog_links:
35+
subcat = pystac.read_file(link)
36+
print(subcat)
37+
# cnt += 1
38+
# if cnt == 20:
39+
# break
40+
41+
# the call on catalog get_all_items() should find all items/features from this and all child catalog and collections
42+
# for some reason the recursion breaks with an error that item does not have property get_all_items()
43+
# this may be caused by bug in pystac or related to how data is presented for arcticdem, don't know
44+
# item_list = list(subcat.get_all_items())
45+
46+
for _link in subcat.links:
47+
if _link.rel == pystac.RelType.CHILD:
48+
item = pystac.read_file(_link.target)
49+
item_list.append(item)
50+
51+
print(f"Number of features: {len(item_list)}")
52+
53+
# Geopandas ignores list-valued keys when opening, so this moves asset hrefs to properties for convenience
54+
for item in item_list:
55+
item.clear_links()
56+
asset_hrefs = pd.DataFrame(
57+
item.to_dict()['assets']).T['href'].to_dict()
58+
item.properties.update(asset_hrefs)
59+
60+
items = pystac.ItemCollection(item_list)
61+
items.save_object('/data/ArcticDem/mosaic.geojson')

0 commit comments

Comments
 (0)