Beispiel #1
0
    def accept(self):
        """
        On accept, we call the FileQueryWriter
        """
        category = self.lineEdit_category.text()
        name = self.lineEdit_name.text()

        # Get folder .qgis2/QuickOSM/queries on linux for instance
        folder = get_user_query_folder()

        ini_file = FileQueryWriter(
            path=folder,
            name=name,
            category=category,
            query=self.query,
            white_list_values=self.white_list_values,
            output_geometry_types=self.output_geometry_types)
        try:

            if not category:
                raise MissingParameterException(suffix='category')
            if not name:
                raise MissingParameterException(suffix='name')

            ini_file.save()
            self.signal_new_query_successful.emit()
            self.hide()
        except QuickOsmException, e:
            self.message_bar.pushMessage(e.msg,
                                         level=e.level,
                                         duration=e.duration)
    def gather_values(self):
        properties = super().gather_values()

        properties['query'] = self.dialog.text_query.toPlainText()

        properties['expected_csv'] = dict()
        if self.dialog.checkbox_points_q.isChecked():
            properties['expected_csv'][LayerType.Points] = (
                self.dialog.edit_csv_points.text())
        if self.dialog.checkbox_lines_q.isChecked():
            properties['expected_csv'][LayerType.Lines] = (
                self.dialog.edit_csv_lines.text())
        if self.dialog.checkbox_multilinestrings_q.isChecked():
            properties['expected_csv'][LayerType.Multilinestrings] = (
                self.dialog.edit_csv_multilinestrings.text())
        if self.dialog.checkbox_multipolygons_q.isChecked():
            properties['expected_csv'][LayerType.Multipolygons] = (
                self.dialog.edit_csv_multipolygons.text())

        # TODO check this regex
        # noinspection RegExpRedundantEscape
        if not properties['place'] and \
                re.search(r'\{\{nominatim\}\}', properties['query']) or \
                re.search(r'\{\{nominatimArea:\}\}', properties['query']) \
                or \
                re.search(r'\{\{geocodeArea:\}\}', properties['query']):
            raise MissingParameterException(suffix='nominatim field')

        return properties
Beispiel #3
0
    def run_query(self):
        """
        Process for running the query
        """

        # Block the button and save the initial text
        self.pushButton_browse_output_file.setDisabled(True)
        self.pushButton_generateQuery.setDisabled(True)
        QApplication.setOverrideCursor(Qt.WaitCursor)
        self.start_process()
        QApplication.processEvents()

        # Get all values
        query = unicode(self.textEdit_query.toPlainText())
        output_directory = self.lineEdit_browseDir.text()
        prefix_file = self.lineEdit_filePrefix.text()
        nominatim = self.nominatim_value()

        # Set bbox
        bbox = None
        if self.radioButton_extentLayer.isChecked() or \
                self.radioButton_extentMapCanvas.isChecked():
            bbox = self.get_bounding_box()

        # Check nominatim
        if nominatim == '':
            nominatim = None

        # Which geometry at the end ?
        output_geometry_types = self.get_output_geometry_types()
        white_list_values = self.get_white_list_values()

        try:
            # Test values
            if not output_geometry_types:
                raise OutPutGeomTypesException

            if output_directory and not isdir(output_directory):
                raise DirectoryOutPutException

            if not nominatim and \
                    re.search(r'\{\{nominatim\}\}', query) or \
                    re.search(r'\{\{nominatimArea:\}\}', query) or \
                    re.search(r'\{\{geocodeArea:\}\}', query):

                raise MissingParameterException(suffix="nominatim field")

            num_layers = process_query(
                dialog=self,
                query=query,
                output_dir=output_directory,
                prefix_file=prefix_file,
                output_geometry_types=output_geometry_types,
                white_list_values=white_list_values,
                nominatim=nominatim,
                bbox=bbox)

            if num_layers:
                display_message_bar(tr('QuickOSM', u'Successful query !'),
                                    level=QgsMessageBar.INFO,
                                    duration=5)
                self.label_progress.setText(
                    tr('QuickOSM', u'Successful query !'))
            else:
                display_message_bar(tr('QuickOSM',
                                       u'Successful query, but no result.'),
                                    level=QgsMessageBar.WARNING,
                                    duration=7)

        except QuickOsmException, e:
            self.display_geo_algorithm_exception(e)
