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 
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     const string &d_dataset;
00126 
00127     char *d_array_data;    //< Holds the Grid's data values
00128     int d_array_data_size;
00129 
00130     double *d_lat;              //< Holds the latitude values
00131     double *d_lon;              //< Holds the longitude values
00132     int d_lat_length;           //< How long is the latitude vector
00133     int d_lon_length;           //< ... longitude vector
00134 
00135     // These four are indexes of the constraint
00136     int d_latitude_index_top;
00137     int d_latitude_index_bottom;
00138     int d_longitude_index_left;
00139     int d_longitude_index_right;
00140 
00141     bool d_bounding_box_set;    //< Has the bounding box been set?
00142     bool d_longitude_rightmost; //< Is longitude the rightmost dimension?
00143 
00144     Notation d_longitude_notation;
00145     LatitudeSense d_latitude_sense;
00146 
00147     Array::Dim_iter d_lon_dim;  //< References the longitude dimension
00148     Array::Dim_iter d_lat_dim;  //< References the latitude dimension
00149 
00150     // Sets of string values used to find stuff in attributes
00151     set<string> d_coards_lat_units;
00152     set<string> d_coards_lon_units;
00153 
00154     set<string> d_lat_names;
00155     set<string> d_lon_names;
00156 
00157     // Hide these three automatically provided methods
00158     GeoConstraint();
00159     GeoConstraint(const GeoConstraint &param);
00160     GeoConstraint &operator=(GeoConstraint &rhs);
00161 
00162 protected:
00171     virtual bool build_lat_lon_maps() = 0;
00172 
00183     virtual bool lat_lon_dimensions_ok() = 0;
00184 
00185     Notation categorize_notation(double left, double right) const;
00186     void transform_constraint_to_pos_notation(double &left, double &right) const;
00187     virtual void transform_longitude_to_pos_notation();
00188     virtual void transform_longitude_to_neg_pos_notation();
00189     virtual bool is_bounding_box_valid(double left, double top, double right,
00190                                        double bottom) const;
00191     void find_longitude_indeces(double left, double right,
00192                                 int &longitude_index_left,
00193                                 int &longitude_index_right) const;
00194 #if 0
00195     virtual void set_bounding_box_longitude(double left, double right) ;
00196 #endif
00197     virtual void reorder_longitude_map(int longitude_index_left);
00198 
00199     virtual LatitudeSense categorize_latitude() const;
00200     void find_latitude_indeces(double top, double bottom, LatitudeSense sense,
00201                                int &latitude_index_top,
00202                                int &latitude_index_bottom) const;
00203 #if 0
00204     virtual void set_bounding_box_latitude(double top, double bottom) ;
00205 #endif
00206     virtual void reorder_data_longitude_axis(Array &a);
00207 
00208 
00209     friend class GridGeoConstraintTest; // Unit tests
00210 
00211 public:
00214     GeoConstraint(const string &ds_name);
00216 
00217     virtual ~GeoConstraint()
00218     {
00219         delete [] d_lat;
00220         delete [] d_lon;
00221         delete [] d_array_data; d_array_data = 0;
00222     }
00223 
00226     string get_dataset() const
00227     {
00228         return d_dataset;
00229     }
00230 
00231     // These are set in reorder_data_longitude_axis()
00232     char *get_array_data() const
00233     {
00234         return d_array_data;
00235     }
00236     int get_array_data_size() const
00237     {
00238         return d_array_data_size;
00239     }
00240 
00241     double *get_lat() const
00242     {
00243         return d_lat;
00244     }
00245     double *get_lon() const
00246     {
00247         return d_lon;
00248     }
00249     void set_lat(double *lat)
00250     {
00251         d_lat = lat;
00252     }
00253     void set_lon(double *lon)
00254     {
00255         d_lon = lon;
00256     }
00257 
00258     int get_lat_length() const
00259     {
00260         return d_lat_length;
00261     }
00262     int get_lon_length() const
00263     {
00264         return d_lon_length;
00265     }
00266     void set_lat_length(int len)
00267     {
00268         d_lat_length = len;
00269     }
00270     void set_lon_length(int len)
00271     {
00272         d_lon_length = len;
00273     }
00274 
00275     Array::Dim_iter get_lon_dim() const
00276     {
00277         return d_lon_dim;
00278     }
00279     Array::Dim_iter get_lat_dim() const
00280     {
00281         return d_lat_dim;
00282     }
00283     void set_lon_dim(Array::Dim_iter lon)
00284     {
00285         d_lon_dim = lon;
00286     }
00287     void set_lat_dim(Array::Dim_iter lat)
00288     {
00289         d_lat_dim = lat;
00290     }
00291 
00292     // These four are indexes of the constraint
00293     int get_latitude_index_top() const
00294     {
00295         return d_latitude_index_top;
00296     }
00297     int get_latitude_index_bottom() const
00298     {
00299         return d_latitude_index_bottom;
00300     }
00301     void set_latitude_index_top(int top)
00302     {
00303         d_latitude_index_top = top;
00304     }
00305     void set_latitude_index_bottom(int bottom)
00306     {
00307         d_latitude_index_bottom = bottom;
00308     }
00309 
00310     int get_longitude_index_left() const
00311     {
00312         return d_longitude_index_left;
00313     }
00314     int get_longitude_index_right() const
00315     {
00316         return d_longitude_index_right;
00317     }
00318     void set_longitude_index_left(int left)
00319     {
00320         d_longitude_index_left = left;
00321     }
00322     void set_longitude_index_right(int right)
00323     {
00324         d_longitude_index_right = right;
00325     }
00326 
00327     bool get_bounding_box_set() const
00328     {
00329         return d_bounding_box_set;
00330     }
00331     bool get_longitude_rightmost() const
00332     {
00333         return d_longitude_rightmost;
00334     }
00335     void set_longitude_rightmost(bool state)
00336     {
00337         d_longitude_rightmost = state;
00338     }
00339 
00340     Notation get_longitude_notation() const
00341     {
00342         return d_longitude_notation;
00343     }
00344     LatitudeSense get_latitude_sense() const
00345     {
00346         return d_latitude_sense;
00347     }
00348     void set_longitude_notation(Notation n)
00349     {
00350         d_longitude_notation = n;
00351     }
00352     void set_latitude_sense(LatitudeSense l)
00353     {
00354         d_latitude_sense = l;
00355     }
00356 
00357     set<string> get_coards_lat_units() const
00358         {
00359             return d_coards_lat_units;
00360         }
00361     set<string> get_coards_lon_units() const
00362         {
00363             return d_coards_lon_units;
00364         }
00365 
00366     set<string> get_lat_names() const
00367         {
00368             return d_lat_names;
00369         }
00370     set<string> get_lon_names() const
00371         {
00372             return d_lon_names;
00373         }
00375 
00376     void set_bounding_box(double left, double top, double right, double bottom);
00377 
00380     virtual void apply_constraint_to_data() = 0;
00381 };
00382 
00383 } // namespace libdap
00384 
00385 #endif // _geo_constraint_h
00386 

Generated on Wed Mar 5 15:27:11 2008 for libdap++ by  doxygen 1.5.4