@@ -202,10 +202,17 @@ def main():
202202 formatter_class = argparse .RawDescriptionHelpFormatter ,
203203 epilog = __doc__
204204 )
205+
206+ # Input method 1: JSON file
207+ parser .add_argument (
208+ "--input" ,
209+ help = "Path to input JSON file specifying layers (recommended)"
210+ )
211+
212+ # Input method 2: Command line arguments (legacy)
205213 parser .add_argument (
206214 "--catalog" ,
207- required = True ,
208- help = "URL to STAC catalog.json"
215+ help = "URL to STAC catalog.json (required if not using --input)"
209216 )
210217 parser .add_argument (
211218 "--output" ,
@@ -215,7 +222,6 @@ def main():
215222 parser .add_argument (
216223 "--layer" ,
217224 action = "append" ,
218- required = True ,
219225 metavar = "COLLECTION:ASSET:KEY:NAME" ,
220226 help = "Layer specification: collection_id:asset_id:layer_key:display_name (can be specified multiple times)"
221227 )
@@ -232,49 +238,92 @@ def main():
232238
233239 args = parser .parse_args ()
234240
235- # Parse layer specifications
241+ # Determine input method
242+ if args .input :
243+ # Load from JSON file
244+ input_path = Path (args .input )
245+ if not input_path .exists ():
246+ print (f"Error: Input file '{ args .input } ' not found" , file = sys .stderr )
247+ sys .exit (1 )
248+
249+ with open (input_path ) as f :
250+ input_config = json .load (f )
251+
252+ catalog_url = input_config .get ("catalog" )
253+ if not catalog_url :
254+ print ("Error: 'catalog' field required in input JSON" , file = sys .stderr )
255+ sys .exit (1 )
256+
257+ titiler_url = input_config .get ("titiler_url" , args .titiler )
258+ layer_specs = input_config .get ("layers" , [])
259+
260+ if not layer_specs :
261+ print ("Error: 'layers' array is empty in input JSON" , file = sys .stderr )
262+ sys .exit (1 )
263+
264+ elif args .catalog and args .layer :
265+ # Use command-line arguments (legacy mode)
266+ catalog_url = args .catalog
267+ titiler_url = args .titiler
268+ layer_specs = []
269+
270+ for layer_spec in args .layer :
271+ parts = layer_spec .split (":" , 3 )
272+ if len (parts ) < 3 :
273+ print (f"Error: Invalid layer specification '{ layer_spec } '" , file = sys .stderr )
274+ print ("Format: collection_id:asset_id:layer_key[:display_name]" , file = sys .stderr )
275+ sys .exit (1 )
276+
277+ layer_specs .append ({
278+ "collection_id" : parts [0 ],
279+ "asset_id" : parts [1 ],
280+ "layer_key" : parts [2 ],
281+ "display_name" : parts [3 ] if len (parts ) > 3 else None ,
282+ "options" : {}
283+ })
284+
285+ else :
286+ print ("Error: Must specify either --input or both --catalog and --layer" , file = sys .stderr )
287+ parser .print_help ()
288+ sys .exit (1 )
289+
290+ # Generate layers configuration
236291 layers_config = {
237292 "version" : "1.0" ,
238293 "description" : "Map layer configuration for California Protected Lands application" ,
239294 "layers" : {}
240295 }
241296
242- for layer_spec in args .layer :
243- parts = layer_spec .split (":" , 3 )
244- if len (parts ) < 3 :
245- print (f"Error: Invalid layer specification '{ layer_spec } '" , file = sys .stderr )
246- print ("Format: collection_id:asset_id:layer_key[:display_name]" , file = sys .stderr )
247- sys .exit (1 )
248-
249- collection_id = parts [0 ]
250- asset_id = parts [1 ]
251- layer_key = parts [2 ]
252- display_name = parts [3 ] if len (parts ) > 3 else None
297+ for spec in layer_specs :
298+ collection_id = spec .get ("collection_id" )
299+ asset_id = spec .get ("asset_id" )
300+ layer_key = spec .get ("layer_key" )
301+ display_name = spec .get ("display_name" )
302+ options = spec .get ("options" , {})
253303
254304 print (f"Processing { collection_id } :{ asset_id } -> { layer_key } ..." , file = sys .stderr )
255305
256306 # Find collection URL
257- collection_url = find_collection_url (args . catalog , collection_id )
307+ collection_url = find_collection_url (catalog_url , collection_id )
258308 if not collection_url :
259309 print (f"Error: Collection '{ collection_id } ' not found in catalog" , file = sys .stderr )
260310 sys .exit (1 )
261311
262312 # Fetch collection
263313 collection = fetch_json (collection_url )
264314
265- # Generate layer config
266- # For COG layers, try to infer rescale from asset title or use default
267- rescale = None
268- if "carbon" in asset_id .lower ():
269- rescale = "0,100" # Reasonable default for carbon data
315+ # Get options with defaults
316+ colormap = options .get ("colormap" , args .colormap )
317+ rescale = options .get ("rescale" )
270318
319+ # Generate layer config
271320 layer_config = generate_layer_config (
272321 collection ,
273322 asset_id ,
274323 layer_key ,
275324 display_name ,
276- args . titiler ,
277- args . colormap ,
325+ titiler_url ,
326+ colormap ,
278327 rescale
279328 )
280329
0 commit comments