libdap::GeoConstraint Class Reference

#include <GeoConstraint.h>

Inheritance diagram for libdap::GeoConstraint:
Inheritance graph
[legend]
Collaboration diagram for libdap::GeoConstraint:
Collaboration graph
[legend]

List of all members.

Public Types

enum  LatitudeSense { unknown_sense, normal, inverted }
enum  Notation { unknown_notation, pos, neg_pos }

Public Member Functions

virtual void apply_constraint_to_data ()=0
 Once the bounding box is set use this method to apply the constraint.
void set_bounding_box (double left, double top, double right, double bottom)
virtual ~GeoConstraint ()
Constructors



 GeoConstraint ()
 Initialize GeoConstraint.
Accessors/Mutators



char * get_array_data () const
int get_array_data_size () const
bool get_bounding_box_set () const
set< string > get_coards_lat_units () const
set< string > get_coards_lon_units () const
double * get_lat () const
Array::Dim_iter get_lat_dim () const
int get_lat_length () const
set< string > get_lat_names () const
int get_latitude_index_bottom () const
int get_latitude_index_top () const
LatitudeSense get_latitude_sense () const
double * get_lon () const
Array::Dim_iter get_lon_dim () const
int get_lon_length () const
set< string > get_lon_names () const
int get_longitude_index_left () const
int get_longitude_index_right () const
Notation get_longitude_notation () const
bool get_longitude_rightmost () const
void set_lat (double *lat)
void set_lat_dim (Array::Dim_iter lat)
void set_lat_length (int len)
void set_latitude_index_bottom (int bottom)
void set_latitude_index_top (int top)
void set_latitude_sense (LatitudeSense l)
void set_lon (double *lon)
void set_lon_dim (Array::Dim_iter lon)
void set_lon_length (int len)
void set_longitude_index_left (int left)
void set_longitude_index_right (int right)
void set_longitude_notation (Notation n)
void set_longitude_rightmost (bool state)

Protected Member Functions

virtual bool build_lat_lon_maps ()=0
virtual LatitudeSense categorize_latitude () const
Notation categorize_notation (double left, double right) const
void find_latitude_indeces (double top, double bottom, LatitudeSense sense, int &latitude_index_top, int &latitude_index_bottom) const
void find_longitude_indeces (double left, double right, int &longitude_index_left, int &longitude_index_right) const
virtual bool is_bounding_box_valid (double left, double top, double right, double bottom) const
virtual bool lat_lon_dimensions_ok ()=0
virtual void reorder_data_longitude_axis (Array &a)
virtual void reorder_longitude_map (int longitude_index_left)
void transform_constraint_to_pos_notation (double &left, double &right) const
virtual void transform_longitude_to_neg_pos_notation ()
virtual void transform_longitude_to_pos_notation ()

Friends

class GridGeoConstraintTest

Detailed Description

Encapsulate the logic needed to handle geographical constraints when they are applied to DAP Grid (and some Array) variables.

This class will apply a longitude/latitude bounding box to a Grid that is a 'geo-referenced' Grid. That is, it follows the COARDS/CF conventions. This may be relaxed...

If the longitude range of the constraint crosses the boundary of the data array so that the constraint creates two separate rectangles, this class will arrange to return the result as a single Grid. It will do this by rearranging the data before control is passed onto the constraint evaluator and serialization logic. Here's a diagram of how it works:

Suppose a constraint for the longitude BB starts at the left edge of L and goes to the right edge of R:

       0.0       180.0       360.0 (longitude, in degrees)
        +----------------------+
        |xxxxxyyyyyyyyyyyyzzzzz|
        -----+            +-----
        |    |            |    |
        | R  |            | L  |
        |    |            |    |
        -----+            +-----
        |                      |
        +----------------------+
    

For example, suppose the client provides a bounding box that starts at 200 degrees and ends at 80. This class will first copy the Left part to new storage and then copy the right part, thus 'stitching together' the two halves of the constraint. The result looks like:

     80.0  360.0/0.0  180.0  ~200.0 (longitude, in degrees)
        +----------------------+
        |zzzzzxxxxxxyyyyyyyyyyy|
        -----++-----           |
        |    ||    |           |
        | L  || R  |           |
        |    ||    |           |
        -----++-----           |
        |                      |
        +----------------------+
    

