From dfd11ab71883a576a4eb79592b2dd9377dd3efba Mon Sep 17 00:00:00 2001 From: Merydian Date: Mon, 10 Jun 2024 10:36:48 +0200 Subject: [PATCH 1/7] feat: transform points before request to epsg4326 --- ORStools/gui/directions_gui.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/ORStools/gui/directions_gui.py b/ORStools/gui/directions_gui.py index bb5b440a..385ad24e 100644 --- a/ORStools/gui/directions_gui.py +++ b/ORStools/gui/directions_gui.py @@ -33,6 +33,8 @@ from ORStools.utils import transform +from qgis.core import QgsPointXY + def _get_avoid_polygons(layer): """ @@ -84,12 +86,13 @@ def _get_avoid_options(avoid_boxes): class Directions: """Extended functionality for directions endpoint for GUI.""" - def __init__(self, dlg): + def __init__(self, dlg, iface): """ :param dlg: Main GUI dialog. :type dlg: QDialog """ self.dlg = dlg + self.iface = iface self.options = dict() @@ -100,15 +103,25 @@ def get_request_line_feature(self): :returns: coordinate list of line :rtype: list """ + map_crs = self.iface.mapCanvas().mapSettings().destinationCrs() + transformer = transform.transformToWGS(map_crs) + coordinates = [] layers_list = self.dlg.routing_fromline_list for idx in range(layers_list.count()): item = layers_list.item(idx).text() param, coords = item.split(":") + coordinates.append([float(coord) for coord in coords.split(", ")]) - return [[round(x, 6), round(y, 6)] for x, y in coordinates] + transformed_coordinates = [] + for coord in coordinates: + point = QgsPointXY(coord[0], coord[1]) + transformed_point = transformer.transform(point) + transformed_coordinates.append([transformed_point.x(), transformed_point.y()]) + + return [[round(x, 6), round(y, 6)] for x, y in transformed_coordinates] def get_parameters(self): """ From 5f80efb0b52b1cf60607561ad57a55a39b0da374 Mon Sep 17 00:00:00 2001 From: Merydian Date: Mon, 10 Jun 2024 10:38:20 +0200 Subject: [PATCH 2/7] feat: show coordinates in routing_from_line_list in project crs --- ORStools/gui/ORStoolsDialog.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/ORStools/gui/ORStoolsDialog.py b/ORStools/gui/ORStoolsDialog.py index 49f6a445..6962f9f9 100644 --- a/ORStools/gui/ORStoolsDialog.py +++ b/ORStools/gui/ORStoolsDialog.py @@ -498,6 +498,7 @@ def _save_vertices_to_layer(self) -> None: self.routing_fromline_list.item(x).text() for x in range(self.routing_fromline_list.count()) ] + map_crs = self._iface.mapCanvas().mapSettings().destinationCrs() if len(items) > 0: point_layer = QgsVectorLayer( @@ -512,6 +513,7 @@ def _save_vertices_to_layer(self) -> None: feature.setAttributes([idx]) point_layer.dataProvider().addFeature(feature) + point_layer.setCrs(map_crs) QgsProject.instance().addMapLayer(point_layer) self._iface.mapCanvas().refresh() @@ -595,11 +597,7 @@ def _on_linetool_init(self) -> None: def _on_linetool_map_click(self, point: QgsPointXY, idx: int) -> None: """Adds an item to QgsListWidget and annotates the point in the map canvas""" - map_crs = self._iface.mapCanvas().mapSettings().destinationCrs() - - transformer = transform.transformToWGS(map_crs) - point_wgs = transformer.transform(point) - self.routing_fromline_list.addItem(f"Point {idx}: {point_wgs.x():.6f}, {point_wgs.y():.6f}") + self.routing_fromline_list.addItem(f"Point {idx}: {point.x():.6f}, {point.y():.6f}") annotation = self._linetool_annotate_point(point, idx) self.project.annotationManager().addAnnotation(annotation) From 25f23529729af6745e8cc67235442b006a81043b Mon Sep 17 00:00:00 2001 From: Merydian Date: Mon, 10 Jun 2024 10:38:56 +0200 Subject: [PATCH 3/7] feat: pass iface to Directions to get project crs there --- ORStools/gui/ORStoolsDialog.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ORStools/gui/ORStoolsDialog.py b/ORStools/gui/ORStoolsDialog.py index 6962f9f9..8372941c 100644 --- a/ORStools/gui/ORStoolsDialog.py +++ b/ORStools/gui/ORStoolsDialog.py @@ -315,7 +315,7 @@ def run_gui_control(self) -> None: clnt = client.Client(provider, agent) clnt_msg = "" - directions = directions_gui.Directions(self.dlg) + directions = directions_gui.Directions(self.dlg, self.iface) params = None try: params = directions.get_parameters() From 163cec7cc92096717a524ef208198a0d48672c3e Mon Sep 17 00:00:00 2001 From: Merydian Date: Mon, 10 Jun 2024 10:39:28 +0200 Subject: [PATCH 4/7] style: refactor clear_annotations name to be non private --- ORStools/gui/ORStoolsDialog.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ORStools/gui/ORStoolsDialog.py b/ORStools/gui/ORStoolsDialog.py index 8372941c..74e7bb96 100644 --- a/ORStools/gui/ORStoolsDialog.py +++ b/ORStools/gui/ORStoolsDialog.py @@ -542,7 +542,7 @@ def _on_clear_listwidget_click(self) -> None: else: # else clear all items and annotations self.routing_fromline_list.clear() - self._clear_annotations() + self.clear_annotations() # Remove blue lines (rubber band) if self.line_tool: @@ -569,7 +569,7 @@ def _linetool_annotate_point( return QgsMapCanvasAnnotationItem(annotation, self.annotation_canvas).annotation() - def _clear_annotations(self) -> None: + def clear_annotations(self) -> None: """Clears annotations""" for annotation_item in self.annotation_canvas.annotationItems(): annotation = annotation_item.annotation() @@ -586,7 +586,7 @@ def _on_linetool_init(self) -> None: self.hide() self.routing_fromline_list.clear() # Remove all annotations which were added (if any) - self._clear_annotations() + self.clear_annotations() self.line_tool = maptools.LineTool(self._iface.mapCanvas()) self._iface.mapCanvas().setMapTool(self.line_tool) @@ -609,7 +609,7 @@ def _reindex_list_items(self) -> None: for x in range(self.routing_fromline_list.count()) ] self.routing_fromline_list.clear() - self._clear_annotations() + self.clear_annotations() crs = QgsCoordinateReferenceSystem(f"EPSG:{4326}") for idx, x in enumerate(items): coords = x.split(":")[1] From 92c25ae0584cb345ea756888dbbb616a0224e143 Mon Sep 17 00:00:00 2001 From: Merydian Date: Mon, 10 Jun 2024 10:39:49 +0200 Subject: [PATCH 5/7] feat: remove dead code --- ORStools/gui/ORStoolsDialog.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/ORStools/gui/ORStoolsDialog.py b/ORStools/gui/ORStoolsDialog.py index 74e7bb96..60861756 100644 --- a/ORStools/gui/ORStoolsDialog.py +++ b/ORStools/gui/ORStoolsDialog.py @@ -269,16 +269,6 @@ def run_gui_control(self) -> None: layer_out.loadNamedStyle(qml_path, True) layer_out.triggerRepaint() - # Associate annotations with map layer, so they get deleted when layer is deleted - for annotation in self.dlg.annotations: - # Has the potential to be pretty cool: instead of deleting, associate with mapLayer - # , you can change order after optimization - # Then in theory, when the layer is remove, the annotation is removed as well - # Doesn't work though, the annotations are still there when project is re-opened - # annotation.setMapLayer(layer_out) - self.project.annotationManager().removeAnnotation(annotation) - self.dlg.annotations = [] - provider_id = self.dlg.provider_combo.currentIndex() provider = configmanager.read_config()["providers"][provider_id] From d091ed9c5c749926f2f2b24ac144aeed53e31341 Mon Sep 17 00:00:00 2001 From: Merydian Date: Mon, 10 Jun 2024 10:42:37 +0200 Subject: [PATCH 6/7] docs: add changelog entry --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d46e9da5..33770d17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,10 @@ RELEASING: 14. Create new release in GitHub with tag version and release title of `vX.X.X` --> +## Unreleased +### added +- Show coordinates in point list in project crs ([#200](https://github.com/GIScience/orstools-qgis-plugin/issues/200)) + ## [1.8.3] - 2024-05-29 ### Fixed From 14052f89af65f74702004bda8fa71b51c915b5f2 Mon Sep 17 00:00:00 2001 From: Merydian Date: Mon, 10 Jun 2024 10:44:02 +0200 Subject: [PATCH 7/7] style: run ruff --- ORStools/gui/ORStoolsDialog.py | 2 +- ORStools/gui/directions_gui.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/ORStools/gui/ORStoolsDialog.py b/ORStools/gui/ORStoolsDialog.py index 60861756..3b133cc2 100644 --- a/ORStools/gui/ORStoolsDialog.py +++ b/ORStools/gui/ORStoolsDialog.py @@ -77,7 +77,7 @@ PREFERENCES, ) from ORStools.gui import directions_gui -from ORStools.utils import exceptions, maptools, logger, configmanager, transform +from ORStools.utils import exceptions, maptools, logger, configmanager from .ORStoolsDialogConfig import ORStoolsDialogConfigMain from .ORStoolsDialogUI import Ui_ORStoolsDialogBase diff --git a/ORStools/gui/directions_gui.py b/ORStools/gui/directions_gui.py index 385ad24e..78e706c7 100644 --- a/ORStools/gui/directions_gui.py +++ b/ORStools/gui/directions_gui.py @@ -112,7 +112,6 @@ def get_request_line_feature(self): item = layers_list.item(idx).text() param, coords = item.split(":") - coordinates.append([float(coord) for coord in coords.split(", ")]) transformed_coordinates = []