osgEarth 2.1.1
Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes

osgEarth::TileMap Class Reference

Inheritance diagram for osgEarth::TileMap:
Collaboration diagram for osgEarth::TileMap:

List of all members.

Public Types

typedef std::vector< TileSetTileSetList

Public Member Functions

 TileMap ()
const std::string & getTileMapService () const
void setTileMapService (const std::string &tileMapService)
const std::string & getVersion () const
void setVersion (const std::string &version)
const std::string & getTitle () const
void setTitle (const std::string &title)
const std::string & getAbstract () const
void setAbstract (const std::string &value)
const std::string & getSRS () const
void setSRS (const std::string &srs)
const std::string & getVerticalSRS () const
void setVerticalSRS (const std::string &vsrs)
const std::string & getFilename () const
void setFilename (const std::string &filename)
unsigned int getMinLevel () const
unsigned int getMaxLevel () const
void computeMinMaxLevel ()
void computeNumTiles ()
double getOriginX () const
void setOriginX (double x)
double getOriginY () const
void setOriginY (double y)
void setOrigin (double x, double y)
void getExtents (double &minX, double &minY, double &maxX, double &maxY) const
void setExtents (double minX, double minY, double maxX, double maxY)
unsigned int getNumTilesWide () const
void setNumTilesWide (unsigned int w)
unsigned int getNumTilesHigh () const
void setNumTilesHigh (unsigned int h)
osgEarth::Profile::ProfileType getProfileType () const
void setProfileType (osgEarth::Profile::ProfileType type)
const ProfilecreateProfile () const
TileFormatgetFormat ()
const TileFormatgetFormat () const
TileSetListgetTileSets ()
const TileSetListgetTileSets () const
DataExtentListgetDataExtents ()
const DataExtentListgetDataExtents () const
std::string getURL (const osgEarth::TileKey &tileKey, bool invertY)
bool intersectsKey (const osgEarth::TileKey &tileKey)
void generateTileSets (unsigned int numLevels=20)

Static Public Member Functions

static TileMapcreate (const std::string &url, const Profile *profile, const std::string &format, int tile_width, int tile_height)
static TileMapcreate (const TileSource *tileSource, const Profile *profile)

Protected Attributes

std::string _tileMapService
std::string _version
std::string _title
std::string _abstract
std::string _srs
std::string _vsrs
double _originX
double _originY
double _minX
double _minY
double _maxX
double _maxY
TileSetList _tileSets
TileFormat _format
std::string _filename
unsigned int _minLevel
unsigned int _maxLevel
unsigned int _numTilesWide
unsigned int _numTilesHigh
osgEarth::Profile::ProfileType _profile_type
DataExtentList _dataExtents

Detailed Description

A TMS tile map

Definition at line 148 of file TMS.


Member Typedef Documentation

A list of TileSets

Definition at line 332 of file TMS.


Constructor & Destructor Documentation

TileMap::TileMap ( )

Definition at line 62 of file TMS.cpp.

                :
_originX(0),
_originY(0),
_minX(0.0),
_minY(0.0),
_maxX(0.0),
_maxY(0.0),
_minLevel(0),
_maxLevel(0),
_numTilesHigh(-1),
_numTilesWide(-1)
{
}

Here is the caller graph for this function:


Member Function Documentation

void TileMap::computeMinMaxLevel ( )

Computes the minimum and maximum levels of valid data for this TileMap

Definition at line 146 of file TMS.cpp.

{
    _minLevel = INT_MAX;
    _maxLevel = 0;
    for (TileSetList::iterator itr = _tileSets.begin(); itr != _tileSets.end(); ++itr)
    { 
        if (itr->getOrder() < _minLevel) _minLevel = itr->getOrder();
        if (itr->getOrder() > _maxLevel) _maxLevel = itr->getOrder();
    }
}

Here is the caller graph for this function:

void TileMap::computeNumTiles ( )

Computes the number of tiles at level 0 from the existing TileSets

Definition at line 157 of file TMS.cpp.

{
    _numTilesWide = -1;
    _numTilesHigh = -1;

    if (_tileSets.size() > 0)
    {
        unsigned int level = _tileSets[0].getOrder();
        double res = _tileSets[0].getUnitsPerPixel();

        _numTilesWide = (int)((_maxX - _minX) / (res * _format.getWidth()));
        _numTilesHigh = (int)((_maxY - _minY) / (res * _format.getWidth()));

        //In case the first level specified isn't level 0, compute the number of tiles at level 0
        for (unsigned int i = 0; i < level; i++)
        {
            _numTilesWide /= 2;
            _numTilesHigh /= 2;
        }

        OE_DEBUG << LC << "TMS has " << _numTilesWide << ", " << _numTilesHigh << " tiles at level 0 " <<  std::endl;
    }
}

