OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
GeoConstraint.h
Go to the documentation of this file.
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 
33 #include <BaseType.h>
34 #include <Array.h>
35 #include <Grid.h>
36 
37 namespace libdap
38 {
39 
96 {
97 public:
101  enum Notation {
105  };
106 
114  };
115 
116 private:
117  char *d_array_data; //< Holds the Grid's data values
118  int d_array_data_size; //< Total size (bytes) of the array data
119 
120  double *d_lat; //< Holds the latitude values
121  double *d_lon; //< Holds the longitude values
122  int d_lat_length; //< Elements (not bytes) in the latitude vector
123  int d_lon_length; //< ... longitude vector
124 
125  // These four are indexes of the constraint
126  int d_latitude_index_top;
127  int d_latitude_index_bottom;
128  int d_longitude_index_left;
129  int d_longitude_index_right;
130 
131  bool d_bounding_box_set; //< Has the bounding box been set?
132  bool d_longitude_rightmost; //< Is longitude the rightmost dimension?
133 
134  Notation d_longitude_notation;
135  LatitudeSense d_latitude_sense;
136 
137  Array::Dim_iter d_lon_dim; //< References the longitude dimension
138  Array::Dim_iter d_lat_dim; //< References the latitude dimension
139 
140  // Sets of string values used to find stuff in attributes
141  set<string> d_coards_lat_units;
142  set<string> d_coards_lon_units;
143 
144  set<string> d_lat_names;
145  set<string> d_lon_names;
146 
147  // Hide these three automatically provided methods
148  GeoConstraint(const GeoConstraint &param);
149  GeoConstraint &operator=(GeoConstraint &rhs);
150 
151 protected:
160  virtual bool build_lat_lon_maps() = 0;
161 
172  virtual bool lat_lon_dimensions_ok() = 0;
173 
174  Notation categorize_notation(const double left, const double right) const;
175  void transform_constraint_to_pos_notation(double &left, double &right) const;
178  virtual bool is_bounding_box_valid(const double left, const double top,
179  const double right, const double bottom) const;
180  void find_longitude_indeces(double left, double right,
181  int &longitude_index_left,
182  int &longitude_index_right) const;
183 
184  virtual void transpose_vector(double *src, const int length);
185  virtual void reorder_longitude_map(int longitude_index_left);
186 
187  virtual LatitudeSense categorize_latitude() const;
188  void find_latitude_indeces(double top, double bottom, LatitudeSense sense,
189  int &latitude_index_top,
190  int &latitude_index_bottom) const;
191 
192  virtual void reorder_data_longitude_axis(Array &a, Array::Dim_iter lon_dim);
193  virtual void flip_latitude_within_array(Array &a, int lat_length,
194  int lon_length);
195 
196  friend class GridGeoConstraintTest; // Unit tests
197 
198 public:
201  GeoConstraint();
203 
204  virtual ~GeoConstraint()
205  {
206  delete [] d_lat; d_lat = 0;
207  delete [] d_lon; d_lon = 0;
208  delete [] d_array_data; d_array_data = 0;
209  }
210 
213  // These are set in reorder_data_longitude_axis()
214  char *get_array_data() const
215  {
216  return d_array_data;
217  }
219  {
220  return d_array_data_size;
221  }
222 
223  double *get_lat() const
224  {
225  return d_lat;
226  }
227  double *get_lon() const
228  {
229  return d_lon;
230  }
231  void set_lat(double *lat)
232  {
233  d_lat = lat;
234  }
235  void set_lon(double *lon)
236  {
237  d_lon = lon;
238  }
239 
240  int get_lat_length() const
241  {
242  return d_lat_length;
243  }
244  int get_lon_length() const
245  {
246  return d_lon_length;
247  }
248  void set_lat_length(int len)
249  {
250  d_lat_length = len;
251  }
252  void set_lon_length(int len)
253  {
254  d_lon_length = len;
255  }
256 
257  Array::Dim_iter get_lon_dim() const
258  {
259  return d_lon_dim;
260  }
261  Array::Dim_iter get_lat_dim() const
262  {
263  return d_lat_dim;
264  }
265  void set_lon_dim(Array::Dim_iter lon)
266  {
267  d_lon_dim = lon;
268  }
269  void set_lat_dim(Array::Dim_iter lat)
270  {
271  d_lat_dim = lat;
272  }
273 
274  // These four are indexes of the constraint
276  {
277  return d_latitude_index_top;
278  }
280  {
281  return d_latitude_index_bottom;
282  }
284  {
285  d_latitude_index_top = top;
286  }
287  void set_latitude_index_bottom(int bottom)
288  {
289  d_latitude_index_bottom = bottom;
290  }
291 
293  {
294  return d_longitude_index_left;
295  }
297  {
298  return d_longitude_index_right;
299  }
301  {
302  d_longitude_index_left = left;
303  }
305  {
306  d_longitude_index_right = right;
307  }
308 
309  bool is_bounding_box_set() const
310  {
311  return d_bounding_box_set;
312  }
314  {
315  return d_longitude_rightmost;
316  }
317  void set_longitude_rightmost(bool state)
318  {
319  d_longitude_rightmost = state;
320  }
321 
323  {
324  return d_longitude_notation;
325  }
327  {
328  return d_latitude_sense;
329  }
331  {
332  d_longitude_notation = n;
333  }
335  {
336  d_latitude_sense = l;
337  }
338 
339  set<string> get_coards_lat_units() const
340  {
341  return d_coards_lat_units;
342  }
343  set<string> get_coards_lon_units() const
344  {
345  return d_coards_lon_units;
346  }
347 
348  set<string> get_lat_names() const
349  {
350  return d_lat_names;
351  }
352  set<string> get_lon_names() const
353  {
354  return d_lon_names;
355  }
357 
358  void set_bounding_box(double top, double left, double bottom, double right);
359 
362  virtual void apply_constraint_to_data() = 0;
363 };
364 
365 } // namespace libdap
366 
367 #endif // _geo_constraint_h
368 
void set_lat_dim(Array::Dim_iter lat)
void transform_constraint_to_pos_notation(double &left, double &right) const
char * get_array_data() const
void set_latitude_index_bottom(int bottom)
void set_lon(double *lon)
virtual void reorder_data_longitude_axis(Array &a, Array::Dim_iter lon_dim)
Reorder the data values relative to the longitude axis so that the reordered longitude map (see GeoCo...
void set_latitude_index_top(int top)
set< string > get_coards_lat_units() const
set< string > get_lon_names() const
void set_longitude_rightmost(bool state)
void set_latitude_sense(LatitudeSense l)
void find_longitude_indeces(double left, double right, int &longitude_index_left, int &longitude_index_right) const
Scan from the left to the right, and the right to the left, looking for the left and right bounding b...
virtual void apply_constraint_to_data()=0
Once the bounding box is set use this method to apply the constraint.
int get_longitude_index_left() const
void set_bounding_box(double top, double left, double bottom, double right)
Set the bounding box for this constraint.
Array::Dim_iter get_lon_dim() const
void find_latitude_indeces(double top, double bottom, LatitudeSense sense, int &latitude_index_top, int &latitude_index_bottom) const
Scan from the top to the bottom, and the bottom to the top, looking for the top and bottom bounding b...
void set_lat(double *lat)
void set_lat_length(int len)
virtual void transpose_vector(double *src, const int length)
Given a vector of doubles, transpose the elements.
virtual void transform_longitude_to_pos_notation()
Given that the Grid has a longitude map that uses the 'neg_pos' notation, transform it to the 'pos' n...
int get_longitude_index_right() const
int get_lat_length() const
int get_array_data_size() const
int get_latitude_index_bottom() const
set< string > get_coards_lon_units() const
virtual void flip_latitude_within_array(Array &a, int lat_length, int lon_length)
virtual LatitudeSense categorize_latitude() const
Take a look at the latitude vector values and record whether the world is normal or upside down...
LatitudeSense
Most of the time, latitude starts at the top of an array with positive values and ends up at the bott...
GeoConstraint()
Initialize GeoConstraint.
virtual void transform_longitude_to_neg_pos_notation()
Given that the Grid has a longitude map that uses the 'pos' notation, transform it to the 'neg_pos' n...
LatitudeSense get_latitude_sense() const
virtual bool is_bounding_box_valid(const double left, const double top, const double right, const double bottom) const
set< string > get_lat_names() const
Notation
The longitude extents of the constraint bounding box can be expressed two ways: using a 0/359 notatio...
void set_longitude_index_right(int right)
void set_longitude_notation(Notation n)
virtual bool lat_lon_dimensions_ok()=0
Are the latitude and longitude dimensions ordered so that this class can properly constrain the data...
virtual bool build_lat_lon_maps()=0
A protected method that searches for latitude and longitude map vectors and sets six key internal fie...
Notation get_longitude_notation() const
virtual void reorder_longitude_map(int longitude_index_left)
Reorder the elements in the longitude map so that the longitude constraint no longer crosses the edge...
int get_lon_length() const
void set_longitude_index_left(int left)
Notation categorize_notation(const double left, const double right) const
A private method that determines if the longitude part of the bounding box uses 0/359 or -180/179 not...
Encapsulate the logic needed to handle geographical constraints when they are applied to DAP Grid (an...
Definition: GeoConstraint.h:95
double * get_lon() const
friend class GridGeoConstraintTest
Array::Dim_iter get_lat_dim() const
bool is_longitude_rightmost() const
bool is_bounding_box_set() const
void set_lon_dim(Array::Dim_iter lon)
int get_latitude_index_top() const
double * get_lat() const
void set_lon_length(int len)