Beispiel #4
0
    def run_query(self):
        """
        Process for running the query
        """
        # Block the button and save the initial text

        self.pushButton_browse_output_file.setDisabled(True)
        QApplication.setOverrideCursor(Qt.WaitCursor)
        self.start_process()
        QApplication.processEvents()

        # Get all values
        query = self.current_query
        output_directory = self.lineEdit_browseDir.text()
        prefix_file = self.lineEdit_filePrefix.text()
        nominatim = self.nominatim_value()

        # Set the bbox
        bbox = None
        if self.radioButton_extentLayer.isChecked() or \
                self.radioButton_extentMapCanvas.isChecked():
            bbox = self.get_bounding_box()

        # Which geometry at the end ?
        output_geometry_types = self.get_output_geometry_types()
        white_list_values = self.get_white_list_values()

        try:
            # Test values
            if not output_geometry_types:
                raise OutPutGeomTypesException

            if output_directory and not isdir(output_directory):
                raise DirectoryOutPutException

            geocode_area = re.search(r'\{\{nominatim\}\}', query) or \
                re.search(r'\{\{nominatimArea:\}\}', query) or \
                re.search(r'\{\{geocodeArea:\}\}', query)

            if not nominatim and geocode_area:
                raise MissingParameterException(suffix="nominatim field")

            num_layers = process_query(
                dialog=self,
                query=query,
                output_dir=output_directory,
                prefix_file=prefix_file,
                output_geometry_types=output_geometry_types,
                white_list_values=white_list_values,
                nominatim=nominatim,
                bbox=bbox,
                config_outputs=self.config_layer)

            if num_layers:
                display_message_bar(tr('Successful query !'),
                                    level=Qgis.Info,
                                    duration=5)
                self.label_progress.setText(tr('Successful query !'))
            else:
                display_message_bar(tr('Successful query, but no result.'),
                                    level=Qgis.Warning,
                                    duration=7)

        except QuickOsmException as e:
            self.display_geo_algorithm_exception(e)
        except Exception as e:  # pylint: disable=broad-except
            self.display_exception(e)

        finally:
            # Resetting the button
            self.pushButton_browse_output_file.setDisabled(False)
            QApplication.restoreOverrideCursor()
            self.end_process()
            QApplication.processEvents()
    def gather_values(self):
        """Called by QuickQuery, Query and Open widgets.

        :return: A dictionary with all values inside.
        :rtype: dict
        """
        caller = self.panels[inspect.stack()[1][3]]
        properties = dict()

        # For all queries
        properties['outputs'] = []
        if self.output_buttons[caller][0].isChecked():
            # noinspection PyTypeChecker
            properties['outputs'].append(LayerType.Points)
        if self.output_buttons[caller][1].isChecked():
            # noinspection PyTypeChecker
            properties['outputs'].append(LayerType.Lines)
        if self.output_buttons[caller][2].isChecked():
            # noinspection PyTypeChecker
            properties['outputs'].append(LayerType.Multilinestrings)
        if self.output_buttons[caller][3].isChecked():
            # noinspection PyTypeChecker
            properties['outputs'].append(LayerType.Multipolygons)

        if not properties['outputs']:
            raise OutPutGeomTypesException

        properties['output_directory'] = (
            self.output_directories[caller].filePath())
        properties['prefix_file'] = self.prefix_edits[caller].text()

        if properties['output_directory'] and not (isdir(
                properties['output_directory'])):
            raise DirectoryOutPutException

        # Specific to files
        if caller == Panels.File:
            properties['osm_file'] = self.osm_file.filePath()
            conf = self.osm_conf.filePath()
            if conf:
                properties['osm_conf'] = conf
            else:
                properties['osm_conf'] = (
                    self.osm_conf.lineEdit().placeholderText())

            properties['load_only'] = self.radio_osm_conf.isChecked()

            if not isfile(properties['osm_file']):
                raise FileDoesntExistException(suffix="*.osm or *.pbf")

            if properties['load_only']:
                if not isfile(properties['osm_conf']):
                    raise FileDoesntExistException(suffix="*.ini")

            # End for OSM file
            return properties

        # Speficif for quick query
        if caller == Panels.QuickQuery:
            osm_objects = []
            if self.checkbox_node.isChecked():
                osm_objects.append(OsmType.Node)
            if self.checkbox_way.isChecked():
                osm_objects.append(OsmType.Way)
            if self.checkbox_relation.isChecked():
                osm_objects.append(OsmType.Relation)
            properties['osm_objects'] = osm_objects

            if not properties['osm_objects']:
                raise OsmObjectsException

            properties['key'] = self.combo_key.currentText()
            properties['value'] = self.combo_value.currentText()
            properties['timeout'] = self.spin_timeout.value()
            properties['distance'] = self.spin_place_qq.value()

        # For quick query and query
        place = self.nominatim_value(caller)
        if place == '':
            place = None
        properties['place'] = place

        # Speficic for query
        if caller == Panels.Query:
            properties['query'] = self.text_query.toPlainText()

            properties['expected_csv'] = dict()
            if self.checkbox_points_q.isChecked():
                properties['expected_csv'][LayerType.Points] = (
                    self.edit_csv_points.text())
            if self.checkbox_lines_q.isChecked():
                properties['expected_csv'][LayerType.Lines] = (
                    self.edit_csv_lines.text())
            if self.checkbox_multilinestrings_q.isChecked():
                properties['expected_csv'][LayerType.Multilinestrings] = (
                    self.edit_csv_multilinestrings.text())
            if self.checkbox_multipolygons_q.isChecked():
                properties['expected_csv'][LayerType.Multipolygons] = (
                    self.edit_csv_multipolygons.text())

            if not place and \
                    re.search(r'\{\{nominatim\}\}', properties['query']) or \
                    re.search(r'\{\{nominatimArea:\}\}', properties['query']) \
                    or \
                    re.search(r'\{\{geocodeArea:\}\}', properties['query']):

                raise MissingParameterException(suffix='nominatim field')

        # For quick query and query
        properties['query_type'] = (
            self.query_type_buttons[caller].currentData())
        properties['is_around'] = properties['query_type'] == 'around'

        if not properties['place']:
            if properties['query_type'] == 'canvas':
                geom_extent = iface.mapCanvas().extent()
                source_crs = iface.mapCanvas().mapSettings().destinationCrs()
            elif properties['query_type'] == 'layer':
                # Else if a layer is checked
                layer = self.layers_buttons[caller].currentLayer()
                geom_extent = layer.extent()
                source_crs = layer.crs()

            geom_extent = QgsGeometry.fromRect(geom_extent)
            epsg_4326 = QgsCoordinateReferenceSystem('EPSG:4326')
            crs_transform = QgsCoordinateTransform(source_crs, epsg_4326,
                                                   QgsProject.instance())
            geom_extent.transform(crs_transform)
            properties['bbox'] = geom_extent.boundingBox()
        else:
            properties['bbox'] = None

        return properties
