bool rspfLandSatModel::setupOptimizer(const rspfString& init_file) { if (traceExec()) rspfNotify(rspfNotifyLevel_DEBUG) << "DEBUG rspfLandSatModel::setupOptimizer(init_file): entering..." << std::endl; theMapProjection = 0; theIntrackOffset = 0.0; theCrtrackOffset = 0.0; theLineGsdCorr = 0.0; theSampGsdCorr = 0.0; theRollOffset = 0.0; theYawOffset = 0.0; theYawRate = 0.0; theMapRotation = 0.0; rspfRefPtr<rspfFfL7> ff_headerp; if (rspfString::downcase(init_file).contains("header.dat")) { rspfRefPtr<rspfFfL5> h = new rspfFfL5(init_file); ff_headerp = h.get(); if (!ff_headerp->getErrorStatus()) { double d = fabs(h->revb()->theUlEasting - h->revb()->theCenterEasting)/h->theGsd; h->theCenterImagePoint.x = static_cast<rspf_int32>(d); // d + 0.5 ??? d = fabs(h->revb()->theUlNorthing - h->revb()->theCenterNorthing)/h->theGsd; h->theCenterImagePoint.y = static_cast<rspf_int32>(d); // d + 0.5 ??? initFromHeader(*ff_headerp); theMapOffset.x = h->revb()->theUlEasting; theMapOffset.y = h->revb()->theUlNorthing; } else { ff_headerp = 0; } } else { ff_headerp=new rspfFfL7(init_file); if (!ff_headerp->getErrorStatus()) { initFromHeader(*ff_headerp); } else { ff_headerp = 0; } } if(!ff_headerp.valid()) { rspfFilename init_filename(init_file); rspfKeywordlist kwl(init_filename); loadState(kwl); } if (traceExec()) rspfNotify(rspfNotifyLevel_DEBUG) << "DEBUG rspfLandSatModel::setupOptimizer(init_file): Exited..." << std::endl; return true; }
void ossimIndexToRgbLutFilter::setLut(const ossimFilename& file) { theLutFile = file; if(file.exists()) { ossimKeywordlist kwl(theLutFile); loadState(kwl); } }
//************************************************************************************************* //! Given a projection instance, this method determines the corresponding EPSG code. Obviously //! this is only needed if the projection does not have its PCS code assigned (it is NULL). This //! happens when the projection was constructed with full parameters instead of the EPSG code. //! Returns integer EPSG code if match was found or 0 if not found. //************************************************************************************************* ossim_uint32 ossimEpsgProjectionDatabase::findProjectionCode(const ossimMapProjection& lost_proj) const { ossimString lost_type (lost_proj.getClassName()); ossimString lookup; ossimRefPtr<ossimMapProjection> found_proj = 0; ossimMapProjectionFactory* factory = ossimMapProjectionFactory::instance(); ossim_uint32 found_code = 0; std::vector<ProjRecord>::const_iterator db_iter = m_projDatabase.begin(); while ((db_iter != m_projDatabase.end()) && (found_code == 0)) { // To avoid having to instantiate all projections in the database, let's peek in the record's // KWL for the projection type and only instantiate those that match: lookup = db_iter->kwl.find(ossimKeywordNames::TYPE_KW); if (lost_type == lookup) { // We have a match, instantiate the projection from the associated KWL in the DB. Trick // the registry into using appropriate factory by setting PCS code temporarily to 0 to // avoid infinite recursion: ossimKeywordlist kwl (db_iter->kwl); // make copy since this is a const method kwl.remove(ossimKeywordNames::PCS_CODE_KW); found_proj = PTR_CAST(ossimMapProjection, factory->createProjection(kwl)); // Test for same-ness between target and found, and return if matching: if (found_proj.valid() && (*found_proj == lost_proj)) { found_code = db_iter->code; // Hack to remap projection code 4087 to 4326 (which is not really a projection // code but other packages like to see 4326 for geographic projections. // Hacked under protest (OLK, 08/2010) if (found_code == 4087) found_code = 4326; } } db_iter++; } return found_code; }
//***************************************************************************** // CONSTRUCTOR: ossimIkonosRpcModel // // Constructs given filenames for metadata and RPC data. // //***************************************************************************** ossimIkonosRpcModel::ossimIkonosRpcModel(const ossimFilename& metadata, const ossimFilename& rpcdata) : ossimRpcModel(), theSupportData(0) { if (traceExec()) ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimIkonosRpcModel Constructor #2: entering..." << std::endl; theSupportData = new ossimIkonosMetaData(); parseMetaData(metadata); parseRpcData (rpcdata); finishConstruction(); //*** // Save current state in RPC model format: //*** ossimString drivePart; ossimString pathPart; ossimString filePart; ossimString extPart; metadata.split(drivePart, pathPart, filePart, extPart); ossimFilename init_rpc_geom; init_rpc_geom.merge(drivePart, pathPart, INIT_RPC_GEOM_FILENAME, ""); // (metadata.path().dirCat(ossimRpcModel::INIT_RPC_GEOM_FILENAME)); ossimKeywordlist kwl (init_rpc_geom); saveState(kwl); if (traceExec()) ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimIkonosRpcModel Constructor #2: returning..." << std::endl; }
bool ossimGeneralRasterElevHandler::setFilename(const ossimFilename& file) { if(file.trim() == "") { return false; } theFilename = file; ossimFilename hdrFile = file; ossimFilename geomFile = file; theGeneralRasterInfo.theFilename = file; theGeneralRasterInfo.theWidth = 0; theGeneralRasterInfo.theHeight = 0; theNullHeightValue = ossim::nan(); hdrFile = hdrFile.setExtension("omd"); geomFile = geomFile.setExtension("geom"); if(!hdrFile.exists()|| !geomFile.exists()) { return false; } ossimKeywordlist kwl(hdrFile); if (kwl.getErrorStatus() == ossimErrorCodes::OSSIM_ERROR) { return false; } kwl.add(ossimKeywordNames::FILENAME_KW, file.c_str(), true); ossimGeneralRasterInfo generalInfo; if(!generalInfo.loadState(kwl)) { return false; } if(generalInfo.numberOfBands() != 1) { ossimNotify(ossimNotifyLevel_WARN) << "ossimGeneralRasterElevHandler::initializeInfo WARNING:The number of bands are not specified in the header file" << std::endl; return false; } kwl.clear(); if(kwl.addFile(geomFile)) { theGeneralRasterInfo.theNullHeightValue = generalInfo.getNullPixelValue(0); theGeneralRasterInfo.theImageRect = generalInfo.imageRect(); theGeneralRasterInfo.theUl = theGeneralRasterInfo.theImageRect.ul(); theGeneralRasterInfo.theLr = theGeneralRasterInfo.theImageRect.lr(); theGeneralRasterInfo.theWidth = theGeneralRasterInfo.theImageRect.width(); theGeneralRasterInfo.theHeight = theGeneralRasterInfo.theImageRect.height(); theGeneralRasterInfo.theImageRect = generalInfo.imageRect(); theGeneralRasterInfo.theByteOrder = generalInfo.getImageDataByteOrder(); theGeneralRasterInfo.theScalarType = generalInfo.getScalarType(); theGeneralRasterInfo.theBytesPerRawLine = generalInfo.bytesPerRawLine(); //add by simbla theGeneralRasterInfo.theGeometry = new ossimImageGeometry; if(!theGeneralRasterInfo.theGeometry->loadState(kwl)) { theGeneralRasterInfo.theGeometry = 0; } if(!theGeneralRasterInfo.theGeometry.valid()) { return false; } ossimGpt defaultDatum; ossimGpt ulGpt; ossimGpt urGpt; ossimGpt lrGpt; ossimGpt llGpt; theGeneralRasterInfo.theDatum = defaultDatum.datum(); theGeneralRasterInfo.theGeometry->localToWorld(theGeneralRasterInfo.theImageRect.ul(), ulGpt); theGeneralRasterInfo.theGeometry->localToWorld(theGeneralRasterInfo.theImageRect.ur(), urGpt); theGeneralRasterInfo.theGeometry->localToWorld(theGeneralRasterInfo.theImageRect.lr(), lrGpt); theGeneralRasterInfo.theGeometry->localToWorld(theGeneralRasterInfo.theImageRect.ll(), llGpt); ulGpt.changeDatum(theGeneralRasterInfo.theDatum); urGpt.changeDatum(theGeneralRasterInfo.theDatum); lrGpt.changeDatum(theGeneralRasterInfo.theDatum); llGpt.changeDatum(theGeneralRasterInfo.theDatum); theMeanSpacing = theGeneralRasterInfo.theGeometry->getMetersPerPixel().y; theGroundRect = ossimGrect(ulGpt, urGpt, lrGpt, llGpt); theGeneralRasterInfo.theWgs84GroundRect = ossimDrect(ulGpt, urGpt, lrGpt, llGpt, OSSIM_RIGHT_HANDED); theNullHeightValue = theGeneralRasterInfo.theNullHeightValue; } else { return false; } return true; }
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; }
bool rspfGeneralRasterElevHandler::setFilename(const rspfFilename& file) { if(file.trim() == "") { return false; } theFilename = file; rspfFilename hdrFile = file; rspfFilename geomFile = file; theGeneralRasterInfo.theFilename = file; theGeneralRasterInfo.theWidth = 0; theGeneralRasterInfo.theHeight = 0; theNullHeightValue = rspf::nan(); hdrFile = hdrFile.setExtension("omd"); geomFile = geomFile.setExtension("geom"); if(!hdrFile.exists()|| !geomFile.exists()) { return false; } rspfKeywordlist kwl(hdrFile); if (kwl.getErrorStatus() == rspfErrorCodes::RSPF_ERROR) { return false; } kwl.add(rspfKeywordNames::FILENAME_KW, file.c_str(), true); rspfGeneralRasterInfo generalInfo; if(!generalInfo.loadState(kwl)) { return false; } if(generalInfo.numberOfBands() != 1) { rspfNotify(rspfNotifyLevel_WARN) << "rspfGeneralRasterElevHandler::initializeInfo WARNING:The number of bands are not specified in the header file" << std::endl; return false; } kwl.clear(); if(kwl.addFile(geomFile)) { theGeneralRasterInfo.theNullHeightValue = generalInfo.getImageMetaData().getNullPix(0); theGeneralRasterInfo.theImageRect = generalInfo.imageRect(); theGeneralRasterInfo.theUl = theGeneralRasterInfo.theImageRect.ul(); theGeneralRasterInfo.theLr = theGeneralRasterInfo.theImageRect.lr(); theGeneralRasterInfo.theWidth = theGeneralRasterInfo.theImageRect.width(); theGeneralRasterInfo.theHeight = theGeneralRasterInfo.theImageRect.height(); theGeneralRasterInfo.theImageRect = generalInfo.imageRect(); theGeneralRasterInfo.theByteOrder = generalInfo.getImageDataByteOrder(); theGeneralRasterInfo.theScalarType = generalInfo.getImageMetaData().getScalarType(); theGeneralRasterInfo.theBytesPerRawLine = generalInfo.bytesPerRawLine(); //add by simbla // --- // Try to determine if there is a prefix like "image0." or not. // --- std::string prefix = ""; if ( kwl.find("image0.type") ) { prefix = "image0."; } theGeneralRasterInfo.theGeometry = new rspfImageGeometry; if(!theGeneralRasterInfo.theGeometry->loadState( kwl, prefix.c_str() )) { theGeneralRasterInfo.theGeometry = 0; } if(!theGeneralRasterInfo.theGeometry.valid()) { return false; } rspfGpt defaultDatum; rspfGpt ulGpt; rspfGpt urGpt; rspfGpt lrGpt; rspfGpt llGpt; theGeneralRasterInfo.theDatum = defaultDatum.datum(); theGeneralRasterInfo.theGeometry->localToWorld(theGeneralRasterInfo.theImageRect.ul(), ulGpt); theGeneralRasterInfo.theGeometry->localToWorld(theGeneralRasterInfo.theImageRect.ur(), urGpt); theGeneralRasterInfo.theGeometry->localToWorld(theGeneralRasterInfo.theImageRect.lr(), lrGpt); theGeneralRasterInfo.theGeometry->localToWorld(theGeneralRasterInfo.theImageRect.ll(), llGpt); ulGpt.changeDatum(theGeneralRasterInfo.theDatum); urGpt.changeDatum(theGeneralRasterInfo.theDatum); lrGpt.changeDatum(theGeneralRasterInfo.theDatum); llGpt.changeDatum(theGeneralRasterInfo.theDatum); theMeanSpacing = theGeneralRasterInfo.theGeometry->getMetersPerPixel().y; theGroundRect = rspfGrect(ulGpt, urGpt, lrGpt, llGpt); theGeneralRasterInfo.theWgs84GroundRect = rspfDrect(ulGpt, urGpt, lrGpt, llGpt, RSPF_RIGHT_HANDED); theNullHeightValue = theGeneralRasterInfo.theNullHeightValue; } else { return false; } return true; }
bool rspfEnviTileSource::open() { static const char MODULE[] = "rspfEnviTileSource::open"; if ( traceDebug() ) { rspfNotify(rspfNotifyLevel_DEBUG) << MODULE << " entered..." << "\nimage file: " << theImageFile << std::endl; } bool result = false; if(isOpen()) { close(); } // Look for a header file: rspfFilename hdr = theImageFile; hdr.setExtension("hdr"); // image.hdr if ( !hdr.exists() ) { hdr = theImageFile; hdr.string() += ".hdr"; // image.ras.hdr } if ( hdr.exists() ) { if ( traceDebug() ) { rspfNotify(rspfNotifyLevel_DEBUG) << "header file: " << hdr << std::endl; } if ( m_enviHdr.open( hdr ) ) { if ( m_rasterInfo.initializeFromEnviHdr( m_enviHdr ) ) { // Set image file for initializeHandler method. m_rasterInfo.setImageFile( theImageFile ); // Look for an omd file: rspfFilename omd = theImageFile; omd.setExtension("omd"); // image.omd if ( !omd.exists() ) { omd.setExtension("kwl"); // image.kwl } if ( omd.exists() ) { if ( traceDebug() ) { rspfNotify(rspfNotifyLevel_DEBUG) << "omd file: " << omd << std::endl; } // Pick up adjusted min / max values if present. rspfKeywordlist kwl( omd ); m_rasterInfo.getImageMetaData().updateMetaData( kwl, std::string("") ); } theMetaData = m_rasterInfo.getImageMetaData(); result = initializeHandler(); if ( result ) { completeOpen(); //--- // This will set default output band list if we are a band selector and // "default bands" key is found in the envi header. If "default bands" // is not found it will set to identity(input = output). //--- setDefaultBandList(); } } } } if ( traceDebug() ) { rspfNotify(rspfNotifyLevel_DEBUG) << MODULE << " Exit status: " << (result?"true":"false") << std::endl; } return result; }
bool rspfSrtmSupportData::setFilename(const rspfFilename& srtmFile, bool scanForMinMax) { theFile = srtmFile; if(traceDebug()) { rspfNotify(rspfNotifyLevel_DEBUG) << "rspfSrtmSupportData::setFilename: entered:" << "\nsrtmFile: " << srtmFile << "\nscanForMinMax flag: " << scanForMinMax << std::endl; } theFileStream = rspfStreamFactoryRegistry::instance()-> createNewIFStream(theFile, std::ios_base::in | std::ios_base::binary); if (theFileStream.valid()) { if(theFileStream->fail()) { if(traceDebug()) { rspfNotify(rspfNotifyLevel_DEBUG) << theFile << " does not exist: leaving ..." << std::endl; } clear(); return false; } } else { return false; } // Start with default. theMinPixelValue = DEFAULT_MIN; theMaxPixelValue = DEFAULT_MAX; // See if we have an rspf metadata file to initialize from. bool outputOmd = false; bool loadedFromOmd = false; rspfFilename omdFile = theFile; omdFile.setExtension(rspfString("omd")); if (omdFile.exists()) { //--- // The loadOmd is called instead of loadState so theFile is not // overwrote. //--- rspfKeywordlist kwl(omdFile); loadedFromOmd = loadOmd(kwl); } if (!loadedFromOmd) { if (!setCornerPoints()) { clear(); return false; } if (!setSize()) { clear(); return false; } outputOmd = true; } if (scanForMinMax) { // These could have been picked up in the loadOmd. if ( (theMinPixelValue == DEFAULT_MIN) || (theMaxPixelValue == DEFAULT_MAX) ) { if ( computeMinMax() ) { outputOmd = true; } else { if(traceDebug()) { rspfNotify(rspfNotifyLevel_DEBUG) << "Unable to compute min max: leaving ..." << std::endl; } clear(); return false; } } } //--- // NOTE: The outputOmd flag should probably be set if !loadedFromOmd. // Leaving as is for now (only set if scanForMinMax). //--- if (outputOmd) { rspfKeywordlist kwl; saveState(kwl); kwl.write(omdFile); } if(theFileStream->is_open()) { theFileStream->close(); } if (traceDebug()) { rspfNotify(rspfNotifyLevel_DEBUG) << *this << std::endl; } return true; }
bool rspfApplanixEOFile::parseStream(std::istream& in) { theRecordIdMap.clear(); rspfString line; int c = '\0'; if(!parseHeader(in, theHeader)) { return false; } // now parse parameters in>>applanix_skipws; line = ""; while(in.good()&& !line.contains("RECORD FORMAT")) { std::getline(in, line.string()); line = line.upcase(); line = line.substitute("\r","\n", true); if(line.contains("KAPPA CARDINAL")) { theKappaCardinal = line; theKappaCardinal = theKappaCardinal.substitute("KAPPA CARDINAL ROTATION",""); theKappaCardinal = theKappaCardinal.substitute(":",""); theKappaCardinal = theKappaCardinal.substitute("\n",""); } else if(line.contains("LEVER ARM")) { rspfKeywordlist kwl('='); line = line.substitute("LEVER ARM VALUES:", ""); line = line.substitute(",", "\n", true); std::istringstream in(line); kwl.parseStream(in); theLeverArmLx = kwl.find("LX"); theLeverArmLy = kwl.find("LY"); theLeverArmLz = kwl.find("LZ"); } else if(line.contains("BORESIGHT VALUES")) { rspfKeywordlist kwl('='); line = line.substitute("BORESIGHT VALUES:", ""); line = line.substitute(",", "\n", true); std::istringstream in(line); kwl.parseStream(in); theBoreSightTx = kwl.find("TX"); theBoreSightTy = kwl.find("TY"); theBoreSightTz = kwl.find("TZ"); } else if(line.contains("SHIFT VALUES:")) { rspfKeywordlist kwl('='); line = line.substitute("SHIFT VALUES:",""); line = line.substitute(",", "\n", true); std::istringstream in(line); kwl.parseStream(in); theShiftValuesX = kwl.find("X"); theShiftValuesY = kwl.find("Y"); theShiftValuesZ = kwl.find("Z"); } else if(line.contains("GRID:")) { rspfKeywordlist kwl(':'); line = line.substitute(";", "\n", true); std::istringstream in(line); kwl.parseStream(in); theUtmZone = kwl.find("ZONE"); if(theUtmZone.contains("NORTH")) { theUtmHemisphere = "North"; } else { theUtmHemisphere = "South"; } theUtmZone = theUtmZone.replaceAllThatMatch("UTM|\\(.*\\)|NORTH|SOUTH",""); theUtmZone = theUtmZone.trim(); } else if(line.contains("FRAME DATUM")) { rspfKeywordlist kwl(':'); line = line.substitute(";", "\n", true); std::istringstream in(line); kwl.parseStream(in); theMappingFrameDatum = kwl.find("MAPPING FRAME DATUM"); theMappingFrameProjection = kwl.find("MAPPING FRAME PROJECTION"); theMappingFrameDatum = theMappingFrameDatum.trim(); theMappingFrameProjection = theMappingFrameProjection.trim(); } else if(line.contains("POSPROC SBET")) { theSbetField = line.after(":"); theSbetField = theSbetField.trim(); } else if(line.contains("CENTRAL MERIDIAN")) { theCentralMeridian = line; theCentralMeridian = theCentralMeridian.substitute("CENTRAL MERIDIAN",""); theCentralMeridian = theCentralMeridian.substitute("=",""); theCentralMeridian = theCentralMeridian.substitute("DEG",""); theCentralMeridian = theCentralMeridian.substitute(";",""); } else if(line.contains("LATITUDE OF THE GRID ORIGIN")) { rspfKeywordlist kwl('='); line = line.substitute(";", "\n", true); std::istringstream in(line); kwl.parseStream(in); theOriginLatitude = kwl.find("LATITUDE OF THE GRID ORIGIN"); theGridScaleFactor = kwl.find("GRID SCALE FACTOR"); } else if(line.contains("FALSE EASTING")) { rspfKeywordlist kwl('='); line = line.substitute(";", "\n", true); std::istringstream in(line); kwl.parseStream(in); theFalseEasting = kwl.find("FALSE EASTING"); theFalseNorthing = kwl.find("FALSE NORTHING"); } } in>>applanix_skipws; c = in.get(); std::vector<rspfString> fieldArray; rspfString field; while(in.good()&& (c!='\n')&& (c!='\r')) { field = ""; while((c != ',')&& (c != '\n')&& (c != '\r')) { field += (char)c; c = in.get(); } if((c!='\n')&& (c!='\r')) { c = in.get(); } field = field.trim(); if(field != "") { theRecordFormat.push_back(field); } } in>>applanix_skipws; if(in.peek() == '(') { std::getline(in, line.string()); } in>>applanix_skipws; rspfRefPtr<rspfApplanixEORecord> record = new rspfApplanixEORecord((rspf_uint32)theRecordFormat.size()); rspf_int32 latIdx = getFieldIdx("LAT"); rspf_int32 lonIdx = getFieldIdx("LONG");; bool hasLatLon = (latIdx >=0)&&(lonIdx >= 0); if(hasLatLon) { theMinLat = 90.0; theMaxLat = -90.0; theMinLon = 180.0; theMaxLon = -180.0; } else { theMinLat = rspf::nan(); theMaxLat = rspf::nan(); theMinLon = rspf::nan(); theMaxLon = rspf::nan(); } while(in.good()&&theRecordFormat.size()) { std::getline(in, line.string()); line = line.trim(); if(line != "") { std::istringstream inStr(line); rspf_uint32 idx; rspfString value; for(idx = 0; idx < theRecordFormat.size(); ++idx) { inStr >> (*record)[idx]; } if(hasLatLon) { double lat = (*record)[latIdx].toDouble(); double lon = (*record)[lonIdx].toDouble(); if(lat<theMinLat) theMinLat = lat; if(lat>theMaxLat) theMaxLat = lat; if(lon<theMinLon) theMinLon = lon; if(lon>theMaxLon) theMaxLon = lon; } theApplanixRecordList.push_back(new rspfApplanixEORecord(*record)); } }
ossimRefPtr<ossimImageGeometry> ossimGeneralRasterTileSource::getImageGeometry() { if ( !theGeometry.valid() ) { // Check for external geom: theGeometry = getExternalImageGeometry(); if ( !theGeometry.valid() ) { theGeometry = new ossimImageGeometry(); ossimString ext = theImageFile.ext(); ossimFilename hdrFile = theImageFile; ossimFilename xmlFile = theImageFile; hdrFile = hdrFile.setExtension("hdr"); xmlFile = xmlFile.setExtension("xml"); if (hdrFile.exists()) { ossimKeywordlist geoKwl; ossimKeywordlist kwl(hdrFile, ' '); kwl.downcaseKeywords(); ossim_uint32 lines = 0; ossim_uint32 samples = 0; ossim_float32 ll_lon = 0.0; ossim_float32 ll_lat = 0.0; ossim_float32 xCellSize = 1.0; ossim_float32 yCellSize = 1.0; const char* lookup = kwl.find("ncols"); if (lookup) { samples = ossimString(lookup).toUInt32(); geoKwl.add(ossimKeywordNames::NUMBER_SAMPLES_KW, samples); } lookup = kwl.find("nrows"); if (lookup) { lines = ossimString(lookup).toUInt32(); geoKwl.add(ossimKeywordNames::NUMBER_LINES_KW, lines); } lookup = kwl.find("cellsize"); if (lookup) { xCellSize = ossimString(lookup).toFloat32(); yCellSize = xCellSize; geoKwl.add(ossimKeywordNames::DECIMAL_DEGREES_PER_PIXEL_LAT, yCellSize); geoKwl.add(ossimKeywordNames::DECIMAL_DEGREES_PER_PIXEL_LON, xCellSize); } lookup = kwl.find("xdim"); if (lookup) { xCellSize = ossimString(lookup).toFloat32(); geoKwl.add(ossimKeywordNames::DECIMAL_DEGREES_PER_PIXEL_LON, xCellSize); } lookup = kwl.find("ydim"); if (lookup) { yCellSize = ossimString(lookup).toFloat32(); geoKwl.add(ossimKeywordNames::DECIMAL_DEGREES_PER_PIXEL_LAT, yCellSize); } lookup = kwl.find("xllcenter"); if (lookup) { ossim_float32 centerX = ossimString(lookup).toFloat32(); ll_lon = centerX + xCellSize * 0.5; geoKwl.add(ossimKeywordNames::TIE_POINT_LON_KW, ll_lon); } lookup = kwl.find("yllcenter"); if (lookup) { ossim_float32 centerY = ossimString(lookup).toFloat32(); ll_lat = (centerY + (lines - 1) * yCellSize) + yCellSize * 0.5; geoKwl.add(ossimKeywordNames::TIE_POINT_LAT_KW, ll_lat); } lookup = kwl.find("xllcorner"); if (lookup) { ll_lon = ossimString(lookup).toFloat32(); geoKwl.add(ossimKeywordNames::TIE_POINT_LON_KW, ll_lon); } lookup = kwl.find("yllcorner"); if (lookup) { ossim_uint32 centerY = ossimString(lookup).toFloat32(); ll_lat = centerY + lines * yCellSize; geoKwl.add(ossimKeywordNames::TIE_POINT_LAT_KW, ll_lat); } lookup = kwl.find("ulxmap"); if (lookup) { ll_lon = ossimString(lookup).toFloat32(); geoKwl.add(ossimKeywordNames::TIE_POINT_LON_KW, ll_lon); } lookup = kwl.find("ulymap"); if (lookup) { ossim_uint32 centerY = ossimString(lookup).toFloat32(); ll_lat = centerY + lines * yCellSize; geoKwl.add(ossimKeywordNames::TIE_POINT_LAT_KW, ll_lat); } kwl.add(ossimKeywordNames::ORIGIN_LATITUDE_KW, ll_lat); geoKwl.add(ossimKeywordNames::TYPE_KW, "ossimEquDistCylProjection"); geoKwl.add(ossimKeywordNames::DATUM_KW, ossimDatumFactory::instance()->wgs84()-> code()); ossimRefPtr<ossimProjection> proj = ossimMapProjectionFactory::instance()-> createProjection(geoKwl); if ( proj.valid() ) { theGeometry->setProjection(proj.get()); } } else if (xmlFile.exists()) { ossimFgdcXmlDoc file; if ( file.open(xmlFile) ) { ossimRefPtr<ossimProjection> proj = file.getProjection(); if ( !proj.valid() ) { proj = file.getGridCoordSysProjection(); } if ( proj.valid() ) { theGeometry->setProjection(proj.get()); } } } // xml file exist... } // Matches second if ( !theGeometry.valid() ) //--- // WARNING: // Must have theGeometry at this point or the next call to // ossimImageGeometryRegistry::extendGeometry will put us in an infinite loop // as it does a recursive call back to ossimImageHandler::getImageGeometry(). //--- // Check for set projection. if ( !theGeometry->getProjection() ) { // Try factories for projection. ossimImageGeometryRegistry::instance()->extendGeometry(this); } // Set image things the geometry object should know about. initImageParameters( theGeometry.get() ); } // Matches first if ( !theGeometry.valid() ) return theGeometry; }
bool ossimIkonosRpcModel::parseTiffFile(const ossimFilename& filename) { bool result = false; ossimRefPtr<ossimTiffTileSource> tiff = new ossimTiffTileSource(); if ( tiff->open(filename) ) { if ( !theSupportData ) { theSupportData = new ossimIkonosMetaData(); } if ( theSupportData->open(filename) == false ) { if(traceDebug()) { // Currently not required by model so we will not error out here. ossimNotify(ossimNotifyLevel_DEBUG) << "WARNING: ossimIkonosMetaData::open returned false.\n" << std::endl; } } else { // copy ossimIkonosMetada-sensor into ossimIkonosRpcModel-sensorId theSensorID = theSupportData->getSensorID(); } //convert file to rpc filename and hdr filename so we can get some info ossimFilename rpcfile = filename.noExtension(); rpcfile += "_rpc.txt"; ossimFilename hdrfile = filename; hdrfile.setExtension(ossimString("hdr")); if( parseHdrData(hdrfile) ) { // parseRpcData sets the error status on error. parseRpcData (rpcfile); if ( !getErrorStatus() ) //check for errors in parsing rpc data { finishConstruction(); //--- // Save current state in RPC model format: //--- ossimString drivePart; ossimString pathPart; ossimString filePart; ossimString extPart; filename.split(drivePart, pathPart, filePart, extPart); ossimFilename init_rpc_geom; init_rpc_geom.merge(drivePart, pathPart, INIT_RPC_GEOM_FILENAME, ""); ossimKeywordlist kwl (init_rpc_geom); saveState(kwl); // If we get here set the return status to true. result = true; } // matches: if ( !getErrorStatus() ) } // matches: if( parseHdrData(hdrfile) ) } // matches: if ( tiff->open(filename) ) if ( traceExec() ) { ossimNotify(ossimNotifyLevel_DEBUG) << "return status: " << (result?"true\n":"false\n") << "DEBUG ossimIkonosRpcModel parseTiffFile: returning..." << std::endl; } return result; }
//***************************************************************************** // CONSTRUCTOR: ossimIkonosRpcModel // // Constructs given a geometry file that specifies the filenames for the // metadata and RPC data files. // //***************************************************************************** ossimIkonosRpcModel::ossimIkonosRpcModel(const ossimFilename& geom_file) : ossimRpcModel(), theSupportData(0) { if (traceExec()) { ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimIkonosRpcModel Constructor #1: entering..." << std::endl; } theSupportData = new ossimIkonosMetaData(); ossimKeywordlist kwl(geom_file); const char* value; //*** // Assure this keywordlist contains correct type info: //*** value = kwl.find(ossimKeywordNames::TYPE_KW); if (!value || (strcmp(value, "ossimIkonosRpcModel"))) { if (traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimIkonosRpcModel Constructor #1:" << "\nFailed attempt to construct. sensor type \""<<value << "\" does not match \"ossimIkonosRpcModel\"." << std::endl; } theErrorStatus++; if (traceExec()) { ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimIkonosRpcModel Constructor #1: returning..." << std::endl; } return; } //*** // Read meta data filename from geom file: //*** value = kwl.find(META_DATA_FILE); if (!value) { theErrorStatus++; if (traceExec()) { ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimIkonosRpcModel Constructor #1: returning..." << std::endl; } return; } ossimFilename metadata (value); //*** // Read RPC data filename from geom file: //*** value = kwl.find(RPC_DATA_FILE); if (!value) { theErrorStatus++; if (traceExec()) ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimIkonosRpcModel Constructor #1: returning..." << std::endl; return; } ossimFilename rpcdata (value); parseMetaData(metadata); parseRpcData (rpcdata); finishConstruction(); ossimString drivePart; ossimString pathPart; ossimString filePart; ossimString extPart; geom_file.split(drivePart, pathPart, filePart, extPart); if (traceExec()) ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG returning..." << std::endl; return; }
//***************************************************************************** // 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; }