def test_raster_should_get_block_list(self): filename = 'data/RGB.byte.tif' raster = Raster(filename) blocks = raster.block_windows() self.assertEqual(blocks.next(), (0, 0, raster.meta['block_size'][0], raster.meta['block_size'][1])) last_block = None length = 1 total_height = raster.block_size[1] while True: try: last_block = blocks.next() length += 1 total_height += last_block[3] except StopIteration: break self.assertEqual(last_block, (0, 717, raster.meta['block_size'][0], 1)) self.assertEqual(length, 240) self.assertEqual(total_height, raster.meta['height'])
def test_raster_should_get_block_list_with_given_size(self): filename = 'data/RGB.byte.tif' raster = Raster(filename) xsize = 7 ysize = 2 lastx = raster.meta['width'] - xsize lasty = raster.meta['height'] - ysize number_blocks = \ raster.meta['width'] / xsize * raster.meta['height'] / ysize blocks = raster.block_windows(block_size=(xsize, ysize)) self.assertEqual(blocks.next(), (0, 0, xsize, ysize)) last_block = None length = 1 while True: try: last_block = blocks.next() length += 1 except StopIteration: break self.assertEqual(last_block, (lastx, lasty, xsize, ysize)) self.assertEqual(length, number_blocks)