qgis-processing-trajectory
qgis-processing-trajectory copied to clipboard
Raise user friendly warning if CRS info is missing
If I drop a GPKG file into QGIS and try and try and create a trajectory, if I haven't gone into the layer's properties and set the projection QGIS will leave it as unknown. I'm then left with this error message till I set the projection. It might be worth just assuming 4326 if the projection can't be determined.
QGIS version: 3.36.0-Maidenhead
QGIS code revision: 09951dc0
Qt version: 5.15.3
Python version: 3.9.18
GDAL version: 3.8.4
GEOS version: 3.12.1-CAPI-1.18.1
PROJ version: Rel. 9.3.1, December 1st, 2023
PDAL version: 2.6.0 (git-version: 3fced5)
Algorithm started at: 2024-03-20T15:30:21
Algorithm 'Create trajectories' starting…
Input parameters:
{ 'INPUT' : 'F:/gis/Global/adsb_lol/2024/traces_2024-02-29_0045.gpkg|layername=traces_2024-02-29_0045|geometrytype=Point|uniqueGeometryType=yes', 'OUTPUT_PTS' : 'TEMPORARY_OUTPUT', 'OUTPUT_TRAJS' : 'TEMPORARY_OUTPUT', 'SPEED_UNIT' : 'km/h', 'TIME_FIELD' : 'observed_at', 'TRAJ_ID_FIELD' : 'r' }
Traceback (most recent call last):
File "C:\Users/markl/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\processing_trajectory\qgis_processing\trajectoriesAlgorithm.py", line 157, in processAlgorithm
tc, crs = self.create_tc(parameters, context)
File "C:\Users/markl/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\processing_trajectory\qgis_processing\trajectoriesAlgorithm.py", line 110, in create_tc
tc = tc_from_pt_layer(
File "C:\Users/markl/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\processing_trajectory\qgis_processing\qgisUtils.py", line 41, in tc_from_pt_layer
crs = CRS(int(layer.sourceCrs().geographicCrsAuthId().split(":")[1]))
ValueError: invalid literal for int() with base 10: ''
diff --git a/qgis_processing/qgisUtils.py b/qgis_processing/qgisUtils.py
index 68218b6..c38ae6b 100644
--- a/qgis_processing/qgisUtils.py
+++ b/qgis_processing/qgisUtils.py
@@ -38,7 +38,12 @@ def tc_from_pt_layer(layer, time_field_name, trajectory_id_field):
my_dict["geom_y"] = pt.y()
data.append(my_dict)
df = pd.DataFrame(data)
- crs = CRS(int(layer.sourceCrs().geographicCrsAuthId().split(":")[1]))
+
+ try:
+ crs = CRS(int(layer.sourceCrs().geographicCrsAuthId().split(":")[1]))
+ except ValueError:
+ crs = CRS(4326)
+
tc = TrajectoryCollection(
df,
traj_id_col=trajectory_id_field,
I tend towards mandatory layer CRS here. However, there should be a user friendly error message if the CRS info is missing