Ejemplo n.º 1
0
def process_query(
        dialog=None,
        query=None,
        area=None,
        bbox=None,
        output_dir=None,
        prefix_file=None,
        output_geometry_types=None,
        layer_name="OsmQuery",
        white_list_values=None,
        config_outputs=None):
    """execute a query and send the result file to open_file."""

    # Prepare outputs
    dialog.set_progress_text(tr('Prepare outputs'))

    # Getting the default overpass api and running the query
    server = get_setting('defaultOAPI', OVERPASS_SERVERS[0]) + 'interpreter'
    dialog.set_progress_text(
        tr('Downloading data from Overpass {server_name}'.format(
            server_name=server)))
    # Replace Nominatim or BBOX
    query = QueryPreparation(query, bbox, area, server)
    QApplication.processEvents()
    final_query = query.prepare_query()
    url = query.prepare_url()
    connexion_overpass_api = ConnexionOAPI(url)
    LOGGER.debug('Encoded URL: {}'.format(url))
    osm_file = connexion_overpass_api.run()

    return open_file(
        dialog=dialog,
        osm_file=osm_file,
        output_geom_types=output_geometry_types,
        white_list_column=white_list_values,
        layer_name=layer_name,
        output_dir=output_dir,
        prefix_file=prefix_file,
        final_query=final_query,
        config_outputs=config_outputs)
Ejemplo n.º 2
0
def process_query(
        dialog=None,
        query=None,
        nominatim=None,
        bbox=None,
        output_dir=None,
        prefix_file=None,
        output_geometry_types=None,
        layer_name="OsmQuery",
        white_list_values=None,
        config_outputs=None):
    """execute a query and send the result file to open_file."""

    # Prepare outputs
    dialog.set_progress_text(tr('Prepare outputs'))

    # Getting the default overpass api and running the query
    server = get_setting('defaultOAPI', OVERPASS_SERVERS[0]) + 'interpreter'
    dialog.set_progress_text(
        tr('Downloading data from Overpass {}').format(server))
    # Replace Nominatim or BBOX
    query = QueryPreparation(query, bbox, nominatim, server)
    QApplication.processEvents()
    final_query = query.prepare_query()
    url = query.prepare_url()
    connexion_overpass_api = ConnexionOAPI(url)
    LOGGER.debug('Encoded URL: {}'.format(url))
    osm_file = connexion_overpass_api.run()

    return open_file(
        dialog=dialog,
        osm_file=osm_file,
        output_geom_types=output_geometry_types,
        white_list_column=white_list_values,
        layer_name=layer_name,
        output_dir=output_dir,
        prefix_file=prefix_file,
        final_query=final_query,
        config_outputs=config_outputs)
Ejemplo n.º 3
0
def reload_query(query: str,
                 layer_name: str = 'Reloaded_query',
                 dialog: QDialog = None,
                 new_file: bool = True):
    """ Reload a query with only the query """
    # Getting the default overpass api and running the query
    server = get_setting('defaultOAPI', OVERPASS_SERVERS[0]) + 'interpreter'

    query = QueryPreparation(query, overpass=server)
    final_query = query.prepare_query()
    url = query.prepare_url()
    connexion_overpass_api = ConnexionOAPI(url)
    LOGGER.debug('Encoded URL: {}'.format(url))
    osm_file = connexion_overpass_api.run()

    if new_file:
        layer_name += "_reloaded"
        return open_file(
            dialog=dialog,
            osm_file=osm_file,
            layer_name=layer_name,
            final_query=final_query,
        )
