Beispiel #1
0
class Carta:
    def __init__(self, filepath, options=None):
        self.raster = Raster(filepath)
        self.ds = self.raster.ds
        self.options = options

    def bounds(self):
        return self.raster.bounds()

    def clip(self, shape):
        return CartaArray(self.raster.clip_as_array(shape), self.options)

    def band(self):
        try:
            return self.options.band
        except:
            return 1

    def iter_band_blocks(self):
        band = self.ds.GetRasterBand(self.band())
        bSize = band.GetBlockSize()[0]
        rows = band.YSize
        cols = band.XSize

        for i in range(0, rows, bSize):
            if i + bSize < rows:
                numRows = bSize
            else:
                numRows = rows - i

            for j in range(0, cols, bSize):
                if j + bSize < cols:
                    numCols = bSize
                else:
                    numCols = cols - j
                block = band.ReadAsArray(j, i, numCols, numRows)
                yield(block)
Beispiel #2
0
 def __init__(self, filepath, options=None):
     self.raster = Raster(filepath)
     self.ds = self.raster.ds
     self.options = options