bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
GDALGrid.cc
1// This file is part of the GDAL OPeNDAP Adapter
2
3// Copyright (c) 2004 OPeNDAP, Inc.
4// Author: Frank Warmerdam <warmerdam@pobox.com>
5//
6// This library is free software; you can redistribute it and/or
7// modify it under the terms of the GNU Lesser General Public
8// License as published by the Free Software Foundation; either
9// version 2.1 of the License, or (at your option) any later version.
10//
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14// Lesser General Public License for more details.
15//
16// You should have received a copy of the GNU Lesser General Public
17// License along with this library; if not, write to the Free Software
18// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19//
20// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
21
22#include "config.h"
23
24#include <string>
25
26#include <gdal.h>
27#include <cpl_conv.h>
28
29#include <BESDebug.h>
30
31#include "GDALTypes.h"
32#include "gdal_utils.h"
33
34using namespace std;
35using namespace libdap;
36
37/************************************************************************/
38/* ==================================================================== */
39/* GDALGrid */
40/* ==================================================================== */
41/************************************************************************/
42
43void GDALGrid::m_duplicate(const GDALGrid &g)
44{
45 filename = g.filename;
46}
47
48// protected
49
50BaseType *
51GDALGrid::ptr_duplicate()
52{
53 return new GDALGrid(*this);
54}
55
56// public
57
58GDALGrid::GDALGrid(const string &filenameIn, const string &name) :
59 Grid(name), filename(filenameIn)
60{
61}
62
63GDALGrid::GDALGrid(const GDALGrid &rhs) : Grid(rhs)
64{
65 m_duplicate(rhs);
66}
67
68GDALGrid &GDALGrid::operator=(const GDALGrid &rhs)
69{
70 if (this == &rhs) return *this;
71
72 m_duplicate(rhs);
73
74 return *this;
75}
76
77GDALGrid::~GDALGrid()
78{
79}
80
81bool GDALGrid::read()
82{
83 BESDEBUG("gdal", "Entering GDALGrid::read()" << endl);
84
85 if (read_p()) // nothing to do
86 return true;
87
88 GDALDatasetH hDS = GDALOpen(filename.c_str(), GA_ReadOnly);
89 if (hDS == NULL)
90 throw Error(string(CPLGetLastErrorMsg()));
91
92 try {
93 // This specialization of Grid::read() is a bit more efficient than using Array::read()
94 // since it only opens the file using GDAL once. Calling Array::read() would open the
95 // file three times. jhrg 5/31/17
96 GDALArray *array = static_cast<GDALArray*>(array_var());
97
98 read_data_array(array, GDALGetRasterBand(hDS, array->get_gdal_band_num()));
99 array->set_read_p(true);
100
101 Map_iter miter = map_begin();
102 array = static_cast<GDALArray*>((*miter));
103 read_map_array(array, GDALGetRasterBand(hDS, array->get_gdal_band_num()), hDS);
104 array->set_read_p(true);
105
106 ++miter;
107 array = static_cast<GDALArray*>(*miter);
108 read_map_array(array, GDALGetRasterBand(hDS, array->get_gdal_band_num()), hDS);
109 array->set_read_p(true);
110 }
111 catch (...) {
112 GDALClose(hDS);
113 throw;
114 }
115
116 GDALClose(hDS);
117
118 return true;
119}