Rasters Sources Using GDAL¶
-
Dataset.
open_raster
(key, path, driver='GTiff', options=(), mode='r')[source]¶ Open a raster file within this Dataset under key. Only metadata are kept in memory.
>>> help(GDALFileRaster)
Parameters
- key: hashable (like a string)
File identifier within Dataset
To avoid using a key, you may use
aopen_raster()
- path: string
- driver: string
gdal driver to use when opening the file http://www.gdal.org/formats_list.html
- options: sequence of str
options for gdal
- mode: one of {‘r’, ‘w’}
Returns
- source: GDALFileRaster
Example
>>> ds.open_raster('ortho', '/path/to/ortho.tif') >>> file_proj4 = ds.ortho.proj4_stored
>>> ds.open_raster('dem', '/path/to/dem.tif', mode='w') >>> nodata_value = ds.dem.nodata
See Also
Dataset.aopen_raster()
: To skip the key assigmentbuzzard.open_raster()
: To skip the key assigment and the explicit Dataset instanciation
-
Dataset.
create_raster
(key, path, fp, dtype, channel_count, channels_schema=None, driver='GTiff', options=(), sr=None, ow=False, **kwargs)[source]¶ Create a raster file and register it under key within this Dataset. Only metadata are kept in memory.
The raster’s values are initialized with channels_schema[‘nodata’] or 0.
>>> help(GDALFileRaster) >>> help(GDALMemRaster)
Parameters
- key: hashable (like a string)
File identifier within Dataset
To avoid using a key, you may use
acreate_raster()
- path: string
Anything that makes sense to GDAL:
A path to a file
An empty string when using driver=MEM
A path or an xml string when using driver=VRT
- fp: Footprint
Description of the location and size of the raster to create.
- dtype: numpy type (or any alias)
- channel_count: integer
number of channels
- channels_schema: dict or None
Channel(s) metadata. (see Channels schema fields below)
- driver: string
gdal driver to use when opening the file http://www.gdal.org/formats_list.html
- options: sequence of str
options for gdal http://www.gdal.org/frmt_gtiff.html
- sr: string or None
Spatial reference of the new file.
In order not to set a spatial reference, use None.
In order to set a spatial reference, use a string that can be converted to WKT by GDAL.
- ow: bool
Overwrite. Whether or not to erase the existing files.
Returns
- source: GDALFileRaster or GDALMemRaster
The type depends on the driver parameter
Example
>>> ds.create_raster('dem_copy', 'dem_copy.tif', ds.dem.fp, ds.dsm.dtype, len(ds.dem)) >>> array = ds.dem.get_data() >>> ds.dem_copy.set_data(array)
Channel schema fields
- Fields:
‘nodata’: None or number ‘interpretation’: None or str ‘offset’: None or number ‘scale’: None or number ‘mask’: None or str
- Interpretation values:
undefined, grayindex, paletteindex, redband, greenband, blueband, alphaband, hueband, saturationband, lightnessband, cyanband, magentaband, yellowband, blackband
- Mask values:
all_valid, per_dataset, alpha, nodata
Additionally:
A field missing or None is kept to default value.
A field can be passed as
a value: All bands are set to this value
a sequence of values of length channel_count: All bands will be set to their respective state
Caveat
When using the GTiff driver, specifying a mask or interpretation field may lead to unexpected results.
See Also
Dataset.acreate_raster()
: To skip the key assigmentbuzzard.create_raster()
: To skip the key assigment and the explicit Dataset instanciation
-
Dataset.
aopen_raster
(path, driver='GTiff', options=(), mode='r')[source]¶ Open a raster file anonymously within this Dataset. Only metadata are kept in memory.
See
open_raster()
Example
>>> ortho = ds.aopen_raster('/path/to/ortho.tif') >>> file_wkt = ortho.wkt_stored
See Also
Dataset.open_raster()
: To assign a key to this source within the Datasetbuzzard.open_raster()
: To skip the explicit Dataset instanciation
-
Dataset.
acreate_raster
(path, fp, dtype, channel_count, channels_schema=None, driver='GTiff', options=(), sr=None, ow=False, **kwargs)[source]¶ Create a raster file anonymously within this Dataset. Only metadata are kept in memory.
See
create_raster()
Example
>>> mask = ds.acreate_raster('mask.tif', ds.dem.fp, bool, 1, options=['SPARSE_OK=YES']) >>> open_options = mask.open_options
>>> channels_schema = { ... 'nodata': -32767, ... 'interpretation': ['blackband', 'cyanband'], ... } >>> out = ds.acreate_raster('output.tif', ds.dem.fp, 'float32', 2, channels_schema) >>> band_interpretation = out.channels_schema['interpretation']
See Also
Dataset.create_raster()
: To assign a key to this source within the Datasetbuzzard.create_raster()
: To skip the explicit Dataset instanciation