libdap++  Updated for version 3.8.2
libdap::ArrayGeoConstraint Class Reference

#include <ArrayGeoConstraint.h>

Inheritance diagram for libdap::ArrayGeoConstraint:
Inheritance graph
Collaboration diagram for libdap::ArrayGeoConstraint:
Collaboration graph

Public Types

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

Public Member Functions

virtual void apply_constraint_to_data ()
 
virtual Arrayget_constrained_array () const
 
void set_bounding_box (double top, double left, double bottom, double right)
 
virtual ~ArrayGeoConstraint ()
 
Constructors
 ArrayGeoConstraint (Array *)
 
 ArrayGeoConstraint (Array *array, double left, double top, double right, double bottom)
 
 ArrayGeoConstraint (Array *array, double left, double top, double right, double bottom, const string &projection, const string &datum)
 
Accessors/Mutators
char * get_array_data () const
 
int get_array_data_size () const
 
double * get_lat () const
 
double * get_lon () const
 
void set_lat (double *lat)
 
void set_lon (double *lon)
 
int get_lat_length () const
 
int get_lon_length () const
 
void set_lat_length (int len)
 
void set_lon_length (int len)
 
Array::Dim_iter get_lon_dim () const
 
Array::Dim_iter get_lat_dim () const
 
void set_lon_dim (Array::Dim_iter lon)
 
void set_lat_dim (Array::Dim_iter lat)
 
int get_latitude_index_top () const
 
int get_latitude_index_bottom () const
 
void set_latitude_index_top (int top)
 
void set_latitude_index_bottom (int bottom)
 
int get_longitude_index_left () const
 
int get_longitude_index_right () const
 
void set_longitude_index_left (int left)
 
void set_longitude_index_right (int right)
 
bool is_bounding_box_set () const
 
bool is_longitude_rightmost () const
 
void set_longitude_rightmost (bool state)
 
Notation get_longitude_notation () const
 
LatitudeSense get_latitude_sense () const
 
void set_longitude_notation (Notation n)
 
void set_latitude_sense (LatitudeSense l)
 
set< string > get_coards_lat_units () const
 
set< string > get_coards_lon_units () const
 
set< string > get_lat_names () const
 
set< string > get_lon_names () const
 

Protected Member Functions

virtual LatitudeSense categorize_latitude () const
 