Here is the call graph for this function:

TileMap * TileMap::create ( const std::string &  url,
const Profile profile,
const std::string &  format,
int  tile_width,
int  tile_height 
) [static]

Creates a TileMap corresponding to one of osgEarth's built-in profile types

Definition at line 336 of file TMS.cpp.

{
    //Profile profile(type);

    const GeoExtent& ex = profile->getExtent();

    TileMap* tileMap = new TileMap();
    tileMap->setProfileType(profile->getProfileType()); //type);
    tileMap->setExtents(ex.xMin(), ex.yMin(), ex.xMax(), ex.yMax());
    tileMap->setOrigin(ex.xMin(), ex.yMin());
    tileMap->_filename = url;
    tileMap->_srs = getSRSString(profile->getSRS());
    tileMap->_vsrs = profile->getVerticalSRS() ? profile->getVerticalSRS()->getInitString() : "";
    tileMap->_format.setWidth( tile_width );
    tileMap->_format.setHeight( tile_height );
    tileMap->_format.setExtension( format );
        profile->getNumTiles( 0, tileMap->_numTilesWide, tileMap->_numTilesHigh );

        tileMap->generateTileSets();
        tileMap->computeMinMaxLevel();
        
    return tileMap;
}

Here is the call graph for this function:

Here is the caller graph for this function:

TileMap * TileMap::create ( const TileSource tileSource,
const Profile profile 
) [static]

Creates a TileMap based on the parameters of a TileSource

Definition at line 364 of file TMS.cpp.

{
    TileMap* tileMap = new TileMap();

    tileMap->setTitle( tileSource->getName() );
    tileMap->setProfileType( profile->getProfileType() );

    const GeoExtent& ex = profile->getExtent();
    
    tileMap->_srs = getSRSString(profile->getSRS()); //srs();
    tileMap->_vsrs = profile->getVerticalSRS() ? profile->getVerticalSRS()->getInitString() : 0L;
    tileMap->_originX = ex.xMin();
    tileMap->_originY = ex.yMin();
    tileMap->_minX = ex.xMin();
    tileMap->_minY = ex.yMin();
    tileMap->_maxX = ex.xMax();
    tileMap->_maxY = ex.yMax();
    profile->getNumTiles( 0, tileMap->_numTilesWide, tileMap->_numTilesHigh );

    tileMap->_format.setWidth( tileSource->getPixelsPerTile() );
    tileMap->_format.setHeight( tileSource->getPixelsPerTile() );
    tileMap->_format.setExtension( tileSource->getExtension() );

    tileMap->generateTileSets();

    return tileMap;
}

Here is the call graph for this function:

const Profile * TileMap::createProfile ( ) const

Definition at line 182 of file TMS.cpp.

{
    osg::ref_ptr< SpatialReference > spatialReference =  osgEarth::SpatialReference::create(_srs);
    
    if (spatialReference->isMercator())
    {
        //HACK:  Some TMS sources, most notably TileCache, use a global mercator extent that is very slightly different than
        //       the automatically computed mercator bounds which can cause rendering issues due to the some texture coordinates
        //       crossing the dateline.  If the incoming bounds are nearly the same as our definion of global mercator, just use our definition.
        double eps = 0.01;
        osg::ref_ptr< const Profile > merc = osgEarth::Registry::instance()->getGlobalMercatorProfile();
        if (_numTilesWide == 1 && _numTilesHigh == 1 &&
            osg::equivalent(merc->getExtent().xMin(), _minX, eps) && 
            osg::equivalent(merc->getExtent().yMin(), _minY, eps) &&
            osg::equivalent(merc->getExtent().xMax(), _maxX, eps) &&
            osg::equivalent(merc->getExtent().yMax(), _maxY, eps))
        {            
            return osgEarth::Registry::instance()->getGlobalMercatorProfile();
        }
    }


    if (_profile_type == Profile::TYPE_GEODETIC) return osgEarth::Registry::instance()->getGlobalGeodeticProfile();
    if (_profile_type == Profile::TYPE_MERCATOR) return osgEarth::Registry::instance()->getGlobalMercatorProfile();
    

    return Profile::create(
        _srs,
        _minX, _minY, _maxX, _maxY,
        _vsrs,
        osg::maximum(_numTilesWide, (unsigned int)1),
        osg::maximum(_numTilesHigh, (unsigned int)1) );
}

Here is the call graph for this function:

Here is the caller graph for this function:

void TileMap::generateTileSets ( unsigned int  numLevels = 20)

