Config TerrainLayer::CacheBinMetadata::getConfig() const { Config conf("osgearth_terrainlayer_cachebin"); conf.addIfSet("cachebin_id", _cacheBinId); conf.addIfSet("source_name", _sourceName); conf.addIfSet("source_driver", _sourceDriver); conf.addIfSet("source_tile_size", _sourceTileSize); conf.addObjIfSet("source_profile", _sourceProfile); conf.addObjIfSet("cache_profile", _cacheProfile); conf.addIfSet("cache_create_time", _cacheCreateTime); if (!_dataExtents.empty()) { Config extents; for (DataExtentList::const_iterator i = _dataExtents.begin(); i != _dataExtents.end(); ++i) { Config extent; extent.set("srs", i->getSRS()->getHorizInitString()); extent.set("xmin", i->xMin()); extent.set("ymin", i->yMin()); extent.set("xmax", i->xMax()); extent.set("ymax", i->yMax()); extent.addIfSet("minlevel", i->minLevel()); extent.addIfSet("maxlevel", i->maxLevel()); extents.add("extent", extent); } conf.add("extents", extents); } return conf; }
void TerrainLayer::initTileSource() { _tileSourceInitAttempted = true; OE_DEBUG << LC << "Initializing tile source ..." << std::endl; // Instantiate it from driver options if it has not already been created. // This will also set a manual "override" profile if the user provided one. if ( !_tileSource.valid() ) { if ( _runtimeOptions->driver().isSet() ) { _tileSource = TileSourceFactory::create(*_runtimeOptions->driver()); } } // Initialize the profile with the context information: if ( _tileSource.valid() ) { // set up the URI options. if ( !_dbOptions.valid() ) { _dbOptions = Registry::instance()->cloneOrCreateOptions(); if ( _cache.valid() ) _cache->apply( _dbOptions.get() ); _initOptions.cachePolicy()->apply( _dbOptions.get() ); URIContext( _runtimeOptions->referrer() ).apply( _dbOptions.get() ); } // report on a manual override profile: if ( _tileSource->getProfile() ) { OE_INFO << LC << "set profile to: " << _tileSource->getProfile()->toString() << std::endl; } // Open the tile source (if it hasn't already been started) TileSource::Status status = _tileSource->getStatus(); if ( status != TileSource::STATUS_OK ) { status = _tileSource->open(TileSource::MODE_READ, _dbOptions.get()); } if ( status == TileSource::STATUS_OK ) { _tileSize = _tileSource->getPixelsPerTile(); #if 0 //debugging // dump out data extents: if ( _tileSource->getDataExtents().size() > 0 ) { OE_INFO << LC << "Data extents reported:" << std::endl; for(DataExtentList::const_iterator i = _tileSource->getDataExtents().begin(); i != _tileSource->getDataExtents().end(); ++i) { const DataExtent& de = *i; OE_INFO << " " << "X(" << i->xMin() << ", " << i->xMax() << ") " << "Y(" << i->yMin() << ", " << i->yMax() << ") " << "Z(" << i->minLevel().get() << ", " << i->maxLevel().get() << ")" << std::endl; } } #endif } else { OE_WARN << LC << "Could not initialize driver" << std::endl; _tileSource = NULL; _tileSourceInitFailed = true; _runtimeOptions->enabled() = true; } } // Set the profile from the TileSource if possible: if ( _tileSource.valid() ) { if ( !_profile.valid() && !_tileSourceInitFailed ) { _profile = _tileSource->getProfile(); } // check for a vertical datum override: if ( _profile.valid() && _runtimeOptions->verticalDatum().isSet() ) { std::string vdatum = *_runtimeOptions->verticalDatum(); if ( !ciEquals(_profile->getSRS()->getVertInitString(), vdatum) ) { OE_INFO << LC << "Overriding vdatum with: " << vdatum << std::endl; ProfileOptions po = _profile->toProfileOptions(); po.vsrsString() = vdatum; _profile = Profile::create(po); } } if ( _profile.valid() ) { OE_INFO << LC << "Profile=" << _profile->toString() << std::endl; } } // Otherwise, force cache-only mode (since there is no tilesource). The layer will try to // establish a profile from the metadata in the cache instead. else if (_cache.valid()) { OE_NOTICE << LC << "Could not initialize TileSource " << _name << ", but a cache exists. Setting layer to cache-only mode." << std::endl; setCachePolicy( CachePolicy::CACHE_ONLY ); } }
static XmlDocument* tileMapToXmlDocument(const TileMap* tileMap) { //Create the root XML document osg::ref_ptr<XmlDocument> doc = new XmlDocument(); doc->setName( ELEM_TILEMAP ); doc->getAttrs()[ ATTR_VERSION ] = tileMap->getVersion(); doc->getAttrs()[ ATTR_TILEMAPSERVICE ] = tileMap->getTileMapService(); doc->addSubElement( ELEM_TITLE, tileMap->getTitle() ); doc->addSubElement( ELEM_ABSTRACT, tileMap->getAbstract() ); doc->addSubElement( ELEM_SRS, tileMap->getSRS() ); doc->addSubElement( ELEM_VERTICAL_SRS, tileMap->getVerticalSRS() ); osg::ref_ptr<XmlElement> e_bounding_box = new XmlElement( ELEM_BOUNDINGBOX ); double minX, minY, maxX, maxY; tileMap->getExtents( minX, minY, maxX, maxY ); e_bounding_box->getAttrs()[ATTR_MINX] = toString(minX); e_bounding_box->getAttrs()[ATTR_MINY] = toString(minY); e_bounding_box->getAttrs()[ATTR_MAXX] = toString(maxX); e_bounding_box->getAttrs()[ATTR_MAXY] = toString(maxY); doc->getChildren().push_back(e_bounding_box.get() ); osg::ref_ptr<XmlElement> e_origin = new XmlElement( ELEM_ORIGIN ); e_origin->getAttrs()[ATTR_X] = toString(tileMap->getOriginX()); e_origin->getAttrs()[ATTR_Y] = toString(tileMap->getOriginY()); doc->getChildren().push_back(e_origin.get()); osg::ref_ptr<XmlElement> e_tile_format = new XmlElement( ELEM_TILE_FORMAT ); e_tile_format->getAttrs()[ ATTR_EXTENSION ] = tileMap->getFormat().getExtension(); e_tile_format->getAttrs()[ ATTR_MIME_TYPE ] = tileMap->getFormat().getMimeType(); e_tile_format->getAttrs()[ ATTR_WIDTH ] = toString<unsigned int>(tileMap->getFormat().getWidth()); e_tile_format->getAttrs()[ ATTR_HEIGHT ] = toString<unsigned int>(tileMap->getFormat().getHeight()); doc->getChildren().push_back(e_tile_format.get()); osg::ref_ptr< const osgEarth::Profile > profile = tileMap->createProfile(); osg::ref_ptr<XmlElement> e_tile_sets = new XmlElement ( ELEM_TILESETS ); std::string profileString = "none"; if (profile->isEquivalentTo(osgEarth::Registry::instance()->getGlobalGeodeticProfile())) { profileString = "global-geodetic"; } else if (profile->isEquivalentTo(osgEarth::Registry::instance()->getGlobalMercatorProfile())) { profileString = "global-mercator"; } else { profileString = "local"; } e_tile_sets->getAttrs()[ ATTR_PROFILE ] = profileString; for (TileMap::TileSetList::const_iterator itr = tileMap->getTileSets().begin(); itr != tileMap->getTileSets().end(); ++itr) { osg::ref_ptr<XmlElement> e_tile_set = new XmlElement( ELEM_TILESET ); e_tile_set->getAttrs()[ATTR_HREF] = itr->getHref(); e_tile_set->getAttrs()[ATTR_ORDER] = toString<unsigned int>(itr->getOrder()); e_tile_set->getAttrs()[ATTR_UNITSPERPIXEL] = toString(itr->getUnitsPerPixel()); e_tile_sets->getChildren().push_back( e_tile_set.get() ); } doc->getChildren().push_back(e_tile_sets.get()); //Write out the data areas if (tileMap->getDataExtents().size() > 0) { osg::ref_ptr<XmlElement> e_data_extents = new XmlElement( ELEM_DATA_EXTENTS ); for (DataExtentList::const_iterator itr = tileMap->getDataExtents().begin(); itr != tileMap->getDataExtents().end(); ++itr) { osg::ref_ptr<XmlElement> e_data_extent = new XmlElement( ELEM_DATA_EXTENT ); e_data_extent->getAttrs()[ATTR_MINX] = toString(itr->xMin()); e_data_extent->getAttrs()[ATTR_MINY] = toString(itr->yMin()); e_data_extent->getAttrs()[ATTR_MAXX] = toString(itr->xMax()); e_data_extent->getAttrs()[ATTR_MAXY] = toString(itr->yMax()); if ( itr->minLevel().isSet() ) e_data_extent->getAttrs()[ATTR_MIN_LEVEL] = toString<unsigned int>(*itr->minLevel()); if ( itr->maxLevel().isSet() ) e_data_extent->getAttrs()[ATTR_MAX_LEVEL] = toString<unsigned int>(*itr->maxLevel()); e_data_extents->getChildren().push_back( e_data_extent ); } doc->getChildren().push_back( e_data_extents.get() ); } return doc.release(); }
TileSource* TerrainLayer::createTileSource() { osg::ref_ptr<TileSource> ts; if ( _tileSource.valid() ) { // this will happen if the layer was created with an explicit TileSource instance. ts = _tileSource.get(); } else { // Instantiate it from driver options if it has not already been created. // This will also set a manual "override" profile if the user provided one. if ( _runtimeOptions->driver().isSet() ) { OE_INFO << LC << "Creating TileSource, driver = \"" << _runtimeOptions->driver()->getDriver() << "\"\n"; ts = TileSourceFactory::create( *_runtimeOptions->driver() ); if ( !ts.valid() ) { OE_WARN << LC << "Failed to create TileSource for driver \"" << _runtimeOptions->driver()->getDriver() << "\"\n"; } } } // Initialize the profile with the context information: if ( ts.valid() ) { // set up the URI options. if ( !_dbOptions.valid() ) { _dbOptions = Registry::instance()->cloneOrCreateOptions(); if ( _cache.valid() ) _cache->apply( _dbOptions.get() ); _initOptions.cachePolicy()->apply( _dbOptions.get() ); URIContext( _runtimeOptions->referrer() ).apply( _dbOptions.get() ); } // report on a manual override profile: if ( ts->getProfile() ) { OE_INFO << LC << "Override profile: " << ts->getProfile()->toString() << std::endl; } // Open the tile source (if it hasn't already been started) TileSource::Status status = ts->getStatus(); if ( status != TileSource::STATUS_OK ) { status = ts->open(TileSource::MODE_READ, _dbOptions.get()); } if ( status == TileSource::STATUS_OK ) { _tileSize = ts->getPixelsPerTile(); #if 0 //debugging // dump out data extents: if ( ts->getDataExtents().size() > 0 ) { OE_INFO << LC << "Data extents reported:" << std::endl; for(DataExtentList::const_iterator i = ts->getDataExtents().begin(); i != ts->getDataExtents().end(); ++i) { const DataExtent& de = *i; OE_INFO << " " << "X(" << i->xMin() << ", " << i->xMax() << ") " << "Y(" << i->yMin() << ", " << i->yMax() << ") " << "Z(" << i->minLevel().get() << ", " << i->maxLevel().get() << ")" << std::endl; } } #endif } else { OE_WARN << LC << "Could not initialize driver" << std::endl; ts = NULL; //_tileSourceInitFailed = true; _runtimeOptions->enabled() = true; } } // Set the profile from the TileSource if possible: if ( ts.valid() ) { if ( !_profile.valid() ) { OE_DEBUG << LC << "Get Profile from tile source" << std::endl; _profile = ts->getProfile(); } if ( _profile.valid() ) { // create the final profile from any overrides: applyProfileOverrides(); OE_INFO << LC << "Profile=" << _profile->toString() << std::endl; } } // Otherwise, force cache-only mode (since there is no tilesource). The layer will try to // establish a profile from the metadata in the cache instead. else if (_cache.valid()) { OE_NOTICE << LC << "Could not initialize TileSource " << _name << ", but a cache exists. Setting layer to cache-only mode." << std::endl; setCachePolicy( CachePolicy::CACHE_ONLY ); } return ts.release(); }