std::ostream& rspfDtedInfo::print(std::ostream& out) const { if ( theFile.size() ) { std::string prefix = "dted."; rspfDtedVol vol(theFile, 0); rspfDtedHdr hdr(theFile, vol.stopOffset()); rspfDtedUhl uhl(theFile, hdr.stopOffset()); rspfDtedDsi dsi(theFile, uhl.stopOffset()); rspfDtedAcc acc(theFile, dsi.stopOffset()); if( vol.getErrorStatus() == rspfErrorCodes::RSPF_OK ) { vol.print(out, prefix); } if( hdr.getErrorStatus() == rspfErrorCodes::RSPF_OK ) { hdr.print(out, prefix); } if( uhl.getErrorStatus() == rspfErrorCodes::RSPF_OK ) { uhl.print(out, prefix); } if( dsi.getErrorStatus() == rspfErrorCodes::RSPF_OK ) { dsi.print(out, prefix); } if( acc.getErrorStatus() == rspfErrorCodes::RSPF_OK ) { acc.print(out, prefix); } } return out; }
bool rspfDtedInfo::open(const rspfFilename& file) { bool result = false; // Test for extension, like dt0, dt1... rspfString ext = file.ext(); rspfRegExp regExp("^[d|D][t|T][0-9]"); if ( regExp.find( ext.c_str() ) ) { rspfDtedVol vol(file, 0); rspfDtedHdr hdr(file, vol.stopOffset()); rspfDtedUhl uhl(file, hdr.stopOffset()); rspfDtedDsi dsi(file, uhl.stopOffset()); rspfDtedAcc acc(file, dsi.stopOffset()); //--- // Check for errors. Must have uhl, dsi and acc records. vol and hdr // are for magnetic tape only; hence, may or may not be there. //--- if ( (uhl.getErrorStatus() == rspfErrorCodes::RSPF_OK) && (dsi.getErrorStatus() == rspfErrorCodes::RSPF_OK) && (acc.getErrorStatus() == rspfErrorCodes::RSPF_OK) ) { theFile = file; result = true; } else { theFile.clear(); } } return result; }
osg::ref_ptr<ossimPlanetDtedElevationDatabase::DtedInfo> ossimPlanetDtedElevationDatabase::getInfo(const std::string& name) { OpenThreads::ScopedLock<OpenThreads::Mutex> lock(theDtedInfoMutex); DtedFilePointerList::iterator iter = theFilePointers.find(name); if(iter != theFilePointers.end()) { iter->second->theTimeStamp = osg::Timer::instance()->tick(); return iter->second; } osg::ref_ptr<DtedInfo> info = new DtedInfo; ossimFilename dtedFile = ossimFilename(theLocation).dirCat(ossimFilename(name)); ifstream in; in.open(dtedFile.c_str(), std::ios::binary|std::ios::in); if(in.fail()) return 0; ossimDtedVol vol(in); ossimDtedHdr hdr(in); ossimDtedUhl uhl(in); in.close(); if((uhl.getErrorStatus() == ossimErrorCodes::OSSIM_ERROR)) { return 0; } info->theNumLonLines = uhl.numLonLines(); info->theNumLatPoints = uhl.numLatPoints(); info->theLatSpacing = uhl.latInterval(); info->theLonSpacing = uhl.lonInterval(); info->theMinLat = uhl.latOrigin(); info->theMinLon = uhl.lonOrigin(); info->theMaxLat = info->theMinLat + info->theLatSpacing*(info->theNumLatPoints-1); info->theMaxLon = info->theMinLon + info->theLonSpacing*(info->theNumLonLines-1); info->theTimeStamp = osg::Timer::instance()->tick(); info->theFilename = dtedFile; info->theHandler = new ossimDtedHandler(dtedFile, false); //info->theHandler->setMemoryMapFlag(false); theFilePointers.insert(std::make_pair(name, info)); shrinkFilePointers(); return info; }
rspfRefPtr<rspfProperty> rspfDtedInfo::getProperty( const rspfString& name)const { rspfRefPtr<rspfProperty> result = 0; //--- // Look through dted records. // Must have uhl, dsi and acc records. vol and hdr // are for magnetic tape only; hence, may or may not be there. //--- rspfDtedVol vol(theFile, 0); if( vol.getErrorStatus() == rspfErrorCodes::RSPF_OK ) { if (name == "dted_vol_record") { rspfContainerProperty* box = new rspfContainerProperty(); box->setName(name); std::vector<rspfString> list; vol.getPropertyNames(list); std::vector< rspfRefPtr<rspfProperty> > propList; std::vector<rspfString>::const_iterator i = list.begin(); while (i != list.end()) { rspfRefPtr<rspfProperty> prop = vol.getProperty( (*i) ); if (prop.valid()) { propList.push_back(prop); } ++i; } box->addChildren(propList); result = box; } } if (result.valid() == false) { rspfDtedHdr hdr(theFile, vol.stopOffset()); if( hdr.getErrorStatus() == rspfErrorCodes::RSPF_OK ) { if (name == "dted_hdr_record") { rspfContainerProperty* box = new rspfContainerProperty(); box->setName(name); std::vector<rspfString> list; hdr.getPropertyNames(list); std::vector< rspfRefPtr<rspfProperty> > propList; std::vector<rspfString>::const_iterator i = list.begin(); while (i != list.end()) { rspfRefPtr<rspfProperty> prop = hdr.getProperty( (*i) ); if (prop.valid()) { propList.push_back(prop); } ++i; } box->addChildren(propList); result = box; } } if (result.valid() == false) { rspfDtedUhl uhl(theFile, hdr.stopOffset()); if( uhl.getErrorStatus() == rspfErrorCodes::RSPF_OK ) { if (name == "dted_uhl_record") { rspfContainerProperty* box = new rspfContainerProperty(); box->setName(name); std::vector<rspfString> list; uhl.getPropertyNames(list); std::vector< rspfRefPtr<rspfProperty> > propList; std::vector<rspfString>::const_iterator i = list.begin(); while (i != list.end()) { rspfRefPtr<rspfProperty> prop = uhl.getProperty( (*i) ); if (prop.valid()) { propList.push_back(prop); } ++i; } box->addChildren(propList); result = box; } } if (result.valid() == false) { rspfDtedDsi dsi(theFile, uhl.stopOffset()); if( dsi.getErrorStatus() == rspfErrorCodes::RSPF_OK ) { if (name == "dted_dsi_record") { rspfContainerProperty* box = new rspfContainerProperty(); box->setName(name); std::vector<rspfString> list; dsi.getPropertyNames(list); std::vector< rspfRefPtr<rspfProperty> > propList; std::vector<rspfString>::const_iterator i = list.begin(); while (i != list.end()) { rspfRefPtr<rspfProperty> prop = dsi.getProperty( (*i) ); if (prop.valid()) { propList.push_back(prop); } ++i; } box->addChildren(propList); result = box; } } if (result.valid() == false) { rspfDtedAcc acc(theFile, dsi.stopOffset()); if( acc.getErrorStatus() == rspfErrorCodes::RSPF_OK ) { if (name == "dted_acc_record") { rspfContainerProperty* box = new rspfContainerProperty(); box->setName(name); std::vector<rspfString> list; acc.getPropertyNames(list); std::vector< rspfRefPtr<rspfProperty> > propList; rspfRefPtr<rspfProperty> prop = 0; std::vector<rspfString>::const_iterator i = list.begin(); while (i != list.end()) { rspfRefPtr<rspfProperty> prop = acc.getProperty( (*i) ); if (prop.valid()) { propList.push_back(prop); } ++i; } box->addChildren(propList); result = box; } } } } } } return result; }
ossimPlanetTextureLayerStateCode ossimPlanetDtedElevationDatabase::open(const std::string& location) { ossimElevManager::ConnectionStringVisitor visitor(location); ossimElevManager::instance()->accept(visitor); //std::cout << "DATABASE ==== " << (visitor.getElevationDatabase()?visitor.getElevationDatabase()->getConnectionString():"NOT FOUND") << std::endl; ossimFilename file(location); bool result = false; theLocation = ""; theExtents = new ossimPlanetExtents; ossim_uint32 count = 0; ossim_uint32 maxCount = 25; if(file.exists()) { if(file.isDir()) { ossimDirectory dir; if(dir.open(file)) { ossimFilename testFile; if(dir.getFirst(testFile)) { ++count; do { ossimRegExp eastern; ossimRegExp western; ossimRegExp easternUp; ossimRegExp westernUp; eastern.compile("e[0-9][0-9][0-9]"); western.compile("w[0-9][0-9][0-9]"); easternUp.compile("E[0-9][0-9][0-9]"); westernUp.compile("W[0-9][0-9][0-9]"); if(testFile.isDir()) { if(eastern.find(testFile.c_str())|| western.find(testFile.c_str())|| easternUp.find(testFile.c_str())|| westernUp.find(testFile.c_str())) { result = true; } if(result) { result = false; // now find a North South file ossimDirectory dirNS; dirNS.open(testFile); if(dirNS.getFirst(testFile)) { do { std::ifstream in; in.open(testFile.c_str(), std::ios::binary|std::ios::in); if(!in.fail()) { ossimDtedVol vol(in); ossimDtedHdr hdr(in); ossimDtedUhl uhl(in); ossimDtedDsi dsi(in); ossimDtedAcc acc(in); if(uhl.getErrorStatus() != ossimErrorCodes::OSSIM_ERROR) { double metersPerPixel = ossimGpt().metersPerDegree().y*uhl.latInterval(); dirtyExtents(); // make sure parents are marked as dirty if(fabs(metersPerPixel - (ossimGpt().metersPerDegree().y *(30.0/3600))) < .25) // 30 arc { setName("DTED0"); setDescription("DTED 1 kilometer elevation database"); theExtents->setMinMaxScale(metersPerPixel, metersPerPixel*std::pow(2.0, 6)); } else if(fabs(metersPerPixel - (ossimGpt().metersPerDegree().y *(3.0/3600))) < .25) // 3 arc { setName("DTED1"); setDescription("DTED 90 meter elevation database"); theExtents->setMinMaxScale(metersPerPixel, metersPerPixel*std::pow(2.0, 8)); } else if(fabs(metersPerPixel - (ossimGpt().metersPerDegree().y *(1.0/3600))) < .25) // 1 arc { setName("DTED2"); setDescription("DTED 30 meter elevation database"); theExtents->setMinMaxScale(metersPerPixel, metersPerPixel*std::pow(2.0, 10)); } else { setName("DTED"); setDescription("DTED elevation database"); theExtents->setMinMaxScale(metersPerPixel, metersPerPixel*std::pow(2.0, 12)); } result = true; } } }while(dirNS.getNext(testFile)&&(!result)); } } } }while(dir.getNext(testFile)&&(!result)&&(count < maxCount)); } } } } theOpenFlag = result; if(theOpenFlag) { theStateCode = ossimPlanetTextureLayer_VALID; theLocation = location; } else { theStateCode = ossimPlanetTextureLayer_NO_SOURCE_DATA; } return theStateCode; }