libdap++  Updated for version 3.11.7
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 #ifndef _basetype_h
34 #include "BaseType.h"
35 #endif
36 
37 #ifndef _array_h
38 #include "Array.h"
39 #endif
40 
41 #ifndef _grid_h
42 #include "Grid.h"
43 #endif
44 
45 namespace libdap
46 {
47 
104 {
105 public:
109  enum Notation {
113  };
114 
122  };
123 
124 private:
125  char *d_array_data; //< Holds the Grid's data values
126  int d_array_data_size; //< Total size (bytes) of the array data
127 
128  double *d_lat; //< Holds the latitude values
129  double *d_lon; //< Holds the longitude values
130  int d_lat_length; //< Elements (not bytes) in the latitude vector
131  int d_lon_length; //< ... longitude vector
132 
133  // These four are indexes of the constraint
134  int d_latitude_index_top;
135  int d_latitude_index_bottom;
136  int d_longitude_index_left;
137  int d_longitude_index_right;
138 
139  bool d_bounding_box_set; //< Has the bounding box been set?
140  bool d_longitude_rightmost; //< Is longitude the rightmost dimension?
141 
142  Notation d_longitude_notation;
143  LatitudeSense d_latitude_sense;
144 
145  Array::Dim_iter d_lon_dim; //< References the longitude dimension
146  Array::Dim_iter d_lat_dim; //< References the latitude dimension
147 
148  // Sets of string values used to find stuff in attributes
149  set<string> d_coards_lat_units;
150  set<string> d_coards_lon_units;
151 
152  set<string> d_lat_names;
153  set<string> d_lon_names;
154 
155  // Hide these three automatically provided methods
156  GeoConstraint(const GeoConstraint &param);
157  GeoConstraint &operator=(GeoConstraint &rhs);
158 
159 protected:
168  virtual bool build_lat_lon_maps() = 0;
169 
180  virtual bool lat_lon_dimensions_ok() = 0;
181 
182  Notation categorize_notation(const double left, const double right) const;
183  void transform_constraint_to_pos_notation(double &left, double &right) const;
186  virtual bool is_bounding_box_valid(const double left, const double top,
187  const double right, const double bottom) const;
188  void find_longitude_indeces(double left, double right,
189  int &longitude_index_left,
190  int &longitude_index_right) const;
191 
192  virtual void transpose_vector(double *src, const int length);
193  virtual void reorder_longitude_map(int longitude_index_left);
194 
195  virtual LatitudeSense categorize_latitude() const;
196  void find_latitude_indeces(double top, double bottom, LatitudeSense sense,
197  int &latitude_index_top,
198  int &latitude_index_bottom) const;
199 
200  virtual void reorder_data_longitude_axis(Array &a, Array::Dim_iter lon_dim);
201  virtual void flip_latitude_within_array(Array &a, int lat_length,
202  int lon_length);
203 
204  friend class GridGeoConstraintTest; // Unit tests
205 
206 public:
209  GeoConstraint();
211 
212  virtual ~GeoConstraint()
213  {
214  delete [] d_lat; d_lat = 0;
215  delete [] d_lon; d_lon = 0;
216  delete [] d_array_data; d_array_data = 0;
217  }
218 
221  // These are set in reorder_data_longitude_axis()
222  char *get_array_data() const
223  {
224  return d_array_data;
225  }
227  {
228  return d_array_data_size;
229  }
230 
231  double *get_lat() const
232  {
233  return d_lat;
234  }
235  double *get_lon() const
236  {
237  return d_lon;
238  }
239  void set_lat(double *lat)
240  {
241  d_lat = lat;
242  }
243  void set_lon(double *lon)
244  {
245  d_lon = lon;
246  }
247 
248  int get_lat_length() const
249  {
250  return d_lat_length;
251  }
252  int get_lon_length() const
253  {
254  return d_lon_length;
255  }
256  void set_lat_length(int len)
257  {
258  d_lat_length = len;
259  }
260  void set_lon_length(int len)
261  {
262  d_lon_length = len;
263  }
264 
266  {
267  return d_lon_dim;
268  }
270  {
271  return d_lat_dim;
272  }
274  {
275  d_lon_dim = lon;
276  }
278  {
279  d_lat_dim = lat;
280  }
281 
282  // These four are indexes of the constraint
284  {
285  return d_latitude_index_top;
286  }
288  {
289  return d_latitude_index_bottom;
290  }
292  {
293  d_latitude_index_top = top;
294  }
295  void set_latitude_index_bottom(int bottom)
296  {
297  d_latitude_index_bottom = bottom;
298  }
299 
301  {
302  return d_longitude_index_left;
303  }
305  {
306  return d_longitude_index_right;
307  }
309  {
310  d_longitude_index_left = left;
311  }
313  {
314  d_longitude_index_right = right;
315  }
316 
317  bool is_bounding_box_set() const
318  {
319  return d_bounding_box_set;
320  }
322  {
323  return d_longitude_rightmost;
324  }
325  void set_longitude_rightmost(bool state)
326  {
327  d_longitude_rightmost = state;
328  }
329 
331  {
332  return d_longitude_notation;
333  }
335  {
336  return d_latitude_sense;
337  }
339  {
340  d_longitude_notation = n;
341  }
343  {
344  d_latitude_sense = l;
345  }
346 
347  set<string> get_coards_lat_units() const
348  {
349  return d_coards_lat_units;
350  }
351  set<string> get_coards_lon_units() const
352  {
353  return d_coards_lon_units;
354  }
355 
356  set<string> get_lat_names() const
357  {
358  return d_lat_names;
359  }
360  set<string> get_lon_names() const
361  {
362  return d_lon_names;
363  }
365 
366  void set_bounding_box(double top, double left, double bottom, double right);
367 
370  virtual void apply_constraint_to_data() = 0;
371 };
372 
373 } // namespace libdap
374 
375 #endif // _geo_constraint_h
376