Commit 461f74ab authored by Opa-'s avatar Opa- Committed by Tim Graham
Browse files

Fixed #26432 -- Fixed size tuple order when using numpy reshape on a GDALBand.

parent 93deb169
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -222,8 +222,10 @@ class GDALBand(GDALBase):
            if as_memoryview:
                return memoryview(data_array)
            elif numpy:
                # reshape() needs a reshape parameter with the height first.
                return numpy.frombuffer(
                    data_array, dtype=numpy.dtype(data_array)).reshape(size)
                    data_array, dtype=numpy.dtype(data_array)
                ).reshape(tuple(reversed(size)))
            else:
                return list(data_array)
        else:
+174 −0

File added.

Preview size limit exceeded, changes collapsed.

+6 −0
Original line number Diff line number Diff line
@@ -320,6 +320,12 @@ class GDALBandTests(SimpleTestCase):
        self.assertEqual(self.band.datatype(), 1)
        self.assertEqual(self.band.datatype(as_string=True), 'GDT_Byte')
        self.assertEqual(self.band.nodata_value, 15)
        data = self.band.data()
        assert_array = numpy.loadtxt(
            os.path.join(os.path.dirname(upath(__file__)), '../data/rasters/raster.numpy.txt')
        )
        numpy.testing.assert_equal(data, assert_array)
        self.assertEqual(data.shape, (self.band.height, self.band.width))
        try:
            smin, smax, smean, sstd = self.band.statistics(approximate=True)
            self.assertEqual(smin, 0)