The changes are made in the Grid variable itself, so once this is done the Grid should not be re-read by the CE or serialization code.

Author:
James Gallagher

Definition at line 103 of file GeoConstraint.h.


Member Enumeration Documentation

Most of the time, latitude starts at the top of an array with positive values and ends up at the bottom with negative ones. But sometimes... the world is upside down.

Enumerator:
unknown_sense 
normal 
inverted 

Definition at line 118 of file GeoConstraint.h.

The longitude extents of the constraint bounding box can be expressed two ways: using a 0/359 notation and using a -180/179 notation. I call the 0/359 notation 'pos' and the -180/179 notation 'neg_pos'.

Enumerator:
unknown_notation 
pos 
neg_pos 

Definition at line 109 of file GeoConstraint.h.


Constructor & Destructor Documentation

libdap::GeoConstraint::GeoConstraint (  ) 
Todo:
Remove ds_name. 10/02/08
Parameters:
ds_name The name of the dataset. Passed to BaseType::read().

Definition at line 510 of file GeoConstraint.cc.

virtual libdap::GeoConstraint::~GeoConstraint (  )  [inline, virtual]

Definition at line 214 of file GeoConstraint.h.


Member Function Documentation

virtual void libdap::GeoConstraint::apply_constraint_to_data (  )  [pure virtual]
virtual bool libdap::GeoConstraint::build_lat_lon_maps (  )  [protected, pure virtual]

A protected method that searches for latitude and longitude map vectors and sets six key internal fields. This method returns false if either map cannot be found.

The d_lon, d_lon_length and d_lon_dim (and matching lat) fields must be set by this method.

Returns:
True if the maps are found, otherwise False
GeoConstraint::LatitudeSense libdap::GeoConstraint::categorize_latitude (  )  const [protected, virtual]

Take a look at the latitude vector values and record whether the world is normal or upside down.

Returns:
normal or inverted.

Definition at line 315 of file GeoConstraint.cc.

References inverted, and normal.

Referenced by set_bounding_box().

GeoConstraint::Notation libdap::GeoConstraint::categorize_notation ( double  left,
double  right 
) const [protected]

A private method that determines if the longitude part of the bounding box uses 0/359 or -180/179 notation. This class only supports latitude constriants which use 90/-90 notation, so there's no need to figure out what sort of notation they use.

Note:
This function assumes that if one of the two values is negative, then the notation is or the -180/179 form, otherwise not. If the user asks for 30 degrees to 50 degress (or 50 to 30, for that matter), there's no real way to tell which notation they are using.
Parameters:
left The left side of the bounding box, in degrees
right The right side of the boubding box
Returns:
The notation (pos or neg_pos)

Definition at line 109 of file GeoConstraint.cc.

References neg_pos, and pos.

Referenced by set_bounding_box().

void libdap::GeoConstraint::find_latitude_indeces ( double  top,
double  bottom,
LatitudeSense  sense,
int &  latitude_index_top,
int &  latitude_index_bottom 
) const [protected]

Scan from the top to the bottom, and the bottom to the top, looking for the top and bottom bounding box edges, respectively.

Parameters:
top The top edge of the bounding box
bottom The bottom edge
sense Does the array/grid store data with larger latitudes at the starting indices or are the latitude 'upside down?'
latitude_index_top Value-result parameter that holds the index in the grid's latitude map of the top bounding box edge. Uses a closed interval for the test.
latitude_index_bottom Value-result parameter for the bottom edge index.

Definition at line 272 of file GeoConstraint.cc.

References normal.

Referenced by set_bounding_box().

void libdap::GeoConstraint::find_longitude_indeces ( double  left,
double  right,
int &  longitude_index_left,
int &  longitude_index_right 
) const [protected]

Scan from the left to the right, and the right to the left, looking for the left and right bounding box edges, respectively.

Parameters:
left The left edge of the bounding box
right The right edge
longitude_index_left Value-result parameter that holds the index in the grid's longitude map of the left bounding box edge. Uses a closed interval for the test.
longitude_index_right Value-result parameter for the right edge index.

Definition at line 182 of file GeoConstraint.cc.

References DBG2.

