No blocksizes in untiled profiles

Closes #502
This commit is contained in:
Sean Gillies 2015-10-22 12:30:22 -06:00
parent 4d79175b6c
commit 49938067bc
6 changed files with 33 additions and 8 deletions

View File

@ -448,6 +448,10 @@ cdef class DatasetReader(object):
else:
return None
@property
def is_tiled(self):
return self.block_shapes[0][1] != self.width
property profile:
"""Basic metadata and creation options of this dataset.
@ -457,10 +461,13 @@ cdef class DatasetReader(object):
def __get__(self):
m = self.meta
m.update(self.tags(ns='rio_creation_kwds'))
m.update(
blockxsize=self.block_shapes[0][1],
blockysize=self.block_shapes[0][0],
tiled=self.block_shapes[0][1] != self.width)
if self.is_tiled:
m.update(
blockxsize=self.block_shapes[0][1],
blockysize=self.block_shapes[0][0],
tiled=True)
else:
m.update(tiled=False)
if self.compression:
m['compress'] = self.compression.name
if self.interleaving:

View File

@ -73,6 +73,7 @@ def merge(ctx, files, output, driver, bounds, res, nodata, force_overwrite,
profile['height'] = dest.shape[1]
profile['width'] = dest.shape[2]
profile['driver'] = driver
profile.update(**creation_options)
with rasterio.open(output, 'w', **profile) as dst:

View File

@ -73,6 +73,8 @@ def _cb_key_val(ctx, param, value):
raise click.BadParameter("Invalid syntax for KEY=VAL arg: {}".format(pair))
else:
k, v = pair.split('=', 1)
k = k.lower()
v = v.lower()
out[k] = v
return out

Binary file not shown.

View File

@ -7,7 +7,7 @@ def test_cb_key_val():
pairs = ['KEY=val', '1==']
expected = {
'KEY': 'val',
'key': 'val',
'1': '=',
}
assert options._cb_key_val(None, None, pairs) == expected

View File

@ -79,11 +79,26 @@ def test_profile_overlay():
assert kwds['count'] == 3
def test_dataset_profile_property(data):
def test_dataset_profile_property_tiled(data):
"""An tiled dataset's profile has block sizes"""
with rasterio.open('tests/data/shade.tif') as src:
assert src.profile['blockxsize'] == 256
assert src.profile['blockysize'] == 256
assert src.profile['tiled'] == True
def test_dataset_profile_property_untiled(data):
"""An untiled dataset's profile has no block sizes"""
with rasterio.open('tests/data/RGB.byte.tif') as src:
assert 'blockxsize' not in src.profile
assert 'blockysize' not in src.profile
assert src.profile['tiled'] == False
def test_dataset_profile_creation_kwds(data):
"""Updated creation keyword tags appear in profile"""
tiffile = str(data.join('RGB.byte.tif'))
with rasterio.open(tiffile, 'r+') as src:
src.update_tags(ns='rio_creation_kwds', foo='bar')
assert src.profile['blockxsize'] == 791
assert src.profile['blockysize'] == 3
assert src.profile['tiled'] == False
assert src.profile['foo'] == 'bar'