bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
ScaleGrid.h
1
2// -*- mode: c++; c-basic-offset:4 -*-
3
4// This file is part of libdap, A C++ implementation of the OPeNDAP Data
5// Access Protocol.
6
7// Copyright (c) 2016 OPeNDAP, Inc.
8// Author: James Gallagher <jgallagher@opendap.org>
9//
10// This library is free software; you can redistribute it and/or
11// modify it under the terms of the GNU Lesser General Public
12// License as published by the Free Software Foundation; either
13// version 2.1 of the License, or (at your option) any later version.
14//
15// This library is distributed in the hope that it will be useful,
16// but WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18// Lesser General Public License for more details.
19//
20// You should have received a copy of the GNU Lesser General Public
21// License along with this library; if not, write to the Free Software
22// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23//
24// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
25
26#ifndef _scale_util_h
27#define _scale_util_h
28
29#include <vector>
30#include <string>
31#include <memory>
32
33#include <gdal.h>
34#include <gdal_priv.h>
35
36#include <libdap/ServerFunction.h>
37
38
39namespace libdap {
40class Array;
41class Grid;
42}
43
44namespace functions {
45
46struct SizeBox {
47 int x_size;
48 int y_size;
49
50 SizeBox(int x, int y) : x_size(x), y_size(y) { }
51 SizeBox(): x_size(0), y_size(0) { }
52};
53
54#if 0
55struct GeoBox {
56 double top; // Latitude
57 double bottom; // Lat
58 double left; // Lon
59 double right; // Lon
60
61 GeoBox(double t, double b, double l, double r) : top(t), bottom(b), left(l), right(r) { }
62 GeoBox() : top(0.0), bottom(0.0), left(0.0), right(0.0) { }
63};
64#endif
65
66SizeBox get_size_box(libdap::Array *x, libdap::Array *y);
67
68std::vector<double> get_geotransform_data(libdap::Array *x, libdap::Array *y, bool test_maps = false);
69// std::auto_ptr< std::vector<GDAL_GCP> >
70std::vector<GDAL_GCP> get_gcp_data(libdap::Array *x, libdap::Array *y, int sample_x = 1, int sample_y = 1);
71
72GDALDataType get_array_type(const libdap::Array *a);
73void read_band_data(const libdap::Array *src, GDALRasterBand* band);
74void add_band_data(const libdap::Array *src, GDALDataset* ds);
75
76std::unique_ptr<GDALDataset> build_src_dataset(libdap::Array *data, libdap::Array *x, libdap::Array *y,
77 const std::string &srs = "WGS84");
78std::unique_ptr<GDALDataset> build_src_dataset_3D(libdap::Array *data, libdap::Array *t,libdap::Array *x, libdap::Array *y,
79 const std::string &srs = "WGS84");
80
81std::unique_ptr<GDALDataset> scale_dataset(std::unique_ptr<GDALDataset>& src, const SizeBox &size,
82 const std::string &crs = "", const std::string &interp = "nearest");
83
84std::unique_ptr<GDALDataset> scale_dataset_3D(std::unique_ptr<GDALDataset>& src, const SizeBox &size,
85 const std::string &crs = "", const std::string &interp = "nearest");
86
87libdap::Array *build_array_from_gdal_dataset(GDALDataset *dst, const libdap::Array *src);
88libdap::Array *build_array_from_gdal_dataset_3D(GDALDataset *dst, const libdap::Array *src);
89void build_maps_from_gdal_dataset(GDALDataset *dst, libdap::Array *x_map, libdap::Array *y_map, bool name_maps = false);
90void build_maps_from_gdal_dataset_3D(GDALDataset *dst, libdap::Array *t, libdap::Array *t_map, libdap::Array *x_map, libdap::Array *y_map, bool name_maps = false);
91
92libdap::Grid *scale_dap_grid(const libdap::Grid *src, const SizeBox &size, const std::string &dest_crs,
93 const std::string &interp);
94libdap::Grid *scale_dap_array(const libdap::Array *data, const libdap::Array *lon, const libdap::Array *lat,
95 const SizeBox &size, const std::string &crs, const std::string &interp);
96libdap::Grid *scale_dap_array_3D(const libdap::Array *data, const libdap::Array *t, const libdap::Array *lon, const libdap::Array *lat, const SizeBox &size,
97 const std::string &crs, const std::string &interp);
98
99void function_scale_grid(int argc, libdap::BaseType * argv[], libdap::DDS &, libdap::BaseType **btpp);
100void function_scale_array(int argc, libdap::BaseType * argv[], libdap::DDS &, libdap::BaseType **btpp);
101void function_scale_array_3D(int argc, libdap::BaseType * argv[], libdap::DDS &, libdap::BaseType **btpp);
102
103class ScaleGrid: public libdap::ServerFunction {
104public:
105 ScaleGrid()
106 {
107 setName("scale_grid");
108 setDescriptionString("Scale a DAP2 Grid");
109 setUsageString("scale_grid(Grid, Y size, X size, CRS, Interpolation method)");
110 setRole("http://services.opendap.org/dap4/server-side-function/scale_grid");
111 setDocUrl("http://docs.opendap.org/index.php/Server_Side_Processing_Functions#scale_grid");
112 setFunction(function_scale_grid);
113 setVersion("1.0");
114 }
115 virtual ~ScaleGrid()
116 {
117 }
118
119};
120
121class ScaleArray: public libdap::ServerFunction {
122public:
123 ScaleArray()
124 {
125 setName("scale_array");
126 setDescriptionString("Scale a DAP2 Array");
127 setUsageString("scale_grid(Array data, Array lon, Array lat, Y size, X size, CRS, Interpolation method)");
128 setRole("http://services.opendap.org/dap4/server-side-function/scale_array");
129 setDocUrl("http://docs.opendap.org/index.php/Server_Side_Processing_Functions#scale_array");
130 setFunction(function_scale_array);
131 setVersion("1.0");
132 }
133 virtual ~ScaleArray()
134 {
135 }
136
137};
138
139class Scale3DArray: public libdap::ServerFunction {
140public:
141 Scale3DArray()
142 {
143 setName("scale_3D_array");
144 setDescriptionString("Scale a DAP2 3D Array");
145 setUsageString("scale_3D_grid(Array data, Array time, Array lon, Array lat, Y size, X size, CRS, Interpolation method)");
146 setRole("http://services.opendap.org/dap4/server-side-function/scale_3D_array");
147 setDocUrl("http://docs.opendap.org/index.php/Server_Side_Processing_Functions#scale_3D_array");
148 setFunction(function_scale_array_3D);
149 setVersion("1.0");
150 }
151 virtual ~Scale3DArray()
152 {
153 }
154
155};
156
157} // namespace functions
158
159#endif // _scale_util_h