-
Notifications
You must be signed in to change notification settings - Fork 0
/
stac_prepare_poland.py
49 lines (46 loc) · 2.12 KB
/
stac_prepare_poland.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import json
import pystac
def process_poland():
with open("poland-data.json") as poland:
lines = poland.readlines()
edited_lines = []
for idx, line in enumerate(lines):
# if idx >= 1:
# break
item = json.loads(line)
assets = item["assets"]
for asset_name, asset in assets.items():
s3_href = asset["alternate"]["s3"]["href"]
s3_auth_ref = asset["alternate"]["s3"]["auth:refs"]
asset["href"] = s3_href
asset["auth:refs"] = s3_auth_ref
asset.pop("alternate:name")
asset.pop("alternate")
item["assets"] = assets
item["stac_extensions"].remove("https://stac-extensions.github.io/alternate-assets/v1.2.0/schema.json")
item["properties"]["auth:schemes"].pop("oidc")
edited_lines.append(item)
# print(item["properties"])
with open("poland-edited.json", "w") as poland_edited:
for line in edited_lines:
json.dump(line, poland_edited)
poland_edited.write('\n')
# with open("single-modified.json", "w") as single:
# single.write(json.dumps(item, indent=2))
# remove "https://stac-extensions.github.io/alternate-assets/v1.2.0/schema.json", from stac_extensions
def process_collection():
with open("collection.json") as collection_file:
collection = json.loads(collection_file.read())
assets = collection["item_assets"]
for asset_name, asset in assets.items():
s3_auth_ref = asset["alternate"]["s3"]["auth:refs"]
asset["auth:refs"] = s3_auth_ref
asset.pop("alternate:name")
asset.pop("alternate")
collection["auth:schemes"].pop("oidc")
collection["stac_extensions"].remove("https://stac-extensions.github.io/alternate-assets/v1.2.0/schema.json")
with open("collection-edited.json", "w") as collection_edited:
json.dump(collection, collection_edited, indent=2)
if __name__ == "__main__":
#process_poland()
process_collection()