osgeo.gdal_array module

osgeo.gdal_array.AddNumpyArrayToDict(PyObject * dict, ArrowSchema const * schemaField, ArrowArray const * arrayField, std::string const & osPrefix, PyObject * pointerArrayKeeper) bool
osgeo.gdal_array.BandRasterIONumPy(Band band, int bWrite, double xoff, double yoff, double xsize, double ysize, PyArrayObject * psArray, GDALDataType buf_type, GDALRIOResampleAlg resample_alg, GDALProgressFunc callback=0, void * callback_data=None) CPLErr
osgeo.gdal_array.BandReadAsArray(band, xoff=0, yoff=0, win_xsize=None, win_ysize=None, buf_xsize=None, buf_ysize=None, buf_type=None, buf_obj=None, resample_alg=0, callback=None, callback_data=None)

Pure python implementation of reading a chunk of a GDAL file into a numpy array. Used by the gdal.Band.ReadAsArray method.

osgeo.gdal_array.BandWriteArray(band, array, xoff=0, yoff=0, resample_alg=0, callback=None, callback_data=None)

Pure python implementation of writing a chunk of a GDAL file from a numpy array. Used by the gdal.Band.WriteArray method.

osgeo.gdal_array.CopyDatasetInfo(src, dst, xoff=0, yoff=0)

Copy georeferencing information and metadata from one dataset to another. src: input dataset dst: output dataset - It can be a ROI - xoff, yoff: dst's offset with respect to src in pixel/line.

Notes: Destination dataset must have update access. Certain formats

do not support creation of geotransforms and/or gcps.

osgeo.gdal_array.DatasetIONumPy(Dataset ds, int bWrite, double xoff, double yoff, double xsize, double ysize, PyArrayObject * psArray, GDALDataType buf_type, GDALRIOResampleAlg resample_alg, GDALProgressFunc callback=0, void * callback_data=None, bool binterleave=True, int band_list=0) CPLErr
osgeo.gdal_array.DatasetReadAsArray(ds, xoff=0, yoff=0, win_xsize=None, win_ysize=None, buf_obj=None, buf_xsize=None, buf_ysize=None, buf_type=None, resample_alg=0, callback=None, callback_data=None, interleave='band', band_list=None)

Pure python implementation of reading a chunk of a GDAL file into a numpy array. Used by the gdal.Dataset.ReadAsArray method.

osgeo.gdal_array.DatasetWriteArray(ds, array, xoff=0, yoff=0, band_list=None, interleave='band', resample_alg=0, callback=None, callback_data=None)

Pure python implementation of writing a chunk of a GDAL file from a numpy array. Used by the gdal.Dataset.WriteArray method.

osgeo.gdal_array.DontUseExceptions()

Disable exceptions in all GDAL related modules (osgeo.gdal, osgeo.ogr, osgeo.osr, osgeo.gnm). Note: prior to GDAL 3.7, this only affected the calling module

class osgeo.gdal_array.ExceptionMgr(useExceptions=True)

Bases: object

Context manager to manage Python Exception state for GDAL/OGR/OSR/GNM.

Separate exception state is maintained for each module (gdal, ogr, etc), and this class appears independently in all of them. This is built in top of calls to the older UseExceptions()/DontUseExceptions() functions.

Example:

>>> print(gdal.GetUseExceptions())
0
>>> with gdal.ExceptionMgr():
...     # Exceptions are now in use
...     print(gdal.GetUseExceptions())
1
>>>
>>> # Exception state has now been restored
>>> print(gdal.GetUseExceptions())
0
osgeo.gdal_array.ExtendedDataTypeToNumPyDataType(dt)
osgeo.gdal_array.GDALTypeCodeToNumericTypeCode(gdal_code)
osgeo.gdal_array.GetArrayFilename(PyArrayObject * psArray) retStringAndCPLFree *
osgeo.gdal_array.GetUseExceptions() int
osgeo.gdal_array.LoadFile(filename, xoff=0, yoff=0, xsize=None, ysize=None, buf_xsize=None, buf_ysize=None, buf_type=None, resample_alg=0, callback=None, callback_data=None, interleave='band', band_list=None)
osgeo.gdal_array.MDArrayIONumPy(bool bWrite, GDALMDArrayHS * mdarray, PyArrayObject * psArray, int nDims1, int nDims3, GDALExtendedDataTypeHS * buffer_datatype) CPLErr
osgeo.gdal_array.MDArrayReadAsArray(mdarray, array_start_idx=None, count=None, array_step=None, buffer_datatype=None, buf_obj=None)
osgeo.gdal_array.MDArrayWriteArray(mdarray, array, array_start_idx=None, array_step=None)
osgeo.gdal_array.NumericTypeCodeToGDALTypeCode(numeric_type)
osgeo.gdal_array.OpenArray(array, prototype_ds=None, interleave='band')
osgeo.gdal_array.OpenMultiDimensionalNumPyArray(PyArrayObject * psArray) Dataset
osgeo.gdal_array.OpenNumPyArray(PyArrayObject * psArray, bool binterleave) Dataset
osgeo.gdal_array.RATReadArray(rat, field, start=0, length=None)

Pure Python implementation of reading a chunk of the RAT into a numpy array. Called from RasterAttributeTable.ReadAsArray

osgeo.gdal_array.RATValuesIONumPyRead(RasterAttributeTable poRAT, int nField, int nStart, int nLength) PyObject *
osgeo.gdal_array.RATValuesIONumPyWrite(RasterAttributeTable poRAT, int nField, int nStart, PyArrayObject * psArray) CPLErr
osgeo.gdal_array.RATWriteArray(rat, array, field, start=0)

Pure Python implementation of writing a chunk of the RAT from a numpy array. Type of array is coerced to one of the types (int, double, string) supported. Called from RasterAttributeTable.WriteArray

osgeo.gdal_array.SaveArray(src_array, filename, format='GTiff', prototype=None, interleave='band')
osgeo.gdal_array.TermProgress_nocb(double dfProgress, char const * pszMessage=None, void * pData=None) int
osgeo.gdal_array.UseExceptions()

Enable exceptions in all GDAL related modules (osgeo.gdal, osgeo.ogr, osgeo.osr, osgeo.gnm). Note: prior to GDAL 3.7, this only affected the calling module

class osgeo.gdal_array.VirtualMem(*args, **kwargs)

Bases: object

Proxy of C++ CPLVirtualMemShadow class.

GetAddr(VirtualMem self)
Pin(VirtualMem self, size_t start_offset=0, size_t nsize=0, int bWriteOp=0)
property thisown

The membership flag

osgeo.gdal_array.VirtualMemGetArray(VirtualMem virtualmem)
osgeo.gdal_array.flip_code(code)