GeoConstraint.h

Go to the documentation of this file.
00001 
00002 // -*- mode: c++; c-basic-offset:4 -*-
00003 
00004 // This file is part of libdap, A C++ implementation of the OPeNDAP Data
00005 // Access Protocol.
00006 
00007 // Copyright (c) 2006 OPeNDAP, Inc.
00008 // Author: James Gallagher <jgallagher@opendap.org>
00009 //
00010 // This library is free software; you can redistribute it and/or
00011 // modify it under the terms of the GNU Lesser General Public
00012 // License as published by the Free Software Foundation; either
00013 // version 2.1 of the License, or (at your option) any later version.
00014 //
00015 // This library is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023 //
00024 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
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 
00092 class GeoConstraint
00093 {
00094 public:
00098     enum Notation {
00099         unknown_notation,
00100         pos,
00101         neg_pos
00102     };
00103 
00107     enum LatitudeSense {
00108         unknown_sense,
00109         normal,
00110         inverted
00111     };
00112 
00113 private:
00114     const string &d_dataset;
00115 
00116     char *d_array_data;    //< Holds the Grid's data values
00117     int d_array_data_size;
00118 
00119     double *d_lat;              //< Holds the latitude values
00120     double *d_lon;              //< Holds the longitude values
00121     int d_lat_length;           //< How long is the latitude vector
00122     int d_lon_length;           //< ... longitude vector
00123 
00124     // These four are indeces of the constraint
00125     int d_latitude_index_top;
00126     int d_latitude_index_bottom;
00127     int d_longitude_index_left;
00128     int d_longitude_index_right;
00129 
00130     bool d_bounding_box_set;    //< Has the bounding box been set?
00131     bool d_longitude_rightmost; //< Is longitude the rightmost dimension?
00132 
00133     Notation d_longitude_notation;
00134     LatitudeSense d_latitude_sense;
00135 
00136     Array::Dim_iter d_lon_dim;  //< References the longitude dimension
00137     Array::Dim_iter d_lat_dim;  //< References the latitude dimension
00138 
00139     // Sets of string values used to find stuff in attributes
00140     set<string> d_coards_lat_units;
00141     set<string> d_coards_lon_units;
00142 
00143     set<string> d_lat_names;
00144     set<string> d_lon_names;
00145 
00146     // Hide these three automatically provided methods
00147     GeoConstraint();
00148     GeoConstraint(const GeoConstraint &param);
00149     GeoConstraint &operator=(GeoConstraint &rhs);
00150 
00151 protected:
00160     virtual bool build_lat_lon_maps() = 0;
00161 
00171     virtual bool lat_lon_dimensions_ok() = 0;
00172 
00173     Notation categorize_notation(double left, double right) const;
00174     void transform_constraint_to_pos_notation(double &left, double &right) const;
00175     virtual void transform_longitude_to_pos_notation();
00176     virtual void transform_longitude_to_neg_pos_notation();
00177     virtual bool is_bounding_box_valid(double left, double top, double right,
00178                                        double bottom) const;
00179     void find_longitude_indeces(double left, double right,
00180                                 int &longitude_index_left,
00181                                 int &longitude_index_right) const;
00182 #if 0
00183     virtual void set_bounding_box_longitude(double left, double right) ;
00184 #endif
00185     virtual void reorder_longitude_map(int longitude_index_left);
00186 
00187     virtual LatitudeSense categorize_latitude() const;
00188     void find_latitude_indeces(double top, double bottom, LatitudeSense sense,
00189                                int &latitude_index_top,
00190                                int &latitude_index_bottom) const;
00191 #if 0
00192     virtual void set_bounding_box_latitude(double top, double bottom) ;
00193 #endif
00194     virtual void reorder_data_longitude_axis(Array &a);
00195 
00196 
00197     friend class GridGeoConstraintTest; // Unit tests
00198 
00199 public:
00202     GeoConstraint(const string &ds_name);
00204 
00205     virtual ~GeoConstraint()
00206     {
00207         delete [] d_lat;
00208         delete [] d_lon;
00209         delete [] d_array_data; d_array_data = 0;
00210     }
00211 
00214     string get_dataset() const
00215     {
00216         return d_dataset;
00217     }
00218 
00219     // These are set in reorder_data_longitude_axis()
00220     char *get_array_data() const
00221     {
00222         return d_array_data;
00223     }
00224     int get_array_data_size() const
00225     {
00226         return d_array_data_size;
00227     }
00228 
00229     double *get_lat() const
00230     {
00231         return d_lat;
00232     }
00233     double *get_lon() const
00234     {
00235         return d_lon;
00236     }
00237     void set_lat(double *lat)
00238     {
00239         d_lat = lat;
00240     }
00241     void set_lon(double *lon)
00242     {
00243         d_lon = lon;
00244     }
00245 
00246     int get_lat_length() const
00247     {
00248         return d_lat_length;
00249     }
00250     int get_lon_length() const
00251     {
00252         return d_lon_length;
00253     }
00254     void set_lat_length(int len)
00255     {
00256         d_lat_length = len;
00257     }
00258     void set_lon_length(int len)
00259     {
00260         d_lon_length = len;
00261     }
00262 
00263     Array::Dim_iter get_lon_dim() const
00264     {
00265         return d_lon_dim;
00266     }
00267     Array::Dim_iter get_lat_dim() const
00268     {
00269         return d_lat_dim;
00270     }
00271     void set_lon_dim(Array::Dim_iter lon)
00272     {
00273         d_lon_dim = lon;
00274     }
00275     void set_lat_dim(Array::Dim_iter lat)
00276     {
00277         d_lat_dim = lat;
00278     }
00279 
00280     // These four are indeces of the constraint
00281     int get_latitude_index_top() const
00282     {
00283         return d_latitude_index_top;
00284     }
00285     int get_latitude_index_bottom() const
00286     {
00287         return d_latitude_index_bottom;
00288     }
00289     void set_latitude_index_top(int top)
00290     {
00291         d_latitude_index_top = top;
00292     }
00293     void set_latitude_index_bottom(int bottom)
00294     {
00295         d_latitude_index_bottom = bottom;
00296     }
00297 
00298     int get_longitude_index_left() const
00299     {
00300         return d_longitude_index_left;
00301     }
00302     int get_longitude_index_right() const
00303     {
00304         return d_longitude_index_right;
00305     }
00306     void set_longitude_index_left(int left)
00307     {
00308         d_longitude_index_left = left;
00309     }
00310     void set_longitude_index_right(int right)
00311     {
00312         d_longitude_index_right = right;
00313     }
00314 
00315     bool get_bounding_box_set() const
00316     {
00317         return d_bounding_box_set;
00318     }
00319     bool get_longitude_rightmost() const
00320     {
00321         return d_longitude_rightmost;
00322     }
00323     void set_longitude_rightmost(bool state)
00324     {
00325         d_longitude_rightmost = state;
00326     }
00327 
00328     Notation get_longitude_notation() const
00329     {
00330         return d_longitude_notation;
00331     }
00332     LatitudeSense get_latitude_sense() const
00333     {
00334         return d_latitude_sense;
00335     }
00336     void set_longitude_notation(Notation n)
00337     {
00338         d_longitude_notation = n;
00339     }
00340     void set_latitude_sense(LatitudeSense l)
00341     {
00342         d_latitude_sense = l;
00343     }
00344 
00345     set<string> get_coards_lat_units() const
00346         {
00347             return d_coards_lat_units;
00348         }
00349     set<string> get_coards_lon_units() const
00350         {
00351             return d_coards_lon_units;
00352         }
00353 
00354     set<string> get_lat_names() const
00355         {
00356             return d_lat_names;
00357         }
00358     set<string> get_lon_names() const
00359         {
00360             return d_lon_names;
00361         }
00363 
00364     void set_bounding_box(double left, double top, double right, double bottom);
00365 
00370     virtual void apply_constraint_to_data() = 0;
00371 };
00372 
00373 #endif // _geo_constraint_h
00374 

Generated on Fri Feb 8 05:14:02 2008 for libdap++ by  doxygen 1.5.4