#NEWLINE# def data( self , data = None , offset = None , size = None , shape = None , as_memoryview = False ) : #NEWLINE# #INDENT# '\n        Reads or writes pixel values for this band. Blocks of data can\n        be accessed by specifying the width, height and offset of the\n        desired block. The same specification can be used to update\n        parts of a raster by providing an array of values.\n\n        Allowed input data types are bytes, memoryview, list, tuple, and array.\n        ' #NEWLINE# if ( not offset ) : #NEWLINE# #INDENT# offset = ( 0 , 0 ) #NEWLINE# #UNINDENT# if ( not size ) : #NEWLINE# #INDENT# size = ( ( self . width - offset [ 0 ] ) , ( self . height - offset [ 1 ] ) ) #NEWLINE# #UNINDENT# if ( not shape ) : #NEWLINE# #INDENT# shape = size #NEWLINE# #UNINDENT# if any ( ( ( x <= 0 ) for x in size ) ) : #NEWLINE# #INDENT# raise ValueError ( 'Offset too big for this raster.' ) #NEWLINE# #UNINDENT# if ( ( size [ 0 ] > self . width ) or ( size [ 1 ] > self . height ) ) : #NEWLINE# #INDENT# raise ValueError ( 'Size is larger than raster.' ) #NEWLINE# #UNINDENT# ctypes_array = ( GDAL_TO_CTYPES [ self . datatype ( ) ] * ( shape [ 0 ] * shape [ 1 ] ) ) #NEWLINE# if ( data is None ) : #NEWLINE# #INDENT# access_flag = 0 #NEWLINE# data_array = ctypes_array ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# access_flag = 1 #NEWLINE# if ( isinstance ( data , ( bytes , six . memoryview ) ) or ( numpy and isinstance ( data , numpy . ndarray ) ) ) : #NEWLINE# #INDENT# data_array = ctypes_array . from_buffer_copy ( data ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# data_array = ctypes_array ( * data ) #NEWLINE# #UNINDENT# #UNINDENT# capi . band_io ( self . _ptr , access_flag , offset [ 0 ] , offset [ 1 ] , size [ 0 ] , size [ 1 ] , byref ( ctypes_array ) , shape [ 0 ] , shape [ 1 ] , self . datatype ( ) , 0 , 0 ) #NEWLINE# if ( data is None ) : #NEWLINE# #INDENT# if as_memoryview : #NEWLINE# #INDENT# return memoryview ( data_array ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if numpy : #NEWLINE# #INDENT# return numpy . frombuffer ( data_array , dtype = numpy . dtype ( data_array ) ) . reshape ( tuple ( reversed ( size ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return list ( data_array ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# self . _flush ( )