00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef _geo_constraint_h
00027 #define _geo_constraint_h 1
00028
00029 #include <string>
00030 #include <sstream>
00031 #include <set>
00032
00033 #ifndef _basetype_h
00034 #include "BaseType.h"
00035 #endif
00036
00037 #ifndef _array_h
00038 #include "Array.h"
00039 #endif
00040
00041 #ifndef _grid_h
00042 #include "Grid.h"
00043 #endif
00044
00045 namespace libdap
00046 {
00047
00103 class GeoConstraint
00104 {
00105 public:
00109 enum Notation {
00110 unknown_notation,
00111 pos,
00112 neg_pos
00113 };
00114
00118 enum LatitudeSense {
00119 unknown_sense,
00120 normal,
00121 inverted
00122 };
00123
00124 private:
00125 char *d_array_data;
00126 int d_array_data_size;
00127
00128 double *d_lat;
00129 double *d_lon;
00130 int d_lat_length;
00131 int d_lon_length;
00132
00133
00134 int d_latitude_index_top;
00135 int d_latitude_index_bottom;
00136 int d_longitude_index_left;
00137 int d_longitude_index_right;
00138
00139 bool d_bounding_box_set;
00140 bool d_longitude_rightmost;
00141
00142 Notation d_longitude_notation;
00143 LatitudeSense d_latitude_sense;
00144
00145 Array::Dim_iter d_lon_dim;
00146 Array::Dim_iter d_lat_dim;
00147
00148
00149 set<string> d_coards_lat_units;
00150 set<string> d_coards_lon_units;
00151
00152 set<string> d_lat_names;
00153 set<string> d_lon_names;
00154
00155
00156 GeoConstraint(const GeoConstraint ¶m);
00157 GeoConstraint &operator=(GeoConstraint &rhs);
00158
00159 protected:
00168 virtual bool build_lat_lon_maps() = 0;
00169
00180 virtual bool lat_lon_dimensions_ok() = 0;
00181
00182 Notation categorize_notation(const double left, const double right) const;
00183 void transform_constraint_to_pos_notation(double &left, double &right) const;
00184 virtual void transform_longitude_to_pos_notation();
00185 virtual void transform_longitude_to_neg_pos_notation();
00186 virtual bool is_bounding_box_valid(const double left, const double top,
00187 const double right, const double bottom) const;
00188 void find_longitude_indeces(double left, double right,
00189 int &longitude_index_left,
00190 int &longitude_index_right) const;
00191
00192 virtual void transpose_vector(double *src, const int length);
00193 virtual void reorder_longitude_map(int longitude_index_left);
00194
00195 virtual LatitudeSense categorize_latitude() const;
00196 void find_latitude_indeces(double top, double bottom, LatitudeSense sense,
00197 int &latitude_index_top,
00198 int &latitude_index_bottom) const;
00199
00200 virtual void reorder_data_longitude_axis(Array &a, Array::Dim_iter lon_dim);
00201 virtual void flip_latitude_within_array(Array &a, int lat_length,
00202 int lon_length);
00203
00204 friend class GridGeoConstraintTest;
00205
00206 public:
00209 GeoConstraint();
00211
00212 virtual ~GeoConstraint()
00213 {
00214 delete [] d_lat; d_lat = 0;
00215 delete [] d_lon; d_lon = 0;
00216 delete [] d_array_data; d_array_data = 0;
00217 }
00218
00221
00222 char *get_array_data() const
00223 {
00224 return d_array_data;
00225 }
00226 int get_array_data_size() const
00227 {
00228 return d_array_data_size;
00229 }
00230
00231 double *get_lat() const
00232 {
00233 return d_lat;
00234 }
00235 double *get_lon() const
00236 {
00237 return d_lon;
00238 }
00239 void set_lat(double *lat)
00240 {
00241 d_lat = lat;
00242 }
00243 void set_lon(double *lon)
00244 {
00245 d_lon = lon;
00246 }
00247
00248 int get_lat_length() const
00249 {
00250 return d_lat_length;
00251 }
00252 int get_lon_length() const
00253 {
00254 return d_lon_length;
00255 }
00256 void set_lat_length(int len)
00257 {
00258 d_lat_length = len;
00259 }
00260 void set_lon_length(int len)
00261 {
00262 d_lon_length = len;
00263 }
00264
00265 Array::Dim_iter get_lon_dim() const
00266 {
00267 return d_lon_dim;
00268 }
00269 Array::Dim_iter get_lat_dim() const
00270 {
00271 return d_lat_dim;
00272 }
00273 void set_lon_dim(Array::Dim_iter lon)
00274 {
00275 d_lon_dim = lon;
00276 }
00277 void set_lat_dim(Array::Dim_iter lat)
00278 {
00279 d_lat_dim = lat;
00280 }
00281
00282
00283 int get_latitude_index_top() const
00284 {
00285 return d_latitude_index_top;
00286 }
00287 int get_latitude_index_bottom() const
00288 {
00289 return d_latitude_index_bottom;
00290 }
00291 void set_latitude_index_top(int top)
00292 {
00293 d_latitude_index_top = top;
00294 }
00295 void set_latitude_index_bottom(int bottom)
00296 {
00297 d_latitude_index_bottom = bottom;
00298 }
00299
00300 int get_longitude_index_left() const
00301 {
00302 return d_longitude_index_left;
00303 }
00304 int get_longitude_index_right() const
00305 {
00306 return d_longitude_index_right;
00307 }
00308 void set_longitude_index_left(int left)
00309 {
00310 d_longitude_index_left = left;
00311 }
00312 void set_longitude_index_right(int right)
00313 {
00314 d_longitude_index_right = right;
00315 }
00316
00317 bool is_bounding_box_set() const
00318 {
00319 return d_bounding_box_set;
00320 }
00321 bool is_longitude_rightmost() const
00322 {
00323 return d_longitude_rightmost;
00324 }
00325 void set_longitude_rightmost(bool state)
00326 {
00327 d_longitude_rightmost = state;
00328 }
00329
00330 Notation get_longitude_notation() const
00331 {
00332 return d_longitude_notation;
00333 }
00334 LatitudeSense get_latitude_sense() const
00335 {
00336 return d_latitude_sense;
00337 }
00338 void set_longitude_notation(Notation n)
00339 {
00340 d_longitude_notation = n;
00341 }
00342 void set_latitude_sense(LatitudeSense l)
00343 {
00344 d_latitude_sense = l;
00345 }
00346
00347 set<string> get_coards_lat_units() const
00348 {
00349 return d_coards_lat_units;
00350 }
00351 set<string> get_coards_lon_units() const
00352 {
00353 return d_coards_lon_units;
00354 }
00355
00356 set<string> get_lat_names() const
00357 {
00358 return d_lat_names;
00359 }
00360 set<string> get_lon_names() const
00361 {
00362 return d_lon_names;
00363 }
00365
00366 void set_bounding_box(double top, double left, double bottom, double right);
00367
00370 virtual void apply_constraint_to_data() = 0;
00371 };
00372
00373 }
00374
00375 #endif // _geo_constraint_h
00376