Ejemplo n.º 4
0
    def process_road(self, context, url):
        """Major step of the process"""

        if self.feedback.isCanceled():
            self.feedback.reportError(
                'The algorithm has been canceled during the building of the url.'
            )
            return self.OUTPUT_CANCEL

        self.feedback.setCurrentStep(1)
        self.feedback.pushInfo('Downloading data and OSM file.')

        connexion_overpass_api = ConnexionOAPI(url)
        osm_file = connexion_overpass_api.run()

        if self.feedback.isCanceled():
            self.feedback.reportError(
                'The algorithm has been canceled during the download.')
            return self.OUTPUT_CANCEL

        self.feedback.setCurrentStep(2)
        self.feedback.pushInfo('Processing downloaded file.')

        out_dir = dirname(self.file) if self.file else None
        out_file = basename(self.file)[:-5] if self.file else None

        osm_parser = OsmParser(osm_file=osm_file,
                               output_format=Format.GeoPackage,
                               output_dir=out_dir,
                               prefix_file=out_file,
                               feedback_alg=True,
                               feedback=self.feedback)

        layers = osm_parser.processing_parse()

        if self.feedback.isCanceled():
            self.feedback.reportError(
                'The algorithm has been canceled during the parsing.')
            return self.OUTPUT_CANCEL

        self.feedback.setCurrentStep(7)
        self.feedback.pushInfo('Decorating the requested layers.')

        layer_output = []
        OUTPUT = {
            'points': self.OUTPUT_POINTS,
            'lines': self.OUTPUT_LINES,
            'multilinestrings': self.OUTPUT_MULTILINESTRINGS,
            'multipolygons': self.OUTPUT_MULTIPOLYGONS
        }

        for layer in layers:
            layers[layer]['layer_decorated'] = processing.run(
                "quickosm:decoratelayer",
                {'LAYER': layers[layer]['vector_layer']},
                feedback=self.feedback)
            context.temporaryLayerStore().addMapLayer(
                layers[layer]['vector_layer'])
            layer_output.append(
                QgsProcessingUtils.mapLayerFromString(
                    layers[layer]['vector_layer'].id(), context, True))
            if 'tags' in layers[layer]:
                layer_details = QgsProcessingContext.LayerDetails(
                    'OSMQuery_' + layer, context.project(), OUTPUT[layer])
                if 'colour' in layers[layer]['tags']:
                    layer_details.setPostProcessor(
                        SetColoringPostProcessor.create(layers[layer]['tags']))
                context.addLayerToLoadOnCompletion(
                    layers[layer]['vector_layer'].id(), layer_details)

        if self.feedback.isCanceled():
            self.feedback.reportError(
                'The algorithm has been canceled during the post processing.')
            return self.OUTPUT_CANCEL

        outputs = {
            self.OUTPUT_POINTS: layer_output[0].id(),
            self.OUTPUT_LINES: layer_output[1].id(),
            self.OUTPUT_MULTILINESTRINGS: layer_output[2].id(),
            self.OUTPUT_MULTIPOLYGONS: layer_output[3].id(),
        }
        return outputs
Ejemplo n.º 5
0
def process_query(dialog: QDialog = None,
                  query: str = None,
                  description: str = None,
                  area: Union[str, List[str]] = None,
                  key: Union[str, List[str]] = None,
                  value: Union[str, List[str]] = None,
                  type_multi_request: list = None,
                  bbox: QgsRectangle = None,
                  output_dir: str = None,
                  output_format: Format = None,
                  prefix_file: str = None,
                  output_geometry_types: list = None,
                  layer_name: str = "OsmQuery",
                  white_list_values: dict = None,
                  config_outputs: dict = None) -> int:
    """execute a query and send the result file to open_file."""
    # Save the query in the historic
    q_manage = QueryManagement(query=query,
                               name=prefix_file if prefix_file else layer_name,
                               description=description,
                               advanced=value is None,
                               type_multi_request=type_multi_request,
                               keys=key,
                               values=value,
                               area=area,
                               bbox=bbox,
                               output_geometry_types=output_geometry_types,
                               white_list_column=white_list_values)
    q_manage.write_query_historic()

    if dialog.feedback_process.isCanceled():
        return None

    # Prepare outputs
    dialog.set_progress_text(tr('Prepare outputs'))

    # Getting the default overpass api and running the query
    server = get_setting('defaultOAPI', OVERPASS_SERVERS[0]) + 'interpreter'
    dialog.set_progress_text(
        tr('Downloading data from Overpass {server_name}'.format(
            server_name=server)))
    # Replace Nominatim or BBOX
    query = QueryPreparation(query, bbox, area, server)
    QApplication.processEvents()
    final_query = query.prepare_query()
    url = query.prepare_url()
    connexion_overpass_api = ConnexionOAPI(url)
    LOGGER.debug('Encoded URL: {}'.format(url))
    osm_file = connexion_overpass_api.run()

    return open_file(dialog=dialog,
                     osm_file=osm_file,
                     output_geom_types=output_geometry_types,
                     white_list_column=white_list_values,
                     key=key,
                     layer_name=layer_name,
                     output_dir=output_dir,
                     output_format=output_format,
                     prefix_file=prefix_file,
                     final_query=final_query,
                     config_outputs=config_outputs,
                     feedback=dialog.feedback_process)