Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_available_output_formats():
"""Check if default output formats can be listed."""
assert set(['GTiff', 'PNG', 'PNG_hillshade', 'GeoJSON']).issubset(
set(available_output_formats()))
def main():
"""Start tests."""
scriptdir = os.path.dirname(os.path.realpath(__file__))
"""drivers"""
from mapchete.formats import (
available_input_formats, available_output_formats, _file_ext_to_driver)
assert set(['Mapchete', 'raster_file', 'vector_file']).issubset(
set(available_input_formats()))
assert set(['GTiff', 'PNG', 'PNG_hillshade']).issubset(
set(available_output_formats()))
ext_to_driver = _file_ext_to_driver()
assert isinstance(ext_to_driver, dict)
assert set(['mapchete', 'tif', 'jp2', 'png', 'vrt']).issubset(
set(ext_to_driver))
for extension, driver in ext_to_driver.iteritems():
assert len(driver) == 1
"""config and base module"""
# Load source process from python file and initialize.
mapchete_file = os.path.join(scriptdir, "example.mapchete")
config = MapcheteConfig(mapchete_file)
process = Mapchete(config)
dummy1_abspath = os.path.join(scriptdir, "testdata/dummy1.tif")
dummy2_abspath = os.path.join(scriptdir, "testdata/dummy2.tif")
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():
click.echo("- %s" % driver)
metatiling=self.output_pyramid.metatiling,
delimiters=self._delimiters,
mode=self.mode
)
if "path" in output_params:
output_params.update(
path=absolute_path(path=output_params["path"], base_dir=self.config_dir)
)
if "format" not in output_params:
raise MapcheteConfigError("output format not specified")
if output_params["format"] not in available_output_formats():
raise MapcheteConfigError(
"format %s not available in %s" % (
output_params["format"], str(available_output_formats())
)
)
return output_params
"--output-format", type=click.Choice(available_output_formats()),
help="Output format."
)
@click.option(
"--output-dtype", type=click.Choice(dtype_ranges.keys()),
help="Output data type (for raster output only)."
)
@creation_options
@click.option(
"--scale-ratio", type=click.FLOAT, default=1.,
help="Scaling factor (for raster output only)."
)
@click.option(
"--scale-offset", type=click.FLOAT, default=0.,
help="Scaling offset (for raster output only)."
)
@utils.opt_resampling_method
"""Output object of driver."""
output_params = self._raw["output"]
if "path" in output_params:
output_params.update(
path=os.path.normpath(
os.path.join(self.config_dir, output_params["path"])))
output_params.update(
type=self.output_pyramid.grid,
pixelbuffer=self.output_pyramid.pixelbuffer,
metatiling=self.output_pyramid.metatiling)
if "format" not in output_params:
raise MapcheteConfigError("output format not specified")
if output_params["format"] not in available_output_formats():
raise MapcheteConfigError(
"format %s not available in %s" % (
output_params["format"], str(available_output_formats())))
writer = load_output_writer(output_params)
try:
writer.is_valid_with_config(output_params)
except Exception as e:
logger.exception(e)
raise MapcheteConfigError(
"driver %s not compatible with configuration: %s" % (
writer.METADATA["driver_name"], e))
return writer
from shapely.geometry import box
import sys
import tilematrix
from mapchete.cli import utils
from mapchete.config import raw_conf, raw_conf_output_pyramid
from mapchete.formats import (
driver_from_file, available_output_formats, available_input_formats
)
from mapchete.io import read_json, get_best_zoom_level
from mapchete.io.vector import reproject_geometry
from mapchete.tile import BufferedTilePyramid
from mapchete._validate import validate_zooms
logger = logging.getLogger(__name__)
OUTPUT_FORMATS = available_output_formats()
@click.command(help="Convert outputs or other geodata.")
@utils.arg_input
@utils.arg_output
@utils.opt_zoom
@utils.opt_bounds
@utils.opt_point
@utils.opt_wkt_geometry
@click.option(
"--clip-geometry", "-c", type=click.Path(exists=True),
help="Clip output by geometry"
)
@click.option(
"--output-pyramid", type=click.Choice(tilematrix._conf.PYRAMID_PARAMS.keys()),
help="Output pyramid to write to."
if logfile:
setup_logfile(logfile)
return logfile
# click arguments #
###################
arg_mapchete_file = click.argument("mapchete_file", type=click.Path(exists=True))
arg_create_mapchete_file = click.argument("mapchete_file", type=click.Path())
arg_mapchete_files = click.argument(
"mapchete_files", type=click.Path(exists=True), nargs=-1,
callback=_validate_mapchete_files
)
arg_process_file = click.argument("process_file", type=click.Path())
arg_out_format = click.argument(
"out_format", type=click.Choice(available_output_formats())
)
arg_input_raster = click.argument("input_raster", type=click.Path(exists=True))
arg_out_dir = click.argument("output_dir", type=click.Path())
arg_input = click.argument("input_", metavar="INPUT", type=click.STRING)
arg_output = click.argument("output", type=click.STRING)
# click options #
#################
opt_out_path = click.option(
"--out-path", "-op", type=click.Path(), default=os.path.join(os.getcwd(), "output"),
help="Process output path."
)
opt_idx_out_dir = click.option(
"--idx-out-dir", "-od", type=click.Path(),
help="Index output directory."
def list_formats(args):
"""List input and/or output formats."""
if args.input_formats == args.output_formats:
show_inputs, show_outputs = True, True
else:
show_inputs, show_outputs = args.input_formats, args.output_formats
if show_inputs:
print("input formats:")
for driver in available_input_formats():
print("-", driver)
if show_outputs:
print("output formats:")
for driver in available_output_formats():
print("-", driver)
def output(self):
"""Output object of driver."""
output_params = self._raw["output"]
if "path" in output_params:
output_params.update(
path=os.path.normpath(
os.path.join(self.config_dir, output_params["path"])))
output_params.update(
type=self.output_pyramid.grid,
pixelbuffer=self.output_pyramid.pixelbuffer,
metatiling=self.output_pyramid.metatiling)
if "format" not in output_params:
raise MapcheteConfigError("output format not specified")
if output_params["format"] not in available_output_formats():
raise MapcheteConfigError(
"format %s not available in %s" % (
output_params["format"], str(available_output_formats())))
writer = load_output_writer(output_params)
try:
writer.is_valid_with_config(output_params)
except Exception as e:
logger.exception(e)
raise MapcheteConfigError(
"driver %s not compatible with configuration: %s" % (
writer.METADATA["driver_name"], e))
return writer