コード例 #1
0
std::shared_ptr<ossim::ifstream> ossimStreamFactoryRegistry::createIFStream(
   const ossimFilename& file, std::ios_base::openmode openMode) const
{
   std::shared_ptr<ossim::ifstream>result(0);
   
   for(ossim_uint32 idx = 0; ((idx < theFactoryList.size())&&(!result)); ++idx)
   {
      result = theFactoryList[idx]->createIFStream(file, openMode);
   }

   if(!result)
   {
      if(file.exists())
      {
         // there is a bug in gcc < 5.0 and we can't use constructors in the 
         // C++11 build.  Will refactor to do a new ifstream then use open
         //

         result = std::make_shared<ossim::ifstream>();
         result->open(file.c_str(), openMode);
         if(!result->is_open())
         {
            result.reset();
         }
      }
   }
   
   return result; 
   
}
コード例 #2
0
ossimRefPtr<ossimNitfRsmModel> getModelFromExtFile( const ossimFilename& file )
{
   ossimRefPtr<ossimNitfRsmModel> result = 0;

   if ( file.exists() )
   {
      result = new ossimNitfRsmModel();
      if ( result->parseFile( file, 0 ) ) // Hard coded entry index of 0 for now.
      {
         cout << "Initialize from ext file success!" << endl;
      }
      else
      {
         result = 0;
         cerr << "Could not open: " << file << endl;
      }
   }
   else
   {
     cerr << "File does not exists: " << file << endl;
   }

   return result;
   
} // End: getModelFromExtFile(...)
コード例 #3
0
void ossimSensorModelFactory::findCoarseGrid(ossimFilename& result,
                                             const ossimFilename& geomFile)const
{
   result = geomFile;
   result.setFile(result.fileNoExtension()+"_ocg");
   result.setExtension("dat");
   
   if(!result.exists())
   {
      result = geomFile;
      result.setExtension("dat");
   }
   
   // let's find a .dat file in the current directory
   //
   if(!result.exists())
   {
      result = "";
      ossimDirectory directoryList(geomFile.path());
      ossimFilename file;
      if(directoryList.getFirst(file,
                                ossimDirectory::OSSIM_DIR_FILES))
      {
         ossimString testString = "OSSIM_DBL_GRID";
         char tempBuf[14];
         do
         {
            if(file.ext().downcase() == "dat")
            {
               std::ifstream in(file.c_str());
               if(in)
               {
                  in.read((char*)tempBuf, 14);
                  in.close();
                  if(ossimString(tempBuf, tempBuf+14) == testString)
                  {
                     result = file;
                  }
               }
               
            }
         }while((directoryList.getNext(file))&&(result == ""));
      }
      // try to find it
   }
}
コード例 #4
0
ファイル: ossim-ws-cmp.cpp プロジェクト: BJangeofan/ossim
void cmpFile(const ossimFilename& wsa,
             const ossimFilename& wsb,
             const ossimFilename& file)
{
   ossimFilename bFile = file.substitute(wsa, wsb);

   if ( !file.exists() )
   {
      cout << "\nnotice: wsb file: " << bFile
           << "\nnotice: wsa file does not exists: " << file
           << "\nb -> a copy command:"
           << "\ncp " << bFile << " " << file << "\n"
           << endl;
   }
   if ( !bFile.exists() )
   {
      cout << "\nnotice: wsa file: " << file
           << "\nnotice: wsb file does not exists: " << bFile
           << "\na -> b copy command:"
           << "\ncp " << file << " " << bFile << "\n"
           << endl;
   }

   if ( file.exists() && bFile.exists() )
   {
      std::string command = "diff -w --ignore-matching-lines=\\$Id ";
      command += file.string();
      command += " ";
      command += bFile.string();
      
      int status = system( command.c_str() );
      
      if ( status != 0 )
      {
         cout << "\nnotice files differ:"
              << "\nwsa file: " << file
              << "\nwsb file: " << bFile
              << "\na -> b copy command:"
              << "\ncp " << file << " " << bFile
              << "\nb -> a copy command:"
              << "\ncp " << bFile << " " << file << "\n"
              << endl;
      }
   }
}
コード例 #5
0
void ossimIndexToRgbLutFilter::setLut(const ossimFilename& file)
{
   theLutFile = file;
   if(file.exists())
   {
      ossimKeywordlist kwl(theLutFile);
      loadState(kwl);
   }
}
コード例 #6
0
ファイル: ossimDtedUhl.cpp プロジェクト: loongfee/ossim-svn
//**************************************************************************
// CONSTRUCTOR
//**************************************************************************
ossimDtedUhl::ossimDtedUhl(const ossimFilename& dted_file, ossim_int32 offset)
   :
      theRecSen(),
      theField2(),
      theLonOrigin(),
      theLatOrigin(),
      theLonInterval(),
      theLatInterval(),
      theAbsoluteLE(),
      theSecurityCode(),
      theNumLonLines(),
      theNumLatPoints(),
      theMultipleAccuracy(),
      theStartOffset(0),
      theStopOffset(0)
{
   if(!dted_file.empty())
   {
      // Check to see that dted file exists.
      if(!dted_file.exists())
      {
         theErrorStatus = ossimErrorCodes::OSSIM_ERROR;
         ossimNotify(ossimNotifyLevel_FATAL) << "FATAL ossimDtedUhl::ossimDtedUhl: The DTED file does not exist: " << dted_file << std::endl;
         return;
      }
      
      // Check to see that the dted file is readable.
      if(!dted_file.isReadable())
      {
         theErrorStatus = ossimErrorCodes::OSSIM_ERROR;
         ossimNotify(ossimNotifyLevel_FATAL) << "FATAL ossimDtedUhl::ossimDtedUhl: The DTED file is not readable --> " << dted_file << std::endl;
         return;
      }
      
      std::ifstream in(dted_file.c_str());
      if(!in)
      {
         theErrorStatus = ossimErrorCodes::OSSIM_ERROR;
         ossimNotify(ossimNotifyLevel_FATAL) << "FATAL ossimDtedUhl::ossimDtedUhl: Error opening the DTED file: " << dted_file << std::endl;
         
         return;
      }
      in.seekg(offset);
      parse(in);
      
      in.close();
   }
}
コード例 #7
0
//*******************************************************************
// Private Method:
//*******************************************************************
bool ossimKeywordlist::parseFile(const ossimFilename& file,
                                 bool ignoreBinaryChars)
{
   if(!file.exists()) return false;
   bool result = false;
   std::ifstream is;
   is.open(file.c_str(), std::ios::in | std::ios::binary);
   
   if(!is.fail())
   {
      result = parseStream(is, ignoreBinaryChars);
   }
   
   is.close();
   
   return result;
}
コード例 #8
0
ファイル: ossimDtedVol.cpp プロジェクト: LucHermitte/ossim
//**************************************************************************
// CONSTRUCTOR
//**************************************************************************
ossimDtedVol::ossimDtedVol(const ossimFilename& dted_file,
                           ossim_int32 offset)
   :
      theStartOffset(0),
      theStopOffset(0)
{
   if(!dted_file.empty())
   {
      // Check to see that dted file exists.
      if(!dted_file.exists())
      {
         theErrorStatus = ossimErrorCodes::OSSIM_ERROR;
         ossimNotify(ossimNotifyLevel_FATAL)
         << "FATAL ossimDtedVol::ossimDtedVol"
         << "\nThe DTED file does not exist: " << dted_file << std::endl;
         return;
      }
      
      // Check to see that the dted file is readable.
      if(!dted_file.isReadable())
      {
         theErrorStatus = ossimErrorCodes::OSSIM_ERROR;
         ossimNotify(ossimNotifyLevel_FATAL)
         << "FATAL ossimDtedVol::ossimDtedVol"
         << "\nThe DTED file is not readable: " << dted_file << std::endl;
         return;
      }
      
      // Open the dted file for reading.
      std::ifstream in(dted_file.c_str());
      if(!in)
      {
         theErrorStatus = ossimErrorCodes::OSSIM_ERROR;
         ossimNotify(ossimNotifyLevel_FATAL)
         << "FATAL ossimDtedVol::ossimDtedVol"
         << "\nUnable to open the DTED file: " << dted_file << std::endl;
         return;
      }
      in.seekg(offset);
      parse(in);
      
      in.close();
   }
}
コード例 #9
0
bool ossimGeneralRasterElevationDatabase::openGeneralRasterDirectory(const ossimFilename& dir)
{
   m_cellHandler = new ossimGeneralRasterElevHandler;
   bool foundOne = false;
   
   if(dir.exists())
   {
      if(dir.isDir())
      {
         ossimDirectory d(dir);
         
         ossimFilename file;
         ossim_uint32 maxCount = 10; // search at least the first 10 files to see if there are any here
         ossim_uint32 count = 0;
         if(d.getFirst(file))
         {
            do
            {
               ++count;
               ossimString ext = file.ext();
               ext = ext.downcase();
               if(ext == "ras")
               {
                  if(m_cellHandler->open(file, m_memoryMapCellsFlag))
                  {
                     m_meanSpacing = m_cellHandler->getMeanSpacingMeters();
                     foundOne = true;
                  }
               }
            } while(d.getNext(file) &&
                    (foundOne ||
                     (!foundOne && (count < maxCount))));
         }
      }
   }  
   
   if(!foundOne)
   {
      m_cellHandler = 0;
   }
   
   return m_cellHandler.valid();
}
コード例 #10
0
std::shared_ptr<ossim::ifstream> ossimStreamFactory::createIFStream(
   const ossimFilename& file, std::ios_base::openmode openMode) const
{
   std::shared_ptr<ossim::ifstream> result(0);

   if ( file.exists() )
   {
      // there is a bug in gcc < 5.0 and we can't use constructors in the 
      // C++11 build.  Will refactor to do a new ifstream then use open
      //
      result = std::make_shared<ossim::ifstream>();
      result->open(file.c_str(), openMode);
      if ( result->is_open() == false )
      {
         result.reset();
      }
   }
   return result;
}
コード例 #11
0
bool ossimAuxFileHandler::isAuxFile(const ossimFilename& file)
{
  bool result = false;

  if ( file.exists() )
  { 
    ossimString ext = file.ext();
    ext.downcase();
    if (ext == "aux")
    {
      result = true;
    }
    else
    {
      result = false;
    } 
  } 

  return result;
}
コード例 #12
0
ossimRefPtr<ossimImageHandler> ossimImageHandlerRegistry::openOverview(
   const ossimFilename& file ) const
{
   ossimRefPtr<ossimImageHandler> result = 0;

   // See if we can open via the stream interface:
   std::shared_ptr<ossim::istream> str = ossim::StreamFactoryRegistry::instance()->
      createIstream( file, std::ios_base::in|std::ios_base::binary);
   
   if ( str )
   {
      std::vector<ossimImageHandlerFactoryBase*>::const_iterator factory = m_factoryList.begin();
      while( factory != m_factoryList.end() )
      {
         result = (*factory)->openOverview( str, file );
         if ( result.valid() )
         {
            break;
         }
         ++factory;
      }

      str = 0;
   }

   if ( (result.valid() == false) && file.exists() )
   {  
      vector<ossimImageHandlerFactoryBase*>::const_iterator factory = m_factoryList.begin();
      while( factory != m_factoryList.end() )
      {
         result = (*factory)->openOverview( file );
         if ( result.valid() )
         {
            break;
         }
         ++factory;
      }
   }
   return result;
}
コード例 #13
0
//*****************************************************************************
// PROTECTED METHOD: ossimIkonosRpcModel::parseHdrData()
//  
//  Parses the Ikonos hdr file.
//  
//*****************************************************************************
bool ossimIkonosRpcModel::parseHdrData(const ossimFilename& data_file)
{
   if (traceExec())
   {
      ossimNotify(ossimNotifyLevel_DEBUG)
         << "DEBUG ossimIkonosRpcModel::parseHdrData(data_file): entering..."
         << std::endl;
   }
   
   if( !data_file.exists() )
   {
      if (traceDebug())
      {
         ossimNotify(ossimNotifyLevel_WARN)
            << "ossimIkonosRpcModel::parseHdrData(data_file) WARN:"
            << "\nrpc data file <" << data_file << ">. "<< "doesn't exist..."
            << std::endl;
      }
      return false;
   }

   FILE* fptr = fopen (data_file, "r");
   if (!fptr)
   {
      ++theErrorStatus;
      
      if (traceDebug())
      { 
         ossimNotify(ossimNotifyLevel_WARN)
            << "ossimIkonosRpcModel::parseHdrData(data_file) WARN:"
            << "\nCould not open hdr data file <" << data_file << ">. "
            << "returning with error..." << std::endl;
      }
      return false;
   }

   char* strptr = 0;
   // char linebuf[80];
   char dummy[80];
   // , name[80];

   //***
   // Read the file into a buffer:
   //***
   char filebuf[5000];
   fread(filebuf, 1, 5000, fptr);

   //***
   // GSD:  NOTE - this will be recomputed by computeGsd method later.
   //***
   strptr = strstr(filebuf, "\nPixel Size X:");
   if (!strptr)
   {
      if(traceDebug())
      {
         ossimNotify(ossimNotifyLevel_WARN)
            << "ossimIkonosRpcModel::parseHdrData(data_file):"
            << "\n\tAborting construction. Error encountered parsing "
            << "presumed hdr file." << endl;
      }
      
      return false;
   }
      
   sscanf(strptr, "%14c %lf", dummy, &theGSD.samp);
   strptr = strstr(strptr, "\nPixel Size Y:");
   if (!strptr)
   {
      if(traceDebug())
      {
         ossimNotify(ossimNotifyLevel_WARN)
            << "ossimIkonosRpcModel::parseHdrData(data_file): "
            << "\n\tAborting construction. Error encountered parsing "
            << "presumed hdr file." << endl;
      }
         
      return false;
   }

   sscanf(strptr, "%14c %lf", dummy, &theGSD.line);

   //***
   // Image size:
   //***
   strptr = strstr(strptr, "\nColumns:");
   if (!strptr)
   {
      if(traceDebug())
      {
         ossimNotify(ossimNotifyLevel_WARN)
            << "ossimIkonosRpcModel::parseHdrData(data_file): "
            << "\n\tAborting construction. Error encountered parsing "
            << "presumed hdr file." << endl;
      }
         
      return false;
   }
   sscanf(strptr, "%s %d", dummy, &theImageSize.samp);
   strptr = strstr(strptr, "\nRows:");
   if (!strptr)
   {
      if(traceDebug())
      {
         ossimNotify(ossimNotifyLevel_WARN)
            << "ossimIkonosRpcModel::parseHdrData(data_file): "
            << "\n\tAborting construction. Error encountered parsing "
            << "presumed hdr file." << endl;
      }
         
      return false;
   }
   sscanf(strptr, "%s %d", dummy, &theImageSize.line);
           
   if (traceExec())
   {
      ossimNotify(ossimNotifyLevel_DEBUG)
         << "DEBUG ossimIkonosRpcModel::parseHdrData(data_file): returning..."
         << std::endl;
   }
   return true;
}
コード例 #14
0
bool ossimGeneralRasterInfo::open( const ossimFilename& imageFile )
{
   static const char MODULE[] = "ossimGeneralRasterInfo::open";
   if ( traceDebug() )
   {
      ossimNotify(ossimNotifyLevel_DEBUG)
         << MODULE << " entered..." << "\nimageFile: " << imageFile << std::endl;
   }

   bool result = false;

   // Wipe any previous state slick.
   clear();

   ossimFilename copyFile = imageFile;
   if ( !imageFile.exists() )
   {
      copyFile = imageFile.expand();
   }

   // Look for the headrer of omd file as they are written out by img2rr.
   ossimFilename hdr = copyFile;
   hdr.setExtension("hdr"); // image.hdr
   if ( !hdr.exists() )
   {
      hdr = imageFile;
      hdr.string() += ".hdr"; // image.ras.hdr
      if ( ! hdr.exists() )
      {
         hdr = imageFile;
         hdr.setExtension("xml"); // image.xml
      }
   }

   if ( hdr.exists() )
   {
      if ( traceDebug() )
      {
         ossimNotify(ossimNotifyLevel_DEBUG) << "header file: " << hdr << std::endl;
      }
      
      ossimString ext = hdr.ext().downcase();
      
      if ( ext == "hdr" )
      {
         if ( ossimEnviHeader::isEnviHeader( hdr ) )
         {
            result = initializeFromEnviHdr( hdr );
         }
         else
         {
            result = initializeFromHdr( imageFile, hdr );
         }

         if ( !result )
         {
            // Could be an ossim meta data file:
            ossimKeywordlist kwl( hdr );
            result = loadState( kwl, 0 );
         }
      }
      else if ( ext == "xml" )
      {
         result = initializeFromXml( imageFile, hdr );
      }
   }
   
   //---
   // Set the file name.  Needed for ossimGeneralRasterTileSource::open.
   // Note set here above loadState call to stop loadState from returning
   // false if no image file found.
   //---
   if ( theImageFileList.empty() )
   {
      setImageFile( imageFile );
   }
   
   ossimFilename omd = imageFile;
   omd.setExtension("omd"); // image.omd
   if ( !omd.exists() )
   {
      omd.setExtension("kwl"); // image.kwl
   }

   if ( omd.exists() )
   {
      if ( traceDebug() )
      {
         ossimNotify(ossimNotifyLevel_DEBUG) << "omd file: " << omd << std::endl;
      }

      ossimKeywordlist kwl( omd );

      if ( result && theMetaData.getNumberOfBands() )
      {
         //---
         // Just update the band info in case it has min/max values from
         // a compute min/max scan.
         //---
         theMetaData.updateMetaData( kwl, std::string("") );
      }
      else
      {
         // We're not initialized yet so do a loadState:
         result = loadState( kwl, 0 );
      }
   }
   
   if ( traceDebug() )
   {
      ossimNotify(ossimNotifyLevel_DEBUG)
         << MODULE  << " Exit status: " << (result?"true":"false") << std::endl;
   }
   
   return result;
}
コード例 #15
0
//*****************************************************************************
// PROTECTED METHOD: ossimQuickbirdMetaData::parseMetaData()
//
//  Parses the Quickbird IMD file.
//
//*****************************************************************************
bool ossimQuickbirdMetaData::parseMetaData(const ossimFilename& data_file)
{
   if (traceExec()) ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimQuickbirdMetaData::parseMetaData(data_file): entering..." << std::endl;
   
   if( !data_file.exists() )
   {
      if (traceExec()) ossimNotify(ossimNotifyLevel_WARN) << "ossimQuickbirdMetaData::parseMetaData(data_file) WARN:" << "\nmetadate data file <" << data_file << ">. " << "doesn't exist..." << std::endl;
      return false;
   }
  

   FILE* fptr = fopen (data_file, "r");
   if (!fptr)
   {
      if (traceDebug())
      {
         ossimNotify(ossimNotifyLevel_DEBUG)
	    << "ossimQuickbirdRpcModel::parseMetaData(data_file) DEBUG:"
	    << "\nCould not open Meta data file:  " << data_file
	    << "\nreturning with error..." << std::endl;
      }
      return false;
   }

   char* strptr(NULL);

   //---
   // Read the file into a buffer:
   //---
   ossim_int32 fileSize = static_cast<ossim_int32>(data_file.fileSize());
   char* filebuf = new char[fileSize];
   fread(filebuf, 1, fileSize, fptr);
   strptr = filebuf;
   fclose(fptr);
   ossimString temp;

   //---
   // Generation time:
   //---
  
   if(getEndOfLine( strptr, ossimString("\ngenerationTime ="), "%17c %s", temp))
      theGenerationDate = ossimString(temp).before(";");
   else
   {
      if(traceDebug())
      {
         ossimNotify(ossimNotifyLevel_FATAL)
	    << "FATAL ossimQuickbirdRpcModel::parseMetaData(data_file): "
	    << "\n\tAborting construction. Error encountered parsing "
	    << "presumed meta-data file." << std::endl;

         delete [] filebuf;
         return false;
      }
   }

   // Number of rows and columns in full image:
   if(getEndOfLine( strptr, ossimString("\nnumRows ="), "%10c %s", temp))
      theImageSize.line = ossimString(temp).before("\";").toInt();

   if(getEndOfLine( strptr, ossimString("\nnumColumns ="), "%13c %s", temp))
      theImageSize.samp = ossimString(temp).before("\";").toInt();

   //---
   // BandId:
   //---
   if(getEndOfLine( strptr, ossimString("\nbandId ="), "%9c %s", temp))
      theBandId = ossimString(temp).after("\"").before("\";");
   else
   {
      if(traceDebug())
      {
         ossimNotify(ossimNotifyLevel_FATAL)
	    << "FATAL ossimQuickbirdRpcModel::parseMetaData(data_file): "
	    << "\n\tAborting construction. Error encountered parsing "
	    << "presumed meta-data file." << std::endl;

         delete [] filebuf;
         return false;
      }
   }
    
  
   //---
   // BitsPerPixel:
   //---
   if(getEndOfLine( strptr, ossimString("\nbitsPerPixel = "), "%16c %s", temp))
      theBitsPerPixel = ossimString(temp).before(";").toInt();
   else
   {
      if(traceDebug())
      {
         ossimNotify(ossimNotifyLevel_FATAL)
	    << "FATAL ossimQuickbirdRpcModel::parseMetaData(data_file): "
	    << "\n\tAborting construction. Error encountered parsing "
	    << "presumed meta-data file." << std::endl;

         delete [] filebuf;
         return false;
      }
   }
     
   //---
   // absCalFactors:
   //---

   char *iter = (char *)filebuf;
   unsigned int nbBand = 0;
   theBandNameList = "";
   for(iter = strstr(iter, "BEGIN_GROUP = BAND_"); iter ; iter = strstr(iter, "BEGIN_GROUP = BAND_"))
   {
      ++nbBand;
      char dummy[80], nameChar[80];
      sscanf(iter, "%19c %s", dummy, nameChar);
      ossimString bandCur = ossimString(nameChar).before("\n");
      theBandNameList = theBandNameList + bandCur + " ";
      ++iter;
   }
   theBandNameList.trim();
   
   //--- Multispectral
   if(theBandId=="Multi")
   {
      std::vector<ossimString> bandList;
      bandList = theBandNameList.split(" ");
      theAbsCalFactors = std::vector<double>(bandList.size(), 1.);
      for(unsigned int j=0; j<bandList.size(); j++)
      {
         ossimString begin_group = "BEGIN_GROUP = BAND_" + bandList[j];
         strptr = strstr(filebuf, begin_group.c_str());
         if(!strptr && traceDebug())
         {	  				
            ossimNotify(ossimNotifyLevel_FATAL)
               << "FATAL ossimQuickbirdRpcModel::parseMetaData(data_file): "
               << "\n\tAborting construction. Error encountered parsing "
               << "presumed meta-data file." << std::endl;
            delete [] filebuf;
            return false;
         }
         else
         {
            char dummy[80], nameChar[80];
            sscanf(strptr, "%19c %s", dummy, nameChar);
            ossimString bandCur = ossimString(nameChar).before("\n");
            if(!strptr && traceDebug())
            {	  				
               ossimNotify(ossimNotifyLevel_FATAL)
                  << "FATAL ossimQuickbirdRpcModel::parseMetaData(data_file): "
                  << "\n\tAborting construction. Error encountered parsing "
                  << "presumed meta-data file." << std::endl;
               delete [] filebuf;
               return false;
            }
            else
            {
               if(bandList[j] == bandCur)
               {
                  strptr = strstr(strptr, "\tabsCalFactor = ");
                  sscanf(strptr, "%16c %s", dummy, nameChar);
                  theAbsCalFactors[j] = ossimString(nameChar).before(";").toDouble();
               }
            }
         }
      }
   }
   //--- Panchromatic
   else
   {
      theAbsCalFactors = std::vector<double>(1, 1.);
      if(getEndOfLine( strptr, ossimString("\tabsCalFactor = "), "%16c %s", temp))
         theAbsCalFactors[0] = ossimString(temp).before(";").toDouble();
      else
      {
         if(traceDebug())
         {
            ossimNotify(ossimNotifyLevel_FATAL)
               << "FATAL ossimQuickbirdRpcModel::parseMetaData(data_file): "
               << "\n\tAborting construction. Error encountered parsing "
               << "presumed meta-data file." << std::endl;

            delete [] filebuf;
            return false;
         }
      }
   }
    
   //---
   // SatID:
   //---
   if(getEndOfLine( strptr, ossimString("\n\tsatId ="), "%9c %s", temp))
      theSatID = ossimString(temp).after("\"").before("\";");
   else
   {
      if(traceDebug())
      {
         ossimNotify(ossimNotifyLevel_FATAL)
	    << "FATAL ossimQuickbirdRpcModel::parseMetaData(data_file): "
	    << "\n\tAborting construction. Error encountered parsing "
	    << "presumed meta-data file." << std::endl;

         delete [] filebuf;
         return false;
      }
   }

   //---
   // TLCTime:
   //---
   if(getEndOfLine( strptr, ossimString("\n\tTLCTime ="), "%11c %s", temp))
      theTLCDate = ossimString(temp).before("\";");
   else
   {
      if(getEndOfLine( strptr, ossimString("\n\tfirstLineTime ="), "%17c %s", temp))
         theTLCDate = ossimString(temp).before("\";");
      else
      {
         if(traceDebug())
         {
            ossimNotify(ossimNotifyLevel_FATAL)
               << "FATAL ossimQuickbirdRpcModel::parseMetaData(data_file): "
               << "\n\tAborting construction. Error encountered parsing "
               << "presumed meta-data file." << std::endl;
            delete [] filebuf;
            return false;
         }
      }
   }
   
   //---
   // Sun Azimuth:
   //---
   if(getEndOfLine( strptr, ossimString("\n\tsunAz ="), "%9c %s", temp))
        theSunAzimuth = ossimString(temp).before(";").toFloat64();
   else
   {
      if(getEndOfLine( strptr, ossimString("\n\tmeanSunAz ="), "%13c %s", temp))
         theSunAzimuth = ossimString(temp).before(";").toFloat64();
      else
      {
         if(traceDebug())
         {
            ossimNotify(ossimNotifyLevel_FATAL)
               << "FATAL ossimQuickbirdRpcModel::parseMetaData(data_file): "
               << "\n\tAborting construction. Error encountered parsing "
               << "presumed meta-data file." << std::endl;

            delete [] filebuf;
            return false;
         }
      }
   }

   //---
   // Sun Elevation:
   //---
   if(getEndOfLine( filebuf, ossimString("\n\tsunEl ="), "%9c %s", temp))
        theSunElevation = ossimString(temp).before(";").toFloat64();
   else
   {
      if(getEndOfLine( filebuf, ossimString("\n\tmeanSunEl ="), "%13c %s", temp))
         theSunElevation = ossimString(temp).before(";").toFloat64();
      else
      {
         if(traceDebug())
         {
            ossimNotify(ossimNotifyLevel_FATAL)
               << "FATAL ossimQuickbirdRpcModel::parseMetaData(data_file): "
               << "\n\tAborting construction. Error encountered parsing "
               << "presumed meta-data file." << std::endl;

            delete [] filebuf;
            return false;
         }
      }
   }

   //---
   // Sun Azimuth:
   //---
   if(getEndOfLine( strptr, ossimString("\n\tsunAz ="), "%9c %s", temp))
      theSunAzimuth = ossimString(temp).before(";").toFloat64();
   else
   {
      if(getEndOfLine( strptr, ossimString("\n\tmeanSunAz ="), "%13c %s", temp))
         theSunAzimuth = ossimString(temp).before(";").toFloat64();
      else
      {
         if(traceDebug())
         {
            ossimNotify(ossimNotifyLevel_FATAL)
               << "FATAL ossimQuickbirdRpcModel::parseMetaData(data_file): "
               << "\n\tAborting construction. Error encountered parsing "
               << "presumed meta-data file." << std::endl;
            
            delete [] filebuf;
            return false;
         }
      }
   }

   //---
   // Sun Elevation:
   //---
   if(getEndOfLine( filebuf, ossimString("\n\tsunEl ="), "%9c %s", temp))
      theSunElevation = ossimString(temp).before(";").toFloat64();
   else
   {
      if(getEndOfLine( filebuf, ossimString("\n\tmeanSunEl ="), "%13c %s", temp))
         theSunElevation = ossimString(temp).before(";").toFloat64();
      else
      {
         if(traceDebug())
         {
            ossimNotify(ossimNotifyLevel_FATAL)
               << "FATAL ossimQuickbirdRpcModel::parseMetaData(data_file): "
               << "\n\tAborting construction. Error encountered parsing "
               << "presumed meta-data file." << std::endl;

            delete [] filebuf;
            return false;
         }
      }
   }


   //---
   // Sat Azimuth:
   //---
   if(getEndOfLine( strptr, ossimString("\n\tsatAz ="), "%9c %s", temp))
      theSatAzimuth = ossimString(temp).before(";").toFloat64();
   else
   {
      if(getEndOfLine( strptr, ossimString("\n\tmeanSatAz ="), "%13c %s", temp))
         theSatAzimuth = ossimString(temp).before(";").toFloat64();
      else
      {
         if(traceDebug())
         {
            ossimNotify(ossimNotifyLevel_FATAL)
               << "FATAL ossimQuickbirdRpcModel::parseMetaData(data_file): "
               << "\n\tAborting construction. Error encountered parsing "
               << "presumed meta-data file." << std::endl;
            
            delete [] filebuf;
            return false;
         }
      }
   }
   
   //---
   // Sat Elevation:
   //---
   if(getEndOfLine( filebuf, ossimString("\n\tsatEl ="), "%9c %s", temp))
      theSatElevation = ossimString(temp).before(";").toFloat64();
   else
   {
      if(getEndOfLine( filebuf, ossimString("\n\tmeanSatEl ="), "%13c %s", temp))
         theSatElevation = ossimString(temp).before(";").toFloat64();
      else
      {
         if(traceDebug())
         {
            ossimNotify(ossimNotifyLevel_FATAL)
               << "FATAL ossimQuickbirdRpcModel::parseMetaData(data_file): "
               << "\n\tAborting construction. Error encountered parsing "
               << "presumed meta-data file." << std::endl;
            
            delete [] filebuf;
            return false;
         }
      }
   }
   
   
   //---
   // TDILevel:
   //---
   if(getEndOfLine( strptr, ossimString("\n\tTDILevel = "), "%13c %s", temp))
      theTDILevel = ossimString(temp).before(";").toInt();
   else
   {
      if(traceDebug())
      {
         ossimNotify(ossimNotifyLevel_FATAL)
	    << "FATAL ossimQuickbirdRpcModel::parseMetaData(data_file): "
	    << "\n\tAborting construction. Error encountered parsing "
	    << "presumed meta-data file." << std::endl;

         delete [] filebuf;
         return false;
      }
   }


   delete [] filebuf;
   filebuf = 0;

   if (traceExec())
   {
      ossimNotify(ossimNotifyLevel_DEBUG)
         << "DEBUG ossimQuickbirdRpcModel::parseMetaData(data_file): returning..."
         << std::endl;
   }

   return true;
}
コード例 #16
0
bool ossimQuickbirdMetaData::getMapProjectionKwl( const ossimFilename& imd_file,
                                                  ossimKeywordlist& kwl )
{
   static const char MODULE[] = "ossimQuickbirdMetaData::getMapProjectionKwl";
   if(traceDebug())
   {
      ossimNotify(ossimNotifyLevel_DEBUG) << MODULE << " entered...\n";
   }
   
   bool result = false;
   
   if( imd_file.exists() )
   {
      FILE* fptr = fopen (imd_file.c_str(), "r");
      if (fptr)
      {

         char* strptr(NULL);
         
         //---
         // Read the file into a buffer:
         //---
         ossim_int32 fileSize = static_cast<ossim_int32>(imd_file.fileSize());
         char* filebuf = new char[fileSize];
         fread(filebuf, 1, fileSize, fptr);
         strptr = filebuf;
         fclose(fptr);
         ossimString imd_key;
         ossimString tempStr;
         std::string key;
         std::string value;


         // Loop until we find all our keys or bust out with error.
         while ( 1 )
         {
            // Verify map projected.
            imd_key = "BEGIN_GROUP = MAP_PROJECTED_PRODUCT";
            if ( strstr( filebuf, imd_key.c_str() ) == NULL )
            {
               break; // Not a map projected product.
            }

            // Get datum:
            if( getEndOfLine( strptr, ossimString("\n\tdatumName = "), "%13c %s", tempStr) )
            {
               if ( tempStr.contains("WE") )
               {
                  key = "dataum";
                  value   = "WGE";
                  kwl.addPair(key, value);
               }
               else
               {
                  if(traceDebug())
                  {
                     ossimNotify(ossimNotifyLevel_WARN)
                        << "Unhandled datum: " << tempStr << "\n";
                  }
               }
            }

            // Get projection:
            if( getEndOfLine( strptr, ossimString("\n\tmapProjName = "), "%15c %s", tempStr) )
            {
               if ( tempStr.contains("UTM") )
               {
                  key = "type";
                  value   = "ossimUtmProjection";
                  kwl.addPair(key, value);
               }
               else
               {
                  if(traceDebug())
                  {
                     ossimNotify(ossimNotifyLevel_WARN)
                        << "Unhandled projection name: " << tempStr << "\n";
                  }
               }
            }

             // Get projection:
            if( getEndOfLine( strptr, ossimString("\n\tmapProjName = "), "%15c %s", tempStr) )
            {
               if ( tempStr.contains("UTM") )
               {
                  key = "type";
                  value   = "ossimUtmProjection";
                  kwl.addPair(key, value);

                  // Get UTM zone:
                  if( getEndOfLine( strptr, ossimString("\n\tmapZone = "), "%11c %s", tempStr) )
                  {
                     key = "zone";
                     value = tempStr.trim(";").string();
                     kwl.addPair(key, value);
                  }
                  else
                  {
                     break;
                  }
                  
                  // Get UTM hemisphere:
                  if( getEndOfLine( strptr, ossimString("\n\tmapHemi = "), "%11c %s", tempStr) )
                  {
                     key = "hemisphere";
                     tempStr = tempStr.trim(";");
                     tempStr = tempStr.trim("\"");
                     value = tempStr.string();
                     kwl.addPair(key, value);
                  }
                  else
                  {
                     break;
                  }
                  
               } // End UTM:
            }

            // Get projection units:
            std::string units;
            if( getEndOfLine( strptr, ossimString("\n\tproductUnits = "), "%16c %s", tempStr) )
            {
               if ( tempStr == "\"M\";" )
               {
                  key = "units";
                  units = "meters";
                  kwl.addPair(key, units);
               }
               else
               {
                  if(traceDebug())
                  {
                     ossimNotify(ossimNotifyLevel_WARN)
                        << "Unhandled units: " << tempStr << "\n";
                  }
               }
            }

            // Get projection tie point:
            ossimDpt dpt;
            dpt.makeNan();
            if( getEndOfLine( strptr, ossimString("\n\toriginX = "), "%11c %s", tempStr) )
            {
               tempStr = tempStr.trim(";");
               dpt.x = tempStr.toFloat64();
            }
            else
            {
               break;
            }
            if( getEndOfLine( strptr, ossimString("\n\toriginY = "), "%11c %s", tempStr) )
            {
               tempStr = tempStr.trim(";");
               dpt.y = tempStr.toFloat64();
            }
            else
            {
               break;
            }
            if ( dpt.hasNans() == false )
            {  
               key = "tie_point_units";
               kwl.addPair(key, units);

               key = "tie_point_xy";
               value = dpt.toString().string();
               kwl.addPair( key, value );
            }
            else
            {
               if(traceDebug())
               {
                  ossimNotify(ossimNotifyLevel_WARN)
                     << "tie point has nans!";
               }
               break;
            }

            // Get projection scale:
            dpt.makeNan();
            if( getEndOfLine( strptr, ossimString("\n\tcolSpacing = "), "%14c %s", tempStr) )
            {
               tempStr = tempStr.trim(";");
               dpt.x = tempStr.toFloat64();
            }
            else
            {
               break;
            }
            if( getEndOfLine( strptr, ossimString("\n\trowSpacing = "), "%14c %s", tempStr) )
            {
               tempStr = tempStr.trim(";");
               dpt.y = tempStr.toFloat64();
            }
            else
            {
               break;
            }

            if ( dpt.hasNans() == false )
            {  
               key = "pixel_scale_units";
               kwl.addPair(key, units);

               key = "pixel_scale_xy";
               value = dpt.toString().string();
               kwl.addPair( key, value );
            }
            else
            {
               if(traceDebug())
               {
                  ossimNotify(ossimNotifyLevel_WARN)
                     << "scale has nans!";
               }
               break;
            }
            
            //---
            // End of key look up. If we get here set the status to true and
            // bust out of loop.
            //---
            result = true;
            break;
         }

         if ( result == false )
         {
            if(traceDebug())
            {
               ossimNotify(ossimNotifyLevel_DEBUG)
                  << "ERROR: Missing or unhandled key in metadat: " << imd_key << "\n";
            }
         }

         delete [] filebuf;
         filebuf = 0;
      }
      else
      {
         if (traceDebug())
         {
            ossimNotify(ossimNotifyLevel_DEBUG)
               << "ossimQuickbirdRpcModel::parseMetaData(imd_file) DEBUG:"
               << "\nCould not open Meta data file:  " << imd_file
	    << "\nreturning with error...\n";
         }
      }
   }

   if(traceDebug())
   {
      ossimNotify(ossimNotifyLevel_DEBUG)
         << MODULE << " exit status = " << (result?"true":"false") << "\n";
   }

   return result;
}
コード例 #17
0
//*****************************************************************************
// PROTECTED METHOD: ossimIkonosRpcModel::parseRpcData()
//  
//  Parses the Ikonos RPC data file.
//  
//*****************************************************************************
void ossimIkonosRpcModel::parseRpcData(const ossimFilename& data_file)
{
   if (traceExec())
   {
      ossimNotify(ossimNotifyLevel_DEBUG)
         << "DEBUG ossimIkonosRpcModel::parseRpcData(data_file): entering..."
         << std::endl;
   }
      
   if( !data_file.exists() )
   {
      if (traceDebug())
      {
         ossimNotify(ossimNotifyLevel_WARN)
            << "ossimIkonosRpcModel::parseRpcData(data_file) WARN:"
            << "\nrpc data file <" << data_file << ">. "<< "doesn't exist..."
            << std::endl;
      }
      ++theErrorStatus;
      return;
   }
   
   //***
   // The Ikonos RPC data file is conveniently formatted as KWL file:
   //***
   ossimKeywordlist kwl (data_file);
   if (kwl.getErrorStatus())
   {
      ossimNotify(ossimNotifyLevel_FATAL)
         << "ERROR ossimIkonosRpcModel::parseRpcData(data_file): Could not open RPC data file <" << data_file << ">. " << "Aborting..." << std::endl;
      ++theErrorStatus;
      if (traceExec())  ossimNotify(ossimNotifyLevel_DEBUG)
         << "returning with error..." << std::endl;
      return;
   }

   const char* buf;
   const char* keyword;
   
   //***
   // Parse data from KWL:
   //***
   keyword = LINE_OFF_KW;
   buf = kwl.find(keyword);
   if (!buf)
   {
      ossimNotify(ossimNotifyLevel_FATAL) << "FATAL ossimIkonosRpcModel::parseRpcData(data_file):"
                                          << "\nAborting construction. Error looking up keyword: "
                                          << keyword << std::endl;
      return;
   }
   theLineOffset = atof(buf);
      
   keyword = SAMP_OFF_KW;
   buf = kwl.find(keyword);
   if (!buf)
   {
      ossimNotify(ossimNotifyLevel_FATAL) << "FATAL ossimIkonosRpcModel::parseRpcData(data_file):"
                                          << "\nAborting construction. Error looking up keyword: "
                                          << keyword << std::endl;
      return;
   }
   theSampOffset = atof(buf);

   keyword = LAT_OFF_KW;
   buf = kwl.find(keyword);
   if (!buf)
   {
      ossimNotify(ossimNotifyLevel_FATAL) << "FATAL ossimIkonosRpcModel::parseRpcData(data_file):"
                                          << "\nAborting construction. Error looking up keyword: "
                                          << keyword << std::endl;
      return;
   }
      
   theLatOffset = atof(buf);
   
   keyword = LONG_OFF_KW;
   buf = kwl.find(keyword);
   if (!buf)
   {
      ossimNotify(ossimNotifyLevel_FATAL) << "FATAL ossimIkonosRpcModel::parseRpcData(data_file):"
                                          << "\nAborting construction. Error looking up keyword: "
                                          << keyword << std::endl;
      return;
   }
   theLonOffset = atof(buf);

   keyword = HEIGHT_OFF_KW;
   buf = kwl.find(keyword);
   if (!buf)
   {
      ossimNotify(ossimNotifyLevel_FATAL) << "FATAL ossimIkonosRpcModel::parseRpcData(data_file):"
                                          << "\nAborting construction. Error looking up keyword: "
                                          << keyword << std::endl;
      return;
   }
      
   theHgtOffset = atof(buf);

   keyword = LINE_SCALE_KW;
   buf = kwl.find(keyword);
   if (!buf)
   {
      ossimNotify(ossimNotifyLevel_FATAL) << "FATAL ossimIkonosRpcModel::parseRpcData(data_file):"
                                          << "\nAborting construction. Error looking up keyword: "
                                          << keyword << std::endl;
      return;
   }
   theLineScale = atof(buf);
   
   keyword = SAMP_SCALE_KW;
   buf = kwl.find(keyword);
   if (!buf)
   {
      ossimNotify(ossimNotifyLevel_FATAL) << "FATAL ossimIkonosRpcModel::parseRpcData(data_file):"
                                          << "\nAborting construction. Error looking up keyword: "
                                          << keyword << std::endl;
      return;
   }
   theSampScale = atof(buf);
   
   keyword = LAT_SCALE_KW;
   buf = kwl.find(keyword);
   if (!buf)
   {
      ossimNotify(ossimNotifyLevel_FATAL) << "FATAL ossimIkonosRpcModel::parseRpcData(data_file):"
                                          << "\nAborting construction. Error looking up keyword: "
                                          << keyword << std::endl;
      return;
   }
   else
     {
       // copy ossimIkonosMetada-sensor into ossimIkonosRpcModel-sensorId
       theSensorID = theSupportData->getSensorID();
     }
   

   theLatScale = atof(buf);
   
   keyword = LONG_SCALE_KW;
   buf = kwl.find(keyword);
   if (!buf)
   {
      ossimNotify(ossimNotifyLevel_FATAL) << "FATAL ossimIkonosRpcModel::parseRpcData(data_file):"
                                          << "\nAborting construction. Error looking up keyword: "
                                          << keyword << std::endl;
      return;
   }
   theLonScale = atof(buf);
   
   keyword = HEIGHT_SCALE_KW;
   buf = kwl.find(keyword);
   if (!buf)
   {
      ossimNotify(ossimNotifyLevel_FATAL) << "FATAL ossimIkonosRpcModel::parseRpcData(data_file):"
                                          << "\nAborting construction. Error looking up keyword: "
                                          << keyword << std::endl;
      return;
   }
      
   theHgtScale = atof(buf);
   
   char kwbuf[32];
   keyword = kwbuf;
   for(int i=1; i<=20; i++)
   {
      sprintf(kwbuf, "%s%d", LINE_NUM_COEFF_KW, i);
      buf = kwl.find(keyword);
      if (!buf)
      {
         ossimNotify(ossimNotifyLevel_FATAL) << "FATAL ossimIkonosRpcModel::parseRpcData(data_file):"
                                             << "\nAborting construction. Error looking up keyword: "
                                             << keyword << std::endl;
         return;
      }
      
      theLineNumCoef[i-1] = atof(buf);
      
      sprintf(kwbuf, "%s%d", LINE_DEN_COEFF_KW, i);
      buf = kwl.find(keyword);
      if (!buf)
      {
         ossimNotify(ossimNotifyLevel_FATAL) << "FATAL ossimIkonosRpcModel::parseRpcData(data_file):"
                                             << "\nAborting construction. Error looking up keyword: "
                                             << keyword << std::endl;
         return;
      }
      theLineDenCoef[i-1] = atof(buf);
      
      sprintf(kwbuf, "%s%d", SAMP_NUM_COEFF_KW, i);
      buf = kwl.find(keyword);
      if (!buf)
      {
         ossimNotify(ossimNotifyLevel_FATAL) << "FATAL ossimIkonosRpcModel::parseRpcData(data_file):"
                                             << "\nAborting construction. Error looking up keyword: "
                                             << keyword << std::endl;
         return;
      }
      theSampNumCoef[i-1] = atof(buf);
      
      sprintf(kwbuf, "%s%d", SAMP_DEN_COEFF_KW, i);
      buf = kwl.find(keyword);
      if (!buf)
      {
         ossimNotify(ossimNotifyLevel_FATAL) << "FATAL ossimIkonosRpcModel::parseRpcData(data_file):"
                                             << "\nAborting construction. Error looking up keyword: "
                                             << keyword << std::endl;
         return;
      }
      theSampDenCoef[i-1] = atof(buf);
   }

   if (traceExec())  ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimIkonosRpcModel::parseRpcData(data_file): returning..." << std::endl;
   return;

   theErrorStatus++;
   if (traceExec())  ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimIkonosRpcModel::parseRpcData(data_file): returning with error..." << std::endl;
   
   return;
}