GDAL
gdalmultidim_array_unscaled.h
1/******************************************************************************
2 *
3 * Name: gdalmultidim_array_unscaled.h
4 * Project: GDAL Core
5 * Purpose: Declaration of GDALMDArrayUnscaled
6 * Author: Even Rouault <even.rouault at spatialys.com>
7 *
8 ******************************************************************************
9 * Copyright (c) 2019, Even Rouault <even.rouault at spatialys.com>
10 *
11 * SPDX-License-Identifier: MIT
12 ****************************************************************************/
13
14#ifndef GDALMULTIDIM_ARRAY_UNSCALED_H
15#define GDALMULTIDIM_ARRAY_UNSCALED_H
16
17#include "gdal_multidim.h"
18#include "gdal_pam_multidim.h"
19
21
22/************************************************************************/
23/* GDALMDArrayUnscaled */
24/************************************************************************/
25
26class GDALMDArrayUnscaled final : public GDALPamMDArray
27{
28 private:
29 std::shared_ptr<GDALMDArray> m_poParent{};
30 const GDALExtendedDataType m_dt;
31 bool m_bHasNoData;
32 const double m_dfScale;
33 const double m_dfOffset;
34 std::vector<GByte> m_abyRawNoData{};
35
36 protected:
37 explicit GDALMDArrayUnscaled(const std::shared_ptr<GDALMDArray> &poParent,
38 double dfScale, double dfOffset,
39 double dfOverriddenDstNodata, GDALDataType eDT)
40 : GDALAbstractMDArray(std::string(),
41 "Unscaled view of " + poParent->GetFullName()),
42 GDALPamMDArray(
43 std::string(), "Unscaled view of " + poParent->GetFullName(),
44 GDALPamMultiDim::GetPAM(poParent), poParent->GetContext()),
45 m_poParent(std::move(poParent)),
46 m_dt(GDALExtendedDataType::Create(eDT)),
47 m_bHasNoData(m_poParent->GetRawNoDataValue() != nullptr),
48 m_dfScale(dfScale), m_dfOffset(dfOffset)
49 {
50 m_abyRawNoData.resize(m_dt.GetSize());
51 const auto eNonComplexDT =
54 &dfOverriddenDstNodata, GDT_Float64, 0, m_abyRawNoData.data(),
55 eNonComplexDT, GDALGetDataTypeSizeBytes(eNonComplexDT),
57 }
58
59 bool IRead(const GUInt64 *arrayStartIdx, const size_t *count,
60 const GInt64 *arrayStep, const GPtrDiff_t *bufferStride,
61 const GDALExtendedDataType &bufferDataType,
62 void *pDstBuffer) const override;
63
64 bool IWrite(const GUInt64 *arrayStartIdx, const size_t *count,
65 const GInt64 *arrayStep, const GPtrDiff_t *bufferStride,
66 const GDALExtendedDataType &bufferDataType,
67 const void *pSrcBuffer) override;
68
69 bool IAdviseRead(const GUInt64 *arrayStartIdx, const size_t *count,
70 CSLConstList papszOptions) const override
71 {
72 return m_poParent->AdviseRead(arrayStartIdx, count, papszOptions);
73 }
74
75 public:
76 static std::shared_ptr<GDALMDArrayUnscaled>
77 Create(const std::shared_ptr<GDALMDArray> &poParent, double dfScale,
78 double dfOffset, double dfDstNodata, GDALDataType eDT)
79 {
80 auto newAr(std::shared_ptr<GDALMDArrayUnscaled>(new GDALMDArrayUnscaled(
81 poParent, dfScale, dfOffset, dfDstNodata, eDT)));
82 newAr->SetSelf(newAr);
83 return newAr;
84 }
85
86 bool IsWritable() const override
87 {
88 return m_poParent->IsWritable();
89 }
90
91 const std::string &GetFilename() const override
92 {
93 return m_poParent->GetFilename();
94 }
95
96 const std::vector<std::shared_ptr<GDALDimension>> &
97 GetDimensions() const override
98 {
99 return m_poParent->GetDimensions();
100 }
101
102 const GDALExtendedDataType &GetDataType() const override
103 {
104 return m_dt;
105 }
106
107 const std::string &GetUnit() const override
108 {
109 return m_poParent->GetUnit();
110 }
111
112 std::shared_ptr<OGRSpatialReference> GetSpatialRef() const override
113 {
114 return m_poParent->GetSpatialRef();
115 }
116
117 const void *GetRawNoDataValue() const override
118 {
119 return m_bHasNoData ? m_abyRawNoData.data() : nullptr;
120 }
121
122 bool SetRawNoDataValue(const void *pRawNoData) override
123 {
124 m_bHasNoData = true;
125 memcpy(m_abyRawNoData.data(), pRawNoData, m_dt.GetSize());
126 return true;
127 }
128
129 std::vector<GUInt64> GetBlockSize() const override
130 {
131 return m_poParent->GetBlockSize();
132 }
133
134 std::shared_ptr<GDALAttribute>
135 GetAttribute(const std::string &osName) const override
136 {
137 return m_poParent->GetAttribute(osName);
138 }
139
140 std::vector<std::shared_ptr<GDALAttribute>>
141 GetAttributes(CSLConstList papszOptions = nullptr) const override
142 {
143 return m_poParent->GetAttributes(papszOptions);
144 }
145
146 bool SetUnit(const std::string &osUnit) override
147 {
148 return m_poParent->SetUnit(osUnit);
149 }
150
151 bool SetSpatialRef(const OGRSpatialReference *poSRS) override
152 {
153 return m_poParent->SetSpatialRef(poSRS);
154 }
155
156 std::shared_ptr<GDALAttribute>
157 CreateAttribute(const std::string &osName,
158 const std::vector<GUInt64> &anDimensions,
159 const GDALExtendedDataType &oDataType,
160 CSLConstList papszOptions = nullptr) override
161 {
162 return m_poParent->CreateAttribute(osName, anDimensions, oDataType,
163 papszOptions);
164 }
165};
166
168
169#endif // GDALMULTIDIM_ARRAY_UNSCALED_H
Abstract class, implemented by GDALAttribute and GDALMDArray.
Definition gdal_multidim.h:498
Class used to represent potentially complex data types.
Definition gdal_multidim.h:54
size_t GetSize() const
Return data type size in bytes.
Definition gdal_multidim.h:138
GDALDataType GetNumericDataType() const
Return numeric data type (only valid when GetClass() == GEDTC_NUMERIC)
Definition gdal_multidim.h:106
This class represents an OpenGIS Spatial Reference System, and contains methods for converting betwee...
Definition ogr_spatialref.h:152
int GPtrDiff_t
Integer type large enough to hold the difference between 2 addresses.
Definition cpl_port.h:236
GIntBig GInt64
Signed 64 bit integer type.
Definition cpl_port.h:216
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition cpl_port.h:1252
GUIntBig GUInt64
Unsigned 64 bit integer type.
Definition cpl_port.h:218
GDALDataType
Definition gdal.h:48
@ GDT_Float64
Definition gdal.h:60
GDALDataType GDALGetNonComplexDataType(GDALDataType)
Return the base data type for the specified input.
Definition gdal_misc.cpp:1081
int GDALDataTypeIsComplex(GDALDataType)
Is data type complex?
Definition gdal_misc.cpp:466
int GDALGetDataTypeSizeBytes(GDALDataType)
Get data type size in bytes.
Definition gdal_misc.cpp:374
void GDALCopyWords64(const void *pSrcData, GDALDataType eSrcType, int nSrcPixelOffset, void *pDstData, GDALDataType eDstType, int nDstPixelOffset, GPtrDiff_t nWordCount)
Copy pixel words from buffer to buffer.
Definition rasterio.cpp:4294