Beispiel #6
0
    def run_query(self):
        """
        Process for running the query
        """

        # Block the button and save the initial text
        self.output_directory.setDisabled(True)
        self.pushButton_generateQuery.setDisabled(True)
        QApplication.setOverrideCursor(Qt.WaitCursor)
        self.start_process()
        QApplication.processEvents()

        # Get all values
        query = self.textEdit_query.toPlainText()
        output_directory = self.output_directory.filePath()
        prefix_file = self.lineEdit_filePrefix.text()
        nominatim = self.nominatim_value()

        # Set bbox
        bbox = None
        if self.cb_query_type.isEnabled():
            query_type = self.cb_query_type.currentData()
            if query_type in ['layer', 'canvas']:
                nominatim = None
                bbox = self.get_bounding_box()

        # Check nominatim
        if nominatim == '':
            nominatim = None

        # Which geometry at the end ?
        output_geometry_types = self.get_output_geometry_types()
        white_list_values = self.get_white_list_values()

        try:
            # Test values
            if not output_geometry_types:
                raise OutPutGeomTypesException

            if output_directory and not isdir(output_directory):
                raise DirectoryOutPutException

            if not nominatim and \
                    re.search(r'\{\{nominatim\}\}', query) or \
                    re.search(r'\{\{nominatimArea:\}\}', query) or \
                    re.search(r'\{\{geocodeArea:\}\}', query):

                raise MissingParameterException(suffix="nominatim field")

            num_layers = process_query(
                dialog=self,
                query=query,
                output_dir=output_directory,
                prefix_file=prefix_file,
                output_geometry_types=output_geometry_types,
                white_list_values=white_list_values,
                nominatim=nominatim,
                bbox=bbox)

            if num_layers:
                display_message_bar(tr('Successful query'),
                                    level=Qgis.Success,
                                    duration=5)
                self.label_progress.setText(tr('Successful query'))
            else:
                display_message_bar(tr('Successful query, but no result.'),
                                    level=Qgis.Warning,
                                    duration=7)

        except QuickOsmException as e:
            self.display_geo_algorithm_exception(e)
            pass
        except Exception as e:  # pylint: disable=broad-except
            self.display_exception(e)
            pass

        finally:
            # Resetting the button
            self.output_directory.setDisabled(False)
            self.pushButton_generateQuery.setDisabled(False)
            QApplication.restoreOverrideCursor()
            self.end_process()
            QApplication.processEvents()