Skip to content

Commit 791f1ff

Browse files
committed
Fix NULL value handling, fixes #93
1 parent ddfb2c4 commit 791f1ff

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

metadata.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name=Trajectools
33
description=Processing tools for handling trajectory data
44
about=Trajectools adds trajectory analysis algorithms to the QGIS Processing toolbox. Trajectools requires MovingPandas >= 0.22.3 and optionally integrates scikit-mobility (for privacy tests), stonesoup (for smoothing), and gtfs_functions (for GTFS data support). See the plugin homepage for installation recommendations. Sample data for testing the functionality is provided with the plugin download.
55
category=Plugins
6-
version=2.7.1
6+
version=2.7.2
77
qgisMinimumVersion=3.0
88
qgisMaximumVersion=4.0
99

@@ -20,7 +20,9 @@ repository=https://codeberg.org/movingpandas/trajectools
2020
experimental=False
2121
deprecated=False
2222

23-
changelog=2.7.1
23+
changelog=2.7.2
24+
- Fix NULL value handling, fixes #93
25+
2.7.1
2426
- Get correct CRS authid, fixes #97
2527
- Make parallel processing optional, avoids #93
2628
2.7

qgis_processing/qgisUtils.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
QgsFeatureSink,
1414
QgsMessageLog,
1515
Qgis,
16+
NULL,
1617
)
1718
from qgis.PyQt.QtCore import QDateTime
1819

@@ -91,23 +92,26 @@ def trajectories_from_qgis_point_layer(
9192

9293

9394
def df_from_pt_layer(layer, time_field_name, trajectory_id_field):
95+
def to_date(qdatetime):
96+
if qdatetime == NULL:
97+
return None
98+
return qdatetime.toPyDateTime()
99+
94100
names = [field.name() for field in layer.fields()]
95101
data = []
96102
for feature in layer.getFeatures():
97103
my_dict = {}
98104
for i, a in enumerate(feature.attributes()):
99105
# QgsMessageLog.logMessage(f"{names[i]} | {time_field_name}", "Trajectools", level=Qgis.Info )
100-
if names[i] == time_field_name:
101-
try:
102-
a = a.toPyDateTime()
103-
except:
104-
pass
106+
if a == NULL:
107+
a = None
105108
my_dict[names[i]] = a
106109
pt = feature.geometry().asPoint()
107110
my_dict["geom_x"] = pt.x()
108111
my_dict["geom_y"] = pt.y()
109112
data.append(my_dict)
110113
df = pd.DataFrame(data)
114+
df[time_field_name] = df[time_field_name].apply(lambda a: to_date(a))
111115
return df
112116

113117

0 commit comments

Comments
 (0)