osgEarth 2.1.1
|
Public Member Functions | |
GeoExtent () | |
GeoExtent (const SpatialReference *srs, double xmin=FLT_MAX, double ymin=FLT_MAX, double xmax=-FLT_MAX, double ymax=-FLT_MAX) | |
GeoExtent (const GeoExtent &rhs) | |
GeoExtent (const SpatialReference *srs, const Bounds &bounds) | |
bool | operator== (const GeoExtent &rhs) const |
bool | operator!= (const GeoExtent &rhs) const |
const SpatialReference * | getSRS () const |
double | xMin () const |
double & | xMin () |
double | yMin () const |
double & | yMin () |
double | xMax () const |
double & | xMax () |
double | yMax () const |
double & | yMax () |
double | width () const |
double | height () const |
void | getCentroid (double &out_x, double &out_y) const |
bool | crossesDateLine () const |
void | getBounds (double &xmin, double &ymin, double &xmax, double &ymax) const |
bool | isValid () const |
bool | defined () const |
bool | splitAcrossDateLine (GeoExtent &first, GeoExtent &second) const |
GeoExtent | transform (const SpatialReference *to_srs) const |
bool | contains (double x, double y, const SpatialReference *xy_srs=0L) const |
bool | contains (const Bounds &rhs) const |
bool | intersects (const GeoExtent &rhs) const |
Bounds | bounds () const |
void | expandToInclude (double x, double y) |
void | expandToInclude (const Bounds &rhs) |
GeoExtent | intersectionSameSRS (const Bounds &rhs) const |
std::string | toString () const |
void | scale (double x_scale, double y_scale) |
void | expand (double x, double y) |
double | area () const |
Static Public Attributes | |
static GeoExtent | INVALID = GeoExtent() |
Private Attributes | |
osg::ref_ptr< const SpatialReference > | _srs |
double | _xmin |
double | _ymin |
double | _xmax |
double | _ymax |
A georeferenced extent. A bounding box that is aligned with a spatial reference's coordinate system.
TODO: this class needs better integrated support for geographic extents that cross the date line.
GeoExtent::GeoExtent | ( | ) |
GeoExtent::GeoExtent | ( | const SpatialReference * | srs, |
double | xmin = FLT_MAX , |
||
double | ymin = FLT_MAX , |
||
double | xmax = -FLT_MAX , |
||
double | ymax = -FLT_MAX |
||
) |
GeoExtent::GeoExtent | ( | const GeoExtent & | rhs | ) |
GeoExtent::GeoExtent | ( | const SpatialReference * | srs, |
const Bounds & | bounds | ||
) |
double GeoExtent::area | ( | ) | const |
Gets the area of this GeoExtent
Definition at line 434 of file GeoData.cpp.
Bounds GeoExtent::bounds | ( | ) | const |
bool GeoExtent::contains | ( | const Bounds & | rhs | ) | const |
bool GeoExtent::contains | ( | double | x, |
double | y, | ||
const SpatialReference * | xy_srs = 0L |
||
) | const |
Returns true if the specified point falls within the bounds of the extent.
x,y | Coordinates to test |
xy_srs | SRS of input x and y coordinates; if null, the method assumes x and y are in the same SRS as this object. |
Definition at line 336 of file GeoData.cpp.
{ double local_x = x, local_y = y; if (srs && !srs->isEquivalentTo( _srs.get() ) && !srs->transform2D(x, y, _srs.get(), local_x, local_y) ) { return false; } else { //Account for small rounding errors along the edges of the extent if (osg::equivalent(_xmin, local_x)) local_x = _xmin; if (osg::equivalent(_xmax, local_x)) local_x = _xmax; if (osg::equivalent(_ymin, local_y)) local_y = _ymin; if (osg::equivalent(_ymax, local_y)) local_y = _ymax; return local_x >= _xmin && local_x <= _xmax && local_y >= _ymin && local_y <= _ymax; } }
bool GeoExtent::crossesDateLine | ( | ) | const |
Returns true is that extent is in a Geographic (lat/long) SRS that spans the international date line.
Definition at line 268 of file GeoData.cpp.
bool osgEarth::GeoExtent::defined | ( | ) | const [inline] |
void GeoExtent::expand | ( | double | x, |
double | y | ||
) |
void GeoExtent::expandToInclude | ( | double | x, |
double | y | ||
) |
void GeoExtent::expandToInclude | ( | const Bounds & | rhs | ) |
Grow this extent to include the specified GeoExtent (which is assumed to be in the extent's SRS.
Definition at line 388 of file GeoData.cpp.
{ expandToInclude( rhs.xMin(), rhs.yMin() ); expandToInclude( rhs.xMax(), rhs.yMax() ); }
void GeoExtent::getBounds | ( | double & | xmin, |
double & | ymin, | ||
double & | xmax, | ||
double & | ymax | ||
) | const |
void GeoExtent::getCentroid | ( | double & | out_x, |
double & | out_y | ||
) | const |
const SpatialReference * GeoExtent::getSRS | ( | ) | const |
Gets the spatial reference system underlying this extent.
Definition at line 242 of file GeoData.cpp.
{ return _srs.get(); }
double GeoExtent::height | ( | ) | const |
Intersect this extent with another extent in the same SRS and return the result.
Definition at line 395 of file GeoData.cpp.
{ Bounds b( osg::maximum( xMin(), rhs.xMin() ), osg::maximum( yMin(), rhs.yMin() ), osg::minimum( xMax(), rhs.xMax() ), osg::minimum( yMax(), rhs.yMax() ) ); return b.width() > 0 && b.height() > 0 ? GeoExtent( getSRS(), b ) : GeoExtent::INVALID; }
bool GeoExtent::intersects | ( | const GeoExtent & | rhs | ) | const |
Returns TRUE if this extent intersects another extent.
Definition at line 367 of file GeoData.cpp.
{ bool valid = isValid(); if ( !valid ) return false; bool exclusive = _xmin > rhs.xMax() || _xmax < rhs.xMin() || _ymin > rhs.yMax() || _ymax < rhs.yMin(); return !exclusive; }
bool GeoExtent::isValid | ( | ) | const |
True if this object defines a real, valid extent with positive area
Definition at line 236 of file GeoData.cpp.
bool GeoExtent::operator!= | ( | const GeoExtent & | rhs | ) | const |
Definition at line 230 of file GeoData.cpp.
{ return !( *this == rhs ); }
bool GeoExtent::operator== | ( | const GeoExtent & | rhs | ) | const |
Definition at line 214 of file GeoData.cpp.
{ if ( !isValid() && !rhs.isValid() ) return true; else return isValid() && rhs.isValid() && _xmin == rhs._xmin && _ymin == rhs._ymin && _xmax == rhs._xmax && _ymax == rhs._ymax && _srs.valid() && rhs._srs.valid() && _srs->isEquivalentTo( rhs._srs.get() ); }
void GeoExtent::scale | ( | double | x_scale, |
double | y_scale | ||
) |
Inflates this GeoExtent by the given ratios
Definition at line 407 of file GeoData.cpp.
{ double orig_width = width(); double orig_height = height(); double new_width = orig_width * x_scale; double new_height = orig_height * y_scale; double halfXDiff = (new_width - orig_width) / 2.0; double halfYDiff = (new_height - orig_height) /2.0; _xmin -= halfXDiff; _xmax += halfXDiff; _ymin -= halfYDiff; _ymax += halfYDiff; }
If this extent crosses the international date line, populates two extents, one for each side, and returns true. Otherwise returns false and leaves the reference parameters untouched.
Definition at line 275 of file GeoData.cpp.
{ bool success = false; if ( crossesDateLine() ) { if ( _srs->isGeographic() ) { out_first = GeoExtent( _srs.get(), _xmin, _ymin, 180.0, _ymax ); out_second = GeoExtent( _srs.get(), -180.0, _ymin, _xmax, _ymax ); success = true; } else { GeoExtent latlong_extent = transform( _srs->getGeographicSRS() ); GeoExtent first, second; if ( latlong_extent.splitAcrossDateLine( first, second ) ) { out_first = first.transform( _srs.get() ); out_second = second.transform( _srs.get() ); success = out_first.isValid() && out_second.isValid(); } } } return success; }
std::string GeoExtent::toString | ( | ) | const |
Returns a human-readable string containing the extent data (without the SRS)
Definition at line 440 of file GeoData.cpp.
{ std::stringstream buf; if ( !isValid() ) buf << "INVALID"; else buf << "MIN=" << _xmin << "," << _ymin << " MAX=" << _xmax << "," << _ymax; buf << ", SRS=" << _srs->getName(); std::string bufStr; bufStr = buf.str(); return bufStr; }
GeoExtent GeoExtent::transform | ( | const SpatialReference * | to_srs | ) | const |
Returns this extent transformed into another spatial reference.
NOTE! It is possible that the target SRS will not be able to accomadate the extents of the source SRS. (For example, transforming a full WGS84 extent to Mercator will resultin an error since Mercator does not cover the entire globe.) Consider using Profile:clampAndTransformExtent() instead of using this method directly.
Definition at line 303 of file GeoData.cpp.
{ if ( _srs.valid() && to_srs ) { double xmin = _xmin, ymin = _ymin; double xmax = _xmax, ymax = _ymax; if ( _srs->transformExtent( to_srs, xmin, ymin, xmax, ymax ) ) { return GeoExtent( to_srs, xmin, ymin, xmax, ymax ); } } return GeoExtent::INVALID; }
double GeoExtent::width | ( | ) | const |
Definition at line 247 of file GeoData.cpp.
{ return crossesDateLine()? (180-_xmin) + (_xmax+180) : _xmax - _xmin; }
double& osgEarth::GeoExtent::xMax | ( | ) | [inline] |
double osgEarth::GeoExtent::xMax | ( | ) | const [inline] |
double osgEarth::GeoExtent::xMin | ( | ) | const [inline] |
double& osgEarth::GeoExtent::xMin | ( | ) | [inline] |
double& osgEarth::GeoExtent::yMax | ( | ) | [inline] |
double osgEarth::GeoExtent::yMax | ( | ) | const [inline] |
double osgEarth::GeoExtent::yMin | ( | ) | const [inline] |
double& osgEarth::GeoExtent::yMin | ( | ) | [inline] |
osg::ref_ptr<const SpatialReference> osgEarth::GeoExtent::_srs [private] |
double osgEarth::GeoExtent::_xmax [private] |
double osgEarth::GeoExtent::_xmin [private] |
double osgEarth::GeoExtent::_ymax [private] |
double osgEarth::GeoExtent::_ymin [private] |
GeoExtent GeoExtent::INVALID = GeoExtent() [static] |