diff --git a/ohsomeTools/gui/OhsomeToolsDialog.py b/ohsomeTools/gui/OhsomeToolsDialog.py index 46fe215..05645cc 100644 --- a/ohsomeTools/gui/OhsomeToolsDialog.py +++ b/ohsomeTools/gui/OhsomeToolsDialog.py @@ -328,22 +328,10 @@ def run_gui_control(self): return # if there are no centroids or layers, throw an error message - tab_index = self.dlg.request_types_widget.currentIndex() - if tab_index == 0: - self.dlg.global_buttons.button(QDialogButtonBox.Ok).setDisabled( - True - ) - globals()[task_name] = ExtractionTaskFunction( - iface=self.iface, - dlg=self.dlg, - description=f"OHSOME task", - provider=provider, - request_url=preferences.get_request_url(), - preferences=preferences.get_bcircles_request_preferences(), - activate_temporal=preferences.activate_temporal_feature, - ) - QgsApplication.taskManager().addTask(globals()[task_name]) - elif tab_index == 1: + layer_name = self.dlg.comboBox_inputLayer.currentText() + layer = QgsProject.instance().mapLayersByName(layer_name)[0] + wkbType = layer.wkbType() + if wkbType in (QgsWkbTypes.Point, QgsWkbTypes.MultiPoint): self.dlg.global_buttons.button(QDialogButtonBox.Ok).setDisabled( True ) @@ -382,7 +370,7 @@ def run_gui_control(self): last_task = task self.dlg.debug_text.append(f'> cURL: {preferences.cURL(provider)}') QgsApplication.taskManager().addTask(globals()[task_name]) - elif tab_index == 2: + elif wkbType in (QgsWkbTypes.Polygon, QgsWkbTypes.MultiPolygon): self.dlg.global_buttons.button(QDialogButtonBox.Ok).setDisabled( True ) @@ -433,7 +421,7 @@ def run_gui_control(self): ) self.dlg.global_buttons.button(QDialogButtonBox.Ok).setEnabled(True) except Exception as e: - msg = [e.__class__.__name__, str(e)] + msg = f'{e.__class__.__name__} {str(e)}' logger.log("{}: {}".format(*msg), 2) self.dlg.debug_text.append(msg) self.iface.messageBar().pushMessage( @@ -749,44 +737,3 @@ def _on_linetool_map_deactivate(self): QApplication.restoreOverrideCursor() self._iface.mapCanvas().setMapTool(self.last_maptool) self.show() - - def _add_point_layer(self) -> bool: - layer = self.point_layer_input.currentLayer() - list_name = ( - f"{layer.name()} | Radius: {self.point_layer_radius_input.value()}" - ) - if layer and not check_list_duplicates( - self.point_layer_list, list_name - ): - self.point_layer_list.addItem(list_name) - self.point_layer_input.setCurrentIndex(0) - else: - return False - return True - - def _remove_point_layer(self): - layers: QListWidget = self.point_layer_list - selected_layers: [QListWidgetItem] = layers.selectedItems() - if not selected_layers: - return - element: QListWidgetItem - for element in selected_layers: - self.point_layer_list.takeItem(self.point_layer_list.row(element)) - - def _add_polygon_layer(self) -> bool: - layer = self.layer_input.currentLayer() - if layer and not check_list_duplicates(self.layer_list, layer.name()): - self.layer_list.addItem(layer.name()) - self.layer_input.setCurrentIndex(0) - else: - return False - return True - - def _remove_polygon_layer(self): - layers: QListWidget = self.layer_list - selected_layers: [QListWidgetItem] = layers.selectedItems() - if not selected_layers: - return - element: QListWidgetItem - for element in selected_layers: - self.layer_list.takeItem(self.layer_list.row(element)) diff --git a/ohsomeTools/gui/OhsomeToolsDialogUI.py b/ohsomeTools/gui/OhsomeToolsDialogUI.py index e91b1ef..7730799 100644 --- a/ohsomeTools/gui/OhsomeToolsDialogUI.py +++ b/ohsomeTools/gui/OhsomeToolsDialogUI.py @@ -27,6 +27,34 @@ def setupUi(self, OhsomeToolsDialogBase): self.gridLayout_17 = QtWidgets.QGridLayout(OhsomeToolsDialogBase) self.gridLayout_17.setSizeConstraint(QtWidgets.QLayout.SetMinAndMaxSize) self.gridLayout_17.setObjectName("gridLayout_17") + self.global_buttons = QtWidgets.QDialogButtonBox(OhsomeToolsDialogBase) + self.global_buttons.setEnabled(True) + self.global_buttons.setOrientation(QtCore.Qt.Horizontal) + self.global_buttons.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok) + self.global_buttons.setObjectName("global_buttons") + self.gridLayout_17.addWidget(self.global_buttons, 2, 1, 1, 1) + self.control_widget = QtWidgets.QWidget(OhsomeToolsDialogBase) + sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Fixed) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.control_widget.sizePolicy().hasHeightForWidth()) + self.control_widget.setSizePolicy(sizePolicy) + self.control_widget.setMaximumSize(QtCore.QSize(150, 16777215)) + self.control_widget.setObjectName("control_widget") + self.horizontalLayout_8 = QtWidgets.QHBoxLayout(self.control_widget) + self.horizontalLayout_8.setObjectName("horizontalLayout_8") + self.help_button = QtWidgets.QPushButton(self.control_widget) + sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.help_button.sizePolicy().hasHeightForWidth()) + self.help_button.setSizePolicy(sizePolicy) + self.help_button.setObjectName("help_button") + self.horizontalLayout_8.addWidget(self.help_button) + self.about_button = QtWidgets.QPushButton(self.control_widget) + self.about_button.setObjectName("about_button") + self.horizontalLayout_8.addWidget(self.about_button) + self.gridLayout_17.addWidget(self.control_widget, 2, 0, 1, 1) self.tabWidget_main = QtWidgets.QTabWidget(OhsomeToolsDialogBase) self.tabWidget_main.setMinimumSize(QtCore.QSize(550, 0)) self.tabWidget_main.setObjectName("tabWidget_main") @@ -39,12 +67,30 @@ def setupUi(self, OhsomeToolsDialogBase): self.scrollArea_2.setWidgetResizable(True) self.scrollArea_2.setObjectName("scrollArea_2") self.scrollAreaWidgetContents_4 = QtWidgets.QWidget() - self.scrollAreaWidgetContents_4.setGeometry(QtCore.QRect(0, 0, 511, 708)) + self.scrollAreaWidgetContents_4.setGeometry(QtCore.QRect(0, 0, 511, 733)) self.scrollAreaWidgetContents_4.setObjectName("scrollAreaWidgetContents_4") self.verticalLayout_8 = QtWidgets.QVBoxLayout(self.scrollAreaWidgetContents_4) self.verticalLayout_8.setObjectName("verticalLayout_8") self.verticalLayout_5 = QtWidgets.QVBoxLayout() self.verticalLayout_5.setObjectName("verticalLayout_5") + self.gridLayout = QtWidgets.QGridLayout() + self.gridLayout.setContentsMargins(5, 5, 5, 5) + self.gridLayout.setObjectName("gridLayout") + self.label_7 = QtWidgets.QLabel(self.scrollAreaWidgetContents_4) + self.label_7.setMaximumSize(QtCore.QSize(60, 16777215)) + self.label_7.setObjectName("label_7") + self.gridLayout.addWidget(self.label_7, 0, 0, 1, 1) + self.comboBox_inputLayer = QtWidgets.QComboBox(self.scrollAreaWidgetContents_4) + self.comboBox_inputLayer.setObjectName("comboBox_inputLayer") + self.gridLayout.addWidget(self.comboBox_inputLayer, 0, 1, 1, 1) + self.lineEdit_radius = QtWidgets.QLineEdit(self.scrollAreaWidgetContents_4) + self.lineEdit_radius.setClearButtonEnabled(False) + self.lineEdit_radius.setObjectName("lineEdit_radius") + self.gridLayout.addWidget(self.lineEdit_radius, 1, 1, 1, 1) + self.label_8 = QtWidgets.QLabel(self.scrollAreaWidgetContents_4) + self.label_8.setObjectName("label_8") + self.gridLayout.addWidget(self.label_8, 1, 0, 1, 1) + self.verticalLayout_5.addLayout(self.gridLayout) self.tabWidget_simple_advanced = QtWidgets.QTabWidget(self.scrollAreaWidgetContents_4) self.tabWidget_simple_advanced.setTabPosition(QtWidgets.QTabWidget.North) self.tabWidget_simple_advanced.setObjectName("tabWidget_simple_advanced") @@ -126,17 +172,6 @@ def setupUi(self, OhsomeToolsDialogBase): self.horizontalLayout_17.addItem(spacerItem1) self.verticalLayout_2.addLayout(self.horizontalLayout_17) self.gridLayout_16.addLayout(self.verticalLayout_2, 4, 0, 1, 1) - self.horizontalLayout_2 = QtWidgets.QHBoxLayout() - self.horizontalLayout_2.setContentsMargins(5, 5, 5, 5) - self.horizontalLayout_2.setObjectName("horizontalLayout_2") - self.label_7 = QtWidgets.QLabel(self.tab_simple) - self.label_7.setMaximumSize(QtCore.QSize(60, 16777215)) - self.label_7.setObjectName("label_7") - self.horizontalLayout_2.addWidget(self.label_7) - self.comboBox_inputLayer = QtWidgets.QComboBox(self.tab_simple) - self.comboBox_inputLayer.setObjectName("comboBox_inputLayer") - self.horizontalLayout_2.addWidget(self.comboBox_inputLayer) - self.gridLayout_16.addLayout(self.horizontalLayout_2, 0, 0, 1, 1) self.tabWidget_simple_advanced.addTab(self.tab_simple, "") self.tab_advanced = QtWidgets.QWidget() self.tab_advanced.setObjectName("tab_advanced") @@ -446,35 +481,7 @@ def setupUi(self, OhsomeToolsDialogBase): self.debug_text.setObjectName("debug_text") self.gridLayout_15.addWidget(self.debug_text, 0, 0, 1, 1) self.tabWidget_main.addTab(self.tab_2, "") - self.gridLayout_17.addWidget(self.tabWidget_main, 0, 0, 1, 2) - self.global_buttons = QtWidgets.QDialogButtonBox(OhsomeToolsDialogBase) - self.global_buttons.setEnabled(True) - self.global_buttons.setOrientation(QtCore.Qt.Horizontal) - self.global_buttons.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok) - self.global_buttons.setObjectName("global_buttons") - self.gridLayout_17.addWidget(self.global_buttons, 2, 1, 1, 1) - self.control_widget = QtWidgets.QWidget(OhsomeToolsDialogBase) - sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Fixed) - sizePolicy.setHorizontalStretch(0) - sizePolicy.setVerticalStretch(0) - sizePolicy.setHeightForWidth(self.control_widget.sizePolicy().hasHeightForWidth()) - self.control_widget.setSizePolicy(sizePolicy) - self.control_widget.setMaximumSize(QtCore.QSize(150, 16777215)) - self.control_widget.setObjectName("control_widget") - self.horizontalLayout_8 = QtWidgets.QHBoxLayout(self.control_widget) - self.horizontalLayout_8.setObjectName("horizontalLayout_8") - self.help_button = QtWidgets.QPushButton(self.control_widget) - sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed) - sizePolicy.setHorizontalStretch(0) - sizePolicy.setVerticalStretch(0) - sizePolicy.setHeightForWidth(self.help_button.sizePolicy().hasHeightForWidth()) - self.help_button.setSizePolicy(sizePolicy) - self.help_button.setObjectName("help_button") - self.horizontalLayout_8.addWidget(self.help_button) - self.about_button = QtWidgets.QPushButton(self.control_widget) - self.about_button.setObjectName("about_button") - self.horizontalLayout_8.addWidget(self.about_button) - self.gridLayout_17.addWidget(self.control_widget, 2, 0, 1, 1) + self.gridLayout_17.addWidget(self.tabWidget_main, 1, 0, 1, 1) self.retranslateUi(OhsomeToolsDialogBase) self.tabWidget_main.setCurrentIndex(0) @@ -507,6 +514,11 @@ def setupUi(self, OhsomeToolsDialogBase): def retranslateUi(self, OhsomeToolsDialogBase): _translate = QtCore.QCoreApplication.translate OhsomeToolsDialogBase.setWindowTitle(_translate("OhsomeToolsDialogBase", "ohsomeTools")) + self.help_button.setText(_translate("OhsomeToolsDialogBase", "Help")) + self.about_button.setText(_translate("OhsomeToolsDialogBase", "About")) + self.label_7.setText(_translate("OhsomeToolsDialogBase", "Input Layer:")) + self.lineEdit_radius.setPlaceholderText(_translate("OhsomeToolsDialogBase", "1000")) + self.label_8.setText(_translate("OhsomeToolsDialogBase", "Radius:")) self.label_6.setText(_translate("OhsomeToolsDialogBase", "OSM tag")) self.label_2.setText(_translate("OhsomeToolsDialogBase", "Key")) self.label_3.setText(_translate("OhsomeToolsDialogBase", "Value")) @@ -520,7 +532,6 @@ def retranslateUi(self, OhsomeToolsDialogBase): self.mcomboBox_osm_type.setItemText(0, _translate("OhsomeToolsDialogBase", "Node")) self.mcomboBox_osm_type.setItemText(1, _translate("OhsomeToolsDialogBase", "Way")) self.mcomboBox_osm_type.setItemText(2, _translate("OhsomeToolsDialogBase", "Relation")) - self.label_7.setText(_translate("OhsomeToolsDialogBase", "Input Layer:")) self.tabWidget_simple_advanced.setTabText(self.tabWidget_simple_advanced.indexOf(self.tab_simple), _translate("OhsomeToolsDialogBase", "Simple")) self.filter_label.setToolTip(_translate("OhsomeToolsDialogBase", "

Combines several attributive filters, e.g. OSM type, the geometry (simple feature) type, as well as the OSM tag.

For more information see: https://docs.ohsome.org/ohsome-api/v1/filter.html

")) self.filter_label.setText(_translate("OhsomeToolsDialogBase", "Filter ")) @@ -571,8 +582,6 @@ def retranslateUi(self, OhsomeToolsDialogBase): self.tabWidget_main.setTabText(self.tabWidget_main.indexOf(self.tab), _translate("OhsomeToolsDialogBase", "Parameter")) self.debug_text.setPlaceholderText(_translate("OhsomeToolsDialogBase", "Queries and errors will be printed here.")) self.tabWidget_main.setTabText(self.tabWidget_main.indexOf(self.tab_2), _translate("OhsomeToolsDialogBase", "Log")) - self.help_button.setText(_translate("OhsomeToolsDialogBase", "Help")) - self.about_button.setText(_translate("OhsomeToolsDialogBase", "About")) from qgscheckablecombobox import QgsCheckableComboBox from qgscollapsiblegroupbox import QgsCollapsibleGroupBox # import resources_rc diff --git a/ohsomeTools/gui/OhsomeToolsDialogUI.ui b/ohsomeTools/gui/OhsomeToolsDialogUI.ui index 1b81616..bfce2cb 100644 --- a/ohsomeTools/gui/OhsomeToolsDialogUI.ui +++ b/ohsomeTools/gui/OhsomeToolsDialogUI.ui @@ -41,7 +41,58 @@ QLayout::SetMinAndMaxSize - + + + + true + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + 0 + 0 + + + + + 150 + 16777215 + + + + + + + + 0 + 0 + + + + Help + + + + + + + About + + + + + + + @@ -74,12 +125,61 @@ 0 0 511 - 708 + 733 + + + + 5 + + + 5 + + + 5 + + + 5 + + + + + + 60 + 16777215 + + + + Input Layer: + + + + + + + + + + 1000 + + + false + + + + + + + Radius: + + + + + @@ -267,38 +367,6 @@ - - - - 5 - - - 5 - - - 5 - - - 5 - - - - - - 60 - 16777215 - - - - Input Layer: - - - - - - - - @@ -1070,57 +1138,6 @@ - - - - true - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - - 0 - 0 - - - - - 150 - 16777215 - - - - - - - - 0 - 0 - - - - Help - - - - - - - About - - - - - - @@ -1511,7 +1528,7 @@ - + diff --git a/ohsomeTools/gui/ohsome_spec.py b/ohsomeTools/gui/ohsome_spec.py index bc82b66..09aa5dc 100644 --- a/ohsomeTools/gui/ohsome_spec.py +++ b/ohsomeTools/gui/ohsome_spec.py @@ -241,33 +241,14 @@ def _get_selected_polygon_layers_geometries(self) -> []: return geojsons def _get_selected_point_layers_geometries(self) -> {}: - ordered_layer_radii = [] + radius = self.dlg.lineEdit_radius.text() ordered_list_of_features = [] - point_layers_list = self.dlg.point_layer_list - for idx in range(point_layers_list.count()): - item: str = point_layers_list.item(idx).text() - file_name, radius = item.rsplit(" | Radius: ") - ordered_layer_radii.append(int(radius)) - layers = QgsProject.instance().mapLayersByName(file_name) - layers = [ - layer - for layer in layers - if layer.geometryType() == QgsWkbTypes.PointGeometry - ] - if len(layers) > 1: - raise exceptions.TooManyInputsFound( - str("error"), - # error, - "Found too many input layers with the same name. Use unique names for your layers.", - ) - features = [ - layer.getFeatures() - for layer in layers - if layer.geometryType() == QgsWkbTypes.PointGeometry - ] - ordered_list_of_features.extend(features) + layer_name = self.dlg.comboBox_inputLayer.currentText() + layer = QgsProject.instance().mapLayersByName(layer_name)[0] + features = [layer.getFeatures()] + ordered_list_of_features.extend(features) list_of_coordinates = convert_point_features_to_ohsome_bcircles( - ordered_list_of_features, ordered_layer_radii + ordered_list_of_features, radius ) return list_of_coordinates diff --git a/ohsomeTools/utils/datamanager.py b/ohsomeTools/utils/datamanager.py index 224b678..d8ce810 100644 --- a/ohsomeTools/utils/datamanager.py +++ b/ohsomeTools/utils/datamanager.py @@ -44,7 +44,7 @@ def _get_layer_polygons(layer): def convert_point_features_to_ohsome_bcircles( - features: [QgsFeature], radii: [int] + features: [QgsFeature], radius: int ): coordinates_list = [] for i in range(len(features)): @@ -55,9 +55,9 @@ def convert_point_features_to_ohsome_bcircles( if geometry.type() == QgsWkbTypes.PointGeometry: point: QgsPointXY = feature.geometry().asPoint() coordinates = ( - f"{coordinates}|id{counter}:{point.x()},{point.y()},{radii[i]}" + f"{coordinates}|id{counter}:{point.x()},{point.y()},{radius}" if coordinates - else f"id{counter}:{point.x()},{point.y()},{radii[i]}" + else f"id{counter}:{point.x()},{point.y()},{radius}" ) counter += 1 if coordinates: