1- from typing import Union
1+ from typing import Union , Iterable
22
33import click
44import logging
77from rapida .connectivity import run_connectivity_analysis
88from rapida .cli .aclick import AsyncCommand
99from rapida .connectivity .isochrone import MODE_MAP
10-
10+ from rapida . cli . assess import get_variables_by_components
1111logger = logging .getLogger (__name__ )
1212
1313
14+
15+ def validate_variables (ctx , param , value ):
16+ """
17+ click callback function to validate polulation
18+ """
19+ valid_vars = get_variables_by_components (['population' ])['population' ]
20+ invalid = [v for v in value if v not in valid_vars ]
21+ if invalid :
22+ raise click .BadParameter (f"Invalid variable{ 's' if len (invalid ) > 1 else '' } : { ', ' .join (invalid )} for population . Valid options: { ', ' .join (valid_vars )} " )
23+ return value
24+
1425def parse_intervals (ctx , param , value ):
1526 """Parses a comma-separated string of numbers into a list of integers."""
1627 if not value :
@@ -46,6 +57,20 @@ def parse_intervals(ctx, param, value):
4657 help = "Comma-separated time intervals in minutes for the catchment areas."
4758)
4859
60+
61+ @click .option (
62+ '-sd' , '--sites-dataset' ,
63+ type = click .Path (exists = True , file_okay = True , dir_okay = False , readable = True ),
64+ default = None ,
65+ help = "Path to an OGR-supported vector data source (e.g., GPKG, Shapefile) containing sites."
66+ )
67+ @click .option (
68+ '-sl' , '--sites-layer' ,
69+ type = str ,
70+ default = "0" ,
71+ help = "Name or index of the layer to use from sites dataset. Defaults to the first layer (layer 0)."
72+ )
73+
4974@click .option (
5075 '-bd' , '--barriers-dataset' ,
5176 type = click .Path (exists = True , file_okay = True , dir_okay = False , readable = True ),
@@ -59,12 +84,19 @@ def parse_intervals(ctx, param, value):
5984 help = "Name or index of the layer to use from barriers dataset. Defaults to the first layer (layer 0)."
6085)
6186
87+
6288@click .option ('-bb' , "--barriers-buffer" ,
6389 type = int ,
6490 default = 5 ,
6591 required = False ,
6692 help = "The value in meters to used to buffer the geometries in barriers/dataset/layer in case the barriers are lines"
6793)
94+
95+ @click .option ('--popvar' , required = False , multiple = True ,
96+ type = str , callback = validate_variables ,
97+ help = f"Open or more RAPIDA population variable to compute zonal stats for withing the connectivity zones"
98+ )
99+
68100@click .option (
69101 "--dst-dir" ,
70102 "-d" , # Short option
@@ -84,12 +116,15 @@ def parse_intervals(ctx, param, value):
84116@click .pass_context
85117async def connectivity (ctx , bbox :tuple [float , float , float , float ]= None , travel_mode :str = None ,
86118 time_intervals :list [int ] = None , dst_dir :str = None ,
87- barriers_dataset :str = None , barriers_layer :str = None , barriers_buffer :int = None
119+ barriers_dataset :str = None , barriers_layer :str = None , barriers_buffer :int = None ,
120+ sites_dataset :str = None , sites_layer :str = None ,popvar :str | tuple [str ]= None
88121 ):
89- logger .info (f'Running connectivity analysis ' )
122+ logger .info (f'Running connectivity analysis' )
90123 progress = ctx .obj .get ('progress' )
91124 with progress :
92125 return await run_connectivity_analysis (
93126 bbox = bbox , dst_dir = dst_dir , travel_mode = travel_mode , time_intervals = time_intervals ,
94- barriers_dataset = barriers_dataset , barriers_layer = barriers_layer , barriers_buffer = barriers_buffer , progress = progress
127+ barriers_dataset = barriers_dataset , barriers_layer = barriers_layer , barriers_buffer = barriers_buffer ,
128+ sites_dataset = sites_dataset , sites_layer = sites_layer , pop_vars = popvar ,
129+ progress = progress
95130 )
0 commit comments