@@ -27,20 +27,36 @@ def groupId(self):
27
27
28
28
class ObservationGapSplitterAlgorithm (SplitTrajectoriesAlgorithm ):
29
29
TIME_GAP = "TIME_GAP"
30
+ TIME_DELTA_UNITS = "TIME_DELTA_UNITS"
31
+ TIME_DELTA_UNITS_OPTIONS = [
32
+ "Weeks" ,
33
+ "Days" ,
34
+ "Hours" ,
35
+ "Minutes" ,
36
+ "Seconds" ,
37
+ "Milliseconds"
38
+ ]
30
39
31
40
def __init__ (self ):
32
41
super ().__init__ ()
33
42
34
43
def initAlgorithm (self , config = None ):
35
44
super ().initAlgorithm (config )
36
45
self .addParameter (
37
- QgsProcessingParameterString (
46
+ QgsProcessingParameterNumber (
38
47
name = self .TIME_GAP ,
39
- description = self .tr ("Time gap (timedelta, e.g. 1 hours, 15 minutes)" ),
40
- defaultValue = "1 hours" ,
41
- optional = True ,
48
+ description = self .tr ("Time gap value" ),
49
+ defaultValue = 1 ,
42
50
)
43
51
)
52
+ self .addParameter (
53
+ QgsProcessingParameterEnum (
54
+ name = self .TIME_DELTA_UNITS ,
55
+ description = self .tr ("Time gap unit" ),
56
+ defaultValue = 3 ,
57
+ options = self .TIME_DELTA_UNITS_OPTIONS ,
58
+ )
59
+ )
44
60
45
61
def name (self ):
46
62
return "split_gap"
@@ -51,9 +67,7 @@ def displayName(self):
51
67
def shortHelpString (self ):
52
68
return self .tr (
53
69
"<p>Splits trajectories into subtrajectories "
54
- "whenever there is a gap in the observations "
55
- "(for supported time gap formats see: "
56
- "https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.to_timedelta.html)</p>"
70
+ "whenever there is a gap in the observations</p>"
57
71
"<p>For more information on trajectory splitters see: "
58
72
"https://movingpandas.readthedocs.io/en/main/api/trajectorysplitter.html</p>"
59
73
"<p><b>Speed</b> is calculated based on the input layer CRS information and "
@@ -64,8 +78,12 @@ def shortHelpString(self):
64
78
)
65
79
66
80
def processTc (self , tc , parameters , context ):
67
- time_gap = self .parameterAsString (parameters , self .TIME_GAP , context )
68
- time_gap = pd .Timedelta (time_gap ).to_pytimedelta ()
81
+ time_gap = self .parameterAsDouble (parameters , self .TIME_GAP , context )
82
+ td_units = self .parameterAsInt (parameters , self .TIME_DELTA_UNITS , context )
83
+ td_units = self .TIME_DELTA_UNITS_OPTIONS [td_units ]
84
+ if td_units == "Weeks" :
85
+ td_units = "W"
86
+ time_gap = pd .Timedelta (f"{ time_gap } { td_units } " ).to_pytimedelta ()
69
87
for traj in tc .trajectories :
70
88
splits = ObservationGapSplitter (traj ).split (gap = time_gap )
71
89
self .tc_to_sink (splits )
0 commit comments