Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Raise user friendly warning if CRS info is missing #26

Open
marklit opened this issue Mar 20, 2024 · 1 comment
Open

Raise user friendly warning if CRS info is missing #26

marklit opened this issue Mar 20, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@marklit
Copy link

marklit commented Mar 20, 2024

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,
@anitagraser
Copy link
Collaborator

I tend towards mandatory layer CRS here. However, there should be a user friendly error message if the CRS info is missing

@anitagraser anitagraser added the enhancement New feature or request label Mar 20, 2024
@anitagraser anitagraser changed the title Default to 4326 for unknown projections Raise user friendly warning if CRS info is missing May 17, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants