示例#1
0
文件: config.py 项目: elfmon/mapchete
    def _get_process_area(self,
                          area=None,
                          bounds=None,
                          area_fallback=None,
                          bounds_fallback=None,
                          area_crs=None,
                          bounds_crs=None):
        """
        Determine process area by combining configuration with instantiation arguments.

        In the configuration the process area can be provided by using the (1) ``area``
        option, (2) ``bounds`` option or (3) a combination of both.

        (1) If only ``area`` is provided, output shall be the area geometry
        (2) If only ``bounds`` is provided, output shall be box(*self.bounds)
        (3) If both are provided, output shall be the intersection between ``area`` and
        ``bounds``

        The area parameter can be provided in multiple variations, see _guess_geometry().
        """
        try:
            dst_crs = self.process_pyramid.crs

            if bounds is None and area is None:
                return area_fallback

            elif bounds is None:
                area, crs = _guess_geometry(area, base_dir=self.config_dir)
                # in case vector file has no CRS use manually provided CRS
                area_crs = crs or area_crs

                return reproject_geometry(area,
                                          src_crs=area_crs or dst_crs,
                                          dst_crs=dst_crs)

            elif area is None:
                return reproject_geometry(box(*validate_bounds(bounds)),
                                          src_crs=bounds_crs or dst_crs,
                                          dst_crs=dst_crs)

            else:
                area, crs = _guess_geometry(area, base_dir=self.config_dir)
                # in case vector file has no CRS use manually provided CRS
                area_crs = crs or area_crs

                bounds = validate_bounds(bounds)

                # reproject area and bounds to process CRS and return intersection
                return reproject_geometry(
                    area, src_crs=area_crs or dst_crs,
                    dst_crs=dst_crs).intersection(
                        reproject_geometry(box(*validate_bounds(bounds)),
                                           src_crs=bounds_crs or dst_crs,
                                           dst_crs=dst_crs), )
        except Exception as e:
            raise MapcheteConfigError(e)
示例#2
0
def bounds_from_opts(wkt_geometry=None,
                     point=None,
                     bounds=None,
                     zoom=None,
                     raw_conf=None):
    """
    Loads the process pyramid of a raw configuration.

    Parameters
    ----------
    raw_conf : dict
        Raw mapchete configuration as dictionary.

    Returns
    -------
    BufferedTilePyramid
    """
    if wkt_geometry:
        return Bounds(*wkt.loads(wkt_geometry).bounds)
    elif point:
        x, y = point
        zoom_levels = get_zoom_levels(
            process_zoom_levels=raw_conf["zoom_levels"], init_zoom_levels=zoom)
        tp = raw_conf_process_pyramid(raw_conf)
        return Bounds(*tp.tile_from_xy(x, y, max(zoom_levels)).bounds)
    else:
        return validate_bounds(bounds) if bounds is not None else bounds
示例#3
0
def clip_bounds(bounds=None, clip=None):
    """
    Clips bounds by clip.

    Parameters
    ----------
    bounds : bounds to be clipped
    clip : clip bounds

    Returns
    -------
    Bounds(left, bottom, right, top)
    """
    bounds = validate_bounds(bounds)
    clip = validate_bounds(clip)
    return Bounds(max(bounds.left, clip.left), max(bounds.bottom, clip.bottom),
                  min(bounds.right, clip.right), min(bounds.top, clip.top))
示例#4
0
 def bounds(self):
     """Process bounds as defined in the configuration."""
     if self._raw["bounds"] is None:
         return self.process_pyramid.bounds
     else:
         try:
             return validate_bounds(self._raw["bounds"])
         except Exception as e:
             raise MapcheteConfigError(e)
示例#5
0
文件: config.py 项目: elfmon/mapchete
def bounds_from_opts(wkt_geometry=None,
                     point=None,
                     point_crs=None,
                     zoom=None,
                     bounds=None,
                     bounds_crs=None,
                     raw_conf=None):
    """
    Return process bounds depending on given inputs.

    Parameters
    ----------
    wkt_geometry : string
        WKT geometry used to generate bounds.
    point : iterable
        x and y coordinates of point whose corresponding process tile bounds shall be
        returned.
    point_crs : str or CRS
        CRS of point (default: process pyramid CRS)
    zoom : int
        Mandatory zoom level if point is provided.
    bounds : iterable
        Bounding coordinates to be used
    bounds_crs : str or CRS
        CRS of bounds (default: process pyramid CRS)

    raw_conf : dict
        Raw mapchete configuration as dictionary.

    Returns
    -------
    BufferedTilePyramid
    """
    if wkt_geometry:
        return Bounds(*wkt.loads(wkt_geometry).bounds)
    elif point:
        x, y = point
        tp = raw_conf_process_pyramid(raw_conf)
        if point_crs:
            reproj = reproject_geometry(Point(x, y),
                                        src_crs=point_crs,
                                        dst_crs=tp.crs)
            x = reproj.x
            y = reproj.y
        zoom_levels = get_zoom_levels(
            process_zoom_levels=raw_conf["zoom_levels"], init_zoom_levels=zoom)
        return Bounds(*tp.tile_from_xy(x, y, max(zoom_levels)).bounds)
    elif bounds:
        bounds = validate_bounds(bounds)
        if bounds_crs:
            tp = raw_conf_process_pyramid(raw_conf)
            bounds = Bounds(*reproject_geometry(
                box(*bounds), src_crs=bounds_crs, dst_crs=tp.crs).bounds)
        return bounds
    else:
        return
示例#6
0
    def init_bounds(self):
        """
        Process bounds this process is currently initialized with.

        This gets triggered by using the ``init_bounds`` kwarg. If not set, it will
        be equal to self.bounds.
        """
        if self._raw["init_bounds"] is None:
            return self.bounds
        else:
            try:
                return validate_bounds(self._raw["init_bounds"])
            except Exception as e:
                raise MapcheteConfigError(e)
示例#7
0
def snap_bounds(bounds=None, pyramid=None, zoom=None):
    """
    Snaps bounds to tiles boundaries of specific zoom level.

    Parameters
    ----------
    bounds : bounds to be snapped
    pyramid : TilePyramid
    zoom : int

    Returns
    -------
    Bounds(left, bottom, right, top)
    """
    bounds = validate_bounds(bounds)
    pyramid = validate_bufferedtilepyramid(pyramid)
    lb = pyramid.tile_from_xy(bounds.left,
                              bounds.bottom,
                              zoom,
                              on_edge_use="rt").bounds
    rt = pyramid.tile_from_xy(bounds.right, bounds.top, zoom,
                              on_edge_use="lb").bounds
    return Bounds(lb.left, lb.bottom, rt.right, rt.top)
示例#8
0
def _validate_bounds(ctx, param, bounds):
    return validate_bounds(bounds) if bounds else None