vector<string> LandsatEtmPlusImporter::getBandFilenames(std::string strInHeaderFileName, LandsatEtmPlusImporter::BandSetType bandSet) const { vector<string> bandFilenames; if (strInHeaderFileName.empty()) { return bandFilenames; } FactoryResource<Filename> headerFileName; VERIFYRV(headerFileName.get() != NULL, bandFilenames); headerFileName->setFullPathAndName(strInHeaderFileName); string bandFilePath = headerFileName->getPath(); // get the requested band filenames FactoryResource<FileFinder> fileFinder; if (bandSet == PANCHROMATIC) { if (!fileFinder->findFile(bandFilePath, mFieldHPN[FILENAME_1])) { return vector<string>(); } fileFinder->findNextFile(); string path; fileFinder->getFullPath(path); bandFilenames += path; } else { vector<string> fileNames; fileNames += mFieldHRF[FILENAME_1], mFieldHRF[FILENAME_2], mFieldHRF[FILENAME_3], mFieldHRF[FILENAME_4], mFieldHRF[FILENAME_5], ((bandSet == LOW_GAIN) ? mFieldHTM[FILENAME_1] : mFieldHTM[FILENAME_2]), mFieldHRF[FILENAME_6]; for (vector<string>::const_iterator fileName = fileNames.begin(); fileName != fileNames.end(); ++fileName) { if (!fileFinder->findFile(bandFilePath, *fileName)) { return vector<string>(); } fileFinder->findNextFile(); string path; fileFinder->getFullPath(path); bandFilenames += path; } } return bandFilenames; }
bool LandsatEtmPlusImporter::readHeader(const string& strInFstHeaderFileName) { if (strInFstHeaderFileName.empty()) { return false; } //The HTM header file contains information for Band 6 Channel 1 and 2. //This set extracts the info needed to process HTM(band 6) header mFieldHTM.clear(); string baseFileName = strInFstHeaderFileName.substr(0, strInFstHeaderFileName.length() - 7); FactoryResource<Filename> filename; filename->setFullPathAndName(baseFileName); FactoryResource<FileFinder> fileFinder; string htmFileName = filename->getFileName() + "HTM.FST"; if (fileFinder->findFile(filename->getPath(), htmFileName)) { fileFinder->findNextFile(); fileFinder->getFullPath(htmFileName); } LargeFileResource htmFile; if (htmFile.open(htmFileName, O_RDONLY, S_IREAD)) { //process HTM header vector<char> buf(5120); size_t count = static_cast<size_t>(htmFile.read(&buf.front(), 5120)); VERIFY(htmFile.eof()); string htmHeaderFull(&buf.front(), count); vector<string> htmHeaderLines = StringUtilities::split(htmHeaderFull, '\n'); if (!parseHeader(htmHeaderLines, mFieldHTM)) //parse band 6 header { mFieldHTM.clear(); } } htmFile.close(); // The HRF Header file contains the parameters for Bands 1-5 and 7. mFieldHRF.clear(); string hrfFileName = filename->getFileName() + "HRF.FST"; if (fileFinder->findFile(filename->getPath(), hrfFileName)) { fileFinder->findNextFile(); fileFinder->getFullPath(hrfFileName); } LargeFileResource hrfFile; if (hrfFile.open(hrfFileName, O_RDONLY, S_IREAD)) { //process HRF header vector<char> buf(5120); size_t count = static_cast<size_t>(hrfFile.read(&buf.front(), 5120)); VERIFY(hrfFile.eof()); string hrfHeaderFull(&buf.front(), count); vector<string> hrfHeaderLines = StringUtilities::split(hrfHeaderFull, '\n'); if (!parseHeader(hrfHeaderLines, mFieldHRF)) //parse bands 1-5 and 7 header { mFieldHRF.clear(); } } hrfFile.close(); // The HPN Header file contains the parameters for Band 8. mFieldHPN.clear(); string hpnFileName = filename->getFileName() + "HPN.FST"; if (fileFinder->findFile(filename->getPath(), hpnFileName)) { fileFinder->findNextFile(); fileFinder->getFullPath(hpnFileName); } LargeFileResource hpnFile; if (hpnFile.open(hpnFileName, O_RDONLY, S_IREAD)) { //process HPN header vector<char> buf(5120); size_t count = static_cast<size_t>(hpnFile.read(&buf.front(), 5120)); VERIFY(hpnFile.eof()); string hpnHeaderFull(&buf.front(), count); vector<string> hpnHeaderLines = StringUtilities::split(hpnHeaderFull, '\n'); if (!parseHeader(hpnHeaderLines, mFieldHPN)) //parse band 8 header { mFieldHPN.clear(); } } hpnFile.close(); return (!mFieldHRF.empty() || !mFieldHTM.empty() || !mFieldHPN.empty()); }
bool BandMath::createReturnValue(string partialResultsName) { // Set the short and long result names FactoryResource<Filename> pFilename; string shortResultsName; string longResultsName; if (pFilename.get() != NULL) { pFilename->setFullPathAndName(mpCube->getFilename()); shortResultsName = pFilename->getTitle() + " = " + partialResultsName; longResultsName = pFilename->getPath() + "/" + pFilename->getTitle() + " = " + partialResultsName; } mResultsName = longResultsName; const RasterDataDescriptor* pOrigDescriptor = dynamic_cast<RasterDataDescriptor*>(mpCube->getDataDescriptor()); const vector<DimensionDescriptor>& origRows = pOrigDescriptor->getRows(); const vector<DimensionDescriptor>& origColumns = pOrigDescriptor->getColumns(); mpResultData = NULL; unsigned int bandCount = mCubeBands; if (mbCubeMath == false) { bandCount = 1; } RasterElement* pParent = NULL; if (mbAsLayerOnExistingView) { pParent = mpCube; } RasterElement* pRaster = RasterUtilities::createRasterElement(mResultsName, origRows.size(), origColumns.size(), bandCount, FLT4BYTES, BIP, pOrigDescriptor->getProcessingLocation() == IN_MEMORY, pParent); if (pRaster == NULL) { mstrProgressString = "Error creating result raster element"; meGabbiness = ERRORS; displayErrorMessage(); mbError = true; return false; } if (!mbAsLayerOnExistingView) { // need to copy classification since parent was NULL in call to createRasterElement pRaster->copyClassification(mpCube); // make copies of existing GcpLists only if going into a new view vector<DataElement*> gcps = mpDataModel->getElements(mpCube, "GcpList"); if (!gcps.empty()) { vector<DataElement*>::iterator iter; for (iter = gcps.begin(); iter != gcps.end(); ++iter) { GcpList* theGcp = dynamic_cast<GcpList*>(*iter); theGcp->copy(theGcp->getName(), pRaster); } } } mpResultData = pRaster; RasterDataDescriptor* pDescriptor = dynamic_cast<RasterDataDescriptor*> (mpResultData->getDataDescriptor()); if (pDescriptor != NULL) { // Rows vector<DimensionDescriptor> rows = pDescriptor->getRows(); for (unsigned int i = 0; i < origRows.size(); ++i) { // Original number DimensionDescriptor origRow = origRows[i]; if (origRow.isOriginalNumberValid() == true) { rows[i].setOriginalNumber(origRow.getOriginalNumber()); } } pDescriptor->setRows(rows); // Columns vector<DimensionDescriptor> columns = pDescriptor->getColumns(); for (unsigned int i = 0; i < origColumns.size(); ++i) { // Original number DimensionDescriptor origColumn = origColumns[i]; if (origColumn.isOriginalNumberValid() == true) { columns[i].setOriginalNumber(origColumn.getOriginalNumber()); } } pDescriptor->setColumns(columns); } return true; }