bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
GeoConstraint.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) 2006 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 _geo_constraint_h
27#define _geo_constraint_h 1
28
29#include <string>
30#include <sstream>
31#include <set>
32
33namespace libdap {
34class BaseType;
35class Array;
36class Grid;
37}
38
39namespace functions
40{
41
96
97class GeoConstraint
98{
99public:
103 enum Notation {
104 unknown_notation,
105 pos,
106 neg_pos
107 };
108
113 unknown_sense,
114 normal,
115 inverted
116 };
117
118private:
119 char *d_array_data; //< Holds the Grid's data values
120 int d_array_data_size; //< Total size (bytes) of the array data
121
122 double *d_lat; //< Holds the latitude values
123 double *d_lon; //< Holds the longitude values
124 int d_lat_length; //< Elements (not bytes) in the latitude vector
125 int d_lon_length; //< ... longitude vector
126
127 // These four are indexes of the constraint
128 int d_latitude_index_top;
129 int d_latitude_index_bottom;
130 int d_longitude_index_left;
131 int d_longitude_index_right;
132
133 bool d_bounding_box_set; //< Has the bounding box been set?
134 bool d_longitude_rightmost; //< Is longitude the rightmost dimension?
135
136 Notation d_longitude_notation;
137 LatitudeSense d_latitude_sense;
138
139 libdap::Array::Dim_iter d_lon_dim; //< References the longitude dimension
140 libdap::Array::Dim_iter d_lat_dim; //< References the latitude dimension
141
142 // Sets of string values used to find stuff in attributes
143 set<string> d_coards_lat_units;
144 set<string> d_coards_lon_units;
145
146 set<string> d_lat_names;
147 set<string> d_lon_names;
148
149 // Hide these three automatically provided methods
150 GeoConstraint(const GeoConstraint &param);
151 GeoConstraint &operator=(GeoConstraint &rhs);
152
153protected:
162 virtual bool build_lat_lon_maps() = 0;
163
174 virtual bool lat_lon_dimensions_ok() = 0;
175
176 Notation categorize_notation(const double left, const double right) const;
177 void transform_constraint_to_pos_notation(double &left, double &right) const;
178 virtual void transform_longitude_to_pos_notation();
179 virtual void transform_longitude_to_neg_pos_notation();
180 virtual bool is_bounding_box_valid(const double left, const double top,
181 const double right, const double bottom) const;
182 void find_longitude_indeces(double left, double right,
183 int &longitude_index_left,
184 int &longitude_index_right) const;
185
186 virtual void transpose_vector(double *src, const int length);
187 virtual void reorder_longitude_map(int longitude_index_left);
188
189 virtual LatitudeSense categorize_latitude() const;
190 void find_latitude_indeces(double top, double bottom, LatitudeSense sense,
191 int &latitude_index_top,
192 int &latitude_index_bottom) const;
193
194 virtual void reorder_data_longitude_axis(libdap::Array &a,libdap:: Array::Dim_iter lon_dim);
195 virtual void flip_latitude_within_array(libdap::Array &a, int lat_length, int lon_length);
196
197 friend class GridGeoConstraintTest; // Unit tests
198
199public:
202 GeoConstraint();
204
205 virtual ~GeoConstraint()
206 {
207 delete [] d_lat; d_lat = 0;
208 delete [] d_lon; d_lon = 0;
209 delete [] d_array_data; d_array_data = 0;
210 }
211
214 // These are set in reorder_data_longitude_axis()
215 char *get_array_data() const
216 {
217 return d_array_data;
218 }
219 int get_array_data_size() const
220 {
221 return d_array_data_size;
222 }
223
224 double *get_lat() const
225 {
226 return d_lat;
227 }
228 double *get_lon() const
229 {
230 return d_lon;
231 }
232 void set_lat(double *lat)
233 {
234 d_lat = lat;
235 }
236 void set_lon(double *lon)
237 {
238 d_lon = lon;
239 }
240
241 int get_lat_size() const
242 {
243 return d_lat_length;
244 }
245 int get_lon_size() const
246 {
247 return d_lon_length;
248 }
249 void set_lat_size(int len)
250 {
251 d_lat_length = len;
252 }
253 void set_lon_size(int len)
254 {
255 d_lon_length = len;
256 }
257
258 libdap::Array::Dim_iter get_lon_dim() const
259 {
260 return d_lon_dim;
261 }
262 libdap::Array::Dim_iter get_lat_dim() const
263 {
264 return d_lat_dim;
265 }
266 void set_lon_dim(libdap::Array::Dim_iter lon)
267 {
268 d_lon_dim = lon;
269 }
270 void set_lat_dim(libdap::Array::Dim_iter lat)
271 {
272 d_lat_dim = lat;
273 }
274
275 // These four are indexes of the constraint
276 int get_latitude_index_top() const
277 {
278 return d_latitude_index_top;
279 }
280 int get_latitude_index_bottom() const
281 {
282 return d_latitude_index_bottom;
283 }
284 void set_latitude_index_top(int top)
285 {
286 d_latitude_index_top = top;
287 }
288 void set_latitude_index_bottom(int bottom)
289 {
290 d_latitude_index_bottom = bottom;
291 }
292
293 int get_longitude_index_left() const
294 {
295 return d_longitude_index_left;
296 }
297 int get_longitude_index_right() const
298 {
299 return d_longitude_index_right;
300 }
301 void set_longitude_index_left(int left)
302 {
303 d_longitude_index_left = left;
304 }
305 void set_longitude_index_right(int right)
306 {
307 d_longitude_index_right = right;
308 }
309
310 bool is_bounding_box_set() const
311 {
312 return d_bounding_box_set;
313 }
314 bool is_longitude_rightmost() const
315 {
316 return d_longitude_rightmost;
317 }
318 void set_longitude_rightmost(bool state)
319 {
320 d_longitude_rightmost = state;
321 }
322
323 Notation get_longitude_notation() const
324 {
325 return d_longitude_notation;
326 }
327 LatitudeSense get_latitude_sense() const
328 {
329 return d_latitude_sense;
330 }
331 void set_longitude_notation(Notation n)
332 {
333 d_longitude_notation = n;
334 }
335 void set_latitude_sense(LatitudeSense l)
336 {
337 d_latitude_sense = l;
338 }
339
340 set<string> get_coards_lat_units() const
341 {
342 return d_coards_lat_units;
343 }
344 set<string> get_coards_lon_units() const
345 {
346 return d_coards_lon_units;
347 }
348
349 set<string> get_lat_names() const
350 {
351 return d_lat_names;
352 }
353 set<string> get_lon_names() const
354 {
355 return d_lon_names;
356 }
358
359 void set_bounding_box(double top, double left, double bottom, double right);
360
363 virtual void apply_constraint_to_data() = 0;
364};
365
366} // namespace libdap
367
368#endif // _geo_constraint_h
369
virtual bool build_lat_lon_maps()=0
virtual void apply_constraint_to_data()=0
Once the bounding box is set use this method to apply the constraint.
virtual bool lat_lon_dimensions_ok()=0
STL class.