Python Utilities

osgeo.gdal. AutoCreateWarpedVRT ( Dataset src_ds , char const * src_wkt=None , char const * dst_wkt=None , GDALResampleAlg eResampleAlg=GRA_NearestNeighbour , double maxerror=0.0 ) → Dataset  osgeo.gdal. BuildVRT ( destName , srcDSOrSrcDSTab , ** kwargs ) 

Build a VRT from a list of datasets.

Create a BuildVRTOptions() object that can be passed to gdal.BuildVRT()

Apply a DEM processing.

Create a DEMProcessingOptions() object that can be passed to gdal.DEMProcessing()

Compute the footprint of a raster

  1. Special mode to get deserialized GeoJSON (in EPSG:4326 if dstSRS not specified):
>>> deserialized_geojson = gdal.Footprint(None, src_ds, format="GeoJSON") 
  1. Special mode to get WKT:
>>> wkt = gdal.Footprint(None, src_ds, format="WKT") 
  1. Get result in a GeoPackage
>>> gdal.Footprint("out.gpkg", src_ds, format="GPKG") 

osgeo.gdal. FootprintOptions ( options = None , format = None , bands = None , combineBands = None , srcNodata = None , ovr = None , targetCoordinateSystem = None , dstSRS = None , splitPolys = None , convexHull = None , densify = None , simplify = None , maxPoints = None , minRingArea = None , layerName = None , locationFieldName = 'location' , writeAbsolutePath = False , layerCreationOptions = None , datasetCreationOptions = None , callback = None , callback_data = None ) 

Create a FootprintOptions() object that can be passed to gdal.Footprint()

Fill selected raster regions by interpolation from the edges.

This algorithm will interpolate values for all designated nodata pixels (marked by zeros in maskBand ). For each pixel a four direction conic search is done to find values to interpolate from (using inverse distance weighting by default). Once all values are interpolated, zero or more smoothing iterations (3x3 average filters on interpolated pixels) are applied to smooth out artifacts.

This algorithm is generally suitable for interpolating missing regions of fairly continuously varying rasters (such as elevation models for instance). It is also suitable for filling small holes and cracks in more irregularly varying images (like airphotos). It is generally not so great for interpolating a raster from sparse point data. See Grid() for that case.

CE_None on success or CE_Failure on failure.

>>> import numpy as np >>> data = np.array([[1, 2], [9, 9], [9, 9], [3, 4]], dtype=np.float32) >>> ds = gdal.GetDriverByName('MEM').Create('', 2, 4, eType=gdal.GDT_Float32) >>> ds.WriteArray(data) 0 >>> mask = data != 9 # replace pixels with value = 9 >>> mask_ds = gdal.GetDriverByName('MEM').Create('', 2, 4, eType=gdal.GDT_Byte) >>> mask_ds.WriteArray(mask) 0 >>> gdal.FillNodata(ds.GetRasterBand(1), mask_ds.GetRasterBand(1), 5, 0) 0 >>> ds.ReadAsArray() array([[1. , 2. ], [2.1485982, 2.6666667], [2.721169 , 3.3333333], [3. , 4. ]], dtype=float32) >>> gdal.FillNodata(ds.GetRasterBand(1), mask_ds.GetRasterBand(1), 5, 0, 'INTERPOLATION':'NEAREST'>) 0 >>> ds.ReadAsArray() array([[1., 2.], [1., 2.], [3., 4.], [3., 4.]], dtype=float32) 
osgeo.gdal. Grid ( destName , srcDS , ** kwargs ) 

Create raster from the scattered data.

Create a GridOptions() object that can be passed to gdal.Grid()

Return information on a raster dataset.

Create a InfoOptions() object that can be passed to gdal.Info() options can be be an array of strings, a string or let empty and filled from other keywords.

osgeo.gdal. Nearblack ( destNameOrDestDS , srcDS , ** kwargs ) 

Convert nearly black/white borders to exact value.

Create a NearblackOptions() object that can be passed to gdal.Nearblack()

Burns vector geometries into a raster

Create a RasterizeOptions() object that can be passed to gdal.Rasterize()

Suggest output dataset size and extent.

SuggestedWarpOutput(src: Dataset, transformer: Transformer) -> SuggestedWarpOutputRes SuggestedWarpOutput(src: Dataset, options: list[str]) -> SuggestedWarpOutputRes

This function is used to suggest the size, and georeferenced extents appropriate given the indicated transformation and input file. It walks the edges of the input file (approximately 20 sample points along each edge) transforming into output coordinates in order to get an extents box.

Then a resolution is computed with the intent that the length of the distance from the top left corner of the output imagery to the bottom right corner would represent the same number of pixels as in the source image. Note that if the image is somewhat rotated the diagonal taken isn't of the whole output bounding rectangle, but instead of the locations where the top/left and bottom/right corners transform. The output pixel size is always square. This is intended to approximately preserve the resolution of the input data in the output file.

There are 2 forms of this method:

>>> ds = gdal.Open("my.tif") . res = gdal.SuggestedWarpOutput(ds, ["DST_SRS=EPSG:4326"]) . print(res.width, res.height, res.xmin, res.ymin, res.xmax, res.ymax, res.geotransform) 
osgeo.gdal. TileIndex ( destName , srcFilenames , ** kwargs ) 

Build a tileindex from a list of datasets.

Create a TileIndexOptions() object that can be passed to gdal.TileIndex()

Convert a dataset.

Create a TranslateOptions() object that can be passed to gdal.Translate()

Warp one or several datasets.

Create a WarpOptions() object that can be passed to gdal.Warp()

Multidimensional Raster Utilities

osgeo.gdal. MultiDimInfo ( ds , ** kwargs ) 

Return information on a dataset.

Create a MultiDimInfoOptions() object that can be passed to gdal.MultiDimInfo() options can be be an array of strings, a string or let empty and filled from other keywords.

osgeo.gdal. MultiDimTranslate ( destName , srcDSOrSrcDSTab , ** kwargs ) 

MultiDimTranslate one or several datasets.

Create a MultiDimTranslateOptions() object that can be passed to gdal.MultiDimTranslate()

Vector Utilities

osgeo.gdal. VectorInfo ( ds , ** kwargs ) 

Return information on a vector dataset.

Create a VectorInfoOptions() object that can be passed to gdal.VectorInfo() options can be be an array of strings, a string or let empty and filled from other keywords.

Convert one vector dataset

Create a VectorTranslateOptions() object that can be passed to gdal.VectorTranslate()