@@ -21,12 +21,12 @@ def parse_args():
21
21
parser .add_argument ('-rp' , '--path_replace_with' , help = 'If --path_remove, instead of setting that portion of the internal path to "", replaces it with this value.' )
22
22
parser .add_argument ('-u' , '--upsert' , help = 'Allow overwriting existing STAC items' , action = 'store_true' )
23
23
parser .add_argument ('-r' , '--regex' , help = 'If folder, only create stac items for files that match this regex' )
24
- parser .add_argument ('-d ' , '--dev ' , help = 'dev mode that does other things ' , action = 'store_true' )
24
+ parser .add_argument ('-t ' , '--time_from_fn ' , help = 'time format to read from filename ' , type = str , default = None )
25
25
26
26
args = parser .parse_args ()
27
27
return args
28
28
29
- def create_stac_items (mmgis_url , mmgis_token , collection_id , file_or_folder_path , path_remove , path_replace_with , upsert = False , regex = None , dev = False ):
29
+ def create_stac_items (mmgis_url , mmgis_token , collection_id , file_or_folder_path , path_remove , path_replace_with , upsert = False , regex = None , time_from_fn = False ):
30
30
31
31
isDir = os .path .isdir (file_or_folder_path )
32
32
@@ -59,44 +59,27 @@ def create_stac_items(mmgis_url, mmgis_token, collection_id, file_or_folder_path
59
59
else :
60
60
asset_href = file .replace (path_remove , "" )
61
61
62
- if dev :
63
- item = create_stac_item (
64
- file ,
65
- input_datetime = datetime .fromisoformat (f"2024-11-0{ (idx % 9 ) + 1 } T00:00:00Z" ),
66
- #extensions=extensions,
67
- #collection=collection,
68
- #collection_url=collection_url,
69
- #properties=property,
70
- #id=id,
71
- #asset_name=asset_name,
72
- asset_href = asset_href ,
73
- #asset_media_type=asset_mediatype,
74
- with_proj = True ,
75
- with_raster = True ,
76
- with_eo = True ,
77
- #raster_max_size=max_raster_size,
78
- #geom_densify_pts=densify_geom,
79
- #geom_precision=geom_precision,
80
- )
81
- else :
82
- item = create_stac_item (
83
- file ,
84
- #input_datetime=input_datetime,
85
- #extensions=extensions,
86
- #collection=collection,
87
- #collection_url=collection_url,
88
- #properties=property,
89
- #id=id,
90
- #asset_name=asset_name,
91
- asset_href = asset_href ,
92
- #asset_media_type=asset_mediatype,
93
- with_proj = True ,
94
- with_raster = True ,
95
- with_eo = True ,
96
- #raster_max_size=max_raster_size,
97
- #geom_densify_pts=densify_geom,
98
- #geom_precision=geom_precision,
99
- )
62
+ input_datetime = None
63
+ if args .time_from_fn is not None :
64
+ input_datetime = datetime .strptime (os .path .basename (file ),args .time_from_fn )
65
+ item = create_stac_item (
66
+ file ,
67
+ input_datetime = input_datetime ,
68
+ #extensions=extensions,
69
+ #collection=collection,
70
+ #collection_url=collection_url,
71
+ #properties=property,
72
+ #id=id,
73
+ #asset_name=asset_name,
74
+ asset_href = asset_href ,
75
+ #asset_media_type=asset_mediatype,
76
+ with_proj = True ,
77
+ with_raster = True ,
78
+ with_eo = True ,
79
+ #raster_max_size=max_raster_size,
80
+ #geom_densify_pts=densify_geom,
81
+ #geom_precision=geom_precision,
82
+ )
100
83
item_dict = item .to_dict ()
101
84
102
85
items [item_dict .get ('id' )] = item_dict
@@ -121,5 +104,5 @@ def create_stac_items(mmgis_url, mmgis_token, collection_id, file_or_folder_path
121
104
122
105
if __name__ == '__main__' :
123
106
args = parse_args ()
124
- create_stac_items (args .mmgis_url , args .mmgis_token , args .collection_id , args .file_or_folder_path , args .path_remove , args .path_replace_with , args .upsert , args .regex , args .dev )
107
+ create_stac_items (args .mmgis_url , args .mmgis_token , args .collection_id , args .file_or_folder_path , args .path_remove , args .path_replace_with , args .upsert , args .regex , args .time_from_fn )
125
108
exit ()
0 commit comments