Ejemplo n.º 1
0
def test_overview_valid(monkeypatch):
    """Should work as expected (create cogeo file)."""
    monkeypatch.setenv("GDAL_DISABLE_READDIR_ON_OPEN", "TRUE")
    monkeypatch.setenv("GDAL_TIFF_INTERNAL_MASK", "TRUE")
    monkeypatch.setenv("GDAL_TIFF_OVR_BLOCKSIZE", "128")

    runner = CliRunner()
    with runner.isolated_filesystem():
        with open("mosaic.json", "w") as f:
            f.write(json.dumps(mosaic_content))
        create_low_level_cogs("mosaic.json", deflate_profile)
        with rasterio.open("mosaic_ovr_0.tif") as src:
            assert src.height == 512
            assert src.width == 512
            assert src.meta["dtype"] == "uint16"
            assert src.is_tiled
            assert src.profile["blockxsize"] == 256
            assert src.profile["blockysize"] == 256
            assert src.compression.value == "DEFLATE"
            assert src.interleaving.value == "PIXEL"
            assert src.overviews(1) == [2]
            assert src.tags()["OVR_RESAMPLING_ALG"] == "NEAREST"

        with rasterio.open("mosaic_ovr_0.tif", OVERVIEW_LEVEL=0) as src:
            assert src.block_shapes[0] == (128, 128)
Ejemplo n.º 2
0
def overview(input_mosaic, cogeo_profile, prefix, threads, overview_level,
             creation_options):
    """Create COG overviews for a mosaic."""
    mosaic_def = get_mosaic_content(input_mosaic)

    output_profile = cog_profiles.get(cogeo_profile)
    output_profile.update(dict(BIGTIFF=os.environ.get("BIGTIFF", "IF_SAFER")))
    if creation_options:
        output_profile.update(creation_options)

    config = dict(
        GDAL_NUM_THREADS="ALL_CPU",
        GDAL_TIFF_INTERNAL_MASK=os.environ.get("GDAL_TIFF_INTERNAL_MASK",
                                               True),
        GDAL_TIFF_OVR_BLOCKSIZE="128",
    )
    if not prefix:
        prefix = os.path.basename(input_mosaic).split(".")[0]

    create_low_level_cogs(
        mosaic_def,
        output_profile,
        prefix,
        max_overview_level=overview_level,
        config=config,
        threads=threads,
    )
Ejemplo n.º 3
0
def create_overview(file, output_profile, config, overview_level):
    create_low_level_cogs(
        str(file),
        output_profile=output_profile,
        prefix=Path(file).stem,
        max_overview_level=overview_level,
        config=config,
        threads=1,
    )
Ejemplo n.º 4
0
def test_overview_valid():
    """Should work as expected (create cogeo file)."""
    runner = CliRunner()
    with runner.isolated_filesystem():
        create_low_level_cogs(mosaic_content, deflate_profile)
        with rasterio.open("mosaic_ovr_0.tif") as src:
            assert src.height == 512
            assert src.width == 512
            assert src.meta["dtype"] == "uint16"
            assert src.is_tiled
            assert src.profile["blockxsize"] == 256
            assert src.profile["blockysize"] == 256
            assert src.compression.value == "DEFLATE"
            assert src.interleaving.value == "PIXEL"
            assert src.overviews(1) == [2]
            assert src.tags()["OVR_RESAMPLING_ALG"] == "NEAREST"

        with rasterio.open("mosaic_ovr_0.tif", OVERVIEW_LEVEL=0) as src:
            assert src.block_shapes[0] == (128, 128)
Ejemplo n.º 5
0
def overview(input_mosaic, cogeo_profile, prefix, threads, overview_level,
             creation_options, yes):
    """Create a low resolution version of a mosaic."""
    if input_mosaic.startswith("dynamodb://") and not yes:
        value = click.prompt(
            click.style(
                f"Creating overviews from a DynamoDB-backed mosaic will many read requests and might be expensive. Continue? (Y/n)"
            ),
            type=str,
            default="Y",
            err=True,
        )

        if value.lower() != "y":
            click.secho("Alright, this might be a good thing!", err=True)
            return

    output_profile = cog_profiles.get(cogeo_profile)
    output_profile.update(dict(BIGTIFF=os.environ.get("BIGTIFF", "IF_SAFER")))
    if creation_options:
        output_profile.update(creation_options)

    config = dict(
        GDAL_NUM_THREADS="ALL_CPU",
        GDAL_TIFF_INTERNAL_MASK=os.environ.get("GDAL_TIFF_INTERNAL_MASK",
                                               True),
        GDAL_TIFF_OVR_BLOCKSIZE="128",
    )
    if not prefix:
        prefix = os.path.basename(input_mosaic).split(".")[0]

    create_low_level_cogs(
        input_mosaic,
        output_profile,
        prefix,
        max_overview_level=overview_level,
        config=config,
        threads=threads,
    )