Commit fdef2d76 authored by Daniel Scheffler's avatar Daniel Scheffler

Fixed issue #19 (GeoArray.tiles() fails in case of 2D array).

parent 38f67b09
Pipeline #2937 failed with stages
in 1 minute and 21 seconds
......@@ -1365,7 +1365,12 @@ class GeoArray(object):
def __iter__(self):
return self.gen
out_gen = ((((rS, rE), (cS, cE)), self[rS: rE + 1, cS: cE + 1, :]) for (rS, rE), (cS, cE) in bounds_alltiles)
if self.ndim == 3:
out_gen = ((((rS, rE), (cS, cE)), self[rS: rE + 1, cS: cE + 1, :])
for (rS, rE), (cS, cE) in bounds_alltiles)
else:
out_gen = ((((rS, rE), (cS, cE)), self[rS: rE + 1, cS: cE + 1])
for (rS, rE), (cS, cE) in bounds_alltiles)
return GeneratorLen(out_gen, length=len(bounds_alltiles))
......
......@@ -458,11 +458,15 @@ class Test_GeoarrayFunctions(unittest.TestCase):
self.assertIsInstance(self.testtiff.metadata, geopandas.GeoDataFrame)
def test_tiles(self):
tiles = self.testtiff.tiles(tilesize=(50, 50))
self.assertIsInstance(tiles, Iterable)
test_gAs = [self.testtiff, # 3D
GeoArray(self.testtiff[:, :, 0], geotransform=self.testtiff.gt, projection=self.testtiff.prj)] # 2D
for ((rS, rE), (cS, cE)), tile in tiles:
self.assertTrue(np.array_equal(tile, self.testtiff[rS: rE + 1, cS: cE + 1]))
for gA in test_gAs:
tiles = gA.tiles(tilesize=(50, 50))
self.assertIsInstance(tiles, Iterable)
for ((rS, rE), (cS, cE)), tile in tiles:
self.assertTrue(np.array_equal(tile, gA[rS: rE + 1, cS: cE + 1]))
def test_get_subset_3D_geoarray(self):
# test without resetting band names
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment