GDAL
|
Class modeling a multi-dimensional array. More...
#include <gdal_priv.h>
Public Member Functions | |
GUInt64 | GetTotalCopyCost () const |
Return a total "cost" to copy the array. More... | |
virtual bool | CopyFrom (GDALDataset *poSrcDS, const GDALMDArray *poSrcArray, bool bStrict, GUInt64 &nCurCost, const GUInt64 nTotalCost, GDALProgressFunc pfnProgress, void *pProgressData) |
Copy the content of an array into a new (generally empty) array. More... | |
virtual bool | IsWritable () const =0 |
Return whether an array is writable;. | |
virtual CSLConstList | GetStructuralInfo () const |
Return structural information on the array. More... | |
virtual const std::string & | GetUnit () const |
Return the array unit. More... | |
virtual bool | SetUnit (const std::string &osUnit) |
Set the variable unit. More... | |
virtual bool | SetSpatialRef (const OGRSpatialReference *poSRS) |
Assign a spatial reference system object to the the array. More... | |
virtual std::shared_ptr< OGRSpatialReference > | GetSpatialRef () const |
Return the spatial reference system object associated with the array. More... | |
virtual const void * | GetRawNoDataValue () const |
Return the nodata value as a "raw" value. More... | |
double | GetNoDataValueAsDouble (bool *pbHasNoData=nullptr) const |
Return the nodata value as a double. More... | |
virtual bool | SetRawNoDataValue (const void *pRawNoData) |
Set the nodata value as a "raw" value. More... | |
bool | SetNoDataValue (double dfNoData) |
Set the nodata value as a double. More... | |
virtual double | GetOffset (bool *pbHasOffset=nullptr) const |
Get the offset value to apply to raw values. More... | |
virtual double | GetScale (bool *pbHasScale=nullptr) const |
Get the scale value to apply to raw values. More... | |
virtual bool | SetOffset (double dfOffset) |
Set the offset value to apply to raw values. More... | |
virtual bool | SetScale (double dfScale) |
Set the scale value to apply to raw values. More... | |
std::shared_ptr< GDALMDArray > | GetView (const std::string &viewExpr) const |
Return a view of the array using slicing or field access. More... | |
std::shared_ptr< GDALMDArray > | operator[] (const std::string &fieldName) const |
Return a view of the array using field access. More... | |
template<typename... GUInt64VarArg> | |
std::shared_ptr< GDALMDArray > | at (GUInt64 idx, GUInt64VarArg... tail) const |
Return a view of the array using integer indexing. More... | |
virtual std::shared_ptr< GDALMDArray > | Transpose (const std::vector< int > &anMapNewAxisToOldAxis) const |
Return a view of the array whose axis have been reordered. More... | |
std::shared_ptr< GDALMDArray > | GetUnscaled () const |
Return an array that is the unscaled version of the current one. More... | |
virtual std::shared_ptr< GDALMDArray > | GetMask (CSLConstList papszOptions) const |
Return an array that is a mask for the current array. More... | |
virtual GDALDataset * | AsClassicDataset (size_t iXDim, size_t iYDim) const |
Return a view of this array as a "classic" GDALDataset (ie 2D) More... | |
virtual CPLErr | GetStatistics (GDALDataset *poDS, bool bApproxOK, bool bForce, double *pdfMin, double *pdfMax, double *pdfMean, double *padfStdDev, GUInt64 *pnValidCount, GDALProgressFunc pfnProgress, void *pProgressData) |
Fetch statistics. More... | |
virtual bool | ComputeStatistics (GDALDataset *poDS, bool bApproxOK, double *pdfMin, double *pdfMax, double *pdfMean, double *pdfStdDev, GUInt64 *pnValidCount, GDALProgressFunc, void *pProgressData) |
Compute statistics. More... | |
bool | AdviseRead (const GUInt64 *arrayStartIdx, const size_t *count) const |
Advise driver of upcoming read requests. More... | |
![]() | |
const std::string & | GetName () const |
Return the name of an array or attribute. More... | |
const std::string & | GetFullName () const |
Return the name of an array or attribute. More... | |
GUInt64 | GetTotalElementsCount () const |
Return the total number of values in the array. More... | |
virtual size_t | GetDimensionCount () const |
Return the number of dimensions. More... | |
virtual const std::vector< std::shared_ptr< GDALDimension > > & | GetDimensions () const =0 |
Return the dimensions of an attribute/array. More... | |
virtual const GDALExtendedDataType & | GetDataType () const =0 |
Return the data type of an attribute/array. More... | |
virtual std::vector< GUInt64 > | GetBlockSize () const |
Return the "natural" block size of the array along all dimensions. More... | |
virtual std::vector< size_t > | GetProcessingChunkSize (size_t nMaxChunkMemory) const |
Return an optimal chunk size for read/write oerations, given the natural block size and memory constraints specified. More... | |
virtual bool | ProcessPerChunk (const GUInt64 *arrayStartIdx, const GUInt64 *count, const size_t *chunkSize, FuncProcessPerChunkType pfnFunc, void *pUserData) |
Call a user-provided function to operate on an array chunk by chunk. More... | |
bool | Read (const GUInt64 *arrayStartIdx, const size_t *count, const GInt64 *arrayStep, const GPtrDiff_t *bufferStride, const GDALExtendedDataType &bufferDataType, void *pDstBuffer, const void *pDstBufferAllocStart=nullptr, size_t nDstBufferAllocSize=0) const |
Read part or totality of a multidimensional array or attribute. More... | |
bool | Write (const GUInt64 *arrayStartIdx, const size_t *count, const GInt64 *arrayStep, const GPtrDiff_t *bufferStride, const GDALExtendedDataType &bufferDataType, const void *pSrcBuffer, const void *pSrcBufferAllocStart=nullptr, size_t nSrcBufferAllocSize=0) |
Write part or totality of a multidimensional array or attribute. More... | |
![]() | |
virtual std::shared_ptr< GDALAttribute > | GetAttribute (const std::string &osName) const |
Return an attribute by its name. More... | |
virtual std::vector< std::shared_ptr< GDALAttribute > > | GetAttributes (CSLConstList papszOptions=nullptr) const |
Return the list of attributes contained in a GDALMDArray or GDALGroup. More... | |
virtual std::shared_ptr< GDALAttribute > | CreateAttribute (const std::string &osName, const std::vector< GUInt64 > &anDimensions, const GDALExtendedDataType &oDataType, CSLConstList papszOptions=nullptr) |
Create an attribute within a GDALMDArray or GDALGroup. More... | |
Additional Inherited Members | |
![]() | |
typedef bool(* | FuncProcessPerChunkType) (GDALAbstractMDArray *array, const GUInt64 *chunkArrayStartIdx, const size_t *chunkCount, GUInt64 iCurChunk, GUInt64 nChunkCount, void *pUserData) |
Type of pfnFunc argument of ProcessPerChunk(). More... | |
![]() | |
std::shared_ptr< GDALAttribute > | GetAttributeFromAttributes (const std::string &osName) const |
Possible fallback implementation for GetAttribute() using GetAttributes(). | |
Class modeling a multi-dimensional array.
It has a name, values organized as an array and a list of GDALAttribute.
This is based on the HDF5 dataset concept
bool GDALMDArray::AdviseRead | ( | const GUInt64 * | arrayStartIdx, |
const size_t * | count | ||
) | const |
Advise driver of upcoming read requests.
Some GDAL drivers operate more efficiently if they know in advance what set of upcoming read requests will be made. The AdviseRead() method allows an application to notify the driver of the region of interest.
Many drivers just ignore the AdviseRead() call, but it can dramatically accelerate access via some drivers. One such case is when reading through a DAP dataset with the netCDF driver (a in-memory cache array is then created with the region of interest defined by AdviseRead())
This is the same as the C function GDALMDArrayAdviseRead().
arrayStartIdx | Values representing the starting index to read in each dimension (in [0, aoDims[i].GetSize()-1] range). Array of GetDimensionCount() values. Can be nullptr as a synonymous for [0 for i in range(GetDimensionCount() ] |
count | Values representing the number of values to extract in each dimension. Array of GetDimensionCount() values. Can be nullptr as a synonymous for [ aoDims[i].GetSize() - arrayStartIdx[i] for i in range(GetDimensionCount() ] |
|
virtual |
Return a view of this array as a "classic" GDALDataset (ie 2D)
In the case of > 2D arrays, additional dimensions will be represented as raster bands.
The "reverse" method is GDALRasterBand::AsMDArray().
This is the same as the C function GDALMDArrayAsClassicDataset().
iXDim | Index of the dimension that will be used as the X/width axis. |
iYDim | Index of the dimension that will be used as the Y/height axis. Ignored if the dimension count is 1. |
|
inline |
Return a view of the array using integer indexing.
Equivalent of GetView("[indices_0,indices_1,.....,indices_last]")
Example:
|
virtual |
Compute statistics.
Returns the minimum, maximum, mean and standard deviation of all pixel values in this array.
Pixels taken into account in statistics are those whose mask value (as determined by GetMask()) is non-zero.
Once computed, the statistics will generally be "set" back on the owing dataset (if poDS is not NULL).
Cached statistics can be cleared with GDALDataset::ClearStatistics().
This method is the same as the C function GDALMDArrayComputeStatistics().
poDS | Owing dataset. If set to non-NULL, the method will attempt to store computed statistics in it (generally its persistent auxiliary metadata) for further retrieval by GetStatistics() |
bApproxOK | Currently ignored. In the future, should be set to true if statistics on the whole array are wished, or to false if a subset of it may be used. |
pdfMin | Location into which to load image minimum (may be NULL). |
pdfMax | Location into which to load image maximum (may be NULL).- |
pdfMean | Location into which to load image mean (may be NULL). |
pdfStdDev | Location into which to load image standard deviation (may be NULL). |
pnValidCount | Number of samples whose value is different from the nodata value. (may be NULL) |
pfnProgress | a function to call to report progress, or NULL. |
pProgressData | application data to pass to the progress function. |
|
virtual |
Copy the content of an array into a new (generally empty) array.
poSrcDS | Source dataset. Migt be nullptr (but for correct behavior of some output drivers this is not recommended) |
poSrcArray | Source array. Should NOT be nullptr. |
bStrict | Whether to enable stict mode. In strict mode, any error will stop the copy. In relaxed mode, the copy will be attempted to be pursued. |
nCurCost | Should be provided as a variable initially set to 0. |
nTotalCost | Total cost from GetTotalCopyCost(). |
pfnProgress | Progress callback, or nullptr. |
pProgressData | Progress user data, or nulptr. |
|
virtual |
Return an array that is a mask for the current array.
This array will be of type Byte, with values set to 0 to indicate invalid pixels of the current array, and values set to 1 to indicate valid pixels.
The generic implementation honours the NoDataValue, as well as various netCDF CF attributes: missing_value, _FillValue, valid_min, valid_max and valid_range.
This is the same as the C function GDALMDArrayGetMask().
papszOptions | NULL-terminated list of options, or NULL. |
double GDALMDArray::GetNoDataValueAsDouble | ( | bool * | pbHasNoData = nullptr | ) | const |
Return the nodata value as a double.
The value returned might be nullptr in case of no nodata value. When a nodata value is registered, a non-nullptr will be returned whose size in bytes is GetDataType().GetSize().
This is the same as the C function GDALMDArrayGetNoDataValueAsDouble().
pbHasNoData | Pointer to a output boolean that will be set to true if a nodata value exists and can be converted to double. Might be nullptr. |
|
virtual |
Get the offset value to apply to raw values.
unscaled_value = raw_value * GetScale() + GetOffset()
This is the same as the C function GDALMDArrayGetOffset().
pbHasOffset | Pointer to a output boolean that will be set to true if a offset value exists. Might be nullptr. |
|
virtual |
Return the nodata value as a "raw" value.
The value returned might be nullptr in case of no nodata value. When a nodata value is registered, a non-nullptr will be returned whose size in bytes is GetDataType().GetSize().
The returned value should not be modified or freed. It is valid until the array is destroyed, or the next call to GetRawNoDataValue() or SetRawNoDataValue(), or any similar methods.
This is the same as the C function GDALMDArrayGetRawNoDataValue().
|
virtual |
Get the scale value to apply to raw values.
unscaled_value = raw_value * GetScale() + GetOffset()
This is the same as the C function GDALMDArrayGetScale().
pbHasScale | Pointer to a output boolean that will be set to true if a scale value exists. Might be nullptr. |
|
virtual |
Return the spatial reference system object associated with the array.
This is the same as the C function GDALMDArrayGetSpatialRef().
|
virtual |
Fetch statistics.
Returns the minimum, maximum, mean and standard deviation of all pixel values in this array.
If bForce is FALSE results will only be returned if it can be done quickly (i.e. without scanning the data). If bForce is FALSE and results cannot be returned efficiently, the method will return CE_Warning but no warning will have been issued. This is a non-standard use of the CE_Warning return value to indicate "nothing done".
When cached statistics are not available, and bForce is TRUE, ComputeStatistics() is called.
Note that file formats using PAM (Persistent Auxiliary Metadata) services will generally cache statistics in the .aux.xml file allowing fast fetch after the first request.
Cached statistics can be cleared with GDALDataset::ClearStatistics().
This method is the same as the C function GDALMDArrayGetStatistics().
poDS | Owing dataset. If set to NULL, this method will always call ComputeStatistics(). If set to non-NULL, the method will attempt to retrieve from it (generally its persistent auxiliary metadata) already cached statistics. |
bApproxOK | Currently ignored. In the future, should be set to true if statistics on the whole array are wished, or to false if a subset of it may be used. |
bForce | If false statistics will only be returned if it can be done without rescanning the image. |
pdfMin | Location into which to load image minimum (may be NULL). |
pdfMax | Location into which to load image maximum (may be NULL).- |
pdfMean | Location into which to load image mean (may be NULL). |
pdfStdDev | Location into which to load image standard deviation (may be NULL). |
pnValidCount | Number of samples whose value is different from the nodata value. (may be NULL) |
pfnProgress | a function to call to report progress, or NULL. |
pProgressData | application data to pass to the progress function. |
|
virtual |
Return structural information on the array.
This may be the compression, etc..
The return value should not be freed and is valid until GDALMDArray is released or this function called again.
This is the same as the C function GDALMDArrayGetStruturalInfo().
GUInt64 GDALMDArray::GetTotalCopyCost | ( | ) | const |
Return a total "cost" to copy the array.
Used as a parameter for CopyFrom()
|
virtual |
Return the array unit.
Values should conform as much as possible with those allowed by the NetCDF CF conventions: http://cfconventions.org/Data/cf-conventions/cf-conventions-1.7/cf-conventions.html#units but others might be returned.
Few examples are "meter", "degrees", "second", ... Empty value means unknown.
This is the same as the C function GDALMDArrayGetUnit()
std::shared_ptr< GDALMDArray > GDALMDArray::GetUnscaled | ( | ) | const |
Return an array that is the unscaled version of the current one.
That is each value of the unscaled array will be unscaled_value = raw_value * GetScale() + GetOffset()
This is the same as the C function GDALMDArrayGetUnscaled().
std::shared_ptr< GDALMDArray > GDALMDArray::GetView | ( | const std::string & | viewExpr | ) | const |
Return a view of the array using slicing or field access.
The slice expression uses the same syntax as NumPy basic slicing and indexing. See https://www.numpy.org/devdocs/reference/arrays.indexing.html#basic-slicing-and-indexing Or it can use field access by name. See https://www.numpy.org/devdocs/reference/arrays.indexing.html#field-access
Multiple [] bracket elements can be concatenated, with a slice expression or field name inside each.
For basic slicing and indexing, inside each [] bracket element, a list of indexes that apply to successive source dimensions, can be specified, using integer indexing (e.g. 1), range indexing (start:stop:step), ellipsis (...) or newaxis, using a comma separator.
Examples with a 2-dimensional array whose content is [[0,1,2,3],[4,5,6,7]].
One difference with NumPy behavior is that ranges that would result in zero elements are not allowed (dimensions of size 0 not being allowed in the GDAL multidimensional model).
For field access, the syntax to use is ["field_name"] or ['field_name']. Multiple field specification is not supported currently.
Both type of access can be combined, e.g. GetView("[1]['field_name']")
The returned array holds a reference to the original one, and thus is a view of it (not a copy). If the content of the original array changes, the content of the view array too. When using basic slicing and indexing, the view can be written if the underlying array is writable.
This is the same as the C function GDALMDArrayGetView()
viewExpr | Expression expressing basic slicing and indexing, or field access. |
std::shared_ptr< GDALMDArray > GDALMDArray::operator[] | ( | const std::string & | fieldName | ) | const |
Return a view of the array using field access.
Equivalent of GetView("['fieldName']")
bool GDALMDArray::SetNoDataValue | ( | double | dfNoData | ) |
Set the nodata value as a double.
If the natural data type of the attribute/array is not double, type conversion will occur to the type returned by GetDataType().
This is the same as the C function GDALMDArraySetNoDataValueAsDouble().
|
virtual |
Set the offset value to apply to raw values.
unscaled_value = raw_value * GetScale() + GetOffset()
This is the same as the C function GDALMDArraySetOffset().
|
virtual |
Set the nodata value as a "raw" value.
The value passed might be nullptr in case of no nodata value. When a nodata value is registered, a non-nullptr whose size in bytes is GetDataType().GetSize() must be passed.
This is the same as the C function GDALMDArraySetRawNoDataValue().
|
virtual |
Set the scale value to apply to raw values.
unscaled_value = raw_value * GetScale() + GetOffset()
This is the same as the C function GDALMDArraySetScale().
|
virtual |
Assign a spatial reference system object to the the array.
This is the same as the C function GDALMDArraySetSpatialRef().
|
virtual |
Set the variable unit.
Values should conform as much as possible with those allowed by the NetCDF CF conventions: http://cfconventions.org/Data/cf-conventions/cf-conventions-1.7/cf-conventions.html#units but others might be returned.
Few examples are "meter", "degrees", "second", ... Empty value means unknown.
This is the same as the C function GDALMDArraySetUnit()
osUnit | unit name. |
|
virtual |
Return a view of the array whose axis have been reordered.
The anMapNewAxisToOldAxis parameter should contain all the values between 0 and GetDimensionCount() - 1, and each only once. -1 can be used as a special index value to ask for the insertion of a new axis of size 1. The new array will have anMapNewAxisToOldAxis.size() axis, and if i is the index of one of its dimension, it corresponds to the axis of index anMapNewAxisToOldAxis[i] from the current array.
This is similar to the numpy.transpose() method
The returned array holds a reference to the original one, and thus is a view of it (not a copy). If the content of the original array changes, the content of the view array too. The view can be written if the underlying array is writable.
Note that I/O performance in such a transposed view might be poor.
This is the same as the C function GDALMDArrayTranspose().