Skip to main content

GDALRaster

Wrap a raster GDAL Data Source object.

Attributes

AttributeTypeDescription
destructorcallable = capi.close_dsThe GDAL C API function used to close the data source and release resources when the object is destroyed.

Constructor

Signature

def GDALRaster(
ds_input: str | Path | bytes | dict | c_void_p,
write: boolean = False
) - > null

Parameters

NameTypeDescription
ds_input`strPath
writeboolean = FalseIndicates whether the raster should be opened or created in write mode.

Methods


vsi_buffer()

@classmethod
def vsi_buffer() - > bytes

Retrieves the raw bytes from an in-memory VSI-based raster and deletes the buffer upon reading.

Returns

TypeDescription
bytesThe binary data of the raster buffer, or None if not a VSI memory raster

is_vsi_based()

@classmethod
def is_vsi_based() - > boolean

Determines if the raster is stored within the GDAL Virtual File System (VSI).

Returns

TypeDescription
booleanTrue if the raster path starts with the VSI prefix, False otherwise

name()

@classmethod
def name() - > string

Return the name of this raster. Corresponds to filename for file-based rasters.

Returns

TypeDescription
stringThe description or filename of the GDAL data source

driver()

@classmethod
def driver() - > [Driver](../../driver/driver.md?sid=django_contrib_gis_gdal_driver_driver)

Return the GDAL Driver used for this raster.

Returns

TypeDescription
[Driver](../../driver/driver.md?sid=django_contrib_gis_gdal_driver_driver)The GDAL Driver instance associated with this raster

width()

@classmethod
def width() - > integer

Width (X axis) in pixels.

Returns

TypeDescription
integerThe number of pixels along the X axis

height()

@classmethod
def height() - > integer

Height (Y axis) in pixels.

Returns

TypeDescription
integerThe number of pixels along the Y axis

srs()

@classmethod
def srs() - > [SpatialReference](../../srs/spatialreference.md?sid=django_contrib_gis_gdal_srs_spatialreference)

Return the SpatialReference used in this GDALRaster.

Returns

TypeDescription
[SpatialReference](../../srs/spatialreference.md?sid=django_contrib_gis_gdal_srs_spatialreference)The spatial reference system object, or None if not defined

srid()

@classmethod
def srid() - > integer

Shortcut to access the srid of this GDALRaster.

Returns

TypeDescription
integerThe spatial reference identifier (SRID)

geotransform()

@classmethod
def geotransform() - > array

Return the geotransform of the data source. Return the default geotransform if it does not exist or has not been set previously. The default is [0.0, 1.0, 0.0, 0.0, 0.0, -1.0].

Returns

TypeDescription
arrayA list of 6 coefficients for transforming pixel/line coordinates into georeferenced coordinates

origin()

@classmethod
def origin() - > [TransformPoint](transformpoint.md?sid=django_contrib_gis_gdal_raster_source_transformpoint)

Coordinates of the raster origin.

Returns

TypeDescription
[TransformPoint](transformpoint.md?sid=django_contrib_gis_gdal_raster_source_transformpoint)A point object representing the X and Y coordinates of the top-left corner

scale()

@classmethod
def scale() - > [TransformPoint](transformpoint.md?sid=django_contrib_gis_gdal_raster_source_transformpoint)

Pixel scale in units of the raster projection.

Returns

TypeDescription
[TransformPoint](transformpoint.md?sid=django_contrib_gis_gdal_raster_source_transformpoint)A point object representing the pixel width and height

skew()

@classmethod
def skew() - > [TransformPoint](transformpoint.md?sid=django_contrib_gis_gdal_raster_source_transformpoint)

Skew of pixels (rotation parameters).

Returns

TypeDescription
[TransformPoint](transformpoint.md?sid=django_contrib_gis_gdal_raster_source_transformpoint)A point object representing the X and Y skew/rotation coefficients

extent()

@classmethod
def extent() - > array

Return the extent as a 4-tuple (xmin, ymin, xmax, ymax).

Returns

TypeDescription
arrayA tuple containing the minimum and maximum X and Y coordinates

bands()

@classmethod
def bands() - > [BandList](../band/bandlist.md?sid=django_contrib_gis_gdal_raster_band_bandlist)

Provides access to the collection of raster bands.

Returns

TypeDescription
[BandList](../band/bandlist.md?sid=django_contrib_gis_gdal_raster_band_bandlist)An iterable list-like object containing the GDALBand instances

warp()

@classmethod
def warp(
ds_input: dict,
resampling: string = NearestNeighbour,
max_error: float = 0.0
) - > [GDALRaster](gdalraster.md?sid=django_contrib_gis_gdal_raster_source_gdalraster)

Return a warped GDALRaster with the given input characteristics.

Parameters

NameTypeDescription
ds_inputdictDictionary containing target raster parameters like width, height, SRID, and origin
resamplingstring = NearestNeighbourThe resampling algorithm to use during the warp process
max_errorfloat = 0.0The maximum error measured in input pixels that is allowed in approximating the transformation

Returns

TypeDescription
[GDALRaster](gdalraster.md?sid=django_contrib_gis_gdal_raster_source_gdalraster)A new GDALRaster instance containing the warped data

clone()

@classmethod
def clone(
name: string = null
) - > [GDALRaster](gdalraster.md?sid=django_contrib_gis_gdal_raster_source_gdalraster)

Return a clone of this GDALRaster.

Parameters

NameTypeDescription
namestring = nullThe filename or path for the cloned raster; if omitted, a default name is generated based on the driver

Returns

TypeDescription
[GDALRaster](gdalraster.md?sid=django_contrib_gis_gdal_raster_source_gdalraster)A new GDALRaster instance that is a copy of the current one

transform()

@classmethod
def transform(
srs: SpatialReference|int|str,
driver: string = null,
name: string = null,
resampling: string = NearestNeighbour,
max_error: float = 0.0
) - > [GDALRaster](gdalraster.md?sid=django_contrib_gis_gdal_raster_source_gdalraster)

Return a copy of this raster reprojected into the given spatial reference system.

Parameters

NameTypeDescription
srs`SpatialReferenceint
driverstring = nullThe name of the GDAL driver to use for the transformed raster
namestring = nullThe filename or path for the transformed raster
resamplingstring = NearestNeighbourThe resampling algorithm to use during reprojection
max_errorfloat = 0.0The maximum error allowed in approximating the transformation

Returns

TypeDescription
[GDALRaster](gdalraster.md?sid=django_contrib_gis_gdal_raster_source_gdalraster)A new GDALRaster instance reprojected to the target SRS

info()

@classmethod
def info() - > string

Return information about this raster in a string format equivalent to the output of the gdalinfo command line utility.

Returns

TypeDescription
stringA formatted string containing metadata and technical details about the raster