Пример #1
0
    def _check_parameters(self):
        """Internal function to check that the query can be built."""
        if self._query_type not in QueryType:
            raise QueryFactoryException(tr('Wrong query type'))

        if len(self._osm_objects) < 1:
            raise QueryFactoryException(tr('OSM object required'))

        for osmObject in self._osm_objects:
            if osmObject not in OsmType:
                raise QueryFactoryException(tr('Wrong OSM object'))

        if self._query_type == QueryType.AroundArea and not self._distance_around:
            raise QueryFactoryException(tr('No distance provided with "around".'))

        areas = [
            QueryType.InArea, QueryType.AroundArea]
        if self._query_type in areas and not self._area:
            raise QueryFactoryException(tr('Named area required or WKT.'))
Пример #2
0
    def _check_parameters(self):
        """Internal function to check that the query can be built.

        :raise QueryFactoryException
        :return True if everything went fine.
        """
        if type(self._query_type) != QueryType:
            raise QueryFactoryException(tr('Wrong query type.'))

        for osmObject in self._osm_objects:
            if type(osmObject) != OsmType:
                raise QueryFactoryException(tr('Wrong OSM object.'))

        if self._query_type == QueryType.AroundArea:
            if not self._distance_around:
                raise QueryFactoryException(
                    tr('No distance provided with "around".'))

            try:
                int(self._distance_around)
            except ValueError:
                raise QueryFactoryException(
                    tr('Wrong distance parameter.'))

        if self._distance_around and self._query_type == QueryType.InArea:
            raise QueryFactoryException(
                tr('Distance parameter is incompatible with this query.'))

        areas = [
            QueryType.InArea, QueryType.AroundArea]
        if self._query_type in areas and not self._area:
            raise QueryFactoryException(tr('Named area required or WKT.'))

        if not self._key and self._value:
            raise QueryFactoryException(
                tr('Not possible to query a value without a key.'))

        if len(self._key) > len(self._value):
            if len(self._key) != 1:
                raise QueryFactoryException(
                    tr('Missing some values for some keys'))

        if len(self._key) < len(self._value):
            raise QueryFactoryException(
                tr('Missing some keys for some values'))

        self._checked = True
        return True
Пример #3
0
    def _check_parameters(self):
        """Internal function to check that the query can be built."""
        if self._query_type not in QueryType:
            raise QueryFactoryException('Wrong query type')

        if len(self._osm_objects) < 1:
            raise QueryFactoryException('OSM object required')

        for osmObject in self._osm_objects:
            if osmObject not in ALL_OSM_TYPES:
                raise QueryFactoryException('Wrong OSM object')

        if self._query_type == QueryType.AroundNominatimPlace and not self._distance_around:
            raise QueryFactoryException('No distance provided with "around".')

        nominatim = [
            QueryType.InNominatimPlace, QueryType.AroundNominatimPlace
        ]
        if self._query_type in nominatim and not self._nominatim_place:
            raise QueryFactoryException('Nominatim place required.')
Пример #4
0
    def check_parameters(self):
        if self.__nominatim and self.__bbox:
            raise QueryFactoryException(
                suffix=tr('QuickOSM', 'nominatim OR bbox, not both'))

        if len(self.__osm_objects) < 1:
            raise QueryFactoryException(
                suffix=tr('QuickOSM', 'osm object required'))

        for osmObject in self.__osm_objects:
            if osmObject not in QueryFactory.OSM_TYPES:
                raise QueryFactoryException(
                    suffix=tr('QuickOSM', 'wrong OSM object'))

        if self.__is_around and not self.__distance:
            raise QueryFactoryException(
                suffix=tr('QuickOSM', 'No distance provided with "around".'))

        if self.__is_around and not self.__nominatim:
            raise QueryFactoryException(
                suffix=tr('QuickOSM', 'No nominatim provided with "around".'))
Пример #5
0
    def replace_bbox(self):
        """Replace {{bbox}} by the extent BBOX if needed.

        The temporary query will be updated.
        """
        template = r'{{bbox}}'
        if not re.search(template, self._query_prepared):
            return
        else:
            if self._extent is None:
                raise QueryFactoryException(tr('Missing extent parameter.'))

        y_min = self._extent.yMinimum()
        y_max = self._extent.yMaximum()
        x_min = self._extent.xMinimum()
        x_max = self._extent.xMaximum()

        # make sure we don't query for invalid bounds #222
        area_is_too_big = False
        if y_min < -90:
            y_min = -90
            area_is_too_big = True
        if y_max > 90:
            y_max = 90
            area_is_too_big = True
        if x_min < -180:
            x_min = -180
            area_is_too_big = True
        if x_max > 180:
            x_max = 180
            area_is_too_big = True

        if area_is_too_big:
            LOGGER.info(
                tr('The area was overlapping the WGS84 limits ±90 / ±180 degrees. The query has '
                   'been restricted.'))

        if self.is_oql_query():
            new_string = '{},{},{},{}'.format(y_min, x_min, y_max, x_max)
        else:
            new_string = 'e="{}" n="{}" s="{}" w="{}"'.format(
                x_max, y_max, y_min, x_min)
        self._query_prepared = (re.sub(template, new_string,
                                       self._query_prepared))
Пример #6
0
    def _replace_center(self):
        """Replace {{center}} by the centroid of the extent if needed.

        The temporary query will be updated.
        """
        template = r'{{center}}'
        if not re.search(template, self._query_prepared):
            return
        if self._extent is None:
            raise QueryFactoryException(tr('Missing extent parameter.'))

        coord_y = self._extent.center().y()
        coord_x = self._extent.center().x()
        if self.is_oql_query():
            new_string = '{},{}'.format(coord_y, coord_x)
        else:
            new_string = 'lat="{}" lon="{}"'.format(coord_y, coord_x)

        self._query_prepared = (re.sub(template, new_string,
                                       self._query_prepared))
Пример #7
0
    def replace_bbox(self):
        """Replace {{bbox}} by the extent BBOX if needed.

        The temporary query will be updated.
        """
        template = r'{{bbox}}'
        if not re.search(template, self._query_prepared):
            return
        else:
            if self._extent is None:
                raise QueryFactoryException(tr('Missing extent parameter'))

        y_min = self._extent.yMinimum()
        y_max = self._extent.yMaximum()
        x_min = self._extent.xMinimum()
        x_max = self._extent.xMaximum()

        if self.is_oql_query():
            new_string = '{},{},{},{}'.format(y_min, x_min, y_max, x_max)
        else:
            new_string = 'e="{}" n="{}" s="{}" w="{}"'.format(
                x_max, y_max, y_min, x_min)
        self._query_prepared = (
            re.sub(template, new_string, self._query_prepared))
Пример #8
0
    def _check_parameters(self) -> bool:
        """Internal function to check that the query can be built.

        :return: True if everything went fine.

        :raise QueryFactoryException:
        """
        if type(self._query_type) != QueryType:
            raise QueryFactoryException(tr('Wrong query type.'))

        for osmObject in self._osm_objects:
            if type(osmObject) != OsmType:
                raise QueryFactoryException(tr('Wrong OSM object.'))

        if self._query_type == QueryType.AroundArea:
            if not self._distance_around:
                raise QueryFactoryException(
                    tr('No distance provided with the "around" query.'))

            try:
                int(self._distance_around)
            except ValueError:
                raise QueryFactoryException(
                    tr('Wrong distance parameter.'))

        if self._distance_around and self._query_type == QueryType.InArea:
            raise QueryFactoryException(
                tr('Distance parameter is incompatible with this query.'))

        if self._query_type == QueryType.InArea and not self._area:
            raise QueryFactoryException(
                tr('Named area is required when the query is "In".'))

        if self._query_type == QueryType.AroundArea and not self._area:
            raise QueryFactoryException(
                tr('Named area or a WKT is required when the query is "Around".'))

        if not self._key and self._value:
            raise QueryFactoryException(
                tr('Not possible to query a specific value without a key.'))

        if self._query_type == QueryType.NotSpatial:
            if not self._key:
                raise QueryFactoryException(
                    tr('A key is required.'))

        if len(self._key) > len(self._value):
            if len(self._key) != 1:
                raise QueryFactoryException(
                    tr('Missing some values for some keys.'))

        if len(self._key) < len(self._value):
            raise QueryFactoryException(
                tr('Missing some keys for some values.'))

        self._checked = True
        return True