bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
GDALArray.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 <BESDebug.h>
27
28#include "GDALTypes.h"
29#include "gdal_utils.h"
30
31using namespace std;
32using namespace libdap;
33
34/************************************************************************/
35/* ==================================================================== */
36/* GDALArray */
37/* ==================================================================== */
38/************************************************************************/
39
40void GDALArray::m_duplicate(const GDALArray &a)
41{
42 filename = a.filename;
43 eBufType = a.eBufType;
44 iBandNum = a.iBandNum;
45}
46
47BaseType *
48GDALArray::ptr_duplicate()
49{
50 return new GDALArray(*this);
51}
52
53GDALArray::GDALArray(const string &n, BaseType *v) : Array(n, v), filename(""), eBufType(GDT_Unknown), iBandNum(0)
54{
55 BESDEBUG("gdal", " Called GDALArray::GDALArray() 1" << endl);
56}
57
58GDALArray::GDALArray(const string &name, BaseType *proto, const string &filenameIn, GDALDataType eBufTypeIn,int iBandNumIn) :
59 Array(name, proto), filename(filenameIn), eBufType(eBufTypeIn), iBandNum(iBandNumIn)
60{
61 BESDEBUG("gdal", " Called GDALArray::GDALArray() 2" << endl);
62}
63
64GDALArray::GDALArray(const GDALArray &src) : Array(src)
65{
66 m_duplicate(src);
67}
68
69GDALArray::~GDALArray()
70{
71}
72
73bool
74GDALArray::read()
75{
76 BESDEBUG("gdal", "Entering GDALArray::read()" << endl);
77
78 if (read_p()) return true;
79
80 GDALDatasetH hDS = GDALOpen(filename.c_str(), GA_ReadOnly);
81 if (hDS == NULL)
82 throw Error(string(CPLGetLastErrorMsg()));
83
84 try {
85 if (name() == "northing" || name() == "easting")
86 read_map_array(this, GDALGetRasterBand(hDS, get_gdal_band_num()), hDS);
87 else
88 read_data_array(this, GDALGetRasterBand(hDS, get_gdal_band_num()));
89
90 set_read_p(true);
91 }
92 catch (...) {
93 GDALClose(hDS);
94 throw;
95 }
96
97 GDALClose(hDS);
98
99 return true;
100}