Ejemplo n.º 1
0
    def save_final_query(self):
        """
        Save the query without any templates, usefull for bbox
        """

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

        query = unicode(self.textEdit_query.toPlainText())
        nominatim = unicode(self.lineEdit_nominatim.text())
        bbox = self.get_bounding_box()

        # Delete any templates
        query = prepare_query(query=query,
                              extent=bbox,
                              nominatim_name=nominatim)

        # Save the query
        save_query_dialog = SaveQueryDialog(
            query=query,
            output_geometry_types=output_geometry_types,
            white_list_values=white_list_values)
        save_query_dialog.signal_new_query_successful.connect(
            self.signal_new_query_successful.emit)
        save_query_dialog.exec_()
Ejemplo n.º 2
0
 def test_prepare_query(self):
     """Test prepare query."""
     # Test geocodeArea simple.
     query = '<osm-script output="xml" timeout="25">    <id-query {{geoco' \
             'deArea:paris}} into="area_0"/>    <union>        <query typ' \
             'e="node">            <has-kv k="a" v="b"/>            <area' \
             '-query from="area_0"/>        </query>        <query type="' \
             'way">            <has-kv k="a" v="b"/>            <area-que' \
             'ry from="area_0"/>        </query>        <query type="rela' \
             'tion">            <has-kv k="a" v="b"/>            <area-qu' \
             'ery from="area_0"/>        </query>    </union>    <union> ' \
             '       <item/>        <recurse type="down"/>    </union>   ' \
             ' <print mode="body"/></osm-script>'
     expected = '<osm-script output="xml" timeout="25">    <id-query ref=' \
                '"3600007444" type="area" into="area_0"/>    <union>     ' \
                '   <query type="node">            <has-kv k="a" v="b"/> ' \
                '           <area-query from="area_0"/>        </query>  ' \
                '      <query type="way">            <has-kv k="a" v="b"/' \
                '>            <area-query from="area_0"/>        </query>' \
                '        <query type="relation">            <has-kv k="a"' \
                ' v="b"/>            <area-query from="area_0"/>        <' \
                '/query>    </union>    <union>        <item/>        <re' \
                'curse type="down"/>    </union>    <print mode="body"/><' \
                '/osm-script>'
     self.assertEqual(prepare_query(query), expected)
Ejemplo n.º 3
0
 def test_prepare_query(self):
     """Test prepare query."""
     # Test geocodeArea simple.
     query = '<osm-script output="xml" timeout="25">    <id-query {{geoco' \
             'deArea:paris}} into="area_0"/>    <union>        <query typ' \
             'e="node">            <has-kv k="a" v="b"/>            <area' \
             '-query from="area_0"/>        </query>        <query type="' \
             'way">            <has-kv k="a" v="b"/>            <area-que' \
             'ry from="area_0"/>        </query>        <query type="rela' \
             'tion">            <has-kv k="a" v="b"/>            <area-qu' \
             'ery from="area_0"/>        </query>    </union>    <union> ' \
             '       <item/>        <recurse type="down"/>    </union>   ' \
             ' <print mode="body"/></osm-script>'
     expected = '<osm-script output="xml" timeout="25">    <id-query ref=' \
                '"3600007444" type="area" into="area_0"/>    <union>     ' \
                '   <query type="node">            <has-kv k="a" v="b"/> ' \
                '           <area-query from="area_0"/>        </query>  ' \
                '      <query type="way">            <has-kv k="a" v="b"/' \
                '>            <area-query from="area_0"/>        </query>' \
                '        <query type="relation">            <has-kv k="a"' \
                ' v="b"/>            <area-query from="area_0"/>        <' \
                '/query>    </union>    <union>        <item/>        <re' \
                'curse type="down"/>    </union>    <print mode="body"/><' \
                '/osm-script>'
     self.assertEqual(prepare_query(query), expected)
Ejemplo n.º 4
0
    def save_final_query(self):
        """
        Save the query without any templates, usefull for bbox
        """

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

        query = unicode(self.textEdit_query.toPlainText())
        nominatim = unicode(self.lineEdit_nominatim.text())
        bbox = self.get_bounding_box()

        # Delete any templates
        query = prepare_query(
            query=query, extent=bbox, nominatim_name=nominatim)

        # Save the query
        save_query_dialog = SaveQueryDialog(
            query=query,
            output_geometry_types=output_geometry_types,
            white_list_values=white_list_values)
        save_query_dialog.signal_new_query_successful.connect(
            self.signal_new_query_successful.emit)
        save_query_dialog.exec_()
Ejemplo n.º 5
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("QuickOSM", u"Prepare outputs"))

    # Replace Nominatim or BBOX
    query = prepare_query(query=query, nominatim_name=nominatim, extent=bbox)

    # Getting the default overpass api and running the query
    server = get_setting('defaultOAPI')
    dialog.set_progress_text(tr("QuickOSM", u"Downloading data from Overpass"))
    QApplication.processEvents()
    connexion_overpass_api = ConnexionOAPI(url=server, output="xml")
    osm_file = connexion_overpass_api.query(query)

    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,
                     config_outputs=config_outputs)
