Skip to content

Commit 4e43c85

Browse files
committed
script to build arcticdem strip vrts
1 parent f3ec204 commit 4e43c85

File tree

2 files changed

+66
-72
lines changed

2 files changed

+66
-72
lines changed

utils/build_arctic_dem_strips_index.py

Lines changed: 0 additions & 72 deletions
This file was deleted.

utils/build_arctic_dem_strips_vrt.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#
2+
# Build index file (catalog) of ArcticDem hosted on AWS
3+
import os
4+
import geopandas as gpd
5+
import numpy as np
6+
import pandas as pd
7+
import pystac
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+
item_list = []
24+
vrt_list_files = []
25+
26+
cnt = 0
27+
28+
for link in col.links:
29+
if link.rel == pystac.RelType.CHILD:
30+
subcat = pystac.read_file(link.target)
31+
for _link in subcat.links:
32+
if _link.rel == pystac.RelType.CHILD:
33+
item = pystac.read_file(_link)
34+
dem = item.to_dict()['assets']['dem']['href']
35+
dem = dem.replace(".", "", 1)
36+
path = link.target.replace("https:/", "/vsis3")
37+
path = path.replace(".s3.us-west-2.amazonaws.com", "", 1)
38+
path = path.replace(".json", dem)
39+
item_list.append(path)
40+
41+
# print(f"Number of features: {len(item_list)}")
42+
43+
scene_dem_list = path.replace("/vsis3/pgc-opendata-dems/arcticdem/strips/s2s041/2m/", "", 1)
44+
latlon = scene_dem_list.split("/")[0]
45+
scene_dem_list = "/data/ArcticDem/strips/" + latlon + ".txt"
46+
47+
vrt_list_files.append(scene_dem_list)
48+
49+
with open(scene_dem_list, 'w') as f:
50+
for line in item_list:
51+
f.write(f"{line}\n")
52+
53+
print(f"Generated: {scene_dem_list}")
54+
55+
# if cnt == 1:
56+
# break
57+
# cnt += 1
58+
59+
print(f"Generated: {len(vrt_list_files)} vrt list files")
60+
print("Building vrts now")
61+
62+
for file in vrt_list_files:
63+
vrtfile = file.replace("txt", "vrt", 1)
64+
cmd = "gdalbuildvrt -input_file_list " + file + " " + vrtfile
65+
print(f"{cmd}")
66+
os.system(cmd)

0 commit comments

Comments
 (0)