00001 #include "imageinf.h" 00002 #include <qmessagebox.h> 00003 #include <qregexp.h> 00004 #include <iostream> 00005 #include <string> 00006 00007 00008 bool ImageInf::toXML( QDomDocument &doc, 00009 QDomElement &elem, 00010 std::string id ) { 00011 QDomElement base = doc.createElement( "ImageInf" ); 00012 if ( id != "" ) 00013 base.setAttribute( "id", (char*)id.c_str() ); 00014 00015 elem.appendChild( base ); 00016 00017 // 2007-06-14 dls - Removed image ID references and functions 00018 //writeTextTag( doc, base, "ImageID", mImageID ); 00019 writeTextTag( doc, base, "InstID", mInstID ); 00020 writeTextTag( doc, base, "OrigID", mOrigID ); 00021 writeTextTag( doc, base, "LocURL", mLocURL ); 00022 writeTextTag( doc, base, "AquiDateTime", mAquiDateTime ); 00023 00024 writeDoubleTag( doc, base, "CenterLat", mCenterLat ); 00025 writeDoubleTag( doc, base, "CenterLon", mCenterLon ); 00026 writeDoubleTag( doc, base, "CenterLonUnc", mCenterLonUnc ); 00027 writeDoubleTag( doc, base, "CenterLatUnc", mCenterLatUnc ); 00028 writeDoubleTag( doc, base, "ImageAzim", mImageAzim ); 00029 writeDoubleTag( doc, base, "CloudPct", mCloudPct ); 00030 writeDoubleTag( doc, base, "SunAzim", mSunAzim ); 00031 writeDoubleTag( doc, base, "SunElev", mSunElev ); 00032 writeDoubleTag( doc, base, "InstrumentAzimuth", mInstrument_azimuth ); 00033 writeDoubleTag( doc, base, "InstrumentZenith", mInstrument_zenith ); 00034 00035 writeTextTag( doc, base, "Projection", mProjection ); 00036 00037 mP1.toXML( doc, base, "UL" ); 00038 mP2.toXML( doc, base, "UR" ); 00039 mP3.toXML( doc, base, "LR" ); 00040 mP4.toXML( doc, base, "LL" ); 00041 00042 return true; 00043 } 00044 00045 bool ImageInf::fromXML( QDomElement &elem ) { 00046 if ( elem.isNull() ) 00047 return false; 00048 00049 if ( std::string( "ImageInf" ).compare( (const char*)elem.tagName() ) ) 00050 return false; 00051 00052 // 2007-06-14 dls - Removed image ID references and functions 00053 //mImageID = readTextTag( elem, "ImageID" ); 00054 mInstID = readTextTag( elem, "InstID" ); 00055 mOrigID = readTextTag( elem, "OrigID" ); 00056 mLocURL = readTextTag( elem, "LocURL" ); 00057 00058 mAquiDateTime = readTextTag( elem, "AquiDateTime" ); 00059 00060 mCenterLat = readDoubleTag( elem, "CenterLat" ); 00061 mCenterLon = readDoubleTag( elem, "CenterLon" ); 00062 if (mCenterLon < 0.0) { 00063 mCenterLon += 360.0 ; 00064 } 00065 mCenterLonUnc = readDoubleTag( elem, "CenterLonUnc" ); 00066 mCenterLatUnc = readDoubleTag( elem, "CenterLatUnc" ); 00067 00068 mImageAzim = readDoubleTag( elem, "ImageAzim" ); 00069 mCloudPct = readDoubleTag( elem, "CloudPct" ); 00070 mSunAzim = readDoubleTag( elem, "SunAzim" ); 00071 mSunElev = readDoubleTag( elem, "SunElev" ); 00072 00073 mInstrument_azimuth = readDoubleTag( elem, "InstrumentAzimuth" ); 00074 mInstrument_zenith = readDoubleTag( elem, "InstrumentZenith" ); 00075 00076 mProjection = readTextTag( elem, "Projection" ); 00077 00078 QDomNodeList nodeset = elem.elementsByTagName( "Node" ); 00079 for ( unsigned int i=0; i < nodeset.count(); i++ ) { 00080 QDomElement e = nodeset.item( i ).toElement(); 00081 std::string id = (const char*)e.attribute( "id" ); 00082 if ( id == "UL" ) { 00083 mP1.fromXML( e ); 00084 } else if ( id == "UR" ) { 00085 mP2.fromXML( e ); 00086 } else if ( id == "LR" ) { 00087 mP3.fromXML( e ); 00088 } else if ( id == "LL" ) { 00089 mP4.fromXML( e ); 00090 } 00091 } 00092 00093 00094 return true; 00095 } 00096 00097 00098 00099 /* 00100 * Check that required session information is present 00101 */ 00102 bool ImageInf::validate (ValidationReport * valRep) { 00103 bool dataValid = true ; 00104 std::stringstream rptstream ; 00105 00106 valRep->breakBegin( "Image metadata check..." ) ; 00107 00108 00109 // 2007-06-14 dls - Removed some image ID references and functions 00110 // Image ID 00111 /* 00112 if ( mImageID.empty() ) { 00113 valRep->reportWarning( "Image ID empty." ) ; 00114 } 00115 */ 00116 00117 // Instrument ID 00118 if ( mInstID.empty() ) { 00119 valRep->reportError( "Instrument ID is required." ) ; 00120 dataValid = false ; 00121 } 00122 00123 // Acquisition Date/Time 00124 if ( mAquiDateTime.empty() ) { 00125 valRep->reportError( "Image timestamp is required." ) ; 00126 dataValid = false ; 00127 } 00128 else if ( mAquiDateTime.empty() || !(validIso8601DateTime(mAquiDateTime)) ) { 00129 rptstream << "Image timestamp format (" << mAquiDateTime << ") is invalid" << endl ; 00130 valRep->reportError( rptstream.str() ) ; 00131 rptstream.str("") ; 00132 dataValid = false ; 00133 } 00134 00135 00136 // Original ID 00137 if ( mOrigID.empty() ) { 00138 valRep->reportError( "Original image ID is required." ) ; 00139 dataValid = false ; 00140 } 00141 00142 // Image location 00143 if ( mLocURL.empty() ) { 00144 valRep->reportWarning( "Image location (URL) is empty." ) ; 00145 } 00146 00147 // Center lat 00148 if ( mCenterLat > 90 || mCenterLat < -90 ) { 00149 valRep->reportError( "Center latitude of image is invalid or missing." ) ; 00150 dataValid = false ; 00151 } 00152 00153 // Center lon 00154 if ( mCenterLon > 360 || mCenterLon < -180 ) { 00155 valRep->reportError( "Center longitude of image is invalid or missing." ) ; 00156 dataValid = false ; 00157 } 00158 00159 // Center Lat Uncertainty 00160 if ( mCenterLatUnc == -999.0 ) { 00161 valRep->reportWarning( "Uncertainty of center latitude is not defined." ) ; 00162 } 00163 00164 // Center Lon Uncertainty 00165 if ( mCenterLonUnc == -999.0 ) { 00166 valRep->reportWarning( "Uncertainty of center longitude is not defined." ) ; 00167 } 00168 00169 // Image Azimuth 00170 if ( mImageAzim == -999.0 ) { 00171 valRep->reportWarning( "Image azimuth is not defined." ) ; 00172 } 00173 00174 // Percent cloud cover 00175 if ( mCloudPct == -999.0 ) { 00176 valRep->reportWarning( "Percentage of cloud cover is not defined." ) ; 00177 } 00178 00179 // Sun Azimuth 00180 if ( mSunAzim == -999.0 ) { 00181 valRep->reportWarning( "Sun azimuth is not defined." ) ; 00182 } 00183 00184 // Sun Elevation 00185 if ( mSunElev == -999.0 ) { 00186 valRep->reportWarning( "Sun elevation is not defined." ) ; 00187 } 00188 00189 // Instrument azimuth 00190 if ( mInstrument_azimuth == -999.0 ) { 00191 valRep->reportWarning( "Instrument azimuth is not defined." ) ; 00192 } 00193 00194 // Instrument zenith 00195 if ( mInstrument_zenith == -999.0 ) { 00196 valRep->reportWarning( "Instrument zenith is not defined." ) ; 00197 } 00198 00199 // Projection 00200 if ( mProjection.empty() ) { 00201 valRep->reportWarning( "Projection may be invalid or missing." ) ; 00202 } 00203 00204 00205 // Finished with checks 00206 if (dataValid) { 00207 valRep->breakEnd( "CHECK COMPLETE: All required image metadata filled in." ) ; 00208 } 00209 else { 00210 valRep->breakEnd( "ERROR: Missing required image metadata." ) ; 00211 } 00212 00213 00214 // return status of lines 00215 return dataValid ; 00216 00217 } 00218 00219 00220 00221 /* 00222 * Do the characters in the input string represent 00223 * a complete and valid date/time string? 00224 */ 00225 bool ImageInf::validIso8601DateTime (std::string str) { 00226 QString newStr (str.c_str()) ; 00227 return validIso8601DateTime (newStr) ; 00228 } 00229 00230 /* 00231 * Do the characters in the input string represent 00232 * a complete and valid date/time string? 00233 */ 00234 bool ImageInf::validIso8601DateTime (QString &str) { 00235 int i = 0 ; 00236 bool valid = true ; 00237 00238 // replace all double quotes with nothing, and get rid of all spaces 00239 str.replace ( QRegExp ("\""), "" ) ; 00240 str.simplifyWhiteSpace () ; 00241 str.replace ( QRegExp (" "), "" ) ; 00242 00243 00244 // YEAR 00245 if (str.length() < 4) { 00246 valid = false ; 00247 return valid ; 00248 } 00249 else { 00250 // check year 00251 for ( ; i <= 3 ; i++ ) { 00252 if ( !(str[i].digitValue() >= 0 && str[i].digitValue() <= 9) ) { 00253 valid = false ; 00254 } 00255 } 00256 if (str.length() == 4) { 00257 return valid ; 00258 } 00259 } 00260 00261 00262 // MONTH 00263 if (str.length() < 7) { 00264 valid = false ; 00265 return valid ; 00266 } 00267 else { 00268 // check dash after year 00269 if (!(str[4] == '-')) { 00270 valid = false ; 00271 } 00272 // check month 00273 if ( !(str[5].digitValue() >= 0 && str[5].digitValue() <= 1) ) { 00274 valid = false ; 00275 } 00276 if ( !(str[6].digitValue() >= 0 && str[6].digitValue() <= 9) ) { 00277 valid = false ; 00278 } 00279 if (str.length() == 7) { 00280 return valid ; 00281 } 00282 } 00283 00284 // DAY 00285 if (str.length() < 10) { 00286 valid = false ; 00287 return valid ; 00288 } 00289 else { 00290 // check dash after month 00291 if (!(str[7] == '-')) { 00292 valid = false ; 00293 } 00294 // check day 00295 if ( !(str[8].digitValue() >= 0 && str[8].digitValue() <= 3) ) { 00296 valid = false ; 00297 } 00298 if ( !(str[9].digitValue() >= 0 && str[9].digitValue() <= 9) ) { 00299 valid = false ; 00300 } 00301 if (str.length() == 10) { 00302 return valid ; 00303 } 00304 // check T after date 00305 if (!(str[10] == 'T')) { 00306 valid = false ; 00307 } 00308 } 00309 00310 // TIME - HOURS/MINUTES 00311 if (str.length() < 22) { 00312 valid = false ; 00313 return valid ; 00314 } 00315 else { 00316 // check hour 00317 if ( !(str[11].digitValue() >= 0 && str[11].digitValue() <= 2) ) { 00318 valid = false ; 00319 } 00320 if ( !(str[12].digitValue() >= 0 && str[12].digitValue() <= 9) ) { 00321 valid = false ; 00322 } 00323 if (!(str[13] == ':')) { 00324 valid = false ; 00325 } 00326 // check minute 00327 if ( !(str[14].digitValue() >= 0 && str[14].digitValue() <= 5) ) { 00328 valid = false ; 00329 } 00330 if ( !(str[15].digitValue() >= 0 && str[16].digitValue() <= 9) ) { 00331 valid = false ; 00332 } 00333 00334 00335 if (str.length() >= 17) { 00336 i = 16 ; 00337 // seconds 00338 if ( str[i] == ':' ) { 00339 if ( !(str[++i].digitValue() >= 0 && str[i].digitValue() <= 5) ) { 00340 valid = false ; 00341 return valid ; 00342 } 00343 if ( !(str[++i].digitValue() >= 0 && str[i].digitValue() <= 9) ) { 00344 valid = false ; 00345 return valid ; 00346 } 00347 // decimal seconds 00348 if ( str[++i] == '.' ) { 00349 // skip past decimal places, there must be at least one 00350 if (str[++i].digitValue() >= 0 && str[i].digitValue() <= 9) { 00351 while (str[++i].digitValue() >= 0 && str[i].digitValue() <= 9) {;} 00352 } 00353 else { 00354 return valid ; 00355 } 00356 } 00357 } 00358 00359 // TZD 00360 if (str[i] == 'Z') { 00361 return valid ; 00362 } 00363 else if (str[i] == '-' || str[i] == '+') { 00364 if ( !(str[++i].digitValue() >= 0 && str[i].digitValue() <= 2) ) { 00365 valid = false ; 00366 } 00367 if ( !(str[++i].digitValue() >= 0 && str[i].digitValue() <= 9) ) { 00368 valid = false ; 00369 } 00370 if ( !(str[++i] == ':') ) { 00371 valid = false ; 00372 } 00373 if ( !(str[++i].digitValue() >= 0 && str[i].digitValue() <= 5) ) { 00374 valid = false ; 00375 } 00376 if ( !(str[++i].digitValue() >= 0 && str[i].digitValue() <= 9) ) { 00377 valid = false ; 00378 } 00379 } 00380 else { 00381 valid = false ; 00382 return valid ; 00383 } 00384 } 00385 } 00386 return valid ; 00387 } 00388 00389
Home |
Search |
Disclaimers & Privacy |
Contact Us GLIMSView Maintainer: dsoltesz@usgs.gov |