Referenced by set_bounding_box().

char* libdap::GeoConstraint::get_array_data (  )  const [inline]
int libdap::GeoConstraint::get_array_data_size (  )  const [inline]
bool libdap::GeoConstraint::get_bounding_box_set (  )  const [inline]
set<string> libdap::GeoConstraint::get_coards_lat_units (  )  const [inline]

Definition at line 349 of file GeoConstraint.h.

set<string> libdap::GeoConstraint::get_coards_lon_units (  )  const [inline]

Definition at line 353 of file GeoConstraint.h.

double* libdap::GeoConstraint::get_lat (  )  const [inline]
Array::Dim_iter libdap::GeoConstraint::get_lat_dim (  )  const [inline]
int libdap::GeoConstraint::get_lat_length (  )  const [inline]

Definition at line 250 of file GeoConstraint.h.

set<string> libdap::GeoConstraint::get_lat_names (  )  const [inline]

Definition at line 358 of file GeoConstraint.h.

int libdap::GeoConstraint::get_latitude_index_bottom (  )  const [inline]
int libdap::GeoConstraint::get_latitude_index_top (  )  const [inline]
LatitudeSense libdap::GeoConstraint::get_latitude_sense (  )  const [inline]
double* libdap::GeoConstraint::get_lon (  )  const [inline]
Array::Dim_iter libdap::GeoConstraint::get_lon_dim (  )  const [inline]
int libdap::GeoConstraint::get_lon_length (  )  const [inline]
set<string> libdap::GeoConstraint::get_lon_names (  )  const [inline]

Definition at line 362 of file GeoConstraint.h.

int libdap::GeoConstraint::get_longitude_index_left (  )  const [inline]
int libdap::GeoConstraint::get_longitude_index_right (  )  const [inline]
Notation libdap::GeoConstraint::get_longitude_notation (  )  const [inline]
bool libdap::GeoConstraint::get_longitude_rightmost (  )  const [inline]

Definition at line 323 of file GeoConstraint.h.

Referenced by reorder_data_longitude_axis().

bool libdap::GeoConstraint::is_bounding_box_valid ( double  left,
double  top,
double  right,
double  bottom 
) const [protected, virtual]

Definition at line 150 of file GeoConstraint.cc.

References normal.

Referenced by set_bounding_box().

virtual bool libdap::GeoConstraint::lat_lon_dimensions_ok (  )  [protected, pure virtual]

