osgEarth 2.1.1
Public Member Functions | Static Public Attributes | Private Attributes

osgEarth::GeoExtent Class Reference

Inheritance diagram for osgEarth::GeoExtent:
Collaboration diagram for osgEarth::GeoExtent:

List of all members.

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 SpatialReferencegetSRS () 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

Detailed Description

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.

Definition at line 68 of file GeoData.


Constructor & Destructor Documentation

GeoExtent::GeoExtent ( )

Default ctor creates an "invalid" extent

Definition at line 178 of file GeoData.cpp.

                    :
_xmin(FLT_MAX),
_ymin(FLT_MAX),
_xmax(-FLT_MAX),
_ymax(-FLT_MAX)
{
    //NOP - invalid
}

Here is the caller graph for this function:

GeoExtent::GeoExtent ( const SpatialReference srs,
double  xmin = FLT_MAX,
double  ymin = FLT_MAX,
double  xmax = -FLT_MAX,
double  ymax = -FLT_MAX 
)

Contructs a valid extent

Definition at line 187 of file GeoData.cpp.

                                                                         :
_srs( srs ),
_xmin(xmin),_ymin(ymin),_xmax(xmax),_ymax(ymax)
{
    //NOP
}
GeoExtent::GeoExtent ( const GeoExtent rhs)

Copy ctor

Definition at line 206 of file GeoData.cpp.

                                           :
_srs( rhs._srs ),
_xmin( rhs._xmin ), _ymin( rhs._ymin ), _xmax( rhs._xmax ), _ymax( rhs._ymax )
{
    //NOP
}
GeoExtent::GeoExtent ( const SpatialReference srs,
const Bounds bounds 
)

create from Bounds object

Definition at line 196 of file GeoData.cpp.

                                                                        :
_srs( srs ),
_xmin( bounds.xMin() ),
_ymin( bounds.yMin() ),
_xmax( bounds.xMax() ),
_ymax( bounds.yMax() )
{
    //nop
}

Member Function Documentation

double GeoExtent::area ( ) const

Gets the area of this GeoExtent

Definition at line 434 of file GeoData.cpp.

{
    return width() * height();
}

Here is the call graph for this function:

Bounds GeoExtent::bounds ( ) const

Direct access to the anonymous bounding box

Definition at line 329 of file GeoData.cpp.

{
    return Bounds( _xmin, _ymin, _xmax, _ymax );
}

Here is the caller graph for this function:

bool GeoExtent::contains ( const Bounds rhs) const

Returns true if this extent fully contains the target bounds.

Definition at line 357 of file GeoData.cpp.

{
    return 
        rhs.xMin() >= _xmin &&
        rhs.yMin() >= _ymin &&
        rhs.xMax() <= _xmax &&
        rhs.yMax() <= _ymax;
}
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.

Parameters:
x,yCoordinates to test
xy_srsSRS 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;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

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.

{
    return _xmax < _xmin;
    //return _srs.valid() && _srs->isGeographic() && _xmax < _xmin;
}

Here is the caller graph for this function:

bool osgEarth::GeoExtent::defined ( ) const [inline]

Definition at line 119 of file GeoData.

{ return isValid(); }
void GeoExtent::expand ( double  x,
double  y 
)

Expands the extent by x and y.

Definition at line 425 of file GeoData.cpp.

{
    _xmin -= .5*x;
    _xmax += .5*x;
    _ymin -= .5*y;
    _ymax += .5*y;
}
void GeoExtent::expandToInclude ( double  x,
double  y 
)

Grow this extent to include the specified point (which is assumed to be in the extent's SRS.

Definition at line 380 of file GeoData.cpp.

{
    if ( x < _xmin ) _xmin = x;
    if ( x > _xmax ) _xmax = x;
    if ( y < _ymin ) _ymin = y;
    if ( y > _ymax ) _ymax = y;
}

Here is the caller graph for this function:

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() );
}

Here is the call graph for this function:

void GeoExtent::getBounds ( double &  xmin,
double &  ymin,
double &  xmax,
double &  ymax 
) const

Returns the raw bounds in a single function call

Definition at line 320 of file GeoData.cpp.

{
    xmin = _xmin;
    ymin = _ymin;
    xmax = _xmax;
    ymax = _ymax;
}

Here is the caller graph for this function:

void GeoExtent::getCentroid ( double &  out_x,
double &  out_y 
) const

Definition at line 261 of file GeoData.cpp.

{
    out_x = _xmin+width()/2.0;
    out_y = _ymin+height()/2.0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

const SpatialReference * GeoExtent::getSRS ( ) const

Gets the spatial reference system underlying this extent.

Definition at line 242 of file GeoData.cpp.

                        {
    return _srs.get(); 
}

Here is the caller graph for this function:

double GeoExtent::height ( ) const

Definition at line 255 of file GeoData.cpp.

{
    return _ymax - _ymin;
}

Here is the caller graph for this function:

GeoExtent GeoExtent::intersectionSameSRS ( const Bounds rhs) 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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool GeoExtent::isValid ( ) const

True if this object defines a real, valid extent with positive area

Definition at line 236 of file GeoData.cpp.

{
    return _srs.valid() && width() > 0 && height() > 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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() );
}

Here is the call graph for this function:

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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool GeoExtent::splitAcrossDateLine ( GeoExtent first,
GeoExtent second 
) const

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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

double GeoExtent::width ( ) const

Definition at line 247 of file GeoData.cpp.

{
    return crossesDateLine()?
        (180-_xmin) + (_xmax+180) :
        _xmax - _xmin;
}

Here is the call graph for this function:

Here is the caller graph for this function:

double& osgEarth::GeoExtent::xMax ( ) [inline]

Definition at line 97 of file GeoData.

{ return _xmax; }
double osgEarth::GeoExtent::xMax ( ) const [inline]

Definition at line 96 of file GeoData.

{ return _xmax; }

Here is the caller graph for this function:

double osgEarth::GeoExtent::xMin ( ) const [inline]

Definition at line 92 of file GeoData.

{ return _xmin; }

Here is the caller graph for this function:

double& osgEarth::GeoExtent::xMin ( ) [inline]

Definition at line 93 of file GeoData.

{ return _xmin; }
double& osgEarth::GeoExtent::yMax ( ) [inline]

Definition at line 99 of file GeoData.

{ return _ymax; }
double osgEarth::GeoExtent::yMax ( ) const [inline]

Definition at line 98 of file GeoData.

{ return _ymax; }

Here is the caller graph for this function:

double osgEarth::GeoExtent::yMin ( ) const [inline]

Definition at line 94 of file GeoData.

{ return _ymin; }

Here is the caller graph for this function:

double& osgEarth::GeoExtent::yMin ( ) [inline]

Definition at line 95 of file GeoData.

{ return _ymin; }

Member Data Documentation

osg::ref_ptr<const SpatialReference> osgEarth::GeoExtent::_srs [private]

Definition at line 205 of file GeoData.

double osgEarth::GeoExtent::_xmax [private]

Definition at line 206 of file GeoData.

double osgEarth::GeoExtent::_xmin [private]

Definition at line 206 of file GeoData.

double osgEarth::GeoExtent::_ymax [private]

Definition at line 206 of file GeoData.

double osgEarth::GeoExtent::_ymin [private]

Definition at line 206 of file GeoData.

Definition at line 202 of file GeoData.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines