-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathbag_surfacecorrectionsdescriptor.cpp
More file actions
342 lines (293 loc) · 8.49 KB
/
bag_surfacecorrectionsdescriptor.cpp
File metadata and controls
342 lines (293 loc) · 8.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
#include "bag_dataset.h"
#include "bag_private.h"
#include "bag_surfacecorrections.h"
#include "bag_surfacecorrectionsdescriptor.h"
#include <array>
#include <H5Cpp.h>
namespace BAG {
namespace {
//! Retrieve the size of a node of the specified topography.
/*!
\param type
The topography type.
\param numCorrectors
The number of correctors.
Valid values are 1-10.
\return
The size of a node in the specified topography.
*/
uint8_t getElementSize(
BAG_SURFACE_CORRECTION_TOPOGRAPHY type) noexcept
{
return (type == BAG_SURFACE_IRREGULARLY_SPACED)
? sizeof(BAG::VerticalDatumCorrections)
: sizeof(BAG::VerticalDatumCorrectionsGridded);
}
} // namespace
//! Constructor.
/*!
\param id
The unique layer id.
\param type
The type of surface corrections.
\param numCorrectors
The number of correctors.
\param chunkSize
The chunk size the HDF5 DataSet will use.
\param compressionLevel
The compression level the HDF5 DataSet will use.
*/
SurfaceCorrectionsDescriptor::SurfaceCorrectionsDescriptor(
uint32_t id,
BAG_SURFACE_CORRECTION_TOPOGRAPHY type,
uint8_t numCorrectors,
uint64_t chunkSize,
int compressionLevel)
: LayerDescriptor(id, Layer::getInternalPath(Surface_Correction),
kLayerTypeMapString.at(Surface_Correction), Surface_Correction,
0, 0, chunkSize, compressionLevel) // Dims default to 0,0 like derived type
, m_surfaceType(type)
, m_elementSize(BAG::getElementSize(type))
, m_numCorrectors(numCorrectors)
{
}
//! Constructor.
/*!
\param dataset
The BAG Dataset this layer belongs to.
*/
SurfaceCorrectionsDescriptor::SurfaceCorrectionsDescriptor(
const Dataset& dataset)
: LayerDescriptor(dataset, Surface_Correction, 0, 0) // Dims set in body
{
const auto h5dataSet = dataset.getH5file().openDataSet(
Layer::getInternalPath(Surface_Correction));
// Read the attributes.
// surface type
uint8_t surfaceType = 0;
{
const auto att = h5dataSet.openAttribute(VERT_DATUM_CORR_SURFACE_TYPE);
att.read(att.getDataType(), &surfaceType);
}
m_surfaceType = static_cast<BAG_SURFACE_CORRECTION_TOPOGRAPHY>(surfaceType);
if (m_surfaceType != BAG_SURFACE_GRID_EXTENTS &&
m_surfaceType != BAG_SURFACE_IRREGULARLY_SPACED)
throw UnknownSurfaceType{};
// vertical datums
{
const auto att = h5dataSet.openAttribute(VERT_DATUM_CORR_VERTICAL_DATUM);
att.read(att.getDataType(), m_verticalDatums);
}
// Read extra attributes if the surface type provides them.
if (m_surfaceType == BAG_SURFACE_GRID_EXTENTS)
{
auto att = h5dataSet.openAttribute(VERT_DATUM_CORR_SWX);
att.read(att.getDataType(), &m_swX);
att = h5dataSet.openAttribute(VERT_DATUM_CORR_SWY);
att.read(att.getDataType(), &m_swY);
att = h5dataSet.openAttribute(VERT_DATUM_CORR_NSX);
att.read(att.getDataType(), &m_xSpacing);
att = h5dataSet.openAttribute(VERT_DATUM_CORR_NSY);
att.read(att.getDataType(), &m_ySpacing);
}
// Number of corrections.
const auto h5fileCompType = h5dataSet.getCompType();
const int memberNum = h5fileCompType.getMemberIndex("z");
const auto h5zDataType = h5fileCompType.getMemberArrayType(memberNum);
std::array<hsize_t, H5S_MAX_RANK> zDims{};
// Read the number of Z corrections.
const int zRank = h5zDataType.getArrayDims(zDims.data());
if (zRank == 2)
if (zDims[1] > BAG_SURFACE_CORRECTOR_LIMIT)
throw TooManyCorrections{};
else
m_numCorrectors = static_cast<uint8_t>(zDims[1]);
else
throw CannotReadNumCorrections{};
// Element size.
m_elementSize = BAG::getElementSize(m_surfaceType);
// Number of rows & columns.
const auto h5Space = h5dataSet.getSpace();
std::array<hsize_t, kRank> dims{};
h5Space.getSimpleExtentDims(dims.data());
this->setDims(static_cast<uint32_t>(dims[0]),
static_cast<uint32_t>(dims[1]));
}
//! Create a surface corrections layer.
/*!
\param dataset
The BAG Dataset this layer belongs to.
\param type
The type of surface corrections.
\param numCorrectors
The number of correctors.
\param chunkSize
The chunk size the HDF5 DataSet will use.
\param compressionLevel
The compression level the HDF5 DataSet will use.
*/
std::shared_ptr<SurfaceCorrectionsDescriptor>
SurfaceCorrectionsDescriptor::create(
const Dataset& dataset,
BAG_SURFACE_CORRECTION_TOPOGRAPHY type,
uint8_t numCorrectors,
uint64_t chunkSize,
int compressionLevel)
{
if (type != BAG_SURFACE_GRID_EXTENTS &&
type != BAG_SURFACE_IRREGULARLY_SPACED)
throw UnknownSurfaceType{};
if (numCorrectors > BAG_SURFACE_CORRECTOR_LIMIT)
throw TooManyCorrections{};
return std::shared_ptr<SurfaceCorrectionsDescriptor>(
new SurfaceCorrectionsDescriptor{dataset.getNextId(), type,
numCorrectors, chunkSize, compressionLevel});
}
//! Open an existing surface corrections layer.
/*!
\param dataset
The BAG Dataset this layer belongs to.
*/
std::shared_ptr<SurfaceCorrectionsDescriptor>
SurfaceCorrectionsDescriptor::open(
const Dataset& dataset)
{
return std::shared_ptr<SurfaceCorrectionsDescriptor>(
new SurfaceCorrectionsDescriptor{dataset});
}
//! \copydoc LayerDescriptor::getDataType
DataType SurfaceCorrectionsDescriptor::getDataTypeProxy() const noexcept
{
return Layer::getDataType(Surface_Correction);
}
//! Retrieve the dimensions of the surface corrections layer.
/*!
\return
The dimensions of the surface corrections layer.
*/
std::tuple<uint32_t, uint32_t> SurfaceCorrectionsDescriptor::getDims() const noexcept
{
return {m_numRows, m_numColumns};
}
//! \copydoc LayerDescriptor::getElementSize
uint8_t SurfaceCorrectionsDescriptor::getElementSizeProxy() const noexcept
{
return m_elementSize;
}
//! Retrieve the number of correctors.
/*!
\return
The number of correctors.
*/
uint8_t SurfaceCorrectionsDescriptor::getNumCorrectors() const noexcept
{
return m_numCorrectors;
}
//! Retrieve the south west corner of the surface corrections layer.
/*!
\return
The south west corner of the surface corrections layer.
*/
std::tuple<double, double>
SurfaceCorrectionsDescriptor::getOrigin() const noexcept
{
return {m_swX, m_swY};
}
//! Retrieve the X and Y spacing/resolution of the surface corrections layer.
/*!
\return
The X and Y spacing/resolution of the surface corrections layer.
*/
std::tuple<double, double>
SurfaceCorrectionsDescriptor::getSpacing() const noexcept
{
return {m_xSpacing, m_ySpacing};
}
//! Retrieve surface correction topography.
/*!
\return
The surface correction topography.
*/
BAG_SURFACE_CORRECTION_TOPOGRAPHY
SurfaceCorrectionsDescriptor::getSurfaceType() const noexcept
{
return m_surfaceType;
}
//! Retrieve the vertical datums.
/*!
\return
The vertical datums.
*/
const std::string&
SurfaceCorrectionsDescriptor::getVerticalDatums() const & noexcept
{
return m_verticalDatums;
}
//! Set the grid dimensions.
/*!
\param numRows
The new number of rows.
\param numColumns
The new number of columns.
\return
The surface corrections descriptor.
*/
SurfaceCorrectionsDescriptor& SurfaceCorrectionsDescriptor::setDims(
uint32_t numRows,
uint32_t numColumns) & noexcept
{
m_numRows = numRows;
m_numColumns = numColumns;
LayerDescriptor::setDims(numRows, numColumns);
return *this;
}
//! Set the south west corner.
/*!
\param swX
The X value of the south west corner.
Geographic location.
\param swY
The Y value of the south west corner.
Geographic location.
\return
The surface corrections descriptor.
*/
SurfaceCorrectionsDescriptor& SurfaceCorrectionsDescriptor::setOrigin(
double swX,
double swY) & noexcept
{
m_swX = swX;
m_swY = swY;
return *this;
}
//! Set the X and Y spacing/resolution.
/*!
\param xSpacing
The X spacing/resolution.
\param ySpacing
The Y spacing/resolution.
\return
The surface corrections descriptor.
*/
SurfaceCorrectionsDescriptor& SurfaceCorrectionsDescriptor::setSpacing(
double xSpacing,
double ySpacing) & noexcept
{
m_xSpacing = xSpacing;
m_ySpacing = ySpacing;
return *this;
}
//! Set the vertical datums.
/*!
\param verticalDatums
The vertical datums.
\return
The surface corrections descriptor.
*/
SurfaceCorrectionsDescriptor& SurfaceCorrectionsDescriptor::setVerticalDatums(
std::string verticalDatums) & noexcept
{
m_verticalDatums = std::move(verticalDatums);
return *this;
}
} // namespace BAG