libdap Updated for version 3.21.1
libdap4 is an implementation of OPeNDAP's DAP protocol.
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 <set>
30#include <sstream>
31#include <string>
32
33namespace libdap {
34class BaseType;
35class Array;
36class Grid;
37} // namespace libdap
38
39namespace functions {
40
95
96class GeoConstraint {
97public:
102
107
108private:
109 char *d_array_data; //< Holds the Grid's data values
110 int d_array_data_size; //< Total size (bytes) of the array data
111
112 double *d_lat; //< Holds the latitude values
113 double *d_lon; //< Holds the longitude values
114 int d_lat_length; //< Elements (not bytes) in the latitude vector
115 int d_lon_length; //< ... longitude vector
116
117 // These four are indexes of the constraint
118 int d_latitude_index_top;
119 int d_latitude_index_bottom;
120 int d_longitude_index_left;
121 int d_longitude_index_right;
122
123 bool d_bounding_box_set; //< Has the bounding box been set?
124 bool d_longitude_rightmost; //< Is longitude the rightmost dimension?
125
126 Notation d_longitude_notation;
127 LatitudeSense d_latitude_sense;
128
129 libdap::Array::Dim_iter d_lon_dim; //< References the longitude dimension
130 libdap::Array::Dim_iter d_lat_dim; //< References the latitude dimension
131
132 // Sets of string values used to find stuff in attributes
133 set<string> d_coards_lat_units;
134 set<string> d_coards_lon_units;
135
136 set<string> d_lat_names;
137 set<string> d_lon_names;
138
139 // Hide these three automatically provided methods
140 GeoConstraint(const GeoConstraint &param);
141 GeoConstraint &operator=(GeoConstraint &rhs);
142
143protected:
152 virtual bool build_lat_lon_maps() = 0;
153
164 virtual bool lat_lon_dimensions_ok() = 0;
165
166 Notation categorize_notation(const double left, const double right) const;
167 void transform_constraint_to_pos_notation(double &left, double &right) const;
170 virtual bool is_bounding_box_valid(const double left, const double top, const double right,
171 const double bottom) const;
172 void find_longitude_indeces(double left, double right, int &longitude_index_left, int &longitude_index_right) const;
173
174 virtual void transpose_vector(double *src, const int length);
175 virtual void reorder_longitude_map(int longitude_index_left);
176
177 virtual LatitudeSense categorize_latitude() const;
178 void find_latitude_indeces(double top, double bottom, LatitudeSense sense, int &latitude_index_top,
179 int &latitude_index_bottom) const;
180
182 virtual void flip_latitude_within_array(libdap::Array &a, int lat_length, int lon_length);
183
184 friend class GridGeoConstraintTest; // Unit tests
185
186public:
191
192 virtual ~GeoConstraint() {
193 delete[] d_lat;
194 d_lat = 0;
195 delete[] d_lon;
196 d_lon = 0;
197 delete[] d_array_data;
198 d_array_data = 0;
199 }
200
203 // These are set in reorder_data_longitude_axis()
204 char *get_array_data() const { return d_array_data; }
205 int get_array_data_size() const { return d_array_data_size; }
206
207 double *get_lat() const { return d_lat; }
208 double *get_lon() const { return d_lon; }
209 void set_lat(double *lat) { d_lat = lat; }
210 void set_lon(double *lon) { d_lon = lon; }
211
212 int get_lat_length() const { return d_lat_length; }
213 int get_lon_length() const { return d_lon_length; }
214 void set_lat_length(int len) { d_lat_length = len; }
215 void set_lon_length(int len) { d_lon_length = len; }
216
217 libdap::Array::Dim_iter get_lon_dim() const { return d_lon_dim; }
218 libdap::Array::Dim_iter get_lat_dim() const { return d_lat_dim; }
219 void set_lon_dim(libdap::Array::Dim_iter lon) { d_lon_dim = lon; }
220 void set_lat_dim(libdap::Array::Dim_iter lat) { d_lat_dim = lat; }
221
222 // These four are indexes of the constraint
223 int get_latitude_index_top() const { return d_latitude_index_top; }
224 int get_latitude_index_bottom() const { return d_latitude_index_bottom; }
225 void set_latitude_index_top(int top) { d_latitude_index_top = top; }
226 void set_latitude_index_bottom(int bottom) { d_latitude_index_bottom = bottom; }
227
228 int get_longitude_index_left() const { return d_longitude_index_left; }
229 int get_longitude_index_right() const { return d_longitude_index_right; }
230 void set_longitude_index_left(int left) { d_longitude_index_left = left; }
231 void set_longitude_index_right(int right) { d_longitude_index_right = right; }
232
233 bool is_bounding_box_set() const { return d_bounding_box_set; }
234 bool is_longitude_rightmost() const { return d_longitude_rightmost; }
235 void set_longitude_rightmost(bool state) { d_longitude_rightmost = state; }
236
237 Notation get_longitude_notation() const { return d_longitude_notation; }
238 LatitudeSense get_latitude_sense() const { return d_latitude_sense; }
239 void set_longitude_notation(Notation n) { d_longitude_notation = n; }
240 void set_latitude_sense(LatitudeSense l) { d_latitude_sense = l; }
241
242 set<string> get_coards_lat_units() const { return d_coards_lat_units; }
243 set<string> get_coards_lon_units() const { return d_coards_lon_units; }
244
245 set<string> get_lat_names() const { return d_lat_names; }
246 set<string> get_lon_names() const { return d_lon_names; }
248
249 void set_bounding_box(double top, double left, double bottom, double right);
250
253 virtual void apply_constraint_to_data() = 0;
254};
255
256} // namespace functions
257
258#endif // _geo_constraint_h
GeoConstraint()
Initialize GeoConstraint.
friend class GridGeoConstraintTest
set< string > get_coards_lon_units() const
int get_latitude_index_bottom() const
libdap::Array::Dim_iter get_lon_dim() const
void transform_constraint_to_pos_notation(double &left, double &right) const
virtual bool build_lat_lon_maps()=0
libdap::Array::Dim_iter get_lat_dim() const
set< string > get_lat_names() const
virtual void transform_longitude_to_pos_notation()
virtual void reorder_longitude_map(int longitude_index_left)
virtual void transform_longitude_to_neg_pos_notation()
virtual void reorder_data_longitude_axis(libdap::Array &a, libdap::Array::Dim_iter lon_dim)
void set_lon(double *lon)
void set_lon_dim(libdap::Array::Dim_iter lon)
void set_longitude_rightmost(bool state)
bool is_longitude_rightmost() const
double * get_lat() const
void set_lat(double *lat)
void set_longitude_index_right(int right)
int get_latitude_index_top() const
Notation get_longitude_notation() const
LatitudeSense get_latitude_sense() const
char * get_array_data() const
void find_latitude_indeces(double top, double bottom, LatitudeSense sense, int &latitude_index_top, int &latitude_index_bottom) const
void set_lat_dim(libdap::Array::Dim_iter lat)
int get_longitude_index_left() const
virtual void apply_constraint_to_data()=0
Once the bounding box is set use this method to apply the constraint.
void set_longitude_notation(Notation n)
Notation categorize_notation(const double left, const double right) const
bool is_bounding_box_set() const
set< string > get_coards_lat_units() const
set< string > get_lon_names() const
void set_latitude_index_top(int top)
virtual void flip_latitude_within_array(libdap::Array &a, int lat_length, int lon_length)
void find_longitude_indeces(double left, double right, int &longitude_index_left, int &longitude_index_right) const
int get_longitude_index_right() const
virtual bool lat_lon_dimensions_ok()=0
void set_latitude_index_bottom(int bottom)
double * get_lon() const
virtual void transpose_vector(double *src, const int length)
virtual bool is_bounding_box_valid(const double left, const double top, const double right, const double bottom) const
void set_latitude_sense(LatitudeSense l)
virtual LatitudeSense categorize_latitude() const
void set_longitude_index_left(int left)
void set_bounding_box(double top, double left, double bottom, double right)
A multidimensional array of identical data types.
Definition Array.h:121
std::vector< dimension >::iterator Dim_iter
Definition Array.h:225
The basic data type for the DODS DAP types.
Definition BaseType.h:118
Holds the Grid data type.
Definition Grid.h:121
top level DAP object to house generic methods
Definition AISConnect.cc:30