Wrap a raster GDAL Data Source object.
Attributes
| Attribute | Type | Description |
|---|
| destructor | callable = capi.close_ds | The 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
| Name | Type | Description |
|---|
| ds_input | `str | Path |
| write | boolean = False | Indicates 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
| Type | Description |
|---|
bytes | The 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
| Type | Description |
|---|
boolean | True 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
| Type | Description |
|---|
string | The 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
| Type | Description |
|---|
[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
| Type | Description |
|---|
integer | The number of pixels along the X axis |
height()
@classmethod
def height() - > integer
Height (Y axis) in pixels.
Returns
| Type | Description |
|---|
integer | The 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
| Type | Description |
|---|
[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
| Type | Description |
|---|
integer | The spatial reference identifier (SRID) |
@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
| Type | Description |
|---|
array | A 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
| Type | Description |
|---|
[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
| Type | Description |
|---|
[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
| Type | Description |
|---|
[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
| Type | Description |
|---|
array | A 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
| Type | Description |
|---|
[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
| Name | Type | Description |
|---|
| ds_input | dict | Dictionary containing target raster parameters like width, height, SRID, and origin |
| resampling | string = NearestNeighbour | The resampling algorithm to use during the warp process |
| max_error | float = 0.0 | The maximum error measured in input pixels that is allowed in approximating the transformation |
Returns
| Type | Description |
|---|
[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
| Name | Type | Description |
|---|
| name | string = null | The filename or path for the cloned raster; if omitted, a default name is generated based on the driver |
Returns
| Type | Description |
|---|
[GDALRaster](gdalraster.md?sid=django_contrib_gis_gdal_raster_source_gdalraster) | A new GDALRaster instance that is a copy of the current one |
@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
| Name | Type | Description |
|---|
| srs | `SpatialReference | int |
| driver | string = null | The name of the GDAL driver to use for the transformed raster |
| name | string = null | The filename or path for the transformed raster |
| resampling | string = NearestNeighbour | The resampling algorithm to use during reprojection |
| max_error | float = 0.0 | The maximum error allowed in approximating the transformation |
Returns
| Type | Description |
|---|
[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
| Type | Description |
|---|
string | A formatted string containing metadata and technical details about the raster |