Automatically generates a number of TileSets

Definition at line 296 of file TMS.cpp.

{
    osg::ref_ptr<const Profile> profile = createProfile();

    _tileSets.clear();

    double width = (_maxX - _minX);
//    double height = (_maxY - _minY);

    for (unsigned int i = 0; i < numLevels; ++i)
    {
        unsigned int numCols, numRows;
        profile->getNumTiles(i, numCols, numRows);
        double res = (width / (double)numCols) / (double)_format.getWidth();

        TileSet ts;
        ts.setUnitsPerPixel(res);
        ts.setOrder(i);
        _tileSets.push_back(ts);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

const std::string& osgEarth::TileMap::getAbstract ( ) const [inline]

Gets the abstract of this TileMap

Definition at line 186 of file TMS.

{return _abstract;}

Here is the caller graph for this function:

DataExtentList& osgEarth::TileMap::getDataExtents ( ) [inline]

Definition at line 340 of file TMS.

{ return _dataExtents;}

Here is the caller graph for this function:

const DataExtentList& osgEarth::TileMap::getDataExtents ( ) const [inline]

Definition at line 341 of file TMS.

{ return _dataExtents;}
void TileMap::getExtents ( double &  minX,
double &  minY,
double &  maxX,
double &  maxY 
) const

Gets the extents of this TileMap

Parameters:
minXThe minimum x coordinate of the extents
minYThe minimum y coordinate of the extents
maxXThe maximum x coordinate of the extents
maxYThe maximum y coordinate of the extents

Definition at line 82 of file TMS.cpp.

{
    minX = _minX;
    minY = _minY;
    maxX = _maxX;
    maxY = _maxY;
}

Here is the caller graph for this function:

const std::string& osgEarth::TileMap::getFilename ( ) const [inline]

Gets the filename that this TileMap was loaded from

Definition at line 216 of file TMS.

{return _filename;}
TileFormat& osgEarth::TileMap::getFormat ( ) [inline]

Gets the TileFormat for this TileMap

Definition at line 325 of file TMS.

{return _format;}

Here is the caller graph for this function:

const TileFormat& osgEarth::TileMap::getFormat ( ) const [inline]

Gets the TileFormat for this TileMap

Definition at line 328 of file TMS.

{return _format;}
unsigned int osgEarth::TileMap::getMaxLevel ( ) const [inline]

Gets the maximum level that this TileMap has valid data for

Definition at line 231 of file TMS.

{return _maxLevel;}
unsigned int osgEarth::TileMap::getMinLevel ( ) const [inline]

Gets the minimum zoom level that this TileMap has valid data for

Definition at line 226 of file TMS.

{return _minLevel;}
unsigned int osgEarth::TileMap::getNumTilesHigh ( ) const [inline]

Gets the number of tiles high at lod 0

Definition at line 312 of file TMS.

{ return _numTilesHigh; }
unsigned int osgEarth::TileMap::getNumTilesWide ( ) const [inline]

Gets the number of tiles wide at lod 0

Definition at line 302 of file TMS.

{ return _numTilesWide; }
double osgEarth::TileMap::getOriginX ( ) const [inline]

Gets the x coordinate of the origin of this TileMap

Definition at line 246 of file TMS.

{return _originX;}

Here is the caller graph for this function:

double osgEarth::TileMap::getOriginY ( ) const [inline]

Gets the y coordinate of the origin of this TileMap

Definition at line 256 of file TMS.

{return _originY;}

Here is the caller graph for this function:

osgEarth::Profile::ProfileType osgEarth::TileMap::getProfileType ( ) const [inline]

Definition at line 319 of file TMS.

{return _profile_type;}
const std::string& osgEarth::TileMap::getSRS ( ) const [inline]

Gets the spatial reference of this TileMap

Definition at line 196 of file TMS.

{return _srs;}

Here is the caller graph for this function:

const std::string& osgEarth::TileMap::getTileMapService ( ) const [inline]

Gets the tile map service for this TileMap

Definition at line 156 of file TMS.

{return _tileMapService;}

Here is the caller graph for this function:

TileSetList& osgEarth::TileMap::getTileSets ( ) [inline]

Gets the TileSets for this TileMap

Definition at line 335 of file TMS.

{return _tileSets;}

Here is the caller graph for this function:

const TileSetList& osgEarth::TileMap::getTileSets ( ) const [inline]

Gets the TileSets for this TileMap

Definition at line 338 of file TMS.

{return _tileSets;}
const std::string& osgEarth::TileMap::getTitle ( ) const [inline]

Gets the title of this TileMap

Definition at line 176 of file TMS.

{return _title;}

Here is the caller graph for this function:

std::string TileMap::getURL ( const osgEarth::TileKey tileKey,
bool  invertY 
)

Gets a URL string that can be used to retrieve the image for the given TileKey

Parameters:
tileKeyThe TileKey to get the URL for.
invertYIf false, treat tile 0,0 as the lower left tile in the the map. If true, treat 0,0 as the top left tile in the map.
Returns:
The URL if the data intersects the TileKey.

Definition at line 218 of file TMS.cpp.

{
    if (!intersectsKey(tilekey))
    {
        //OE_NOTICE << LC << "No key intersection for tile key " << tilekey.str() << std::endl;
        return "";
    }

    unsigned int zoom = tilekey.getLevelOfDetail();

    unsigned int x, y;
    tilekey.getTileXY(x, y);

    //Some TMS like services swap the Y coordinate so 0,0 is the upper left rather than the lower left.  The normal TMS
    //specification has 0,0 at the bottom left, so inverting Y will make 0,0 in the upper left.
    //http://code.google.com/apis/maps/documentation/overlays.html#Google_Maps_Coordinates
    if (!invertY)
    {
        unsigned int numRows, numCols;
        tilekey.getProfile()->getNumTiles(tilekey.getLevelOfDetail(), numCols, numRows);
        y  = numRows - y - 1;
    }

    //OE_NOTICE << LC << "KEY: " << tilekey.str() << " level " << zoom << " ( " << x << ", " << y << ")" << std::endl;

    //Select the correct TileSet
    if ( _tileSets.size() > 0 )
    {
        for (TileSetList::iterator itr = _tileSets.begin(); itr != _tileSets.end(); ++itr)
        { 
            if (itr->getOrder() == zoom)
            {
                std::stringstream ss;
                std::string path = osgDB::getFilePath(_filename);
                ss << path << "/" << zoom << "/" << x << "/" << y << "." << _format.getExtension();
                //OE_NOTICE << LC << "Returning URL " << ss.str() << std::endl;
                std::string ssStr;
                                ssStr = ss.str();
                                return ssStr;
            }
        }
    }
    else // Just go with it. No way of knowing the max level.
    {
        std::stringstream ss;
        std::string path = osgDB::getFilePath(_filename);
        ss << path << "/" << zoom << "/" << x << "/" << y << "." << _format.getExtension();
        std::string ssStr;
                ssStr = ss.str();
                return ssStr;        
    }

    return "";
}

Here is the call graph for this function:

const std::string& osgEarth::TileMap::getVersion ( ) const [inline]

Gets the version of this TileMap

Definition at line 166 of file TMS.

{return _version;}

Here is the caller graph for this function:

const std::string& osgEarth::TileMap::getVerticalSRS ( ) const [inline]

Gets the vertical spatial reference of this TileMap

Definition at line 206 of file TMS.

{ return _vsrs; }

Here is the caller graph for this function:

bool TileMap::intersectsKey ( const osgEarth::TileKey tileKey)

Determines whether or not the given TileKey intersects the TileMap

Definition at line 274 of file TMS.cpp.

{
    double keyMinX, keyMinY, keyMaxX, keyMaxY;

    //Check to see if the key overlaps the bounding box using lat/lon.  This is necessary to check even in 
    //Mercator situations in case the BoundingBox is described using lat/lon coordinates such as those produced by GDAL2Tiles
    //This should be considered a bug on the TMS production side, but we can work around it for now...
    tilekey.getExtent().getBounds(keyMinX, keyMinY, keyMaxX, keyMaxY);

    bool inter = intersects(_minX, _minY, _maxX, _maxY, keyMinX, keyMinY, keyMaxX, keyMaxY);

    if (!inter && tilekey.getProfile()->getSRS()->isMercator())
    {
        tilekey.getProfile()->getSRS()->transform2D(keyMinX, keyMinY, tilekey.getProfile()->getSRS()->getGeographicSRS(), keyMinX, keyMinY);
        tilekey.getProfile()->getSRS()->transform2D(keyMaxX, keyMaxY, tilekey.getProfile()->getSRS()->getGeographicSRS(), keyMaxX, keyMaxY);
        inter = intersects(_minX, _minY, _maxX, _maxY, keyMinX, keyMinY, keyMaxX, keyMaxY);
    }

    return inter;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void osgEarth::TileMap::setAbstract ( const std::string &  value) [inline]

Sets the abstract of this TileMap

Definition at line 191 of file TMS.

{_abstract = value;}
void TileMap::setExtents ( double  minX,
double  minY,
double  maxX,
double  maxY 
)

Sets the extents of this TileMap

Parameters:
minXThe minimum x coordinate of the extents
minYThe minimum y coordinate of the extents
maxXThe maximum x coordinate of the extents
maxYThe maximum y coordinate of the extents

Definition at line 90 of file TMS.cpp.

{
    _minX = minX;
    _minY = minY;
    _maxX = maxX;
    _maxY = maxY;
}

Here is the caller graph for this function:

void osgEarth::TileMap::setFilename ( const std::string &  filename) [inline]

Sets the filename that this TileMap was loaded from

Definition at line 221 of file TMS.

{_filename = filename;}

Here is the caller graph for this function:

void osgEarth::TileMap::setNumTilesHigh ( unsigned int  h) [inline]

Sets the number of tiles high at lod 0

Definition at line 317 of file TMS.

void osgEarth::TileMap::setNumTilesWide ( unsigned int  w) [inline]

Sets the number of tiles wide at lod 0

Definition at line 307 of file TMS.

{ _numTilesWide = w; }
void TileMap::setOrigin ( double  x,
double  y 
)

Sets the origin of this TileMap

Parameters:
xThe origin's x coordinate
yThe origin's y coordinate

Definition at line 76 of file TMS.cpp.

{
    _originX = x;
    _originY = y;
}

Here is the caller graph for this function:

void osgEarth::TileMap::setOriginX ( double  x) [inline]

Sets the x coordinate of the origin of this TileMap

Definition at line 251 of file TMS.

{_originX = x;}
void osgEarth::TileMap::setOriginY ( double  y) [inline]

Sets the y coordinate of the origin of this TileMap

Definition at line 261 of file TMS.

{_originY = y;}
void osgEarth::TileMap::setProfileType ( osgEarth::Profile::ProfileType  type) [inline]

Definition at line 320 of file TMS.

{_profile_type = type;}

Here is the caller graph for this function:

void osgEarth::TileMap::setSRS ( const std::string &  srs) [inline]

Sets the spatial reference of this TileMap

Definition at line 201 of file TMS.

{_srs = srs;}
void osgEarth::TileMap::setTileMapService ( const std::string &  tileMapService) [inline]

Sets the tile map service for this TileMap

Definition at line 161 of file TMS.

{_tileMapService = tileMapService;}
void osgEarth::TileMap::setTitle ( const std::string &  title) [inline]

Sets the title of this TileMap

Definition at line 181 of file TMS.

{_title = title;}

Here is the caller graph for this function:

void osgEarth::TileMap::setVersion ( const std::string &  version) [inline]

Sets the version of this TileMap

Definition at line 171 of file TMS.

{_version = version;}
void osgEarth::TileMap::setVerticalSRS ( const std::string &  vsrs) [inline]

Sets the vertical spatial reference of this TileMap

Definition at line 211 of file TMS.

{ _vsrs = vsrs; }

Member Data Documentation

std::string osgEarth::TileMap::_abstract [protected]

Definition at line 387 of file TMS.

Definition at line 410 of file TMS.

std::string osgEarth::TileMap::_filename [protected]

Definition at line 400 of file TMS.

Definition at line 398 of file TMS.

unsigned int osgEarth::TileMap::_maxLevel [protected]

Definition at line 403 of file TMS.

double osgEarth::TileMap::_maxX [protected]

Definition at line 394 of file TMS.

double osgEarth::TileMap::_maxY [protected]

Definition at line 394 of file TMS.

unsigned int osgEarth::TileMap::_minLevel [protected]

Definition at line 402 of file TMS.

double osgEarth::TileMap::_minX [protected]

Definition at line 394 of file TMS.

double osgEarth::TileMap::_minY [protected]

Definition at line 394 of file TMS.

unsigned int osgEarth::TileMap::_numTilesHigh [protected]

Definition at line 406 of file TMS.

unsigned int osgEarth::TileMap::_numTilesWide [protected]

Definition at line 405 of file TMS.

double osgEarth::TileMap::_originX [protected]

Definition at line 392 of file TMS.

double osgEarth::TileMap::_originY [protected]

Definition at line 392 of file TMS.

Definition at line 408 of file TMS.

std::string osgEarth::TileMap::_srs [protected]

Definition at line 388 of file TMS.

std::string osgEarth::TileMap::_tileMapService [protected]

Definition at line 384 of file TMS.

Definition at line 396 of file TMS.

std::string osgEarth::TileMap::_title [protected]

Definition at line 386 of file TMS.

std::string osgEarth::TileMap::_version [protected]

Definition at line 385 of file TMS.

std::string osgEarth::TileMap::_vsrs [protected]

Definition at line 389 of file TMS.


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