How to use the mapchete.cli.utils function in mapchete

To help you get started, we’ve selected a few mapchete examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ungarj / mapchete / mapchete / cli / default / convert.py View on Github external
@utils.opt_resampling_method
@utils.opt_overwrite
@utils.opt_verbose
@utils.opt_no_pbar
@utils.opt_debug
@utils.opt_multi
@utils.opt_logfile
@utils.opt_vrt
@utils.opt_idx_out_dir
def convert(
    input_,
    output,
    zoom=None,
    bounds=None,
    point=None,
    wkt_geometry=None,
    clip_geometry=None,
github ungarj / mapchete / mapchete / cli / default / execute.py View on Github external
no_pbar=False,
    debug=False,
    max_chunksize=None,
    vrt=False,
    idx_out_dir=None
):
    """Execute a Mapchete process."""
    mode = "overwrite" if overwrite else "continue"
    # send verbose messages to /dev/null if not activated
    verbose_dst = open(os.devnull, 'w') if debug or not verbose else sys.stdout

    for mapchete_file in mapchete_files:
        tqdm.tqdm.write("preparing to process %s" % mapchete_file, file=verbose_dst)
        # process single tile
        if tile:
            utils._process_single_tile(
                raw_conf_process_pyramid=raw_conf_process_pyramid,
                mapchete_config=mapchete_file,
                tile=tile,
                mode=mode,
                input_file=input_file,
                debug=debug,
                verbose_dst=verbose_dst,
                vrt=vrt,
                idx_out_dir=idx_out_dir,
                no_pbar=no_pbar
            )
        # process area
        else:
            utils._process_area(
                debug=debug,
                mapchete_config=mapchete_file,
github ungarj / mapchete / mapchete / cli / default / execute.py View on Github external
@utils.opt_verbose
@utils.opt_no_pbar
@utils.opt_debug
@utils.opt_max_chunksize
@utils.opt_vrt
@utils.opt_idx_out_dir
def execute(
    mapchete_files,
    zoom=None,
    bounds=None,
    point=None,
    wkt_geometry=None,
    tile=None,
    overwrite=False,
    multi=None,
    input_file=None,
    logfile=None,
github ungarj / mapchete / mapchete / cli / default / formats.py View on Github external
@utils.opt_input_formats
@utils.opt_output_formats
@utils.opt_debug
def formats(input_formats, output_formats, debug=False):
    """List input and/or output formats."""
    if input_formats == output_formats:
        show_inputs, show_outputs = True, True
    else:
        show_inputs, show_outputs = input_formats, output_formats

    if show_inputs:
        click.echo("input formats:")
        for driver in available_input_formats():
            click.echo("- %s" % driver)
    if show_outputs:
        click.echo("output formats:")
        for driver in available_output_formats():
github ungarj / mapchete / mapchete / cli / default / execute.py View on Github external
@utils.opt_logfile
@utils.opt_verbose
@utils.opt_no_pbar
@utils.opt_debug
@utils.opt_max_chunksize
def execute(
    mapchete_files,
    zoom=None,
    bounds=None,
    point=None,
    wkt_geometry=None,
    tile=None,
    overwrite=False,
    multi=None,
    input_file=None,
    logfile=None,
    verbose=False,
github ungarj / mapchete / mapchete / cli / default / processes.py View on Github external
@utils.opt_debug
def processes(process_name=None, docstrings=False, debug=False):
    """List available processes."""
    processes = process_names_docstrings(process_name=process_name)
    click.echo("%s processes found" % len(processes))
    for process_info in processes:
        _print_process_info(process_info, print_docstring=process_name is not None)
github ungarj / mapchete / mapchete / cli / default / index.py View on Github external
@utils.opt_point
@utils.opt_wkt_geometry
@utils.opt_tile
@utils.opt_verbose
@utils.opt_no_pbar
@utils.opt_debug
@utils.opt_logfile
def index(
    mapchete_files,
    idx_out_dir=None,
    geojson=False,
    gpkg=False,
    shp=False,
    vrt=False,
    txt=False,
    fieldname=None,
    basepath=None,
github ungarj / mapchete / mapchete / cli / default / execute.py View on Github external
return BufferedTilePyramid(
                _raw_conf()["pyramid"]["grid"],
                metatiling=_raw_conf()["pyramid"].get("metatiling", 1),
                pixelbuffer=_raw_conf()["pyramid"].get("pixelbuffer", 0)
            )

        # process single tile
        if tile:
            tile = _tp().tile(*tile)
            with mapchete.open(
                mapchete_file, mode=mode, bounds=tile.bounds,
                zoom=tile.zoom, single_input_file=input_file
            ) as mp:
                tqdm.tqdm.write("processing 1 tile", file=verbose_dst)
                for result in mp.batch_processor(tile=tile):
                    utils.write_verbose_msg(result, dst=verbose_dst)

        # initialize and run process
        else:
            if wkt_geometry:
                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
                )
                bounds = _tp().tile_from_xy(x, y, max(zoom_levels)).bounds
            else:
                bounds = bounds
            with mapchete.open(
                mapchete_file, bounds=bounds, zoom=zoom,
github ungarj / mapchete / mapchete / cli / default / convert.py View on Github external
click.echo(
                "Process area is empty: clip bounds don't intersect with input bounds."
            )
            return
    # add process bounds and output type
    mapchete_config.update(
        bounds=(
            clip_intersection.bounds
            if clip_geometry
            else inp_bounds
        ),
        clip_to_output_dtype=mapchete_config["output"].get("dtype", None)
    )
    logger.debug("temporary config generated: %s", pformat(mapchete_config))

    utils._process_area(
        debug=debug,
        mapchete_config=mapchete_config,
        mode="overwrite" if overwrite else "continue",
        zoom=zoom,
        wkt_geometry=wkt_geometry,
        point=point,
        bounds=bounds,
        multi=multi or cpu_count(),
        verbose_dst=open(os.devnull, 'w') if debug or not verbose else sys.stdout,
        no_pbar=no_pbar,
        vrt=vrt,
        idx_out_dir=idx_out_dir
    )
github ungarj / mapchete / mapchete / cli / default / create.py View on Github external
@utils.opt_out_path
@utils.opt_pyramid_type
@utils.opt_force
def create(
    mapchete_file,
    process_file,
    out_format,
    out_path=None,
    pyramid_type=None,
    force=False
):
    """Create an empty Mapchete and process file in a given directory."""
    if os.path.isfile(process_file) or os.path.isfile(mapchete_file):
        if not force:
            raise IOError("file(s) already exists")

    out_path = out_path if out_path else os.path.join(os.getcwd(), "output")