This commit is contained in:
Sean Gillies 2015-11-05 16:59:37 -07:00
parent 9bd498a724
commit 3304f8be45
3 changed files with 33 additions and 10 deletions

View File

@ -1298,6 +1298,13 @@ cdef class RasterUpdater(RasterReader):
continue
kwds.append((k.lower(), v))
k, v = k.upper(), str(v).upper()
# Guard against block size that exceed image size.
if k == 'BLOCKXSIZE' and int(v) > self.width:
raise ValueError("blockxsize exceeds raster width.")
if k == 'BLOCKYSIZE' and int(v) > self.height:
raise ValueError("blockysize exceeds raster height.")
key_b = k.encode('utf-8')
val_b = v.encode('utf-8')
key_c = key_b
@ -1310,6 +1317,7 @@ cdef class RasterUpdater(RasterReader):
self._hds = _gdal.GDALCreate(
drv, fname, self.width, self.height, self._count,
gdal_dtype, options)
if self._hds == NULL:
raise ValueError("NULL dataset")

View File

@ -1,15 +1,16 @@
import logging
import os.path
import unittest
import shutil
import subprocess
import sys
import tempfile
import unittest
import numpy
import rasterio
logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
class WindowTest(unittest.TestCase):
@ -120,4 +121,3 @@ class WindowWriteTest(unittest.TestCase):
"Minimum=0.000, Maximum=127.000, "
"Mean=31.750, StdDev=54.993" in info.decode('utf-8'),
info)

View File

@ -60,14 +60,29 @@ def test_gtiff_profile_protected_driver():
def test_open_with_profile(tmpdir):
tiffname = str(tmpdir.join('foo.tif'))
with rasterio.open(
tiffname,
'w',
**default_gtiff_profile(
count=1, width=1, height=1)) as dst:
data = dst.read()
assert data.flatten().tolist() == [0]
tiffname = str(tmpdir.join('foo.tif'))
with rasterio.open(
tiffname,
'w',
**default_gtiff_profile(
count=1, width=256, height=256)) as dst:
data = dst.read()
def test_blockxsize_guard(tmpdir):
"""blockxsize can't be greater than image width."""
tiffname = str(tmpdir.join('foo.tif'))
with pytest.raises(ValueError):
_ = rasterio.open(tiffname, 'w', **default_gtiff_profile(
count=1, width=128, height=256))
def test_blockysize_guard(tmpdir):
"""blockysize can't be greater than image height."""
tiffname = str(tmpdir.join('foo.tif'))
with pytest.raises(ValueError):
_ = rasterio.open(tiffname, 'w', **default_gtiff_profile(
count=1, width=256, height=128))
def test_profile_overlay():