Are the latitude and longitude dimensions ordered so that this class can properly constrain the data? This method throws Error if lat and lon are not to two 'fastest-varying' (or 'rightmost) dimensions. It sets the internal property longitude_rightmost if that's true.

Note:
Called by the constructor once build_lat_lon_maps() has returned.
Returns:
True if the lat/lon maps are the two rightmost maps, false otherwise
void libdap::GeoConstraint::reorder_data_longitude_axis ( Array a  )  [protected, virtual]

Reorder the data values relative to the longitude axis so that the reordered longitude map (see GeoConstraint::reorder_longitude_map()) and the data values match.

Note:
This method should set the d_array_data and d_array_data_size fields. If those are set, apply_constraint_to_data() will use those values.
First set all the other constraints, including the latitude and then make this call. Other constraints, besides latitude, will be simple range constraints. Latitude might require that values be inverted, but that can be done _after_ the longitude reordering takes place. The latitude constraint can be imposed by inverting the top and bottom indices if the sense of the grid is inverted, before data are read in this method. Then apply the longitude constraint, then invert the result of the merge, if needed.
Todo:
Fix this code so that it works with latitude as the rightmost map

Definition at line 400 of file GeoConstraint.cc.

References libdap::Array::add_constraint(), libdap::Vector::buf2val(), DBG, DBG2, get_lon_length(), get_longitude_index_left(), get_longitude_index_right(), get_longitude_rightmost(), libdap::Vector::length(), libdap::Array::print_val(), libdap::BaseType::read(), libdap::Vector::set_read_p(), libdap::Vector::value(), libdap::Vector::var(), and libdap::BaseType::width().

Referenced by libdap::GridGeoConstraint::apply_constraint_to_data(), and libdap::ArrayGeoConstraint::apply_constraint_to_data().

Here is the call graph for this function:

void libdap::GeoConstraint::reorder_longitude_map ( int  longitude_index_left  )  [protected, virtual]

Reorder the elements in the longitude map so that the longitude constraint no longer crosses the edge of the map's storage. The d_lon field is modified.

Note:
The d_lon vector always has double values regardless of the type of d_longitude.
Parameters:
longitude_index_left The left edge of the bounding box.

Definition at line 360 of file GeoConstraint.cc.

Referenced by libdap::GridGeoConstraint::apply_constraint_to_data().

void libdap::GeoConstraint::set_bounding_box ( double  left,
double  top,
double  right,
double  bottom 
)

Set the bounding box for this constraint. After calling this method the object has values for the indexes for the latitude and longitude extent as well as the sense of the latitude (south pole at the top or bottom of the Array or Grid). These are used by the apply_constraint_to_data() method to actually constrain the data.

Parameters:
left The left side of the bounding box.
right The right side
top The top
bottom The bottom

Definition at line 549 of file GeoConstraint.cc.

References categorize_latitude(), categorize_notation(), DBG, libdap::double_to_string(), find_latitude_indeces(), find_longitude_indeces(), is_bounding_box_valid(), neg_pos, transform_constraint_to_pos_notation(), and transform_longitude_to_pos_notation().

Here is the call graph for this function:

void libdap::GeoConstraint::set_lat ( double *  lat  )  [inline]

Definition at line 241 of file GeoConstraint.h.

void libdap::GeoConstraint::set_lat_dim ( Array::Dim_iter  lat  )  [inline]

Definition at line 279 of file GeoConstraint.h.

void libdap::GeoConstraint::set_lat_length ( int  len  )  [inline]

Definition at line 258 of file GeoConstraint.h.

void libdap::GeoConstraint::set_latitude_index_bottom ( int  bottom  )  [inline]
void libdap::GeoConstraint::set_latitude_index_top ( int  top  )  [inline]
void libdap::GeoConstraint::set_latitude_sense ( LatitudeSense  l  )  [inline]

Definition at line 344 of file GeoConstraint.h.

void libdap::GeoConstraint::set_lon ( double *  lon  )  [inline]

Definition at line 245 of file GeoConstraint.h.

void libdap::GeoConstraint::set_lon_dim ( Array::Dim_iter  lon  )  [inline]

Definition at line 275 of file GeoConstraint.h.

void libdap::GeoConstraint::set_lon_length ( int  len  )  [inline]

Definition at line 262 of file GeoConstraint.h.

void libdap::GeoConstraint::set_longitude_index_left ( int  left  )  [inline]
void libdap::GeoConstraint::set_longitude_index_right ( int  right  )  [inline]
void libdap::GeoConstraint::set_longitude_notation ( Notation  n  )  [inline]

Definition at line 340 of file GeoConstraint.h.

void libdap::GeoConstraint::set_longitude_rightmost ( bool  state  )  [inline]

Definition at line 327 of file GeoConstraint.h.

void libdap::GeoConstraint::transform_constraint_to_pos_notation ( double &  left,
double &  right 
) const [protected]

Definition at line 120 of file GeoConstraint.cc.

Referenced by set_bounding_box().

void libdap::GeoConstraint::transform_longitude_to_neg_pos_notation (  )  [protected, virtual]

Given that the Grid has a longitude map that uses the 'pos' notation, transform it to the 'neg_pos' notation. This method modifies the d_longitude Array.

Definition at line 144 of file GeoConstraint.cc.

Referenced by libdap::GridGeoConstraint::apply_constraint_to_data().

void libdap::GeoConstraint::transform_longitude_to_pos_notation (  )  [protected, virtual]

Given that the Grid has a longitude map that uses the 'neg_pos' notation, transform it to the 'pos' notation. This method modifies the d_longitude Array.

Definition at line 132 of file GeoConstraint.cc.

Referenced by set_bounding_box().


Friends And Related Function Documentation

friend class GridGeoConstraintTest [friend]

Reimplemented in libdap::GridGeoConstraint.

Definition at line 206 of file GeoConstraint.h.


The documentation for this class was generated from the following files:

Generated on Sat Dec 5 12:26:12 2009 for libdap++ by  doxygen 1.6.1