Exemple #1
0
void landsat_optimization(ossimFilename gcpFile, ossimFilename headerFile, ossimFilename elevationpath)
{

	ossimFilename workfold = headerFile.path();
	ossimFilename sourcefile = workfold + "\\header.dat";
	ossimFilename gcpfile = gcpFile;
	ossimFilename reportfile = workfold + "\\report.txt";

	ossimKeywordlist MapProjection;
	MyProject prj;
	prj.m_CtrlGptSet = new ossimTieGptSet;
	prj.m_ChkGptSet = new ossimTieGptSet;
	//vector < ossimTieLine > tieLineList;
	vector<ossimDFeature> imageFeatureList;
	vector<ossimGFeature> groundFeatureList;
	prj.ReadGcpAndProjection(ossimFilename(gcpfile));

	prj.theMgr = ossimElevManager::instance();
	//prj.theMgr->loadElevationPath(ossimFilename(elevationpath));//
	prj.m_DemPath=ossimFilename(elevationpath);

	prj.GetElevations(prj.m_CtrlGptSet);
	prj.GetElevations(prj.m_ChkGptSet);

	ossimMapProjection *MapPar = prj.m_MapPar;
	MapProjection = prj.m_MapProjection;

	prj.m_ImgFileNameUnc = sourcefile;
	prj.InitiateSensorModel(sourcefile);
	prj.UpdateSensorModel(*prj.m_CtrlGptSet, prj.m_sensorModel, prj.geom);
	prj.m_sensorModel->loadState(prj.geom);
	prj.OutputReport(reportfile, prj.m_sensorModel, prj.m_CtrlGptSet, prj.m_ChkGptSet);
}
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
   }
}
Exemple #3
0
//*******************************************************************
// Private Method:
//*******************************************************************
bool ossimKeywordlist::parseFile(const ossimFilename& file,
                                 bool ignoreBinaryChars)
{
   std::ifstream is;
   is.open(file.c_str(), std::ios::in | std::ios::binary);

   if ( !is.is_open() )
   {
      // ESH 07/2008, Trac #234: OSSIM is case sensitive 
      // when using worldfile templates during ingest
      // -- If first you don't succeed with the user-specified
      // filename, try again with the results of a case insensitive search.
      ossimDirectory directory(file.path());
      ossimFilename filename(file.file());

      std::vector<ossimFilename> result;
      bool bSuccess = directory.findCaseInsensitiveEquivalents( filename, result );
      if ( bSuccess == true )
      {
         int numResults = (int)result.size();
         int i;
         for ( i=0; i<numResults && !is.is_open(); ++i )
         {
            is.open( result[i].c_str(), std::ios::in | std::ios::binary );
         }
      }

      if ( !is.is_open() )
      {
         if ( traceDebug() ) 
         {
            // report all errors that aren't existence problems.
            // we want to know about things like permissions, too many open files, etc.
            ossimNotify(ossimNotifyLevel_DEBUG)
            << "Error opening file: " << file.c_str() << std::endl;
         }
         return false;
      }
   }

   bool result = parseStream(is, ignoreBinaryChars);

   is.close();

   return result;
}
Exemple #4
0
void LandsatRpc(ossimFilename gcpFile, ossimFilename headerFile, ossimFilename elevationpath)
{
	ossimFilename workfold = headerFile.path();
	ossimFilename sourcefile = workfold + "\\header.dat";
	ossimFilename gcpfile = gcpFile;
	ossimFilename reportfile = workfold + "\\report.txt";

	ossimKeywordlist MapProjection;
	MyProject prj;
	prj.m_CtrlGptSet = new ossimTieGptSet;
	prj.m_ChkGptSet = new ossimTieGptSet;
	//vector < ossimTieLine > tieLineList;
	vector<ossimDFeature> imageFeatureList;
	vector<ossimGFeature> groundFeatureList;
	prj.ReadGcpAndProjection(ossimFilename(gcpfile));
	prj.theMgr = ossimElevManager::instance();
	//prj.theMgr->loadElevationPath(ossimFilename(elevationpath));//
	prj.m_DemPath=ossimFilename(elevationpath);

	prj.GetElevations(prj.m_CtrlGptSet);
	prj.GetElevations(prj.m_ChkGptSet);

	ossimMapProjection *MapPar = prj.m_MapPar;
	MapProjection = prj.m_MapProjection;

	prj.m_ImgFileNameUnc = sourcefile;
	prj.m_OutBandList.clear();
	prj.m_OutBandList.push_back(6);
	prj.m_OutBandList.push_back(3);
	prj.m_OutBandList.push_back(1);
	prj.InitiateSensorModel(sourcefile);

	int num = static_cast<int>(prj.m_CtrlGptSet->getTiePoints().size());
	ossimRpcSolver *solver = new ossimRpcSolver(true, false);
	vector < ossimDpt > imagePoints(num);
	vector < ossimGpt > groundControlPoints(num);
	ossimGpt gpt;
	for(int i = 0;i < num;i++)
	{
		groundControlPoints[i] = prj.m_CtrlGptSet->getTiePoints()[i]->getGroundPoint();
		ossimGpt gpt = prj.m_MapPar->inverse(ossimDpt(groundControlPoints[i].lat, groundControlPoints[i].lon));
		gpt.hgt = groundControlPoints[i].hgt;
		groundControlPoints[i] = gpt;
		imagePoints[i] = prj.m_CtrlGptSet->getTiePoints()[i]->getImagePoint();
	}
	solver->solveCoefficients(imagePoints, groundControlPoints);

	ossimImageGeometry *imageGeom = solver->createRpcModel();
	ossimKeywordlist geom;
	imageGeom->saveState(geom);
	ossimRpcModel* rpcModel = new ossimRpcModel();
	rpcModel->loadState(geom, "projection.");

	prj.m_sensorModel = rpcModel;
	prj.m_sensorModel->m_proj = prj.m_MapPar;
	//// 使用RPC模型
	//ossimImageHandler *handler   = ossimImageHandlerRegistry::instance()->open(sourcefile);
	//if(!handler) return;   //应该弹出警告对话框
	//prj.m_sensorModel = createRpcModelFromProjection(handler->getImageRectangle(), *prj.m_sensorModel);
	//prj.m_sensorModel->m_proj = prj.m_MapPar;
	//handler->close();
	//delete handler;fstream rpcStruct;
	fstream rpcStruct;
	prj.m_sensorModel = rpcModel;
	prj.m_sensorModel->m_proj = prj.m_MapPar;
	prj.m_sensorModel->saveState(prj.geom);
	rpcModel->loadState(prj.geom);
	rpcStruct.open((workfold+"\\rpcStruct0.txt").c_str(), ios_base::out);
	rpcModel->saveRpcModelStruct(rpcStruct);
	rpcStruct.close();
	//prj.OutputReport(reportfile, prj.m_sensorModel, prj.m_CtrlGptSet, prj.m_ChkGptSet, false);
	//return;

	//double tmp;
	//for(int i = 0;i < num;i++)
	//{
	//	groundControlPoints.push_back(prj.m_CtrlGptSet->getTiePoints()[i]->getGroundPoint());
	//	imagePoints.push_back(prj.m_CtrlGptSet->getTiePoints()[i]->getImagePoint());
	//}
	//prj.m_sensorModel->optimizeFit(*prj.m_CtrlGptSet, &tmp);		//用优化控制点进行模型优化
	//prj.m_sensorModel->updateModel();
	//prj.m_sensorModel->saveState(prj.geom);
	//prj.OutputReport(reportfileall, prj.m_sensorModel, prj.m_CtrlGptSet, prj.m_ChkGptSet);
	//for(int i = 0;i < static_cast<int>(prj.m_CtrlGptSet->getTiePoints().size());i++)
	//{
	//	ossimDpt dpt = prj.m_MapPar->forward(*prj.m_CtrlGptSet->getTiePoints()[i]);
	//	ossimGpt gpt(dpt.x,dpt.y);
	//	prj.m_CtrlGptSet->refTiePoints()[i]->setGroundPoint(ossimGpt(dpt.x,dpt.y,prj.m_CtrlGptSet->getTiePoints()[i]->hgt));
	//}
	
	//// 全参数优化
	//prj.UpdateSensorModel(*prj.m_CtrlGptSet, prj.m_sensorModel, prj.geom);
	//prj.m_sensorModel->saveState(prj.geom);
	//rpcModel->loadState(prj.geom);
	// 像方仿射变换
	prj.m_sensorModel = rpcModel;
	prj.m_sensorModel->m_proj = prj.m_MapPar;
	prj.UpdateSensorModel(*prj.m_CtrlGptSet, prj.m_sensorModel, prj.geom);
	prj.OutputReport(reportfile, prj.m_sensorModel, prj.m_CtrlGptSet, prj.m_ChkGptSet, false);
	return;
	//prj.Orthograph(outfile);
}
void ossimLandsatTileSource::openHeader(const ossimFilename& file)
{
   //***
   // Landsat file name example:  l71024031_03119990929_hpn.fst
   // Three header header file type substrings:
   // HPN = Pan
   // HRF = VNIR/SWIR (visible near infrared/shortwave infrared)
   // HTM = Thermal
   //***
   ossimFilename hdr = file.file();
   hdr.downcase();
   theFfHdr = 0;
   if ( hdr.contains("hpn") || hdr.contains("hrf") || hdr.contains("htm") )
   {
      theFfHdr = new ossimFfL7(file.c_str());      
   } 
	else if (hdr.contains("header.dat"))
   {
      theFfHdr = new ossimFfL5(file.c_str());
   } 
	else 
	{
      theFfHdr = 0;
      return;
   }
   if (theFfHdr->getErrorStatus() != ossimErrorCodes::OSSIM_OK)
   {
      theFfHdr = 0;
   }
   return;

   // I had to force the open to go with a header since there are duplicate entries when scanning
   // landsat directories.
   //  For now I am commenting this code out.
   //
#if 0
   //***
   // User may have passed in an image file name in which case the header file
   // must be derived from it.
   //***
   if (hdr.size() < 25)
   {
      // file name not long enough...
      if (traceDebug())
      {
         ossimNotify(ossimNotifyLevel_DEBUG)
            << "ossimLandsatTileSource::openHeader DEBUG:"
            << "\nNot a standard landsat 7 file name:  " << hdr << std::endl;
         return;
      }
   }
   
   char substr[4];
   const char* f = hdr.c_str();
   strncpy(substr, (f+22), 3);
   substr[3] = '\0';
   ossimString s1 = substr;
   ossimString s2;
   s1.downcase();
   if (s1 == "b80")
   {
      s2 = "hpn";
   }
   else if (s1 == "b61" || s1 == "b62")
   {
      s2 = "htm";
   }
   else if (s1 == "b10" || s1 == "b20" || s1 == "b30" ||
            s1 == "b40" || s1 == "b50" || s1 == "b70")
   {
      s2 = "hrf";
   }
   else
   {
      // Not of any format we know of...
      if (traceDebug())
      {
         ossimNotify(ossimNotifyLevel_DEBUG)
            << "ossimLandsatTileSource::openHeader DEBUG:"
            << "\nCould not derive header name from:  " << file
            << std::endl;
      }

      return;
   }

   // Set the case to be the same as the file passed in.
   if (substr[0] == 0x42) // ascii "B"
   {
      s1.upcase();
      s2.upcase();
      hdr.upcase();

      // Header files alway start with "L71"
      hdr = hdr.substitute(ossimString("L72"), ossimString("L71"));  
   }
   else
   {
      // Header files alway start with "l71"
      hdr = hdr.substitute(ossimString("l72"), ossimString("l71")); 
   }

   // Make the hdr file name.
   hdr = hdr.substitute(s1, s2);

   ossimFilename f1 = file.drive();
   f1 += file.path();
   hdr = f1.dirCat(hdr);
   theFfHdr = new ossimFfL7(hdr.c_str());

   if (theFfHdr->getErrorStatus() != ossimErrorCodes::OSSIM_OK)
   {
      delete theFfHdr;
      theFfHdr = NULL;
   }
#endif
}