Python rasterio.windows() Examples

The following are 11 code examples of rasterio.windows(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module rasterio , or try the search function .
Example #1
Source File: raster.py    From Pyspatialml with GNU General Public License v3.0 6 votes vote down vote up
def block_shape(self, value):
        """Set the windows size used for raster calculations, specified as a tuple
        (rows, columns).

        Parameters
        ----------
        value : tuple
            Tuple of integers for default block shape to read and write data from the
            Raster object for memory-safe calculations. Specified as (n_rows,n_columns).
        """
        if not isinstance(value, tuple):
            raise ValueError(
                "block_shape must be set using an integer tuple " "as (rows, cols)"
            )

        rows, cols = value

        if not isinstance(rows, int) or not isinstance(cols, int):
            raise ValueError(
                "tuple must consist of integer values referring "
                "to number of rows, cols"
            )

        self._block_shape = (rows, cols) 
Example #2
Source File: raster.py    From Pyspatialml with GNU General Public License v3.0 5 votes vote down vote up
def block_shape(self):
        """Return the windows size used for raster calculations, specified as a tuple
        (rows, columns).

        Returns
        -------
        tuple
            Block window shape that is currently set for the Raster as a tuple in the
            format of (n_rows, n_columns) in pixels.
        """
        return self._block_shape 
Example #3
Source File: raster.py    From Pyspatialml with GNU General Public License v3.0 5 votes vote down vote up
def block_shapes(self, rows, cols):
        """Generator for windows for optimal reading and writing based on the raster
        format Windows are returns as a tuple with xoff, yoff, width, height.

        Parameters
        ----------
        rows : int
            Height of window in rows.

        cols : int
            Width of window in columns.
        """

        for i in range(0, self.width, rows):
            if i + rows < self.width:
                num_cols = rows
            else:
                num_cols = self.width - i

            for j in range(0, self.height, cols):
                if j + cols < self.height:
                    num_rows = rows
                else:
                    num_rows = self.height - j

                yield Window(i, j, num_cols, num_rows) 
Example #4
Source File: distanceWeightCalculation_raster2Polygon.py    From python-urbanPlanning with MIT License 5 votes vote down vote up
def divide_chunks(l,n):
    # looping till length l 
    for i in range(0, len(l), n):  
        yield l[i:i + n] 
#建立用于rasterio库分批读取一个较大Raster数据的windows列表(如果内存溢出,而要处理较大的单独raster数据时)
#关于rasterio的window数据格式可以查看其官方网站 
Example #5
Source File: distanceWeightCalculation_raster2Polygon.py    From python-urbanPlanning with MIT License 5 votes vote down vote up
def rasterio_windows(totalWidth,totalHeight,subWidth,subHeight):
    w_n=list(divide_chunks(list(range(totalWidth)), subWidth))
    h_n=list(divide_chunks(list(range(totalHeight)), subHeight))
    wins=[Window(w[0],h[0],len(w),len(h)) for h in h_n for w in w_n]
    # print(wins)
    print("raster windows amount:",len(wins))
    return wins

#meter=degree*(2 * math.pi * 6378137.0)/ 360  degree=50/(2 * math.pi * 6378137.0) * 360 
Example #6
Source File: rasterBuildingHeightZSplit.py    From python-urbanPlanning with MIT License 5 votes vote down vote up
def divide_chunks(l,n):
    # looping till length l 
    for i in range(0, len(l), n):  
        yield l[i:i + n] 

#建立用于rasterio库分批读取一个较大Raster数据的windows列表(如果内存溢出,而要处理较大的单独raster数据时)
#关于rasterio的window数据格式可以查看其官方网站 
Example #7
Source File: rasterBuildingHeightZSplit.py    From python-urbanPlanning with MIT License 5 votes vote down vote up
def rasterio_windows(totalWidth,totalHeight,subWidth,subHeight):
    w_n=list(divide_chunks(list(range(totalWidth)), subWidth))
    h_n=list(divide_chunks(list(range(totalHeight)), subHeight))
    wins=[Window(w[0],h[0],len(w),len(h)) for h in h_n for w in w_n]
    # print(wins)
    '''之下的代码繁复,并无法处理边界高宽问题,弃之'''
    # if totalWidth%subWidth==0 and totalHeight%subHeight==0:
    #     w_n=[subWidth*i for i in range(totalWidth//subWidth)]
    #     h_n=[subHeight*i for i in range(totalHeight//subHeight)]
    #     wins=[Window(w,h,subWidth,subHeight) for h in h_n for w in w_n]
    
    # if totalWidth%subWidth==0 and totalHeight%subHeight!=0:
    #     w_n=[subWidth*i for i in range(totalWidth//subWidth)]
    #     h_n=[subHeight*i for i in range(totalHeight//subHeight+1)]
    #     wins=[Window(w,h,subWidth,subHeight) for h in h_n for w in w_n]
            
    # if totalWidth%subWidth!=0 and totalHeight%subHeight==0:
    #     w_n=[subWidth*i for i in range(totalWidth//subWidth+1)]
    #     h_n=[subHeight*i for i in range(totalHeight//subHeight)]
    #     wins=[Window(w,h,subWidth,subHeight) for h in h_n for w in w_n]    
        
    # if totalWidth%subWidth!=0 and totalHeight%subHeight!=0:
    #     w_n=[subWidth*i for i in range(totalWidth//subWidth+1)]
    #     h_n=[subHeight*i for i in range(totalHeight//subHeight+1)]
    #     wins=[Window(w,h,subWidth,subHeight) for h in h_n for w in w_n]            
        
    print("raster windows amount:",len(wins))
    return wins

#testing 测试部分,可丢弃 
Example #8
Source File: rasterBuildingHeightZSplit_reclassify.py    From python-urbanPlanning with MIT License 5 votes vote down vote up
def rasterio_windows(totalWidth,totalHeight,subWidth,subHeight):
    w_n=list(divide_chunks(list(range(totalWidth)), subWidth))
    h_n=list(divide_chunks(list(range(totalHeight)), subHeight))
    wins=[Window(w[0],h[0],len(w),len(h)) for h in h_n for w in w_n]
    # print(wins)
        
    print("raster windows amount:",len(wins))
    return wins

# @njit(parallel=True)
#栅格重分类计算。如果栅格数据很大,采用rasterio的window读取数据,并计算,可以避免内存溢出 
Example #9
Source File: SVF_array_Final_bigRaster.py    From python-urbanPlanning with MIT License 5 votes vote down vote up
def rasterio_windows(totalWidth,totalHeight,subWidth,subHeight):
    w_n=list(divide_chunks(list(range(totalWidth)), subWidth))
    h_n=list(divide_chunks(list(range(totalHeight)), subHeight))
    wins=[Window(w[0],h[0],len(w),len(h)) for h in h_n for w in w_n]
    # print(wins)
    print("raster windows amount:",len(wins))
    return wins


# @njit(parallel=True)
# @cuda.jit(debug=True) 
Example #10
Source File: SVF_array_Final_bigRaster.py    From python-urbanPlanning with MIT License 5 votes vote down vote up
def divide_chunks(l,n):
    # looping till length l 
    for i in range(0, len(l), n):  
        yield l[i:i + n] 
#建立用于rasterio库分批读取一个较大Raster数据的windows列表(如果内存溢出,而要处理较大的单独raster数据时)
#关于rasterio的window数据格式可以查看其官方网站 
Example #11
Source File: SVF_array_Final_bigRaster.py    From python-urbanPlanning with MIT License 5 votes vote down vote up
def rasterio_windows(totalWidth,totalHeight,subWidth,subHeight):
    w_n=list(divide_chunks(list(range(totalWidth)), subWidth))
    h_n=list(divide_chunks(list(range(totalHeight)), subHeight))
    wins=[Window(w[0],h[0],len(w),len(h)) for h in h_n for w in w_n]
    # print(wins)
    print("raster windows amount:",len(wins))
    return wins


# @njit(parallel=True)
# @cuda.jit(debug=True)