Skip to content

Commit

Permalink
feat: add option to export vertices list to temp layer (#198)
Browse files Browse the repository at this point in the history
Co-authored-by: Jakob Schnell <Jakob.Schnell@heigit.org>
  • Loading branch information
merydian and koebi authored Dec 21, 2023
1 parent 1d2a653 commit 4b05e86
Show file tree
Hide file tree
Showing 10 changed files with 11,118 additions and 5,523 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ RELEASING:
- Mention omission of configuration options when using traveling salesman
- option to set location type for isochrones ([#191](https://github.com/GIScience/orstools-qgis-plugin/pull/191))
- make items in centroid list drag and droppable ([#144](https://github.com/GIScience/orstools-qgis-plugin/issues/144))
- Add save button for vertices ([#144](https://github.com/GIScience/orstools-qgis-plugin/issues/144))

## [1.6.0] - 2023-07-25

Expand Down
34 changes: 33 additions & 1 deletion ORStools/gui/ORStoolsDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,17 @@
import os
import processing
import webbrowser

from qgis._core import Qgis
from qgis.core import (
QgsProject,
QgsVectorLayer,
QgsTextAnnotation,
QgsMapLayerProxyModel,
QgsCoordinateReferenceSystem,
QgsFeature,
QgsPointXY,
QgsGeometry,
QgsCoordinateReferenceSystem,
)
from qgis.gui import QgsMapCanvasAnnotationItem

Expand Down Expand Up @@ -410,6 +414,7 @@ def __init__(self, iface, parent=None):
# Routing tab
self.routing_fromline_map.clicked.connect(self._on_linetool_init)
self.routing_fromline_clear.clicked.connect(self._on_clear_listwidget_click)
self.save_vertices.clicked.connect(self._save_vertices_to_layer)

# Batch
self.batch_routing_points.clicked.connect(
Expand All @@ -435,6 +440,33 @@ def __init__(self, iface, parent=None):
self.routing_fromline_list.model().rowsMoved.connect(self._reindex_list_items)
self.routing_fromline_list.model().rowsRemoved.connect(self._reindex_list_items)

def _save_vertices_to_layer(self):
"""Saves the vertices list to a temp layer"""
items = [
self.routing_fromline_list.item(x).text()
for x in range(self.routing_fromline_list.count())
]

if len(items) > 0:
point_layer = QgsVectorLayer(
"point?crs=epsg:4326&field=ID:integer", "Vertices", "memory"
)
point_layer.updateFields()
for idx, x in enumerate(items):
coords = x.split(":")[1]
x, y = (float(i) for i in coords.split(", "))
feature = QgsFeature()
feature.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(x, y)))
feature.setAttributes([idx])

point_layer.dataProvider().addFeature(feature)
QgsProject.instance().addMapLayer(point_layer)
self._iface.mapCanvas().refresh()

self._iface.messageBar().pushMessage(
"Success", "Vertices saved to layer.", level=Qgis.Success
)

def _on_prov_refresh_click(self):
"""Populates provider dropdown with fresh list from config.yml"""

Expand Down
29 changes: 21 additions & 8 deletions ORStools/gui/ORStoolsDialogUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
class Ui_ORStoolsDialogBase(object):
def setupUi(self, ORStoolsDialogBase):
ORStoolsDialogBase.setObjectName("ORStoolsDialogBase")
ORStoolsDialogBase.resize(412, 868)
ORStoolsDialogBase.resize(412, 686)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
Expand Down Expand Up @@ -196,7 +196,19 @@ def setupUi(self, ORStoolsDialogBase):
self.routing_fromline_list.setSelectionMode(QtWidgets.QAbstractItemView.MultiSelection)
self.routing_fromline_list.setResizeMode(QtWidgets.QListView.Fixed)
self.routing_fromline_list.setObjectName("routing_fromline_list")
self.gridLayout.addWidget(self.routing_fromline_list, 0, 2, 3, 1)
self.gridLayout.addWidget(self.routing_fromline_list, 0, 1, 4, 1)
self.save_vertices = QtWidgets.QPushButton(self.widget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.save_vertices.sizePolicy().hasHeightForWidth())
self.save_vertices.setSizePolicy(sizePolicy)
self.save_vertices.setText("")
icon4 = QtGui.QIcon()
icon4.addPixmap(QtGui.QPixmap(":/plugins/ORStools/img/save_vertices.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.save_vertices.setIcon(icon4)
self.save_vertices.setObjectName("save_vertices")
self.gridLayout.addWidget(self.save_vertices, 2, 0, 1, 1)
self.verticalLayout_7.addWidget(self.widget)
self.advances_group = QgsCollapsibleGroupBox(self.qwidget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Fixed)
Expand Down Expand Up @@ -427,15 +439,15 @@ def setupUi(self, ORStoolsDialogBase):
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.help_button.sizePolicy().hasHeightForWidth())
self.help_button.setSizePolicy(sizePolicy)
icon4 = QtGui.QIcon()
icon4.addPixmap(QtGui.QPixmap(":/plugins/ORStools/img/icon_help.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.help_button.setIcon(icon4)
icon5 = QtGui.QIcon()
icon5.addPixmap(QtGui.QPixmap(":/plugins/ORStools/img/icon_help.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.help_button.setIcon(icon5)
self.help_button.setObjectName("help_button")
self.horizontalLayout_8.addWidget(self.help_button)
self.about_button = QtWidgets.QPushButton(self.widget_2)
icon5 = QtGui.QIcon()
icon5.addPixmap(QtGui.QPixmap(":/plugins/ORStools/img/icon_about.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.about_button.setIcon(icon5)
icon6 = QtGui.QIcon()
icon6.addPixmap(QtGui.QPixmap(":/plugins/ORStools/img/icon_about.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.about_button.setIcon(icon6)
self.about_button.setObjectName("about_button")
self.horizontalLayout_8.addWidget(self.about_button)
self.global_buttons = QtWidgets.QDialogButtonBox(self.widget_2)
Expand Down Expand Up @@ -472,6 +484,7 @@ def retranslateUi(self, ORStoolsDialogBase):
self.routing_fromline_map.setToolTip(_translate("ORStoolsDialogBase", "<html><head/><body><p>Add wayoints interactively from the map canvas.</p><p>Double-click will terminate waypoint selection.</p></body></html>"))
self.routing_fromline_clear.setToolTip(_translate("ORStoolsDialogBase", "<html><head/><body><p>If waypoints are selected in the list, only these will be deleted. Else all waypoints will be deleted.</p></body></html>"))
self.routing_fromline_list.setToolTip(_translate("ORStoolsDialogBase", "Select waypoints from the map!"))
self.save_vertices.setToolTip(_translate("ORStoolsDialogBase", "<html><head/><body><p>Save points in list to layer.</p></body></html>"))
self.advances_group.setTitle(_translate("ORStoolsDialogBase", "Advanced Configuration"))
self.optimization_group.setToolTip(_translate("ORStoolsDialogBase", "<html><head/><body><p>Enabling Traveling Salesman will omit all other advanced configuration and assume the preference to be <span style=\" font-weight:600;\">fastest</span>.</p></body></html>"))
self.optimization_group.setTitle(_translate("ORStoolsDialogBase", "Traveling Salesman"))
Expand Down
22 changes: 21 additions & 1 deletion ORStools/gui/ORStoolsDialogUI.ui
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@
</property>
</widget>
</item>
<item row="0" column="2" rowspan="3">
<item row="0" column="1" rowspan="4">
<widget class="QListWidget" name="routing_fromline_list">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
Expand Down Expand Up @@ -341,6 +341,26 @@
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QPushButton" name="save_vertices">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Save points in list to layer.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="resources.qrc">
<normaloff>:/plugins/ORStools/img/save_vertices.png</normaloff>:/plugins/ORStools/img/save_vertices.png</iconset>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down
Binary file added ORStools/gui/img/save_vertices.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 4b05e86

Please sign in to comment.