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