00001 #ifndef __GLACIERIDDEF_H 00002 #define __GLACIERIDDEF_H 00003 00004 #include "shape.h" 00005 #include "glimsglobals.h" 00006 #include <string> 00007 #include <qstring.h> 00008 #include <qregexp.h> 00009 #include "ValidationReport.h" 00010 00011 00034 class GlacierIDDef : public XMLSerializeable { 00035 public: 00036 double mLat; 00037 double mLon; 00038 Node mImgCoord; 00039 std::string mName; 00040 std::string mWGMSID; 00041 std::string mLocalID; 00042 std::string mParentID; 00043 int mPrimCsfn; 00044 int mForm; 00045 int mFChar; 00046 int mLChar; 00047 int mDomMassSrc; 00048 int mTongueAct; 00049 float mWidth; 00050 float mLength; 00051 float mArea; 00052 float mAbzoneArea; 00053 float mSpeed; 00054 float mELA; 00055 00056 std::string mELADesc; 00057 00058 00059 float mSnowLineElev; 00060 00067 GlacierIDDef( ) { 00068 mLat = 0.0; // LATITUDE OF GLACIER ID 00069 mLon = 0.0; // LONGITUDE OF GLACIER ID 00070 mName = ""; // NAME OF GLACIER 00071 mWGMSID = ""; // WGMS ID 00072 mLocalID = ""; // LOCAL(TO RC) ID 00073 mParentID = ""; // PARENT GID 00074 mPrimCsfn = -1; // PRIMARY CLASSIFICATION INDEX 00075 mForm = -1; // FORM INDEX 00076 mFChar = -1; // FRONTAL CHARACTERISTICS INDEX 00077 mLChar = -1; // LONGITUDINAL CHARACTERISTICS INDEX 00078 mDomMassSrc = -1; // DOMINANT MASS SOURCE INDEX 00079 mTongueAct = -1; // TOUNGE ACTIVITY INDEX 00080 mWidth = -999.0f; // WIDTH 00081 mLength = -999.0f; // LENGTH 00082 mArea = -999.0f; // AREA 00083 mAbzoneArea = -999.0f; // ABZONE AREA 00084 mSpeed = -999.0f; // SPEED 00085 mELA = -999.0f; // ELA (Equilibrium Line Altitude, i.e., altitude where net mass balance is zero, ablation equals accumulation) 00086 mELADesc = ""; // ELA DESCRIPTION 00087 mSnowLineElev = -999.0f; // SNOW LINE ELEVATION 00088 } 00089 00094 GlacierIDDef( const QString & new_glimsID ) { 00095 mLat = 0.0; // LATITUDE OF GLACIER ID 00096 mLon = 0.0; // LONGITUDE OF GLACIER ID 00097 00098 int len = 0 , ndx = -1 ; 00099 QString strval ; 00100 00101 QRegExp r("G[0-9]+E") ; // matches longitude value in GLIMS ID 00102 ndx = r.match(new_glimsID, 0, &len) ; 00103 if (ndx >= 0) { 00104 strval = new_glimsID.mid (ndx + 1, len - 2) ; // pulls lon value out of GLIMS ID 00105 mLon = (strval.toFloat()) / pow(10, len - 5) ; // converts integer into correct float 00106 // len -2 for G and E characters, and -3 for decimal shift 00107 } 00108 00109 r.setPattern ("E[0-9]+[N|S]") ; // matches latitude value in GLIMS ID 00110 ndx = r.match(new_glimsID, 0, &len) ; 00111 if (ndx >= 0) { 00112 strval = new_glimsID.mid (ndx + 1, len - 2) ; // pulls lat value out of GLIMS ID 00113 mLat = (strval.toFloat()) / pow(10, len - 4) ; // converts integer into correct float 00114 // len -2 for E and N|S characters, and -2 for decimal shift 00115 } 00116 00117 mName = ""; // NAME OF GLACIER 00118 mWGMSID = ""; // WGMS ID 00119 mLocalID = ""; // LOCAL(TO RC) ID 00120 mParentID = ""; // PARENT GID 00121 mPrimCsfn = -1; // PRIMARY CLASSIFICATION INDEX 00122 mForm = -1; // FORM INDEX 00123 mFChar = -1; // FRONTAL CHARACTERISTICS INDEX 00124 mLChar = -1; // LONGITUDINAL CHARACTERISTICS INDEX 00125 mDomMassSrc = -1; // DOMINANT MASS SOURCE INDEX 00126 mTongueAct = -1; // TOUNGE ACTIVITY INDEX 00127 mWidth = -999.0f; // WIDTH 00128 mLength = -999.0f; // LENGTH 00129 mArea = -999.0f; // AREA 00130 mAbzoneArea = -999.0f; // ABZONE AREA 00131 mSpeed = -999.0f; // SPEED 00132 mELA = -999.0f; // ELA (Equilibrium Line Altitude, i.e., altitude where net mass balance is zero, ablation equals accumulation) 00133 mELADesc = ""; // ELA DESCRIPTION 00134 mSnowLineElev = -999.0f; // SNOW LINE ELEVATION 00135 } 00136 00137 00138 ~GlacierIDDef( ) {;} 00139 00140 virtual bool fromXML( QDomElement &elem ) { 00141 if ( std::string( "GlacierIDDef" ).compare( (const char*)elem.tagName() ) ) 00142 return false; 00143 00144 QDomElement imgcoordelem = getElemByTagName( elem, "ImgCoord" ); 00145 mLat = readDoubleTag( elem, "Lat" ); 00146 mLon = readDoubleTag( elem, "Lon" ); 00147 00148 mName = readTextTag( elem, "Name" ); 00149 mWGMSID = readTextTag( elem, "WGMSID" ); 00150 mLocalID = readTextTag( elem, "LocalID" ); 00151 mParentID = readTextTag( elem, "ParentID" ); 00152 00153 mPrimCsfn = readIntTag( elem, "PrimCsfn" ); 00154 mForm = readIntTag( elem, "Form" ); 00155 mFChar = readIntTag( elem, "FChar" ); 00156 mLChar = readIntTag( elem, "LChar" ); 00157 mDomMassSrc = readIntTag( elem, "DomMassSrc" ); 00158 mTongueAct = readIntTag( elem, "TongueAct" ); 00159 00160 mWidth = readDoubleTag( elem, "Width" ); 00161 mLength = readDoubleTag( elem, "Length" ); 00162 mArea = readDoubleTag( elem, "Area" ); 00163 mAbzoneArea = readDoubleTag( elem, "AbzoneArea" ); 00164 mSpeed = readDoubleTag( elem, "Speed" ); 00165 mELA = readDoubleTag( elem, "ELA" ); 00166 mELADesc = readTextTag( elem, "ELADesc" ); 00167 mSnowLineElev = readDoubleTag( elem, "SnowLineElev" ); 00168 00169 return true; 00170 } 00171 00172 virtual bool toXML( QDomDocument &doc, 00173 QDomElement &elem, 00174 std::string id = "" ) { 00175 QDomElement base = doc.createElement( "GlacierIDDef" ); 00176 if ( id != "" ) 00177 base.setAttribute( "id", (char*)id.c_str() ); 00178 elem.appendChild( base ); 00179 00180 writeDoubleTag( doc, base, "Lat", mLat ); 00181 writeDoubleTag( doc, base, "Lon", mLon ); 00182 writeTextTag( doc, base, "Name", mName ); 00183 writeTextTag( doc, base, "WGMSID", mWGMSID ); 00184 writeTextTag( doc, base, "LocalID", mLocalID ); 00185 writeTextTag( doc, base, "ParentID", mParentID ); 00186 writeIntTag( doc, base, "PrimCsfn", mPrimCsfn ); 00187 writeIntTag( doc, base, "Form", mForm ); 00188 writeIntTag( doc, base, "FChar", mFChar ); 00189 writeIntTag( doc, base, "LChar", mLChar ); 00190 writeIntTag( doc, base, "DomMassSrc", mDomMassSrc ); 00191 writeIntTag( doc, base, "TongueAct", mTongueAct ); 00192 writeDoubleTag( doc, base, "Width", mWidth ); 00193 writeDoubleTag( doc, base, "Length", mLength ); 00194 writeDoubleTag( doc, base, "Area", mArea ); 00195 writeDoubleTag( doc, base, "AbzoneArea", mAbzoneArea ); 00196 writeDoubleTag( doc, base, "Speed", mSpeed ); 00197 writeDoubleTag( doc, base, "ELA", mELA ); 00198 writeTextTag( doc, base, "ELADesc", mELADesc ); 00199 writeDoubleTag( doc, base, "SnowLineElev", mSnowLineElev ); 00200 return true; 00201 } 00202 00203 // updateVersion: make applicable fixes to the glacier info in the 00204 // project based on the version date of the project file 00205 virtual void updateVersion (QDate * projectVersion) { 00206 00207 // 5/20/20034: classifications off by 1 - stored as reference to index of dropdown box 00208 // instead of the WGMS specification number 00209 QDate checkDate (2004, 5, 20) ; 00210 if ( *projectVersion < checkDate ) { 00211 mPrimCsfn -= 1 ; 00212 mForm -= 1 ; 00213 mFChar -= 1 ; 00214 mLChar -= 1 ; 00215 mDomMassSrc -= 1 ; 00216 mTongueAct -= 1 ; 00217 } 00218 } 00219 00220 00221 // create a glacier ID string from the lat-lon value 00222 std::string toString( ) { 00223 std::string gid; 00224 char buf[50]; 00225 std::string northing; 00226 std::string flonpad; 00227 std::string flatpad; 00228 std::string blonpad; 00229 std::string blatpad; 00230 int latprec; 00231 int lonprec; 00232 00233 double tLat = mLat ; // temp container for latitude 00234 double tLon = mLon ; // temp container for latitude 00235 00236 // --------------------------------------------------------- 00237 // DETERMINE NORTHING STRING 00238 if ( tLat < 0 ) { 00239 northing = "S"; 00240 tLat *= -1; 00241 } else { 00242 northing = "N"; 00243 } 00244 // --------------------------------------------------------- 00245 00246 // OFFSET LON - get it into -180/180 range and 00247 if ( tLon < 0 ) { 00248 tLon += 360 ; 00249 } 00250 00251 // DETERMINE LAT/LON PRECISION 00252 latprec = (int)((tLat - (int)tLat) * 1000.0 + 0.5); 00253 lonprec = (int)((tLon - (int)tLon) * 1000.0 + 0.5); 00254 00255 // --------------------------------------------------------- 00256 // FILL PADDINGS 00257 if ( tLon < 10 ) 00258 flonpad = "00"; 00259 else if ( tLon < 100 ) 00260 flonpad = "0"; 00261 00262 if ( tLat < 10 ) 00263 flatpad = "0"; 00264 00265 if ( latprec < 10 ) 00266 blatpad = "00"; 00267 else if ( latprec < 100 ) 00268 blatpad = "0"; 00269 00270 if ( lonprec < 10 ) 00271 blonpad = "00"; 00272 else if ( lonprec < 100 ) 00273 blonpad = "0"; 00274 // --------------------------------------------------------- 00275 00276 // LOAD BUFFER 00277 sprintf( buf, 00278 "G%s%d%s%dE%s%d%s%d%s", 00279 flonpad.c_str(), 00280 (int)tLon, 00281 blonpad.c_str(), 00282 lonprec, 00283 flatpad.c_str(), 00284 (int)tLat, 00285 blatpad.c_str(), 00286 latprec, 00287 northing.c_str() ); 00288 00289 gid = buf; 00290 return gid; 00291 } 00292 00300 bool validate (ValidationReport * valRep) { 00301 bool dataValid = true ; 00302 std::stringstream rptstream ; 00303 rptstream << "Checking glacier " << toString () ; 00304 valRep->subsectionBegin( rptstream.str() ) ; 00305 rptstream.str("") ; 00306 00307 00308 // Latitude 00309 if ( mLat < -90 || mLat > 90 ) { 00310 valRep->reportError( "Latitude is invalid." ) ; 00311 dataValid = false ; 00312 } 00313 if ( mLat == 0 ) { 00314 valRep->reportWarning( "Latitude may be invalid or undefined." ) ; 00315 } 00316 00317 // Longitude 00318 if ( mLon < -180 || mLon > 360 ) { 00319 valRep->reportError( "Longitude is invalid." ) ; 00320 dataValid = false ; 00321 } 00322 if ( mLon == 0 ) { 00323 valRep->reportWarning( "Longitude may be invalid or undefined." ) ; 00324 } 00325 00326 // Name 00327 if ( mName.empty() ) { 00328 valRep->reportWarning( "Glacier name is not defined." ) ; 00329 } 00330 00331 // WGMS ID 00332 if ( mWGMSID.empty() ) { 00333 valRep->reportWarning( "WGMS ID is not defined." ) ; 00334 } 00335 00336 // Local ID 00337 if ( mLocalID.empty() ) { 00338 valRep->reportWarning( "Local ID is not defined." ) ; 00339 } 00340 00341 00342 // Parent ID 00343 if ( mParentID.empty() ) { 00344 valRep->reportWarning( "Parent ID is not defined." ) ; 00345 } 00346 00347 // Primary classification 00348 if ( mPrimCsfn < 0 ) { 00349 valRep->reportWarning( "Primary classification is not defined." ) ; 00350 } 00351 00352 // Form 00353 if ( mForm < -1 ) { 00354 valRep->reportWarning( "Form is not defined." ) ; 00355 } 00356 00357 // Frontal characteristics 00358 if ( mFChar < -1 ) { 00359 valRep->reportWarning( "Frontal characteristic is not defined." ) ; 00360 } 00361 00362 // Longitudinal characteristics 00363 if ( mLChar < -1 ) { 00364 valRep->reportWarning( "Longitudinal characteristic is not defined." ) ; 00365 } 00366 00367 // Mass source 00368 if (mDomMassSrc < -1 ) { 00369 valRep->reportWarning( "Dominant mass source is not defined." ) ; 00370 } 00371 00372 // Tongue activity 00373 if ( mTongueAct < -1 ) { 00374 valRep->reportWarning( "Tongue activity is not defined." ) ; 00375 } 00376 00377 // Width 00378 if ( mWidth == -999.0 ) { 00379 valRep->reportWarning( "Width is not defined." ) ; 00380 } 00381 00382 // Length 00383 if ( mLength == -999.0 ) { 00384 valRep->reportWarning( "Length is not defined." ) ; 00385 } 00386 00387 // Area 00388 if ( mArea == -999.0 ) { 00389 valRep->reportWarning( "Area is not defined." ) ; 00390 } 00391 00392 // Ablation zone area 00393 if ( mAbzoneArea == -999.0 ) { 00394 valRep->reportWarning( "Ablation zone area is not defined." ) ; 00395 } 00396 00397 // Speed 00398 if ( mSpeed == -999.0 ) { 00399 valRep->reportWarning( "Speed is not defined." ) ; 00400 } 00401 00402 // ELA 00403 if ( mELA == -999.0 ) { 00404 valRep->reportWarning( "ELA is not defined." ) ; 00405 } 00406 00407 // ELA Description 00408 if ( mELADesc.empty() ) { 00409 valRep->reportWarning( "ELA description is not defined." ) ; 00410 } 00411 00412 // Snow Line Elevation 00413 if ( mSnowLineElev == -999.0 ) { 00414 valRep->reportWarning( "Snow line elevation is not defined." ) ; 00415 } 00416 00417 // end glacier check 00418 if (dataValid) { 00419 rptstream << "Glacier " << toString () << " is valid." ; 00420 valRep->subsectionEnd( rptstream.str() ) ; 00421 } 00422 else { 00423 rptstream << "Glacier " << toString () << " has missing or invalid information." ; 00424 valRep->subsectionEnd( rptstream.str() ) ; 00425 } 00426 00427 // return status of lines 00428 return dataValid ; 00429 } 00430 00431 00432 }; 00433 00434 #endif 00435 00436
Home |
Search |
Disclaimers & Privacy |
Contact Us GLIMSView Maintainer: dsoltesz@usgs.gov |