bool Nitf::StdidcParser::toDynamicObject(istream& input, size_t numBytes, DynamicObject& output, string &errorMessage) const { vector<char> buf; bool ok(true); bool success(true); success = readFromStream(input, buf, 14); // CCYYMMDDHHMMSS FactoryResource<DateTime> appDTG; string dtg; dtg.resize(15); memcpy(&dtg[0], &buf[0], 15); bool dateValid(false); bool timeValid(false); unsigned short year(0); unsigned short month(0); unsigned short day(0); unsigned short hour; unsigned short min; unsigned short sec; if (success) { success = DtgParseCCYYMMDDhhmmss(dtg, year, month, day, hour, min, sec, &dateValid, &timeValid); } if (success) { success = appDTG->set(year, month, day, hour, min, sec); if (success) { success = output.setAttribute(STDIDC::ACQUISITION_DATE, *appDTG.get()); } } if (!success) { errorMessage += "Parsing " + STDIDC::ACQUISITION_DATE + " failed\n"; } readField<string>(input, output, success, STDIDC::MISSION, 14, errorMessage, buf); readField<string>(input, output, success, STDIDC::PASS, 2, errorMessage, buf); readField<unsigned int>(input, output, success, STDIDC::OP_NUM, 3, errorMessage, buf); readField<string>(input, output, success, STDIDC::START_SEGMENT, 2, errorMessage, buf); readField<unsigned int>(input, output, success, STDIDC::REPRO_NUM, 2, errorMessage, buf); readField<string>(input, output, success, STDIDC::REPLAY_REGEN, 3, errorMessage, buf); readField<string>(input, output, success, STDIDC::BLANK_FILL, 1, errorMessage, buf, true); readField<unsigned int>(input, output, success, STDIDC::START_COLUMN, 3, errorMessage, buf); readField<unsigned int>(input, output, success, STDIDC::START_ROW, 5, errorMessage, buf); readField<string>(input, output, success, STDIDC::END_SEGMENT, 2, errorMessage, buf); readField<unsigned int>(input, output, success, STDIDC::END_COLUMN, 3, errorMessage, buf); readField<unsigned int>(input, output, success, STDIDC::END_ROW, 5, errorMessage, buf); readField<string>(input, output, success, STDIDC::COUNTRY, 2, errorMessage, buf, true); readField<unsigned int>(input, output, success, STDIDC::WAC, 4, errorMessage, buf, true); readField<string>(input, output, success, STDIDC::LOCATION, 11, errorMessage, buf); readField<string>(input, output, success, STDIDC::RESERVED2, 5, errorMessage, buf, true); readField<string>(input, output, success, STDIDC::RESERVED3, 8, errorMessage, buf, true); size_t numRead = input.tellg(); if (numRead != numBytes) { numReadErrMsg(numRead, numBytes, errorMessage); return false; } return success; }
bool Nitf::AimidbParser::toDynamicObject(istream& input, size_t numBytes, DynamicObject& output, string &errorMessage) const { vector<char> buf; unsigned short yy(0); unsigned short mm(0); unsigned short dd(0); unsigned short hh(0); unsigned short min(0); unsigned short ss(0); bool ok(true); bool success = true; success = readFromStream(input, buf, 14) && DtgParseCCYYMMDDhhmmss(string(&buf.front()), yy, mm, dd, hh, min, ss); if (success) { FactoryResource<DateTime> appDTG; success = appDTG->set(yy, mm, dd, hh, min, ss); if (success) { success = output.setAttribute(AIMIDB::ACQUISITION_DATE, *appDTG.get()); if (!success) { errorMessage += "setAttribute " + AIMIDB::ACQUISITION_DATE + " failed\n"; } } else { errorMessage += "DateTime Set " + AIMIDB::ACQUISITION_DATE + " failed\n"; } } else { errorMessage += "Parsing " + AIMIDB::ACQUISITION_DATE + " failed\n"; } readField<string>(input, output, success, AIMIDB::MISSION_NO, 4, errorMessage, buf); readField<string>(input, output, success, AIMIDB::MISSION_IDENTIFICATION, 10, errorMessage, buf); readField<string>(input, output, success, AIMIDB::FLIGHT_NO, 2, errorMessage, buf); readField<int>(input, output, success, AIMIDB::OP_NUM, 3, errorMessage, buf); readField<string>(input, output, success, AIMIDB::CURRENT_SEGMENT, 2, errorMessage, buf); readField<int>(input, output, success, AIMIDB::REPRO_NUM, 2, errorMessage, buf); readField<string>(input, output, success, AIMIDB::REPLAY, 3, errorMessage, buf, true); readField<string>(input, output, success, AIMIDB::RESERVED1, 1, errorMessage, buf, true); readField<int>(input, output, success, AIMIDB::START_TILE_COLUMN, 3, errorMessage, buf); readField<int>(input, output, success, AIMIDB::START_TILE_ROW, 5, errorMessage, buf); readField<string>(input, output, success, AIMIDB::END_SEGMENT, 2, errorMessage, buf); readField<int>(input, output, success, AIMIDB::END_TILE_COLUMN, 3, errorMessage, buf); readField<int>(input, output, success, AIMIDB::END_TILE_ROW, 5, errorMessage, buf); readField<string>(input, output, success, AIMIDB::COUNTRY, 2, errorMessage, buf, true); readField<string>(input, output, success, AIMIDB::RESERVED2, 4, errorMessage, buf, true); readField<string>(input, output, success, AIMIDB::LOCATION, 11, errorMessage, buf, true); readField<string>(input, output, success, AIMIDB::RESERVED3, 13, errorMessage, buf, true); size_t numRead = input.tellg(); if (numRead != numBytes) { numReadErrMsg(numRead, numBytes, errorMessage); return false; } return success; }
void LandsatEtmPlusImporter::populateMetaData(DynamicObject* pMetadata, RasterFileDescriptor* pFileDescriptor, BandSetType bandSet) { vector<string> &field = (bandSet == PANCHROMATIC) ? mFieldHPN : mFieldHRF; if (bandSet != PANCHROMATIC) { vector<double> startWavelengths; startWavelengths += 0.45, 0.525, 0.63, 0.75, 1.55, 10.4, 2.09; pMetadata->setAttributeByPath(START_WAVELENGTHS_METADATA_PATH, startWavelengths); vector<double> centerWavelengths; centerWavelengths += 0.483, 0.565, 0.66, 0.825, 1.65, 11.45, 2.22; pMetadata->setAttributeByPath(CENTER_WAVELENGTHS_METADATA_PATH, centerWavelengths); vector<double> endWavelengths; endWavelengths += 0.515, 0.605, 0.69, 0.9, 1.75, 12.5, 2.35; pMetadata->setAttributeByPath(END_WAVELENGTHS_METADATA_PATH, endWavelengths); } pMetadata->setAttribute("Product", field[PRODUCT]); pMetadata->setAttribute("LOC", field[LOC]); pMetadata->setAttribute("Satellite", field[SATELLITE]); pMetadata->setAttribute("Sensor", field[INSTRUMENT]); pMetadata->setAttribute("Sensor Mode", field[SENSOR_MODE]); pMetadata->setAttribute("Orientation Angle", StringUtilities::fromDisplayString<double>(field[LOOK_ANGLE])); pMetadata->setAttribute("Location", field[LOCATION]); pMetadata->setAttribute("Product Type", field[PRODUCT_TYPE]); pMetadata->setAttribute("Product Size", field[PRODUCT_SIZE]); pMetadata->setAttribute("Geodetic Processing", field[TYPE_OF_PROCESSING]); pMetadata->setAttribute("Resampling", field[RESAMPLING]); pMetadata->setAttribute("Volume Number/Number in Set", field[VOLUME_NUMBER]); pMetadata->setAttribute("Start Line", StringUtilities::fromDisplayString<unsigned int>(field[START_LINE])); pMetadata->setAttribute("Blocking Factor", StringUtilities::fromDisplayString<unsigned int>(field[BLOCKING_FACTOR])); pMetadata->setAttribute("Record Length", StringUtilities::fromDisplayString<unsigned int>(field[REC_SIZE])); pMetadata->setAttribute("Output Bits per Pixel", StringUtilities::fromDisplayString<unsigned int>(field[OUTPUT_BITS_PER_PIXEL])); pMetadata->setAttribute("Acquired Bits per Pixel", StringUtilities::fromDisplayString<unsigned int>(field[ACQUIRED_BITS_PER_PIXEL])); vector<double> gain; vector<double> bias; gain += StringUtilities::fromDisplayString<double>(field[GAIN_1]); bias += StringUtilities::fromDisplayString<double>(field[BIAS_1]); if (bandSet != PANCHROMATIC) { gain += StringUtilities::fromDisplayString<double>(field[GAIN_2]), StringUtilities::fromDisplayString<double>(field[GAIN_3]), StringUtilities::fromDisplayString<double>(field[GAIN_4]), StringUtilities::fromDisplayString<double>(field[GAIN_5]), StringUtilities::fromDisplayString<double>(mFieldHTM[(bandSet == LOW_GAIN) ? GAIN_1 : GAIN_2]), StringUtilities::fromDisplayString<double>(field[GAIN_6]); bias += StringUtilities::fromDisplayString<double>(field[BIAS_2]), StringUtilities::fromDisplayString<double>(field[BIAS_3]), StringUtilities::fromDisplayString<double>(field[BIAS_4]), StringUtilities::fromDisplayString<double>(field[BIAS_5]), StringUtilities::fromDisplayString<double>(mFieldHTM[(bandSet == LOW_GAIN) ? BIAS_1 : BIAS_2]), StringUtilities::fromDisplayString<double>(field[BIAS_6]); } pMetadata->setAttributeByPath("Radiance Adjust/Gain", gain); pMetadata->setAttributeByPath("Radiance Adjust/Bias", bias); pMetadata->setAttribute("Geometric Data Map Projection", field[GEOMETRIC_MAP_PROJECTION]); pMetadata->setAttribute("Earth Ellipsoid", field[ELLIPSOID]); pMetadata->setAttribute("Datum", field[DATUM]); vector<double> projParam; projParam += StringUtilities::fromDisplayString<double>(field[USGS_PROJECTION_PARAMETER_1]), StringUtilities::fromDisplayString<double>(field[USGS_PROJECTION_PARAMETER_2]), StringUtilities::fromDisplayString<double>(field[USGS_PROJECTION_PARAMETER_3]), StringUtilities::fromDisplayString<double>(field[USGS_PROJECTION_PARAMETER_4]), StringUtilities::fromDisplayString<double>(field[USGS_PROJECTION_PARAMETER_5]), StringUtilities::fromDisplayString<double>(field[USGS_PROJECTION_PARAMETER_6]), StringUtilities::fromDisplayString<double>(field[USGS_PROJECTION_PARAMETER_7]), StringUtilities::fromDisplayString<double>(field[USGS_PROJECTION_PARAMETER_8]), StringUtilities::fromDisplayString<double>(field[USGS_PROJECTION_PARAMETER_9]), StringUtilities::fromDisplayString<double>(field[USGS_PROJECTION_PARAMETER_10]), StringUtilities::fromDisplayString<double>(field[USGS_PROJECTION_PARAMETER_11]), StringUtilities::fromDisplayString<double>(field[USGS_PROJECTION_PARAMETER_12]), StringUtilities::fromDisplayString<double>(field[USGS_PROJECTION_PARAMETER_13]), StringUtilities::fromDisplayString<double>(field[USGS_PROJECTION_PARAMETER_14]), StringUtilities::fromDisplayString<double>(field[USGS_PROJECTION_PARAMETER_15]); pMetadata->setAttribute("USGS Projection Parameters", projParam); pMetadata->setAttribute("USGS Map Zone", StringUtilities::fromDisplayString<int>(field[USGS_MAP_ZONE])); pMetadata->setAttribute("UL Easting", StringUtilities::fromDisplayString<double>(field[UL_EASTING])); pMetadata->setAttribute("UL Northing", StringUtilities::fromDisplayString<double>(field[UL_NORTHING])); pMetadata->setAttribute("UR Easting", StringUtilities::fromDisplayString<double>(field[UR_EASTING])); pMetadata->setAttribute("UR Northing", StringUtilities::fromDisplayString<double>(field[UR_NORTHING])); pMetadata->setAttribute("LR Easting", StringUtilities::fromDisplayString<double>(field[LR_EASTING])); pMetadata->setAttribute("LR Northing", StringUtilities::fromDisplayString<double>(field[LR_NORTHING])); pMetadata->setAttribute("LL Easting", StringUtilities::fromDisplayString<double>(field[LL_EASTING])); pMetadata->setAttribute("LL Northing", StringUtilities::fromDisplayString<double>(field[LL_NORTHING])); pMetadata->setAttribute("Center Easting", StringUtilities::fromDisplayString<double>(field[CENTER_EASTING])); pMetadata->setAttribute("Center Northing", StringUtilities::fromDisplayString<double>(field[CENTER_NORTHING])); pMetadata->setAttribute("Scene Center Pixel Number", StringUtilities::fromDisplayString<int>(field[SCENE_CENTER_PIXEL_NUMBER])); pMetadata->setAttribute("Scene Center Line Number", StringUtilities::fromDisplayString<int>(field[SCENE_CENTER_LINE_NUMBER])); pMetadata->setAttribute("Offset", StringUtilities::fromDisplayString<int>(field[OFFSET])); pMetadata->setAttribute("Orientation Angle", StringUtilities::fromDisplayString<double>(field[ORIENTATION])); if (field[INSTRUMENT].substr(0, 2) == "TM") { pMetadata->setAttribute("Sensor Name", string("LandSat ETM+")); pMetadata->setAttribute("Change Detection Format", string("ETM")); } int yyyy = StringUtilities::fromDisplayString<int>(field[ACQUISITION_DATE].substr(0, 4)); int mm = StringUtilities::fromDisplayString<int>(field[ACQUISITION_DATE].substr(4, 2)); int dd = StringUtilities::fromDisplayString<int>(field[ACQUISITION_DATE].substr(6)); FactoryResource<DateTime> collectionDate; VERIFYNRV(collectionDate.get() != NULL); collectionDate->set(yyyy, mm, dd); pMetadata->setAttributeByPath(COLLECTION_DATE_TIME_METADATA_PATH, *collectionDate.get()); pMetadata->setAttribute("Sun Elevation", StringUtilities::fromDisplayString<double>(field[SUN_ELEVATION])); pMetadata->setAttribute("Sun Azimuth", StringUtilities::fromDisplayString<double>(field[SUN_AZIMUTH])); GcpPoint ul; ul.mPixel = LocationType(0,0); ul.mCoordinate = LocationType(Landsat::LatLongConvert(field[UL_LATITUDE]), Landsat::LatLongConvert(field[UL_LONGITUDE])); GcpPoint ur; ur.mPixel = LocationType(mNumCols-1,0); ur.mCoordinate = LocationType(Landsat::LatLongConvert(field[UR_LATITUDE]), Landsat::LatLongConvert(field[UR_LONGITUDE])); GcpPoint lr; lr.mPixel = LocationType(mNumCols-1,mNumRows-1); lr.mCoordinate = LocationType(Landsat::LatLongConvert(field[LR_LATITUDE]), Landsat::LatLongConvert(field[LR_LONGITUDE])); GcpPoint ll; ll.mPixel = LocationType(0,mNumRows-1); ll.mCoordinate = LocationType(Landsat::LatLongConvert(field[LL_LATITUDE]), Landsat::LatLongConvert(field[LL_LONGITUDE])); GcpPoint center; center.mPixel = LocationType(mNumCols/2,mNumRows/2); center.mCoordinate = LocationType(Landsat::LatLongConvert(field[CENTER_LATITUDE]), Landsat::LatLongConvert(field[CENTER_LONGITUDE])); list<GcpPoint> gcps; gcps += ul,ur,lr,ll,center; pFileDescriptor->setGcps(gcps); }
bool ClassificationImp::setClassification(const string& classificationText) { if (classificationText.empty() == true) { return false; } Service<UtilityServices> pUtilities; FactoryResource<Classification> pClassification; const string delimiter = "//"; // Level QString field = QString::fromStdString(classificationText); string::size_type pos = classificationText.find(delimiter); if (pos != string::npos) { field = QString::fromStdString(classificationText.substr(0, pos)); } pClassification->setLevel(field.toStdString()); // All other fields while (pos != string::npos) { // Get the next field pos += delimiter.length(); string::size_type nextPos = classificationText.find(delimiter, pos); if (nextPos != string::npos) { field = QString::fromStdString(classificationText.substr(pos, nextPos - pos)); } else { field = QString::fromStdString(classificationText.substr(pos)); } pos = nextPos; if (field.isEmpty() == true) { continue; } QStringList fieldList = field.split("/", QString::SkipEmptyParts); // Codewords bool codewordsField = true; const vector<string>& codewords = pUtilities->getCodewords(); for (int i = 0; i < fieldList.count(); ++i) { if (std::find(codewords.begin(), codewords.end(), fieldList[i].toStdString()) == codewords.end()) { codewordsField = false; break; } } if (codewordsField == true) { field.replace("/", " "); pClassification->setCodewords(field.toStdString()); continue; } // System bool systemField = true; const vector<string>& systems = pUtilities->getSystems(); for (int i = 0; i < fieldList.count(); ++i) { if (std::find(systems.begin(), systems.end(), fieldList[i].toStdString()) == systems.end()) { systemField = false; break; } } if (systemField == true) { field.replace("/", " "); pClassification->setSystem(field.toStdString()); continue; } // File releasing bool fileReleasingField = true; const QString relTo = "REL TO"; const vector<string>& fileReleasings = pUtilities->getFileReleasing(); for (int i = 0; i < fieldList.count(); ++i) { QString fileReleasing = fieldList[i]; if (fileReleasing.indexOf(relTo) == 0) { fileReleasing = relTo; } if (std::find(fileReleasings.begin(), fileReleasings.end(), fileReleasing.toStdString()) == fileReleasings.end()) { fileReleasingField = false; break; } } if (fileReleasingField == true) { int relToPos = field.indexOf(relTo); if (relToPos != -1) { // Extract the country codes from the file releasing field QString countryCodesField; int slashPos = field.indexOf("/", relToPos); if (slashPos != -1) { countryCodesField = field.mid(relToPos + relTo.length() + 1, slashPos - relToPos - relTo.length() - 1); field.remove(relToPos + relTo.length(), slashPos - relToPos - relTo.length()); } else { countryCodesField = field.mid(relToPos + relTo.length() + 1); field.truncate(relToPos + relTo.length()); } // Add the escape sequence field.replace(relTo, "REL\\ TO"); // Country codes bool validCountryCodes = true; if (countryCodesField.isEmpty() == false) { const vector<string>& countryCodes = pUtilities->getCountryCodes(); QStringList countryList = countryCodesField.split(", ", QString::SkipEmptyParts); for (int i = 0; i < countryList.count(); ++i) { if (std::find(countryCodes.begin(), countryCodes.end(), countryList[i].toStdString()) == countryCodes.end()) { validCountryCodes = false; break; } } } else { validCountryCodes = false; } // Must have valid country codes if (validCountryCodes == false) { return false; } countryCodesField.replace(",", QString()); pClassification->setCountryCode(countryCodesField.toStdString()); } field.replace("/", " "); pClassification->setFileReleasing(field.toStdString()); continue; } // Declassification exemption bool declassExemptionField = true; const vector<string>& exemptions = pUtilities->getDeclassificationExemptions(); for (int i = 0; i < fieldList.count(); ++i) { if (std::find(exemptions.begin(), exemptions.end(), fieldList[i].toStdString()) == exemptions.end()) { declassExemptionField = false; break; } } if (declassExemptionField == true) { field.replace("/", " "); pClassification->setDeclassificationExemption(field.toStdString()); continue; } // Declassification date QDate declassDate = QDate::fromString(field, "yyyyMMdd"); if (declassDate.isValid() == true) { FactoryResource<DateTime> pDeclassDate; pDeclassDate->set(declassDate.year(), declassDate.month(), declassDate.day()); pClassification->setDeclassificationDate(pDeclassDate.get()); continue; } // Classification reason bool reasonField = true; const vector<string>& reasons = pUtilities->getClassificationReasons(); for (int i = 0; i < fieldList.count(); ++i) { if (std::find(reasons.begin(), reasons.end(), fieldList[i].toStdString()) == reasons.end()) { reasonField = false; break; } } if (reasonField == true) { field.replace("/", " "); pClassification->setClassificationReason(field.toStdString()); continue; } // Declassification type bool declassTypeField = true; const vector<string>& declassTypes = pUtilities->getDeclassificationTypes(); for (int i = 0; i < fieldList.count(); ++i) { if (std::find(declassTypes.begin(), declassTypes.end(), fieldList[i].toStdString()) == declassTypes.end()) { declassTypeField = false; break; } } if (declassTypeField == true) { field.replace("/", " "); pClassification->setDeclassificationType(field.toStdString()); continue; } // File downgrades bool fileDowngradeField = true; const vector<string>& fileDowngrades = pUtilities->getFileDowngrades(); for (int i = 0; i < fieldList.count(); ++i) { if (std::find(fileDowngrades.begin(), fileDowngrades.end(), fieldList[i].toStdString()) == fileDowngrades.end()) { fileDowngradeField = false; break; } } if (fileDowngradeField == true) { field.replace("/", " "); pClassification->setFileDowngrade(field.toStdString()); continue; } // File control bool fileControlField = true; const vector<string>& fileControls = pUtilities->getFileControls(); for (int i = 0; i < fieldList.count(); ++i) { if (std::find(fileControls.begin(), fileControls.end(), fieldList[i].toStdString()) == fileControls.end()) { fileControlField = false; break; } } if (fileControlField == true) { field.replace("/", " "); pClassification->setFileControl(field.toStdString()); continue; } // Not a valid field return false; } setClassification(pClassification.get()); return true; }