11use std:: path:: Path ;
22
33use clap:: { Parser , Subcommand } ;
4- use routee_compass_core :: model :: network :: EdgeListId ;
4+ use config :: { Config , File } ;
55use serde:: { Deserialize , Serialize } ;
66
77use crate :: {
8- collection:: {
9- ObjectStoreSource , OvertureMapsCollectionError , OvertureMapsCollectorConfig ,
10- ReleaseVersion , RowFilterConfig , TransportationCollection ,
11- } ,
12- graph:: OmfGraphVectorized ,
8+ app:: { cli_bbox:: parse_bbox, network:: NetworkEdgeListConfiguration , CliBoundingBox } ,
9+ collection:: OvertureMapsCollectionError ,
1310} ;
1411
1512/// Command line tool for batch downloading and summarizing of OMF (Overture Maps Foundation) data
@@ -24,41 +21,64 @@ pub struct OmfApp {
2421#[ derive( Debug , Clone , Serialize , Deserialize , Subcommand ) ]
2522pub enum OmfOperation {
2623 /// download all of the OMF transportation data
27- Download {
24+ Network {
25+ /// configuration file defining how the network is imported and separated
26+ /// into mode-specific edge lists.
27+ #[ arg( short, long) ]
28+ configuration_file : String ,
29+
2830 /// location on disk to write output files. if not provided,
2931 /// use the current working directory.
3032 #[ arg( short, long) ]
3133 output_directory : Option < String > ,
34+
35+ /// use a stored raw data export from a previous run of OmfOperation::Network
36+ /// which is a JSON file containing a TransportationCollection.
37+ #[ arg( short, long) ]
38+ local_source : Option < String > ,
39+
40+ /// write the raw OMF dataset as a JSON blob to the output directory.
41+ #[ arg( short, long) ]
42+ store_raw : bool ,
43+
44+ /// bounding box to filter data (format: xmin,xmax,ymin,ymax)
45+ #[ arg( short, long, value_parser = parse_bbox, allow_hyphen_values( true ) ) ]
46+ bbox : Option < CliBoundingBox > ,
3247 } ,
3348}
3449
3550impl OmfOperation {
3651 pub fn run ( & self ) -> Result < ( ) , OvertureMapsCollectionError > {
3752 match self {
38- OmfOperation :: Download { output_directory } => {
39- let collector =
40- OvertureMapsCollectorConfig :: new ( ObjectStoreSource :: AmazonS3 , 128 ) . build ( ) ?;
41- let release = ReleaseVersion :: Latest ;
42- let row_filter_config = RowFilterConfig :: Bbox {
43- xmin : -105.254 ,
44- xmax : -105.197 ,
45- ymin : 39.733 ,
46- ymax : 39.784 ,
47- } ;
48-
49- let collection = TransportationCollection :: try_from_collector (
50- collector,
51- release,
52- Some ( row_filter_config) ,
53- ) ?;
54- let vectorized_graph = OmfGraphVectorized :: new ( collection, EdgeListId ( 0 ) ) ?;
55- let output_path = match output_directory {
56- Some ( o) => Path :: new ( o) ,
53+ OmfOperation :: Network {
54+ configuration_file,
55+ output_directory,
56+ local_source,
57+ store_raw,
58+ bbox,
59+ } => {
60+ let filepath = Path :: new ( configuration_file) ;
61+ let config = Config :: builder ( )
62+ . add_source ( File :: from ( filepath) )
63+ . build ( )
64+ . map_err ( |e| {
65+ let msg = format ! ( "file '{configuration_file}' produced error: {e}" ) ;
66+ OvertureMapsCollectionError :: InvalidUserInput ( msg)
67+ } ) ?;
68+ let network_config = config
69+ . get :: < Vec < NetworkEdgeListConfiguration > > ( "edge_lists" )
70+ . map_err ( |e| {
71+ let msg = format ! (
72+ "error reading 'edge_lists' key in '{configuration_file}': {e}"
73+ ) ;
74+ OvertureMapsCollectionError :: InvalidUserInput ( msg)
75+ } ) ?;
76+ let outdir = match output_directory {
77+ Some ( out) => Path :: new ( out) ,
5778 None => Path :: new ( "" ) ,
5879 } ;
59- vectorized_graph. write_compass ( output_path, true ) ?;
60-
61- Ok ( ( ) )
80+ let local = local_source. as_ref ( ) . map ( Path :: new) ;
81+ crate :: app:: network:: run ( bbox. as_ref ( ) , & network_config, outdir, local, * store_raw)
6282 }
6383 }
6484 }
0 commit comments