Notation categorize_notation (const double left, const 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 void flip_latitude_within_array (Array &a, int lat_length, int lon_length)
 
virtual bool is_bounding_box_valid (const double left, const double top, const double right, const double bottom) const
 
virtual void reorder_data_longitude_axis (Array &a, Array::Dim_iter lon_dim)
 
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 ()
 
virtual void transpose_vector (double *src, const int length)
 

Friends

class ArrayGeoConstraintTest
 

Detailed Description

Geographical constraint applied to an Array.

Note
This class assumes that the Longitude dimension varies fastest, as does the COARDS conventions.
Author
James Gallagher

Definition at line 55 of file ArrayGeoConstraint.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::ArrayGeoConstraint::ArrayGeoConstraint ( Array )
inline

Definition at line 110 of file ArrayGeoConstraint.h.

libdap::ArrayGeoConstraint::ArrayGeoConstraint ( Array array,
double  left,
double  top,
double  right,
double  bottom 
)

Definition at line 65 of file ArrayGeoConstraint.cc.

libdap::ArrayGeoConstraint::ArrayGeoConstraint ( Array array,
double  left,
double  top,
double  right,
double  bottom,
const string &  projection,
const string &  datum 
)

Definition at line 74 of file ArrayGeoConstraint.cc.

virtual libdap::ArrayGeoConstraint::~ArrayGeoConstraint ( )
inlinevirtual

Definition at line 127 of file ArrayGeoConstraint.h.

Member Function Documentation

void libdap::ArrayGeoConstraint::apply_constraint_to_data ( )
virtual

Once the bounding box is set, apply the constraint. If the data can be sent using Vector::serialize(), do so. If they cannot, read and organize the data so that Vector::serialize() will be able to send the data when asked to.

How can it be that Vector::serialize() would not be able to read the data? If the longitude extent of the bounding box for the constraint wraps around the edge of the data/array, then two reads are required to get the data. This method performs those reads (using the constraints and the read() method so that the data server's type-specific and optimized code will be used to read actual data values) and then loads the combined result back into the object, marking it as having been read. Vector::serialize() will then see the object is loaded with data values, skip the regular read call and send all the data in the buffer.

Implements libdap::GeoConstraint.

Definition at line 150 of file ArrayGeoConstraint.cc.

References libdap::Array::add_constraint(), libdap::GeoConstraint::get_array_data(), libdap::GeoConstraint::get_array_data_size(), libdap::GeoConstraint::get_lat_dim(), libdap::GeoConstraint::get_latitude_index_bottom(), libdap::GeoConstraint::get_latitude_index_top(), libdap::GeoConstraint::get_latitude_sense(), libdap::GeoConstraint::get_lon_dim(), libdap::GeoConstraint::get_lon_length(), libdap::GeoConstraint::get_longitude_index_left(), libdap::GeoConstraint::get_longitude_index_right(), libdap::GeoConstraint::inverted, libdap::GeoConstraint::is_bounding_box_set(), libdap::BaseType::read(), libdap::GeoConstraint::reorder_data_longitude_axis(), libdap::GeoConstraint::set_latitude_index_bottom(), libdap::GeoConstraint::set_latitude_index_top(), libdap::GeoConstraint::set_longitude_index_left(), libdap::GeoConstraint::set_longitude_index_right(), libdap::Vector::set_read_p(), and libdap::Vector::val2buf().

Here is the call graph for this function:

GeoConstraint::LatitudeSense libdap::GeoConstraint::categorize_latitude ( ) const
protectedvirtualinherited

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 336 of file GeoConstraint.cc.

Referenced by libdap::GeoConstraint::set_bounding_box().

GeoConstraint::Notation libdap::GeoConstraint::categorize_notation ( const double  left,
const double  right 
) const
protectedinherited

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 constraints 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 degrees (or 50 to 30, for that matter), there's no real way to tell which notation they are using.
Parameters
leftThe left side of the bounding box, in degrees
rightThe right side of the bounding box
Returns
The notation (pos or neg_pos)

Definition at line 110 of file GeoConstraint.cc.

Referenced by libdap::GeoConstraint::set_bounding_box().

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

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

Parameters
topThe top edge of the bounding box
bottomThe bottom edge
senseDoes the array/grid store data with larger latitudes at the starting indices or are the latitude 'upside down?'
latitude_index_topValue-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_bottomValue-result parameter for the bottom edge index.

Definition at line 285 of file GeoConstraint.cc.

Referenced by libdap::GeoConstraint::set_bounding_box().

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

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

Parameters
leftThe left edge of the bounding box
rightThe right edge
longitude_index_leftValue-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_rightValue-result parameter for the right edge index.

Definition at line 207 of file GeoConstraint.cc.

References DBG2, and libdap::double_to_string().

Referenced by libdap::GeoConstraint::set_bounding_box().

Here is the call graph for this function:

void libdap::GeoConstraint::flip_latitude_within_array ( Array a,
int  lat_length,
int  lon_length 
)
protectedvirtualinherited
char* libdap::GeoConstraint::get_array_data ( ) const
inlineinherited
int libdap::GeoConstraint::get_array_data_size ( ) const
inlineinherited
set<string> libdap::GeoConstraint::get_coards_lat_units ( ) const
inlineinherited

Definition at line 347 of file GeoConstraint.h.

set<string> libdap::GeoConstraint::get_coards_lon_units ( ) const
inlineinherited

Definition at line 351 of file GeoConstraint.h.

virtual Array* libdap::ArrayGeoConstraint::get_constrained_array ( ) const
inlinevirtual

Definition at line 132 of file ArrayGeoConstraint.h.

double* libdap::GeoConstraint::get_lat ( ) const
inlineinherited
Array::Dim_iter libdap::GeoConstraint::get_lat_dim ( ) const
inlineinherited
int libdap::GeoConstraint::get_lat_length ( ) const
inlineinherited

Definition at line 248 of file GeoConstraint.h.

set<string> libdap::GeoConstraint::get_lat_names ( ) const
inlineinherited

Definition at line 356 of file GeoConstraint.h.

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

Definition at line 360 of file GeoConstraint.h.

int libdap::GeoConstraint::get_longitude_index_left ( ) const
inlineinherited
int libdap::GeoConstraint::get_longitude_index_right ( ) const
inlineinherited
Notation libdap::GeoConstraint::get_longitude_notation ( ) const
inlineinherited
bool libdap::GeoConstraint::is_bounding_box_set ( ) const
inlineinherited
bool libdap::GeoConstraint::is_bounding_box_valid ( const double  left,
const double  top,
const double  right,
const double  bottom 
) const
protectedvirtualinherited

Definition at line 175 of file GeoConstraint.cc.

Referenced by libdap::GeoConstraint::set_bounding_box().

bool libdap::GeoConstraint::is_longitude_rightmost ( ) const
inlineinherited

Definition at line 321 of file GeoConstraint.h.

void libdap::GeoConstraint::reorder_data_longitude_axis ( Array a,
Array::Dim_iter  lon_dim 
)
protectedvirtualinherited

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 should be called with the Array that contains the d_lon_dim Array::Dim_iter.
This method must 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 flipped, but that can be done after the longitude reordering takes place.
Todo:
Fix this code so that it works with latitude as the rightmost map

Definition at line 478 of file GeoConstraint.cc.

References libdap::Array::add_constraint(), DBG, DBG2, libdap::Array::print_val(), libdap::BaseType::read(), libdap::Vector::set_read_p(), libdap::Vector::value(), libdap::Vector::var(), libdap::Array::width(), and libdap::BaseType::width().

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

Here is the call graph for this function:

void libdap::GeoConstraint::reorder_longitude_map ( int  longitude_index_left)
protectedvirtualinherited

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_leftThe left edge of the bounding box.

Definition at line 439 of file GeoConstraint.cc.

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

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

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
leftThe left side of the bounding box.
rightThe right side
topThe top
bottomThe bottom

Definition at line 594 of file GeoConstraint.cc.

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

Referenced by libdap::function_geogrid().

Here is the call graph for this function:

void libdap::GeoConstraint::set_lat ( double *  lat)
inlineinherited

Definition at line 239 of file GeoConstraint.h.

void libdap::GeoConstraint::set_lat_dim ( Array::Dim_iter  lat)
inlineinherited

Definition at line 277 of file GeoConstraint.h.

void libdap::GeoConstraint::set_lat_length ( int  len)
inlineinherited

Definition at line 256 of file GeoConstraint.h.

void libdap::GeoConstraint::set_latitude_index_bottom ( int  bottom)
inlineinherited
void libdap::GeoConstraint::set_latitude_index_top ( int  top)
inlineinherited
void libdap::GeoConstraint::set_latitude_sense ( LatitudeSense  l)
inlineinherited

Definition at line 342 of file GeoConstraint.h.

void libdap::GeoConstraint::set_lon ( double *  lon)
inlineinherited

Definition at line 243 of file GeoConstraint.h.

void libdap::GeoConstraint::set_lon_dim ( Array::Dim_iter  lon)
inlineinherited

Definition at line 273 of file GeoConstraint.h.

void libdap::GeoConstraint::set_lon_length ( int  len)
inlineinherited

Definition at line 260 of file GeoConstraint.h.

void libdap::GeoConstraint::set_longitude_index_left ( int  left)
inlineinherited
void libdap::GeoConstraint::set_longitude_index_right ( int  right)
inlineinherited
void libdap::GeoConstraint::set_longitude_notation ( Notation  n)
inlineinherited

Definition at line 338 of file GeoConstraint.h.

void libdap::GeoConstraint::set_longitude_rightmost ( bool  state)
inlineinherited

Definition at line 325 of file GeoConstraint.h.

void libdap::GeoConstraint::transform_constraint_to_pos_notation ( double &  left,
double &  right 
) const
protectedinherited

Definition at line 131 of file GeoConstraint.cc.

Referenced by libdap::GeoConstraint::set_bounding_box().

void libdap::GeoConstraint::transform_longitude_to_neg_pos_notation ( )
protectedvirtualinherited

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_lon array.

Note
: About the two notations: 0 180 360 |------------------------—|----------------------—| 0 180,-180 0

Definition at line 168 of file GeoConstraint.cc.

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

void libdap::GeoConstraint::transform_longitude_to_pos_notation ( )
protectedvirtualinherited

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_lon array.

Note
: About the two notations: 0 180 360 |------------------------—|----------------------—| 0 180,-180 0

Definition at line 149 of file GeoConstraint.cc.

Referenced by libdap::GeoConstraint::set_bounding_box().

void libdap::GeoConstraint::transpose_vector ( double *  src,
const int  length 
)
protectedvirtualinherited

Given a vector of doubles, transpose the elements. Use this to flip the latitude vector for a Grid that stores the southern latitudes at the top instead of the bottom.

Parameters
srcA pointer to the vector
lengthThe number of elements in the vector

Definition at line 369 of file GeoConstraint.cc.

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

Friends And Related Function Documentation

friend class ArrayGeoConstraintTest
friend

Definition at line 105 of file ArrayGeoConstraint.h.


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