Ejemplo n.º 6
0
    def generate_query(self):
        """
        Transform the template to query "out of the box"
        """

        query = unicode(self.textEdit_query.toPlainText())
        nominatim = unicode(self.lineEdit_nominatim.text())
        bbox = self.get_bounding_box()
        query = prepare_query(
            query=query, extent=bbox, nominatim_name=nominatim)
        self.textEdit_query.setPlainText(query)
Ejemplo n.º 7
0
    def generate_query(self):
        """
        Transform the template to query "out of the box"
        """

        query = unicode(self.textEdit_query.toPlainText())
        nominatim = unicode(self.lineEdit_nominatim.text())
        bbox = self.get_bounding_box()
        query = prepare_query(query=query,
                              extent=bbox,
                              nominatim_name=nominatim)
        self.textEdit_query.setPlainText(query)
Ejemplo n.º 8
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."""

    # Check OGR
    if not is_ogr_version_ok():
        raise GDALVersion

    if not is_osm_driver_enabled():
        raise OsmDriverNotFound

    # Get output's format
    output_format = get_setting('outputFormat')

    # Prepare outputs
    dialog.set_progress_text(tr("QuickOSM", u"Prepare outputs"))

    # Replace Nominatim or BBOX
    query = prepare_query(query=query, nominatim_name=nominatim, extent=bbox)

    # Getting the default overpass api and running the query
    server = get_setting('defaultOAPI')
    dialog.set_progress_text(tr("QuickOSM", u"Downloading data from Overpass"))
    QApplication.processEvents()
    connexion_overpass_api = ConnexionOAPI(url=server, output="xml")
    osm_file = connexion_overpass_api.get_file_from_query(query)

    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_format=output_format,
        output_dir=output_dir,
        prefix_file=prefix_file,
        config_outputs=config_outputs)
Ejemplo n.º 9
0
    def processAlgorithm(self, progress):
        progress.setInfo("Preparing the Overpass query")
        progress.setPercentage(0)

        server = self.getParameterValue(self.SERVER)
        query = self.getParameterValue(self.QUERY_STRING)
        nominatim = self.getParameterValue(self.NOMINATIM)

        # Extent of the layer
        extent = self.getParameterValue(self.EXTENT)
        if extent != "0,0,0,0":
            # x_min, x_max, y_min, y_max
            extent = [float(i) for i in extent.split(',')]
            # noinspection PyCallByClass
            geometry_extent = QgsGeometry.fromRect(
                QgsRectangle(extent[0], extent[2], extent[1], extent[3]))
            source_crs = iface.mapCanvas().mapRenderer().destinationCrs()
            crs_transform = QgsCoordinateTransform(
                source_crs, QgsCoordinateReferenceSystem("EPSG:4326"))
            geometry_extent.transform(crs_transform)
            extent = geometry_extent.boundingBox()
        else:
            extent = None

        if nominatim == "":
            nominatim = None

        # Make some transformation on the query ({{box}}, Nominatim, ...
        query = prepare_query(query, extent, nominatim)

        overpass_api = ConnexionOAPI(url=server, output="xml")
        progress.setInfo("Downloading data from Overpass")
        progress.setPercentage(5)
        osm_file = overpass_api.get_file_from_query(query)

        # Set the output file for Processing
        progress.setPercentage(100)
        self.setOutputValue(self.OUTPUT_FILE, osm_file)
Ejemplo n.º 10
0
    def processAlgorithm(self, progress):
        progress.setInfo("Preparing the Overpass query")
        progress.setPercentage(0)

        server = self.getParameterValue(self.SERVER)
        query = self.getParameterValue(self.QUERY_STRING)
        nominatim = self.getParameterValue(self.NOMINATIM)

        # Extent of the layer
        extent = self.getParameterValue(self.EXTENT)
        if extent != "0,0,0,0":
            # x_min, x_max, y_min, y_max
            extent = [float(i) for i in extent.split(',')]
            # noinspection PyCallByClass
            geometry_extent = QgsGeometry.fromRect(
                QgsRectangle(extent[0], extent[2], extent[1], extent[3]))
            source_crs = iface.mapCanvas().mapRenderer().destinationCrs()
            crs_transform = QgsCoordinateTransform(
                source_crs, QgsCoordinateReferenceSystem("EPSG:4326"))
            geometry_extent.transform(crs_transform)
            extent = geometry_extent.boundingBox()
        else:
            extent = None

        if nominatim == "":
            nominatim = None

        # Make some transformation on the query ({{box}}, Nominatim, ...
        query = prepare_query(query, extent, nominatim)

        overpass_api = ConnexionOAPI(url=server, output="xml")
        progress.setInfo("Downloading data from Overpass")
        progress.setPercentage(5)
        osm_file = overpass_api.get_file_from_query(query)

        # Set the output file for Processing
        progress.setPercentage(100)
        self.setOutputValue(self.OUTPUT_FILE, osm_file)