-
Notifications
You must be signed in to change notification settings - Fork 12
/
bag.cpp
4141 lines (3541 loc) · 100 KB
/
bag.cpp
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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "bag.h"
#include "bag_c_types.h"
#include "bag_georefmetadatalayer.h"
#include "bag_dataset.h"
#include "bag_errors.h"
#include "bag_layer.h"
#include "bag_metadata.h"
#include "bag_metadata_import.h"
#include "bag_private.h"
#include "bag_simplelayer.h"
#include "bag_surfacecorrections.h"
#include "bag_surfacecorrectionsdescriptor.h"
#include "bag_trackinglist.h"
#include "bag_valuetable.h"
#include "bag_vrmetadata.h"
#include "bag_vrmetadatadescriptor.h"
#include "bag_vrnode.h"
#include "bag_vrnodedescriptor.h"
#include "bag_vrrefinements.h"
#include "bag_vrrefinementsdescriptor.h"
#include "bag_vrtrackinglist.h"
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4251) // std classes do not have DLL-interface when exporting
#endif
#include <H5Cpp.h>
#include <algorithm>
#include <iterator>
#include <numeric>
#include <sstream>
#include <string>
#include <string.h>
#ifdef _MSC_VER
#pragma warning(pop)
#endif
namespace {
//! Convert a BAG::CompoundDataType (C++) into a BagCompoundDataType (C).
/*!
\param field
The BAG::CompoundDataType.
\return
The BagCompoundDataType created from \e field.
*/
BagCompoundDataType getValue(
const BAG::CompoundDataType& field)
{
BagCompoundDataType result{};
result.type = field.getType();
switch(result.type)
{
case DT_FLOAT32:
result.data.f = field.asFloat();
break;
case DT_UINT32:
result.data.ui32 = field.asUInt32();
break;
case DT_BOOLEAN:
result.data.b = field.asBool();
break;
case DT_STRING: // Copy the string as it will go out of scope.
{
const char* const value = field.asString().c_str();
const auto fieldLen = strlen(value) + 1;
result.data.c = new char[fieldLen];
memcpy(result.data.c, value, fieldLen);
break;
}
default:
result.type = DT_UNKNOWN_DATA_TYPE;
break;
}
return result;
}
//! Convert a BagCompoundDataType (C) into a BAG::CompoundDataType (C++).
/*!
\param field
The BagCompoundDataType.
\return
The BAG::CompoundDataType created from \e field.
*/
BAG::CompoundDataType getValue(
const BagCompoundDataType& field)
{
switch (field.type)
{
case DT_FLOAT32:
return BAG::CompoundDataType{field.data.f};
case DT_UINT32:
return BAG::CompoundDataType{field.data.ui32};
case DT_BOOLEAN:
return BAG::CompoundDataType{field.data.b};
case DT_STRING:
{
const char* value = field.data.c;
return BAG::CompoundDataType{std::string{value}};
}
default:
return {};
}
}
} // namespace
//! Open the specified BAG.
/*!
\param handle
A handle to the new BAG.
Cannot be NULL.
\param accessMode
How to access the BAG.
Read only or reading and writing.
\param fileName
The BAG file name.
Cannot be NULL.
\return
0 if successful.
An error code otherwise.
*/
BagError bagFileOpen(
BagHandle** handle,
BAG_OPEN_MODE accessMode,
const char* fileName)
{
if (!handle)
return BAG_INVALID_BAG_HANDLE;
if (!fileName)
return BAG_INVALID_FUNCTION_ARGUMENT;
try
{
auto pHandle = std::make_unique<BagHandle>();
pHandle->dataset = BAG::Dataset::open(std::string{fileName}, accessMode);
*handle = pHandle.release();
}
catch(const std::exception& /*e*/)
{
return BAG_BAD_FILE_IO_OPERATION;
}
return BAG_SUCCESS;
}
//! Close the specified BAG.
/*!
\param handle
The BAG handle.
Cannot be NULL.
\return
0 if successful.
An error code otherwise.
*/
BagError bagFileClose(
BagHandle* handle)
{
if (!handle)
return BAG_INVALID_BAG_HANDLE;
#ifndef NDEBUG
if (handle->dataset.use_count() > 1)
return BAG_MORE_BAG_INSTANCES_PRESENT;
#endif
handle->dataset.reset();
delete handle;
return BAG_SUCCESS;
}
//! Create a BAG from the specified metadata XML file.
/*!
\param handle
A handle to the new BAG.
Cannot be NULL.
\param fileName
The BAG file name.
Cannot be NULL.
\param metadataFile
The metadata file name.
Cannot be NULL.
\return
0 if successful.
An error code otherwise.
*/
BagError bagCreateFromFile(
BagHandle** handle,
const char* fileName,
const char* metadataFile)
{
if (!handle)
return BAG_INVALID_BAG_HANDLE;
if (!fileName || !metadataFile)
return BAG_INVALID_FUNCTION_ARGUMENT;
try
{
BAG::Metadata metadata;
metadata.loadFromFile(std::string{metadataFile});
constexpr uint64_t chunkSize = 100;
constexpr int compressionLevel = 6;
auto pHandle = std::make_unique<BagHandle>();
pHandle->dataset = BAG::Dataset::create(std::string{fileName},
std::move(metadata), chunkSize, compressionLevel);
*handle = pHandle.release();
}
catch(const std::exception /*e*/)
{
return BAG_BAD_FILE_IO_OPERATION;
}
return BAG_SUCCESS;
}
//! Create a BAG from the specified metadata XML buffer.
/*!
\param handle
A handle to the new BAG.
Cannot be NULL.
\param fileName
The BAG file name.
Cannot be NULL.
\param metadataBuffer
The metadata information in a buffer.
Cannot be NULL.
\param metadataBufferSize
The length of \e metadataBuffer.
\return
0 if successful.
An error code otherwise.
*/
BagError bagCreateFromBuffer(
BagHandle** handle,
const char* fileName,
uint8_t* metadataBuffer,
uint32_t metadataBufferSize)
{
if (!handle)
return BAG_INVALID_BAG_HANDLE;
if (!fileName || !metadataBuffer)
return BAG_INVALID_FUNCTION_ARGUMENT;
try
{
BAG::Metadata metadata;
metadata.loadFromBuffer(
std::string{reinterpret_cast<char*>(metadataBuffer), metadataBufferSize});
constexpr uint64_t chunkSize = 100;
constexpr int compressionLevel = 6;
auto pHandle = std::make_unique<BagHandle>();
pHandle->dataset = BAG::Dataset::create(std::string{fileName},
std::move(metadata), chunkSize, compressionLevel);
*handle = pHandle.release();
}
catch(const std::exception& /*e*/)
{
return BAG_HDF_CREATE_DATASET_FAILURE;
}
return BAG_SUCCESS;
}
//! Create a simple layer in the BAG.
/*!
\param handle
A handle to the BAG.
Cannot be NULL.
\param type
The type of simple layer to create.
\return
0 if successful.
An error code otherwise.
*/
BagError bagCreateLayer(
BagHandle* handle,
BAG_LAYER_TYPE type)
{
if (!handle)
return BAG_INVALID_BAG_HANDLE;
constexpr uint64_t chunkSize = 100;
constexpr int compressionLevel = 6;
try
{
handle->dataset->createSimpleLayer(type, chunkSize, compressionLevel);
}
catch(const std::exception& /*e*/)
{
return BAG_HDF_CREATE_DATASET_FAILURE;
}
return BAG_SUCCESS;
}
//! Retrieve the BAG grid dimensions.
/*!
\param handle
A handle to the BAG.
Cannot be NULL.
\param rows
The number of rows in the BAG.
Cannot be NULL.
\param cols
The number of columns in the BAG.
Cannot be NULL.
\param metadataBufferSize
The length of \e metadataBuffer.
\return
0 if successful.
An error code otherwise.
*/
BagError bagGetGridDimensions(
BagHandle* handle,
uint32_t* rows,
uint32_t* cols)
{
if (!handle)
return BAG_INVALID_BAG_HANDLE;
if (!rows || !cols)
return BAG_INVALID_FUNCTION_ARGUMENT;
std::tie(*rows, *cols) = handle->dataset->getDescriptor().getDims();
return BAG_SUCCESS;
}
//! Retrieve the BAG spacing.
/*!
\param handle
A handle to the BAG.
Cannot be NULL.
\param rows
The number of rows in the BAG.
Cannot be NULL.
\param cols
The number of columns in the BAG.
Cannot be NULL.
\param metadataBufferSize
The length of \e metadataBuffer.
\return
0 if successful.
An error code otherwise.
*/
BagError bagGetSpacing(
BagHandle* handle,
double* rowSpacing,
double* columnSpacing)
{
if (!handle)
return BAG_INVALID_BAG_HANDLE;
if (!rowSpacing || !columnSpacing)
return BAG_INVALID_FUNCTION_ARGUMENT;
const auto& metadata = handle->dataset->getMetadata();
*rowSpacing = metadata.rowResolution();
*columnSpacing = metadata.columnResolution();
return BAG_SUCCESS;
}
//! Retrieve the BAG geographic cover.
/*!
\param handle
A handle to the BAG.
Cannot be NULL.
\param llx
The lower left X geographic value.
Cannot be NULL.
\param lly
The lower left Y geographic value.
Cannot be NULL.
\param urx
The upper right X geographic value.
Cannot be NULL.
\param ury
The upper right Y geographic value.
Cannot be NULL.
\return
0 if successful.
An error code otherwise.
*/
BagError bagGetGeoCover(
BagHandle* handle,
double* llx,
double* lly,
double* urx,
double* ury)
{
if (!handle)
return BAG_INVALID_BAG_HANDLE;
if (!llx || !lly || !urx || !ury)
return BAG_INVALID_FUNCTION_ARGUMENT;
const auto& metadata = handle->dataset->getMetadata();
*llx = metadata.llCornerX();
*lly = metadata.llCornerY();
*urx = metadata.urCornerX();
*ury = metadata.urCornerY();
return BAG_SUCCESS;
}
//! Retrieve the minimum and maximum value of a simple layer.
/*!
\param handle
A handle to the BAG.
Cannot be NULL.
\param type
The simple layer type.
\param minValue
The minimum value.
Cannot be NULL.
\param maxValue
The maximum value.
Cannot be NULL.
\return
0 if successful.
An error code otherwise.
*/
BagError bagGetMinMaxSimple(
BagHandle* handle,
BAG_LAYER_TYPE type,
float* minValue,
float* maxValue)
{
if (!handle)
return BAG_INVALID_BAG_HANDLE;
if (!minValue || !maxValue)
return BAG_INVALID_FUNCTION_ARGUMENT;
const auto layer = handle->dataset->getSimpleLayer(type);
if (!layer)
return 9997; // layer type not found
std::tie(*minValue, *maxValue) = layer->getDescriptor()->getMinMax();
return BAG_SUCCESS;
}
//! Set the minimum and maximum value on a simple layer.
/*!
\param handle
A handle to the BAG.
Cannot be NULL.
\param type
The simple layer type.
\param minValue
The new minimum value.
\param maxValue
The new maximum value.
\return
0 if successful.
An error code otherwise.
*/
BagError bagSetMinMaxSimple(
BagHandle* handle,
BAG_LAYER_TYPE type,
float minValue,
float maxValue)
{
if (!handle)
return BAG_INVALID_BAG_HANDLE;
if (!minValue || !maxValue)
return BAG_INVALID_FUNCTION_ARGUMENT;
auto layer = handle->dataset->getSimpleLayer(type);
if (!layer)
return BAG_SIMPLE_LAYER_MISSING;
layer->getDescriptor()->setMinMax(minValue, maxValue);
return BAG_SUCCESS;
}
//! Retrieve the number of layers in the BAG.
/*!
\param handle
A handle to the BAG.
Cannot be NULL.
\param numLayers
The number of layers.
Cannot be NULL.
\return
0 if successful.
An error code otherwise.
*/
BagError bagGetNumLayers(
BagHandle* handle,
uint32_t* numLayers)
{
if (!handle)
return BAG_INVALID_BAG_HANDLE;
if (!numLayers)
return BAG_INVALID_FUNCTION_ARGUMENT;
*numLayers = static_cast<uint32_t>(handle->dataset->getLayers().size());
return BAG_SUCCESS;
}
//! Determine if the specified layer and optional case-insensitive name exists.
/*!
\param handle
A handle to the BAG.
Cannot be NULL.
\param type
The layer type.
\param layerName
The case-insensitive name of the layer.
Optional unless checking for a georeferenced metadata layer.
\param bagError
BAG_SUCCESS if successful.
The error code, otherwise.
Cannot be NULL.
\return
\e true if the BAG contains the specified layer
\e false otherwise
*/
bool bagContainsLayer(
BagHandle* handle,
BAG_LAYER_TYPE type,
const char* layerName,
BagError* bagError)
{
if (!handle)
{
*bagError = BAG_INVALID_BAG_HANDLE;
return false;
}
if (type == Georef_Metadata && (!layerName || layerName[0] == '\0'))
{
*bagError = BAG_GEOREF_METADATA_LAYER_NAME_MISSING;
return false;
}
*bagError = BAG_SUCCESS;
return handle->dataset->getLayer(type, layerName) != nullptr;
}
//! Read a specific area of a BAG.
/*!
\param handle
A handle to the BAG.
Cannot be NULL.
\param rowStart
The starting row.
\param colStart
The starting column.
\param rowEnd
The end row (inclusive).
\param colEnd
The end column (inclusive).
\param type
The layer type.
\param layerName
The case-insensitive name of the layer.
Optional unless checking for a georeferenced metadata layer.
\param data
The buffer the BAG is read into.
data must be at least large enough to hold the specified number of rows and columns.
Cannot be NULL.
\param x
The geographical position of the \e rowStart.
Cannot be NULL.
\param y
The geographical position of the \e colStart.
Cannot be NULL.
\return
0 if successful.
An error code otherwise.
*/
BagError bagRead(
BagHandle* handle,
uint32_t rowStart,
uint32_t colStart,
uint32_t rowEnd,
uint32_t colEnd,
BAG_LAYER_TYPE type,
const char* layerName,
uint8_t** data,
double* x,
double* y)
{
if (!handle)
return BAG_INVALID_BAG_HANDLE;
if (!data)
return BAG_INVALID_FUNCTION_ARGUMENT;
if (!x || !y)
return BAG_INVALID_FUNCTION_ARGUMENT;
if (type == Georef_Metadata && (!layerName || layerName[0] == '\0'))
return BAG_GEOREF_METADATA_LAYER_NAME_MISSING;
const auto layer = handle->dataset->getLayer(type, layerName);
if (!layer)
return BAG_HDF_DATASET_OPEN_FAILURE;
try
{
auto buffer = layer->read(rowStart, colStart, rowEnd, colEnd);
*data = buffer.release();
// Get the position of the node.
std::tie(*x, *y) = handle->dataset->gridToGeo(rowStart, colStart);
}
catch(const std::exception& /*e*/)
{
return BAG_HDF_READ_FAILURE;
}
return BAG_SUCCESS;
}
//! Write to a specific area of a BAG.
/*!
\param handle
A handle to the BAG.
Cannot be NULL.
\param rowStart
The starting row.
\param colStart
The starting column.
\param rowEnd
The end row (inclusive).
\param colEnd
The end column (inclusive).
\param type
The layer type.
\param layerName
The case-insensitive name of the layer.
Optional unless checking for a georeferenced metadata layer.
\param data
The buffer to write to the BAG.
data must be at least large enough to hold the specified number of rows and columns.
Cannot be NULL.
\return
0 if successful.
An error code otherwise.
*/
BagError bagWrite(
BagHandle* handle,
uint32_t rowStart,
uint32_t colStart,
uint32_t rowEnd,
uint32_t colEnd,
BAG_LAYER_TYPE type,
const char* layerName,
const uint8_t* data)
{
if (!handle)
return BAG_INVALID_BAG_HANDLE;
if (!data)
return BAG_SUCCESS; // nothing to write
if (type == Georef_Metadata && (!layerName || layerName[0] == '\0'))
return BAG_GEOREF_METADATA_LAYER_NAME_MISSING;
auto layer = handle->dataset->getLayer(type, layerName);
if (!layer)
return BAG_HDF_DATASET_OPEN_FAILURE;
try
{
layer->write(rowStart, colStart, rowEnd, colEnd, data);
}
catch(const std::exception& /*e*/)
{
return BAG_HDF_WRITE_FAILURE;
}
return BAG_SUCCESS;
}
/****************************************************************************************/
/*! \brief bagGetErrorString
*
* Description:
* This function provides a short text description for the last error that
* occurred on the BAG specified by bagHandle. Memory for the text string
* is maintained within the library and calling applications do not free this memory.
*
* \param code Error string will be assigned based on the \a bagError argument.
* \param **error The address of a string pointer which will be updated
* to point to a short text string describing the error condition.
*
* \return On success the function returns \a BAG_SUCCESS You can always
* call this function again to see what the error was from the results of the
* original call to \a bagGetErrorString.
*
****************************************************************************************/
BagError bagGetErrorString(
BagError code,
uint8_t** error)
{
constexpr int MAX_STR = 255;
constexpr int RANK = 2;
static char str[MAX_STR];
str[0] = '\0';
if (!error)
return BAG_INVALID_FUNCTION_ARGUMENT;
*error = reinterpret_cast<uint8_t*>(str);
switch (code)
{
case BAG_SUCCESS:
strncpy(str, "Bag returned a successful completion", MAX_STR-1);
break;
case BAG_BAD_FILE_IO_OPERATION:
strncpy(str, "Bad status with file IO operation", MAX_STR-1);
break;
case BAG_NO_FILE_FOUND:
strncpy(str, "File not found", MAX_STR-1);
break;
case BAG_NO_ACCESS_PERMISSION:
strncpy(str, "Failed to access Bag because of permissions", MAX_STR-1);
break;
case BAG_MEMORY_ALLOCATION_FAILED:
strncpy(str, "Memory allocation failed", MAX_STR-1);
break;
case BAG_INVALID_BAG_HANDLE:
strncpy(str, "Invalid or NULL bagHandle", MAX_STR-1);
break;
case BAG_INVALID_FUNCTION_ARGUMENT:
strncpy(str, "Invalid function argument or illegal value passed to Bag", MAX_STR-1);
break;
case BAG_METADTA_NO_HOME:
strncpy(str, "The BAG_HOME environment variable must be set to the configdata directory of the openns distribution", MAX_STR-1);
break;
case BAG_METADTA_SCHEMA_FILE_MISSING:
strncpy(str, "Metadata schema file(s) (*.xsd) was missing, they should be within configdata under smXML or ISO19139/bag. Check BAG_HOME path", MAX_STR-1);
break;
case BAG_METADTA_PARSE_MEM_EXCEPTION:
strncpy(str, "Metadata exceeded memory limit during parsing", MAX_STR-1);
break;
case BAG_METADTA_PARSE_EXCEPTION:
strncpy(str, "Metadata parsing encountered an fatal exception", MAX_STR-1);
break;
case BAG_METADTA_PARSE_DOM_EXCEPTION:
strncpy(str, "Metadata parsing encountered a DOM (document object model) exception, impossible to complete operation", MAX_STR-1);
break;
case BAG_METADTA_PARSE_UNK_EXCEPTION:
strncpy(str, "Metadata parsing encountered an unknown error", MAX_STR-1);
break;
case BAG_METADTA_PARSE_FAILED:
strncpy(str, "Metadata parsing failed, unable to parse input file", MAX_STR-1);
break;
case BAG_METADTA_PARSE_FAILED_MEM:
strncpy(str, "Metadata parsing failed, unable to parse specified input buffer memory overflow", MAX_STR-1);
break;
case BAG_METADTA_VALIDATE_FAILED:
strncpy(str, "Metadata XML validation failed", MAX_STR-1);
break;
case BAG_METADTA_INVALID_HANDLE:
strncpy(str, "Metadata Invalid (NULL) bagHandle supplied to an accessor method", MAX_STR-1);
break;
case BAG_METADTA_INIT_FAILED:
strncpy(str, "Metadata Initialization of the low level XML support system failed", MAX_STR-1);
break;
case BAG_METADTA_NO_PROJECTION_INFO:
strncpy(str, "Metadata No projection information was found in the XML supplied", MAX_STR-1);
break;
case BAG_METADTA_INSUFFICIENT_BUFFER:
strncpy(str, "Metadata supplied buffer is not large enough to hold the extracted contents from XML", MAX_STR-1);
break;
case BAG_METADTA_UNCRT_MISSING:
strncpy(str, "Metadata 'uncertaintyType' information is missing from the XML structure", MAX_STR-1);
break;
case BAG_METADTA_INCOMPLETE_COVER:
strncpy(str, "Metadata One or more elements of the requested coverage are missing from the XML file", MAX_STR-1);
break;
case BAG_METADTA_INVLID_DIMENSIONS:
sprintf(str, "Metadata The number of dimensions is incorrect (not equal to %d)", RANK);
break;
case BAG_METADTA_BUFFER_EXCEEDED:
strncpy(str, "Metadata supplied buffer is too large to be stored in the internal array", MAX_STR-1);
break;
case BAG_METADTA_DPTHCORR_MISSING:
strncpy(str, "The 'depthCorrectionType' information is missing from the XML structure", MAX_STR-1);
break;
case BAG_METADTA_RESOLUTION_MISSING:
strncpy(str, "Metadata resolution information is missing from the XML structure", MAX_STR-1);
break;
case BAG_METADTA_INVALID_PROJECTION:
strncpy(str, "Metadata unsupported projection being used", MAX_STR-1);
break;
case BAG_METADTA_INVALID_DATUM:
strncpy(str, "Metadata unsupported datum being used", MAX_STR-1);
break;
case BAG_METADTA_INVALID_HREF:
strncpy(str, "Metadata horizontal reference system is invalid", MAX_STR-1);
break;
case BAG_METADTA_INVALID_VREF:
strncpy(str, "Metadata vertical reference system is invalid", MAX_STR-1);
break;
case BAG_METADTA_SCHEMA_SETUP_FAILED:
strncpy(str, "Failed to setup the xml schema", MAX_STR-1);
break;
case BAG_METADTA_SCHEMA_VALIDATION_SETUP_FAILED:
strncpy(str, "Failed to setup the xml schema validation", MAX_STR-1);
break;
case BAG_METADTA_EMPTY_DOCUMENT:
strncpy(str, "The metadata document is emtpy", MAX_STR-1);
break;
case BAG_METADTA_MISSING_MANDATORY_ITEM:
strncpy(str, "The metadata is missing a mandatory item", MAX_STR-1);
break;
case BAG_METADTA_NOT_INITIALIZED:
strncpy(str, "The metadata has not been initialized correctly", MAX_STR-1);
break;
case BAG_NOT_HDF5_FILE:
strncpy(str, "HDF Bag is not an HDF5 File", MAX_STR-1);
break;
case BAG_HDF_RANK_INCOMPATIBLE:
sprintf(str, "HDF Bag's rank is incompatible with expected Rank of the Datasets: %d", RANK);
break;
case BAG_HDF_TYPE_NOT_FOUND:
strncpy(str, "HDF Bag surface Datatype parameter not available", MAX_STR-1);
break;
case BAG_HDF_DATASPACE_CORRUPTED:
strncpy(str, "HDF Dataspace for a bag surface is corrupted or could not be read", MAX_STR-1);
break;
case BAG_HDF_ACCESS_EXTENTS_ERROR:
strncpy(str, "HDF Failure in request for access outside the extents of a bag surface's Dataset", MAX_STR-1);
break;
case BAG_HDF_CANNOT_WRITE_NULL_DATA:
strncpy(str, "HDF Cannot write NULL or uninitialized data to Dataset", MAX_STR-1);
break;
case BAG_HDF_INTERNAL_ERROR:
strncpy(str, "HDF There was an internal HDF error detected", MAX_STR-1);
break;
case BAG_HDF_CREATE_FILE_FAILURE:
strncpy(str, "HDF Unable to create new HDF Bag File", MAX_STR-1);
break;
case BAG_HDF_CREATE_DATASPACE_FAILURE:
strncpy(str, "HDF Unable to create the Dataspace", MAX_STR-1);
break;
case BAG_HDF_CREATE_PROPERTY_CLASS_FAILURE:
strncpy(str, "HDF Unable to create the Property class", MAX_STR-1);
break;
case BAG_HDF_SET_PROPERTY_FAILURE:
strncpy(str, "HDF Unable to set value of Property class", MAX_STR-1);
break;
case BAG_HDF_TYPE_COPY_FAILURE:
strncpy(str, "HDF Failed to copy Datatype parameter for Dataset access", MAX_STR-1);
break;
case BAG_HDF_CREATE_DATASET_FAILURE:
strncpy(str, "HDF Unable to create the Dataset", MAX_STR-1);
break;
case BAG_HDF_DATASET_EXTEND_FAILURE:
strncpy(str, "HDF Cannot extend Dataset extents", MAX_STR-1);
break;
case BAG_HDF_CREATE_ATTRIBUTE_FAILURE:
strncpy(str, "HDF Unable to create Attribute", MAX_STR-1);
break;
case BAG_HDF_CREATE_GROUP_FAILURE:
strncpy(str, "HDF Unable to create Group", MAX_STR-1);
break;
case BAG_HDF_WRITE_FAILURE:
strncpy(str, "HDF Failure writing to Dataset", MAX_STR-1);
break;
case BAG_HDF_READ_FAILURE:
strncpy(str, "HDF Failure reading from Dataset", MAX_STR-1);
break;
case BAG_HDF_GROUP_CLOSE_FAILURE:
strncpy(str, "HDF Failure closing Group", MAX_STR-1);
break;
case BAG_HDF_FILE_CLOSE_FAILURE:
strncpy(str, "HDF Failure closing File", MAX_STR-1);
break;
case BAG_HDF_FILE_OPEN_FAILURE:
strncpy(str, "HDF Unable to open File", MAX_STR-1);
break;
case BAG_HDF_GROUP_OPEN_FAILURE:
strncpy(str, "HDF Unable to open Group", MAX_STR-1);
break;
case BAG_HDF_ATTRIBUTE_OPEN_FAILURE:
strncpy(str, "HDF Unable to open Attribute", MAX_STR-1);
break;
case BAG_HDF_ATTRIBUTE_CLOSE_FAILURE:
strncpy(str, "HDF Failure closing Attribute", MAX_STR-1);
break;
case BAG_HDF_DATASET_CLOSE_FAILURE:
strncpy(str, "HDF Failure closing Dataset", MAX_STR-1);
break;
case BAG_HDF_DATASET_OPEN_FAILURE:
strncpy(str, "HDF Unable to open Dataset", MAX_STR-1);
break;
case BAG_HDF_TYPE_CREATE_FAILURE:
strncpy(str, "HDF Unable to create Datatype", MAX_STR-1);
break;
case BAG_HDF_INVALID_COMPRESSION_LEVEL:
strncpy(str, "HDF compression level not in acceptable range of 0 to 9", MAX_STR-1);
break;
case BAG_INVALID_ERROR_CODE:
default:
strncpy(str, "An undefined bagError code was encountered", MAX_STR-1);
return BAG_INVALID_ERROR_CODE;
}
return BAG_SUCCESS;
}
//! Determine the geographic position of a specified grid row and column.
/*!
\param handle
A handle to the BAG.
Cannot be NULL.
\param row
The grid row.
\param col
The grid column.
\param x
The geographical position of \e row.
Cannot be NULL.
\param y
The geographical position of \e col.
Cannot be NULL.
\return
0 if successful.
An error code otherwise.
*/
BagError bagComputePostion(
BagHandle* handle,
uint32_t row,
uint32_t col,
double* x,
double* y)
{
if (!handle)
return BAG_INVALID_BAG_HANDLE;
if (!x || !y)
return BAG_INVALID_FUNCTION_ARGUMENT;
std::tie(*x, *y) = handle->dataset->gridToGeo(row, col);
return BAG_SUCCESS;
}
//! Determine the grid position from the specified geographic position.
/*!
\param handle
A handle to the BAG.
Cannot be NULL.
\param x