Last active
June 14, 2018 15:26
-
-
Save perrygeo/31c58d154bed2e5907775566cc8abb49 to your computer and use it in GitHub Desktop.
Tiled=true fails silently
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from pprint import pprint | |
from functools import reduce | |
import operator | |
import numpy as np | |
from affine import Affine | |
from rasterio.crs import CRS | |
import rasterio | |
image_shape = (4, 128, 128) | |
blocksizes = (128, 128) | |
size = reduce(operator.mul, image_shape, 1) | |
arr = ( | |
np.random.randint(low=-0, high=255, size=size) | |
.astype("uint8") | |
.reshape(image_shape) | |
) | |
options = { | |
"driver": "GTiff", | |
"dtype": "uint8", | |
"nodata": None, | |
"count": image_shape[0], | |
"width": image_shape[1], | |
"height": image_shape[2], | |
"crs": CRS({"init": "epsg:3857"}), | |
"transform": Affine(600, 0.0, -20037508, 0.0, -600, -939258), | |
"tiled": True, | |
"compress": "JPEG", | |
"interleave": "pixel", | |
"blockxsize": blocksizes[0], | |
"blockysize": blocksizes[1], | |
} | |
with rasterio.open('/tmp/out.tif', 'w', **options) as dst: | |
dst.write(arr) | |
with rasterio.open('/tmp/out.tif', 'r') as test_src: | |
pprint(test_src.profile) | |
assert test_src.is_tiled |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Results when the image shape dimensions are less than blocksize (error)
Results when the image dimensions are equal to blocksize (silently ignore geotiff tiling)
Only when the image dimensions are greater than the blocksize does the assertion of internally tiled output hold.