00001 #include "glimsproject.h" 00002 #include "dbfheader.h" 00003 00004 GLIMSProject::GLIMSProject( QWidget *parent, ViewSet *vs ) { 00005 mParent = parent; 00006 mImg = NULL; 00007 mGData = NULL; 00008 mLyrSet = NULL; 00009 mEditor = NULL; 00010 mConfigDlg = NULL; 00011 mViewSet = vs; 00012 mOpen = false; 00013 mNeedSave = false; 00014 mFileName = ""; 00015 GLIMSGlobals::loadGlobals(); 00016 mVersion = new QDate (1900, 1, 1) ; 00017 mValidationReport = new ValidationReport ; 00018 } 00019 00020 bool GLIMSProject::save( ) { 00021 if ( mFileName != "" ) { 00022 mNeedSave = false ; 00023 return toXMLFile( mFileName, "GLIMS_Project" ); 00024 } 00025 else { 00026 return saveAs(); 00027 } 00028 } 00029 00030 00031 bool GLIMSProject::saveAs( ) { 00032 QString fname = QFileDialog::getSaveFileName(); 00033 if ( fname.isNull() ) { 00034 return false; 00035 } 00036 00037 mFileName = (const char*)fname; 00038 mNeedSave = false ; 00039 return toXMLFile( mFileName, "GLIMS_Project" ); 00040 } 00041 00042 bool GLIMSProject::create( ) { 00043 std::string name; 00044 std::string dir; 00045 std::string imgname; 00046 int type; 00047 00048 // ProjectDlg *pdlg = new ProjectDlg( name, dir, imgname, type ); 00049 ImageDlg *idlg = new ImageDlg( imgname, type ); 00050 if ( !idlg->exec() ) 00051 return( mOpen = false ); 00052 00053 delete idlg; 00054 00055 Image *img = Image::openImage( imgname, (Image::MultiFileType)type ); 00056 if ( img == NULL ) { 00057 QMessageBox::information( NULL, "File Error", "Unable to open selected file" ); 00058 return( mOpen = false ); 00059 } 00060 00061 // mFileName = name; 00062 setup( img ); 00063 mGData->getLineData().loadDefaultSet(); 00064 return( mOpen = true ); 00065 } 00066 00067 bool GLIMSProject::open( ) { 00068 QString str = QFileDialog::getOpenFileName(); 00069 if ( str.isNull() ) return( mOpen = false ); 00070 if ( !fromXMLFile( (const char*)str, "GLIMS_Project" ) ) { 00071 return( mOpen = false ); 00072 } 00073 00074 mFileName = str.ascii() ; 00075 return( mOpen = true ); 00076 } 00077 00078 void GLIMSProject::setup( Image *img ) { 00079 mGData = new GLIMSDataset( img ); 00080 mLyrSet = new VectorLayerSet; 00081 mEditor = new VectorEditor( mLyrSet, mViewSet ); 00082 VectorLayer *vl1 = new VectorLayer( &mGData->getLineData() ); 00083 VectorLayer *vl2 = new VectorLayer( &mGData->getGIDData() ); 00084 mLyrSet->addLayer( vl1 ); 00085 mLyrSet->addLayer( vl2 ); 00086 mLyrSet->setActiveLayer( 0 ); 00087 mImg = img ; 00088 00089 mConfigDlg = new ConfigDlg( mParent, 00090 *mGData ); 00091 mConfigDlg->hide(); 00092 00093 mValRepDlg = new ValidationReportDlg ( mValidationReport ) ; 00094 00095 connect( mConfigDlg, 00096 SIGNAL( repaintViews() ), 00097 mViewSet, 00098 SLOT( repaintViews() ) ); 00099 00100 connect( this, 00101 SIGNAL( finishedValidation() ), 00102 mViewSet, 00103 SLOT( repaintViews() ) ); 00104 00105 connect( &mGData->getLineData(), 00106 SIGNAL( datasetChanged() ), 00107 this, 00108 SLOT( setUnsaved() ) ); 00109 00110 connect( &mGData->getGIDData(), 00111 SIGNAL( datasetChanged() ), 00112 this, 00113 SLOT( setUnsaved() ) ); 00114 00115 connect( &(&mGData->getGIDData())->getSelSet(), 00116 SIGNAL( selectionChanged() ), 00117 mConfigDlg, 00118 SLOT( refreshAll() ) ); 00119 00120 connect( mEditor, 00121 SIGNAL( selectionChanged() ), 00122 mConfigDlg, 00123 SLOT( refreshAll() ) ); 00124 00125 } 00126 00127 bool GLIMSProject::toXML( 00128 QDomDocument &doc, 00129 QDomElement &elem, 00130 std::string ) { 00131 ImageState state = mImg->getImageState(); 00132 state.toXML( doc, elem ); 00133 mGData->toXML( doc, elem ); 00134 return true; 00135 } 00136 00137 bool GLIMSProject::fromXML( QDomElement &elem ) { 00138 00139 // pull version date from the GLIMS_Project root node 00140 QDomNode rootNode = elem.parentNode() ; 00141 QDomElement rootElement ; 00142 00143 if ( !rootNode.isNull() ) { 00144 rootElement = rootNode.toElement() ; 00145 } else return false ; 00146 00147 00148 if ( !rootElement.isNull() && rootElement.hasAttribute ("version") ) { 00149 stringToQDate((rootElement.attribute("version")).ascii(), mVersion) ; 00150 } 00151 00152 00153 00154 QDomNode node; 00155 if ( !mImgState.fromXML( elem ) ) 00156 return false; 00157 00158 Image *img = NULL; 00159 do { 00160 img = Image::openImage( mImgState.mFileName, 00161 (Image::MultiFileType)mImgState.mType ); 00162 if ( !img ) { 00163 string msg = "Could not open image:\n"; 00164 msg = msg + mFileName; 00165 int ret = QMessageBox::information( NULL, 00166 "Open Image error", 00167 msg.c_str(), 00168 "Continue", 00169 "Cancel" ); 00170 if ( ret == 1 ) 00171 return false; 00172 00173 ImageDlg *imgdlg = new ImageDlg( mImgState.mFileName, mImgState.mType ); 00174 imgdlg->exec(); 00175 delete imgdlg; 00176 } 00177 } while ( img == NULL ); 00178 00179 img->setBandSel( mImgState ); 00180 setup( img ); 00181 00182 node = elem.nextSibling(); 00183 if ( !node.isElement() ) 00184 return false; 00185 elem = node.toElement(); 00186 mGData->fromXML( elem ); 00187 00188 00189 // call for updates to project info based on version 00190 mGData->updateVersion(mVersion) ; 00191 00192 mConfigDlg->resetAll(); 00193 return true; 00194 } 00195 00196 void GLIMSProject::openConfigDlg( ) { 00197 mConfigDlg->hide(); 00198 mConfigDlg->show(); 00199 mConfigDlg->setFocus(); 00200 } 00201 00202 void GLIMSProject::exportGLIMSIngest( ) { 00203 00204 // ********************************** 00205 // PROJECT VALIDITY 00206 // Is project valid? 00207 if ( !validate() ) { 00208 int ret = QMessageBox::information( NULL, 00209 "GLIMS Shapefile Export: Project Incomplete", 00210 "Your project has incomplete or invalid data. Would you like return to editing, or continue with export?", 00211 "Return to Editing", 00212 "Export" ); 00213 00214 // CONTINUE: don't save the file, return 00215 // without closing project so user 00216 // continue editing 00217 if ( ret == 0 ) { 00218 return ; 00219 } 00220 mValRepDlg->hide () ; 00221 } 00222 00223 00224 DBFHandle hDBF = NULL ; 00225 SHPHandle hSHP = NULL ; 00226 double *vertX, *vertY, *vertZ ; 00227 double x, y ; 00228 std::string fname, dirname ; 00229 unsigned int i ; 00230 00231 setTimeStamp(); 00232 00233 QString qdir = QFileDialog::getExistingDirectory(); 00234 if ( qdir.isNull() ) 00235 return; 00236 dirname = (const char*)qdir; 00237 00238 // ------------------- 00239 // SESSION FILE 00240 fname = dirname + "session"; 00241 Session &session = mGData->getSession(); 00242 hSHP = SHPCreate( fname.c_str(), SHPT_POINTZ ); 00243 if ( hSHP == NULL ) { 00244 QMessageBox::information( NULL, "File Error", "Can not write Shape Files" ); 00245 return; 00246 } 00247 00248 00249 int pdSize = 0 ; 00250 if (session.mProcDesc.size()) { 00251 pdSize = session.mProcDesc.size() ; 00252 } 00253 else { 00254 pdSize = 1 ; 00255 } 00256 00257 int tdSize = 0 ; 00258 if (session.m3d_desc.size()) { 00259 tdSize = session.m3d_desc.size() ; 00260 } 00261 else { 00262 tdSize = 1 ; 00263 } 00264 00265 00266 DBFHeader sesshead[] = { 00267 { "RC_ID", FTInteger, 11, 0}, 00268 { "data_src", FTString, 255, 0}, 00269 { "proc_desc", FTString, pdSize, 0}, 00270 { "anlst_surn", FTString, 50, 0}, 00271 { "anlst_givn", FTString, 50, 0}, 00272 { "3d_desc", FTString, tdSize, 0}, 00273 { "analy_time", FTString, 35, 0} 00274 }; 00275 00276 hDBF = DBFCreate( fname.c_str() ); 00277 for ( i=0; i < 7; i++ ) 00278 DBFAddField( hDBF, 00279 sesshead[i].fieldName, 00280 sesshead[i].type, 00281 sesshead[i].width, 00282 sesshead[i].nDec ); 00283 00284 DBFWriteIntegerAttribute( hDBF, 0, 0, session.mRC_ID ); 00285 DBFWriteStringAttribute ( hDBF, 0, 1, session.mDataSrc.c_str() ); 00286 DBFWriteStringAttribute ( hDBF, 0, 2, session.mProcDesc.c_str() ); 00287 DBFWriteStringAttribute ( hDBF, 0, 3, session.manlst_surn.c_str() ); 00288 DBFWriteStringAttribute ( hDBF, 0, 4, session.manlst_givn.c_str() ); 00289 DBFWriteStringAttribute ( hDBF, 0, 5, session.m3d_desc.c_str() ); 00290 DBFWriteStringAttribute ( hDBF, 0, 6, session.manaly_time.c_str() ); 00291 00292 vertX = new double[1]; 00293 vertY = new double[1]; 00294 vertZ = new double[1]; 00295 x = mImg->width() / 2; 00296 y = mImg->height() / 2; 00297 mImg->getLL( x, y ); 00298 if ( x > 180 ) { 00299 x -= 360 ; 00300 } 00301 vertX[0] = x; 00302 vertY[0] = y; 00303 vertZ[0] = 0; 00304 00305 SHPObject *shp = SHPCreateSimpleObject( SHPT_POINTZ, 1, vertX, vertY, vertZ ); 00306 delete [] vertX; 00307 delete [] vertY; 00308 delete [] vertZ; 00309 00310 SHPWriteObject( hSHP, -1, shp ); 00311 SHPDestroyObject( shp ); 00312 00313 SHPClose( hSHP ); 00314 DBFClose( hDBF ); 00315 00316 00317 // ---------------------------- 00318 // CREATE GLACIER DATA FILE 00319 fname = dirname + "glaciers"; 00320 hSHP = SHPCreate( fname.c_str(), SHPT_POINTZ ); 00321 00322 DBFHeader glachead[] = { 00323 { "ID", FTString, 20, 0}, // 0 00324 { "name", FTString, 40, 0}, // 1 00325 { "prim_class", FTInteger, 5, 0}, // 2 00326 { "form", FTInteger, 5, 0}, // 3 00327 { "front_char", FTInteger, 5, 0}, // 4 00328 { "long_char", FTInteger, 5, 0}, // 5 00329 { "mass_src", FTInteger, 5, 0}, // 6 00330 { "tongue_act", FTInteger, 5, 0}, // 7 00331 { "width_m", FTDouble, 5, 5}, // 8 00332 { "length_m", FTDouble, 5, 5}, // 9 00333 { "area_km2", FTDouble, 5, 5}, // 10 00334 { "abarea_km2", FTDouble, 5, 5}, // 11 00335 { "speed_myr", FTDouble, 5, 5}, // 12 00336 { "snwln_elev", FTDouble, 5, 5}, // 13 00337 { "wgms_id", FTString, 14, 0}, // 14 00338 { "local_id", FTString, 20, 0}, // 15 00339 { "parent_id", FTString, 20, 0}, // 16 00340 00341 // TODO added - need to check correct 00342 // tag and length values 00343 { "ela", FTDouble, 5, 5}, // 17 00344 { "ela_desc", FTString, 255, 0}, // 18 00345 { "rec_status", FTString, 255, 0} // 19 00346 }; 00347 00348 hDBF = DBFCreate( fname.c_str() ); 00349 for ( i=0; i < 20; i++ ) 00350 DBFAddField( hDBF, 00351 glachead[i].fieldName, 00352 glachead[i].type, 00353 glachead[i].width, 00354 glachead[i].nDec ); 00355 00356 // get the Glacier Definition Set (Glacier definition points created by the user) 00357 std::vector<GlacierIDDef> &giddefset = mGData->getGIDData().getDefSet(); 00358 00359 // for each Glacier Definition 00360 for ( i=0; i < giddefset.size(); i++ ) { 00361 GlacierIDDef gid = giddefset[i]; 00362 DBFWriteStringAttribute ( hDBF, i, 0, gid.toString().c_str() ); 00363 DBFWriteStringAttribute ( hDBF, i, 1, gid.mName.c_str() ); 00364 00365 if ( gid.mPrimCsfn < 0 ) { 00366 DBFWriteIntegerAttribute( hDBF, i, 2, -999 ); 00367 } 00368 else { 00369 DBFWriteIntegerAttribute( hDBF, i, 2, gid.mPrimCsfn ); 00370 } 00371 if ( gid.mForm < 0 ) { 00372 DBFWriteIntegerAttribute( hDBF, i, 3, -999 ); 00373 } 00374 else { 00375 DBFWriteIntegerAttribute( hDBF, i, 3, gid.mForm ); 00376 } 00377 if ( gid.mFChar < 0 ) { 00378 DBFWriteIntegerAttribute( hDBF, i, 4, -999 ); 00379 } 00380 else { 00381 DBFWriteIntegerAttribute( hDBF, i, 4, gid.mFChar ); 00382 } 00383 if ( gid.mLChar < 0 ) { 00384 DBFWriteIntegerAttribute( hDBF, i, 5, -999 ); 00385 } 00386 else { 00387 DBFWriteIntegerAttribute( hDBF, i, 5, gid.mLChar ); 00388 } 00389 if ( gid.mDomMassSrc < 0 ) { 00390 DBFWriteIntegerAttribute( hDBF, i, 6, -999 ); 00391 } 00392 else { 00393 DBFWriteIntegerAttribute( hDBF, i, 6, gid.mDomMassSrc ); 00394 } 00395 if ( gid.mTongueAct < 0 ) { 00396 DBFWriteIntegerAttribute( hDBF, i, 7, -999 ); 00397 } 00398 else { 00399 DBFWriteIntegerAttribute( hDBF, i, 7, gid.mTongueAct ); 00400 } 00401 00402 DBFWriteDoubleAttribute ( hDBF, i, 8, gid.mWidth ); 00403 DBFWriteDoubleAttribute ( hDBF, i, 9, gid.mLength ); 00404 DBFWriteDoubleAttribute ( hDBF, i, 10, gid.mArea ); 00405 DBFWriteDoubleAttribute ( hDBF, i, 11, gid.mAbzoneArea ); 00406 DBFWriteDoubleAttribute ( hDBF, i, 12, gid.mSpeed ); 00407 DBFWriteDoubleAttribute ( hDBF, i, 13, gid.mSnowLineElev ); 00408 DBFWriteStringAttribute ( hDBF, i, 14, gid.mWGMSID.c_str() ); 00409 DBFWriteStringAttribute ( hDBF, i, 15, gid.mLocalID.c_str() ); 00410 DBFWriteStringAttribute ( hDBF, i, 16, gid.mParentID.c_str() ); 00411 00412 // TODO added ad hoc - need to check correct tag, len 00413 DBFWriteDoubleAttribute ( hDBF, i, 17, gid.mELA ); 00414 DBFWriteStringAttribute ( hDBF, i, 18, gid.mELADesc.c_str() ); 00415 // TODO: should there be a "record_status" written to the file 00416 // (defined above in glacier header)... which member of gid? 00417 //DBFWriteStringAttribute ( hDBF, i, 19, gid.RECORD_STATUS.c_str() ); 00418 00419 00420 vertX = new double[1]; 00421 vertY = new double[1]; 00422 vertZ = new double[1]; 00423 vertX[0] = gid.mLon; 00424 vertY[0] = gid.mLat; 00425 vertZ[0] = 0; 00426 shp = SHPCreateSimpleObject( SHPT_POINTZ, 1, vertX, vertY, vertZ ); 00427 00428 delete [] vertX; 00429 delete [] vertY; 00430 delete [] vertZ; 00431 00432 SHPWriteObject( hSHP, -1, shp ); 00433 SHPDestroyObject( shp ); 00434 00435 } 00436 00437 SHPClose( hSHP ); 00438 DBFClose( hDBF ); 00439 00440 00441 // --------------------- 00442 // CREATE IMAGE FILE 00443 fname = dirname + "images" ; 00444 hSHP = SHPCreate( fname.c_str(), SHPT_ARCZ ) ; 00445 ImageInf &imginf = mGData->getImageInf() ; 00446 00447 // 2007-06-14 dls - Removed image ID references and functions 00448 /* 00449 int imidSize = 1 ; 00450 if (imginf.mImageID.size() > 0) { 00451 imidSize = imginf.mImageID.size() ; 00452 } 00453 */ 00454 00455 int inidSize = 1 ; 00456 if (imginf.mInstID.size() > 0) { 00457 inidSize = imginf.mInstID.size() ; 00458 } 00459 00460 DBFHeader imaghead[] = { 00461 // 2007-06-14 dls - Removed image ID references and functions 00462 //{ "image_id", FTString, imidSize, 0}, 00463 { "inst_id", FTString, inidSize, 0}, 00464 { "orig_id", FTString, 50, 0}, 00465 { "imglocurl", FTString, 120, 0}, 00466 { "acq_time", FTString, 35, 0}, 00467 { "imgctrlon", FTDouble, 7, 5}, 00468 { "imgctrlat", FTDouble, 7, 5}, 00469 { "img_lon_unc", FTDouble, 7, 5}, 00470 { "img_lat_unc", FTDouble, 7, 5}, 00471 { "image_azim", FTDouble, 7, 4}, 00472 { "cloud_pct", FTDouble, 7, 9}, 00473 { "sun_azim", FTDouble, 7, 4}, 00474 { "sun_elev", FTDouble, 7, 4}, 00475 { "inst_zen", FTDouble, 7, 4}, 00476 { "inst_azim", FTDouble, 7, 4}, 00477 { "projection", FTString, 30, 0} 00478 }; 00479 00480 hDBF = DBFCreate( fname.c_str() ) ; 00481 00482 for ( i = 0; i < 15 ; i++ ) { 00483 DBFAddField( hDBF, 00484 imaghead[i].fieldName, 00485 imaghead[i].type, 00486 imaghead[i].width, 00487 imaghead[i].nDec ); 00488 } 00489 00490 00491 //removed as per e-mail from Bruce Raup 2007-06-14 00492 //DBFWriteStringAttribute( hDBF, 0, 0, imginf.mImageID.c_str() ); 00493 DBFWriteStringAttribute( hDBF, 0, 0, imginf.mInstID.c_str() ); 00494 DBFWriteStringAttribute( hDBF, 0, 1, imginf.mOrigID.c_str() ); 00495 DBFWriteStringAttribute( hDBF, 0, 2, imginf.mLocURL.c_str() ); 00496 DBFWriteStringAttribute( hDBF, 0, 3, imginf.mAquiDateTime.c_str() ); 00497 DBFWriteDoubleAttribute( hDBF, 0, 4, imginf.mCenterLon ); 00498 DBFWriteDoubleAttribute( hDBF, 0, 5, imginf.mCenterLat ); 00499 DBFWriteDoubleAttribute( hDBF, 0, 6, imginf.mCenterLonUnc ); 00500 DBFWriteDoubleAttribute( hDBF, 0, 7, imginf.mCenterLatUnc ); 00501 DBFWriteDoubleAttribute( hDBF, 0, 8, imginf.mImageAzim ); 00502 DBFWriteDoubleAttribute( hDBF, 0, 9, imginf.mCloudPct ); 00503 DBFWriteDoubleAttribute( hDBF, 0, 10, imginf.mSunAzim ); 00504 DBFWriteDoubleAttribute( hDBF, 0, 11, imginf.mSunElev ); 00505 DBFWriteDoubleAttribute( hDBF, 0, 12, imginf.mInstrument_zenith ); 00506 DBFWriteDoubleAttribute( hDBF, 0, 13, imginf.mInstrument_azimuth ); 00507 DBFWriteStringAttribute( hDBF, 0, 14, imginf.mProjection.c_str() ); 00508 00509 vertX = new double[5]; 00510 vertY = new double[5]; 00511 vertZ = new double[5]; 00512 mImg->setCornerPnts( imginf ); 00513 vertX[0] = imginf.mP1.x; // PNT 1 00514 vertY[0] = imginf.mP1.y; 00515 vertZ[0] = 0; 00516 if ( vertX[0] > 180 ) { 00517 vertX[0] -= 360 ; 00518 } 00519 vertX[1] = imginf.mP2.x; // PNT 2 00520 vertY[1] = imginf.mP2.y; 00521 vertZ[1] = 0; 00522 if ( vertX[1] > 180 ) { 00523 vertX[1] -= 360 ; 00524 } 00525 vertX[2] = imginf.mP3.x; // PNT 3 00526 vertY[2] = imginf.mP3.y; 00527 vertZ[2] = 0; 00528 if ( vertX[2] > 180 ) { 00529 vertX[2] -= 360 ; 00530 } 00531 vertX[3] = imginf.mP4.x; // PNT 4 00532 vertY[3] = imginf.mP4.y; 00533 vertZ[3] = 0; 00534 if ( vertX[3] > 180 ) { 00535 vertX[3] -= 360 ; 00536 } 00537 vertX[4] = imginf.mP1.x; // PNT 5 00538 vertY[4] = imginf.mP1.y; 00539 vertZ[4] = 0; 00540 if ( vertX[4] > 180 ) { 00541 vertX[4] -= 360 ; 00542 } 00543 00544 shp = SHPCreateSimpleObject( SHPT_ARCZ, 5, vertX, vertY, vertZ ); 00545 delete [] vertX; 00546 delete [] vertY; 00547 delete [] vertZ; 00548 00549 SHPWriteObject( hSHP, -1, shp ); 00550 SHPDestroyObject( shp ); 00551 00552 SHPClose( hSHP ); 00553 DBFClose( hDBF ); 00554 00555 00556 00557 // ----------------------- 00558 // CREATE SEGMENTS DBF FILE 00559 00560 fname = dirname + "segments"; 00561 hSHP = SHPCreate( fname.c_str(), SHPT_ARCZ ); 00562 DBFHeader seghead[] = { 00563 { "category", FTString, 20, 0}, // 0 00564 { "ID", FTString, 20, 0}, // 1 00565 { "type", FTString, 30, 0}, // 2 00566 { "label", FTString, 32, 0}, // 3 00567 { "loc_unc_x", FTDouble, 5, 5}, // 4 00568 { "loc_unc_y", FTDouble, 5, 5}, // 5 00569 { "glob_unc_x", FTDouble, 5, 5}, // 6 00570 { "glob_unc_y", FTDouble, 5, 5}, // 7 00571 { "left_mat", FTString, 3, 0}, // 8 00572 { "right_mat", FTString, 3, 0}, // 9 00573 { "left_feat", FTString, 3, 0}, // 10 00574 { "right_feat", FTString, 3, 0} // 11 00575 }; 00576 00577 hDBF = DBFCreate( fname.c_str() ); 00578 for ( i=0; i < 12; i++ ) { 00579 DBFAddField( hDBF, 00580 seghead[i].fieldName, 00581 seghead[i].type, 00582 seghead[i].width, 00583 seghead[i].nDec ); 00584 } 00585 00586 std::vector<Shape*> &lineset = mGData->getLineData().getLLSet(); 00587 LineDefSet &ldfset = mGData->getLineData().getLDFSet(); 00588 std::vector<GlacierIDDef> &gidset = mGData->getGIDData().getDefSet(); 00589 00590 for ( i = 0; i < lineset.size(); i++ ) { 00591 char buf[50]; 00592 std::string gidlbl; 00593 00594 Shape &s = *lineset[i]; 00595 GlacierLine &gline = dynamic_cast<GlacierLine&>( s ); 00596 LineDef ldf; 00597 00598 if ( gline.mLDF >= 0 ) { 00599 ldf = ldfset[gline.mLDF]; 00600 } 00601 00602 sprintf( buf, 00603 "gtype: %d, lat: %d, label: %d", 00604 ldf.mGlacType, ldf.mLMat, ldf.mLabel ); 00605 00606 gidlbl = "UNDEFINED"; 00607 if ( gline.mGID >= 0 && gline.mGID < (int)gidset.size() ) { 00608 gidlbl = gidset[gline.mGID].toString(); 00609 } 00610 00611 DBFWriteStringAttribute( hDBF, i, 0, GLIMSGlobals::mGlbGlacTypes[ldf.mGlacType].id.c_str() ); 00612 DBFWriteStringAttribute( hDBF, i, 1, gidlbl.c_str() ); 00613 DBFWriteStringAttribute( hDBF, i, 2, GLIMSGlobals::mGlbTypes[ldf.mType].id.c_str() ); 00614 DBFWriteStringAttribute( hDBF, i, 3, GLIMSGlobals::mGlbLbls[ldf.mLabel].id.c_str() ); 00615 DBFWriteDoubleAttribute( hDBF, i, 4, ldf.mLXUncert ); 00616 DBFWriteDoubleAttribute( hDBF, i, 5, ldf.mLYUncert ); 00617 DBFWriteDoubleAttribute( hDBF, i, 6, ldf.mGXUncert ); 00618 DBFWriteDoubleAttribute( hDBF, i, 7, ldf.mGYUncert ); 00619 DBFWriteStringAttribute( hDBF, i, 8, GLIMSGlobals::mGlbMDF[ldf.mLMat].id.c_str() ); 00620 DBFWriteStringAttribute( hDBF, i, 9, GLIMSGlobals::mGlbMDF[ldf.mRMat].id.c_str() ); 00621 DBFWriteStringAttribute( hDBF, i, 10, GLIMSGlobals::mGlbFtrs[ldf.mLFeature].id.c_str() ); 00622 DBFWriteStringAttribute( hDBF, i, 11, GLIMSGlobals::mGlbFtrs[ldf.mRFeature].id.c_str() ); 00623 00624 int npts = gline.size(); 00625 vertX = new double[ npts ]; 00626 vertY = new double[ npts ]; 00627 vertZ = new double[ npts ]; 00628 for ( int a = 0; a < npts; a++ ) { 00629 vertX[a] = gline[a].x; 00630 vertY[a] = gline[a].y; 00631 vertZ[a] = gline[a].z; 00632 if ( vertX[a] > 180 ) { 00633 vertX[a] -= 360 ; 00634 } 00635 } 00636 00637 shp = SHPCreateSimpleObject( SHPT_ARCZ, npts, vertX, vertY, vertZ ); 00638 delete [] vertX; 00639 delete [] vertY; 00640 delete [] vertZ; 00641 00642 SHPWriteObject( hSHP, -1, shp ); 00643 SHPDestroyObject( shp ); 00644 } 00645 00646 SHPClose( hSHP ); 00647 DBFClose( hDBF ); 00648 00649 mConfigDlg->resetAll() ; 00650 00651 return; 00652 } 00653 00654 00655 void GLIMSProject::importGIDsFromShapefile( ) { 00656 std::string fname; 00657 int nrec = 0 ; 00658 00659 // get shapefile filename 00660 QString qfname = QFileDialog::getOpenFileName(QString::null, "*.shp", 0, "Open Glacier IDs Shapefile"); 00661 if ( qfname.isNull() ) 00662 return; 00663 fname = (const char*)qfname; 00664 00665 // load shapefile 00666 SHPHandle hshp = SHPOpen( fname.c_str(), "rb" ); 00667 if ( !hshp ) { 00668 return; 00669 } 00670 00671 SHPGetInfo( hshp, &nrec, NULL, NULL, NULL ); 00672 SHPObject *shpobj ; 00673 00674 00675 // load DBF file 00676 DBFHandle hdbf ; 00677 hdbf = DBFOpen( fname.c_str(), "rb" ); 00678 00679 int ndbfrec = DBFGetRecordCount( hdbf ); 00680 int dbffields = DBFGetFieldCount( hdbf ) ; 00681 00682 // walk through all records in shapefile 00683 for ( int igid = 0 ; igid < nrec ; igid++ ) { 00684 Node n; 00685 GlacierIDDef gid; 00686 int curdbffield = -1 ; 00687 00688 // skip this record if there's too many or too few vertices 00689 shpobj = SHPReadObject( hshp, igid ); 00690 if ( shpobj->nVertices != 1 ) 00691 continue; 00692 00693 // read from DBF file if there's a record for current point 00694 if (ndbfrec > 0 && igid < ndbfrec) { 00695 00696 if (dbffields > 0) { 00697 00698 char fldName [12] ; 00699 int fldWidth ; 00700 int fldDecimals ; 00701 DBFFieldType fldType ; 00702 std::string tempstr ; 00703 00704 curdbffield = DBFGetFieldIndex ( hdbf, "name" ) ; 00705 if (curdbffield >= 0 && !DBFIsAttributeNULL(hdbf, igid, curdbffield)) { 00706 fldType = DBFGetFieldInfo ( hdbf, curdbffield, fldName, &fldWidth, &fldDecimals ) ; 00707 switch (fldType) { 00708 case (FTDouble): 00709 case (FTInteger): 00710 case (FTString): 00711 gid.mName = DBFReadStringAttribute( hdbf, igid, curdbffield ); 00712 break ; 00713 default: break ; 00714 } 00715 } 00716 00717 curdbffield = DBFGetFieldIndex ( hdbf, "prim_class" ) ; 00718 if (curdbffield >= 0 && !DBFIsAttributeNULL(hdbf, igid, curdbffield)) { 00719 fldType = DBFGetFieldInfo ( hdbf, curdbffield, fldName, &fldWidth, &fldDecimals ) ; 00720 switch (fldType) { 00721 case (FTDouble): 00722 case (FTInteger): 00723 case (FTString): 00724 tempstr = DBFReadStringAttribute( hdbf, igid, curdbffield ); 00725 if (tempstr.empty()) { 00726 gid.mPrimCsfn = -1 ; 00727 break ; 00728 } 00729 gid.mPrimCsfn = findIndexOfIdOrValue( tempstr, GLIMSGlobals::mGlbPrimCsfn ); 00730 if (gid.mPrimCsfn > 0) { 00731 gid.mPrimCsfn = atoi( (GLIMSGlobals::mGlbPrimCsfn[gid.mPrimCsfn].id).c_str() ) ; 00732 } 00733 else { 00734 gid.mPrimCsfn = -1 ; 00735 } 00736 break ; 00737 default: break ; 00738 } 00739 } 00740 00741 curdbffield = DBFGetFieldIndex ( hdbf, "form" ) ; 00742 if (curdbffield >= 0 && !DBFIsAttributeNULL(hdbf, igid, curdbffield)) { 00743 fldType = DBFGetFieldInfo ( hdbf, curdbffield, fldName, &fldWidth, &fldDecimals ) ; 00744 switch (fldType) { 00745 case (FTDouble): 00746 case (FTInteger): 00747 case (FTString): 00748 tempstr = DBFReadStringAttribute( hdbf, igid, curdbffield ); 00749 if (tempstr.empty()) { 00750 gid.mForm = -1 ; 00751 break ; 00752 } 00753 gid.mForm = findIndexOfIdOrValue( tempstr, GLIMSGlobals::mGlbForm ); 00754 if (gid.mForm > 0) { 00755 gid.mForm = atoi( (GLIMSGlobals::mGlbPrimCsfn[gid.mForm].id).c_str() ) ; 00756 } 00757 else { 00758 gid.mForm = -1 ; 00759 } 00760 break ; 00761 default: break ; 00762 } 00763 } 00764 00765 curdbffield = DBFGetFieldIndex ( hdbf, "front_char" ) ; 00766 if (curdbffield >= 0 && !DBFIsAttributeNULL(hdbf, igid, curdbffield)) { 00767 fldType = DBFGetFieldInfo ( hdbf, curdbffield, fldName, &fldWidth, &fldDecimals ) ; 00768 switch (fldType) { 00769 case (FTDouble): 00770 case (FTInteger): 00771 case (FTString): 00772 tempstr = DBFReadStringAttribute( hdbf, igid, curdbffield ); 00773 if (tempstr.empty()) { 00774 gid.mFChar = -1 ; 00775 break ; 00776 } 00777 gid.mFChar = findIndexOfIdOrValue( tempstr, GLIMSGlobals::mGlbFrntChar ); 00778 if (gid.mFChar > 0) { 00779 gid.mFChar = atoi( (GLIMSGlobals::mGlbPrimCsfn[gid.mFChar].id).c_str() ) ; 00780 } 00781 else { 00782 gid.mFChar = -1 ; 00783 } 00784 break ; 00785 default: break ; 00786 } 00787 } 00788 00789 curdbffield = DBFGetFieldIndex ( hdbf, "long_char" ) ; 00790 if (curdbffield >= 0 && !DBFIsAttributeNULL(hdbf, igid, curdbffield)) { 00791 fldType = DBFGetFieldInfo ( hdbf, curdbffield, fldName, &fldWidth, &fldDecimals ) ; 00792 switch (fldType) { 00793 case (FTDouble): 00794 case (FTInteger): 00795 case (FTString): 00796 tempstr = DBFReadStringAttribute( hdbf, igid, curdbffield ); 00797 if (tempstr.empty()) { 00798 gid.mLChar = -1 ; 00799 break ; 00800 } 00801 gid.mLChar = findIndexOfIdOrValue( tempstr, GLIMSGlobals::mGlbLonChar ); 00802 if (gid.mLChar > 0) { 00803 gid.mLChar = atoi( (GLIMSGlobals::mGlbPrimCsfn[gid.mLChar].id).c_str() ) ; 00804 } 00805 else { 00806 gid.mLChar = -1 ; 00807 } 00808 break ; 00809 default: break ; 00810 } 00811 } 00812 00813 curdbffield = DBFGetFieldIndex ( hdbf, "mass_src" ) ; 00814 if (curdbffield >= 0 && !DBFIsAttributeNULL(hdbf, igid, curdbffield)) { 00815 fldType = DBFGetFieldInfo ( hdbf, curdbffield, fldName, &fldWidth, &fldDecimals ) ; 00816 switch (fldType) { 00817 case (FTDouble): 00818 case (FTInteger): 00819 case (FTString): 00820 tempstr = DBFReadStringAttribute( hdbf, igid, curdbffield ); 00821 if (tempstr.empty()) { 00822 gid.mDomMassSrc = -1 ; 00823 break ; 00824 } 00825 gid.mDomMassSrc = findIndexOfIdOrValue( tempstr, GLIMSGlobals::mGlbDomMassSrc ); 00826 if (gid.mDomMassSrc > 0) { 00827 gid.mDomMassSrc = atoi( (GLIMSGlobals::mGlbPrimCsfn[gid.mDomMassSrc].id).c_str() ) ; 00828 } 00829 else { 00830 gid.mDomMassSrc = -1 ; 00831 } 00832 break ; 00833 default: break ; 00834 } 00835 } 00836 00837 curdbffield = DBFGetFieldIndex ( hdbf, "tongue_act" ) ; 00838 if (curdbffield >= 0 && !DBFIsAttributeNULL(hdbf, igid, curdbffield)) { 00839 fldType = DBFGetFieldInfo ( hdbf, curdbffield, fldName, &fldWidth, &fldDecimals ) ; 00840 switch (fldType) { 00841 case (FTDouble): 00842 case (FTInteger): 00843 case (FTString): 00844 tempstr = DBFReadStringAttribute( hdbf, igid, curdbffield ); 00845 if (tempstr.empty()) { 00846 gid.mTongueAct = -1 ; 00847 break ; 00848 } 00849 gid.mTongueAct = findIndexOfIdOrValue( tempstr, GLIMSGlobals::mGlbTongueAct ); 00850 if (gid.mTongueAct > 0) { 00851 gid.mTongueAct = atoi( (GLIMSGlobals::mGlbPrimCsfn[gid.mTongueAct].id).c_str() ) ; 00852 } 00853 else { 00854 gid.mTongueAct = -1 ; 00855 } 00856 break ; 00857 default: break ; 00858 } 00859 } 00860 00861 curdbffield = DBFGetFieldIndex ( hdbf, "width_m" ) ; 00862 if (curdbffield >= 0 && !DBFIsAttributeNULL(hdbf, igid, curdbffield)) { 00863 fldType = DBFGetFieldInfo ( hdbf, curdbffield, fldName, &fldWidth, &fldDecimals ) ; 00864 switch (fldType) { 00865 case (FTDouble): 00866 case (FTInteger): 00867 gid.mWidth = (float)DBFReadDoubleAttribute ( hdbf, igid, curdbffield ); 00868 break ; 00869 case (FTString): 00870 gid.mWidth = strtod(DBFReadStringAttribute ( hdbf, igid, curdbffield ), NULL) ; 00871 break ; 00872 default: break ; 00873 } 00874 } 00875 00876 curdbffield = DBFGetFieldIndex ( hdbf, "length_m" ) ; 00877 if (curdbffield >= 0 && !DBFIsAttributeNULL(hdbf, igid, curdbffield)) { 00878 fldType = DBFGetFieldInfo ( hdbf, curdbffield, fldName, &fldWidth, &fldDecimals ) ; 00879 switch (fldType) { 00880 case (FTDouble): 00881 case (FTInteger): 00882 gid.mLength = (float)DBFReadDoubleAttribute ( hdbf, igid, curdbffield ); 00883 break ; 00884 case (FTString): 00885 gid.mLength = strtod(DBFReadStringAttribute ( hdbf, igid, curdbffield ), NULL) ; 00886 break ; 00887 default: break ; 00888 } 00889 } 00890 00891 curdbffield = DBFGetFieldIndex ( hdbf, "area_km2" ) ; 00892 if (curdbffield >= 0 && !DBFIsAttributeNULL(hdbf, igid, curdbffield)) { 00893 fldType = DBFGetFieldInfo ( hdbf, curdbffield, fldName, &fldWidth, &fldDecimals ) ; 00894 switch (fldType) { 00895 case (FTDouble): 00896 case (FTInteger): 00897 gid.mArea = (float)DBFReadDoubleAttribute ( hdbf, igid, curdbffield ); 00898 break ; 00899 case (FTString): 00900 gid.mArea = strtod(DBFReadStringAttribute ( hdbf, igid, curdbffield ), NULL) ; 00901 break ; 00902 default: break ; 00903 } 00904 } 00905 00906 curdbffield = DBFGetFieldIndex ( hdbf, "abarea_km2" ) ; 00907 if (curdbffield >= 0 && !DBFIsAttributeNULL(hdbf, igid, curdbffield)) { 00908 fldType = DBFGetFieldInfo ( hdbf, curdbffield, fldName, &fldWidth, &fldDecimals ) ; 00909 switch (fldType) { 00910 case (FTDouble): 00911 case (FTInteger): 00912 gid.mAbzoneArea = (float)DBFReadDoubleAttribute ( hdbf, igid, curdbffield ); 00913 break ; 00914 case (FTString): 00915 gid.mAbzoneArea = strtod(DBFReadStringAttribute ( hdbf, igid, curdbffield ), NULL) ; 00916 break ; 00917 default: break ; 00918 } 00919 } 00920 00921 curdbffield = DBFGetFieldIndex ( hdbf, "speed_myr" ) ; 00922 if (curdbffield >= 0 && !DBFIsAttributeNULL(hdbf, igid, curdbffield)) { 00923 fldType = DBFGetFieldInfo ( hdbf, curdbffield, fldName, &fldWidth, &fldDecimals ) ; 00924 switch (fldType) { 00925 case (FTDouble): 00926 case (FTInteger): 00927 gid.mSpeed = (float)DBFReadDoubleAttribute ( hdbf, igid, curdbffield ); 00928 break ; 00929 case (FTString): 00930 gid.mSpeed = strtod(DBFReadStringAttribute ( hdbf, igid, curdbffield ), NULL) ; 00931 break ; 00932 default: break ; 00933 } 00934 } 00935 00936 curdbffield = DBFGetFieldIndex ( hdbf, "snwln_elev" ) ; 00937 if (curdbffield >= 0 && !DBFIsAttributeNULL(hdbf, igid, curdbffield)) { 00938 fldType = DBFGetFieldInfo ( hdbf, curdbffield, fldName, &fldWidth, &fldDecimals ) ; 00939 switch (fldType) { 00940 case (FTDouble): 00941 case (FTInteger): 00942 gid.mSnowLineElev = (float)DBFReadDoubleAttribute ( hdbf, igid, curdbffield ); 00943 break ; 00944 case (FTString): 00945 gid.mSnowLineElev = strtod(DBFReadStringAttribute ( hdbf, igid, curdbffield ), NULL) ; 00946 break ; 00947 default: break ; 00948 } 00949 } 00950 00951 curdbffield = DBFGetFieldIndex ( hdbf, "wgms_id" ) ; 00952 if (curdbffield >= 0 && !DBFIsAttributeNULL(hdbf, igid, curdbffield)) { 00953 fldType = DBFGetFieldInfo ( hdbf, curdbffield, fldName, &fldWidth, &fldDecimals ) ; 00954 switch (fldType) { 00955 case (FTString): 00956 gid.mWGMSID = DBFReadStringAttribute ( hdbf, igid, curdbffield ); 00957 break ; 00958 default: break ; 00959 } 00960 } 00961 00962 curdbffield = DBFGetFieldIndex ( hdbf, "local_id" ) ; 00963 if (curdbffield >= 0 && !DBFIsAttributeNULL(hdbf, igid, curdbffield)) { 00964 fldType = DBFGetFieldInfo ( hdbf, curdbffield, fldName, &fldWidth, &fldDecimals ) ; 00965 switch (fldType) { 00966 case (FTString): 00967 gid.mLocalID = DBFReadStringAttribute ( hdbf, igid, curdbffield ); 00968 break ; 00969 default: break ; 00970 } 00971 } 00972 00973 curdbffield = DBFGetFieldIndex ( hdbf, "parent_id" ) ; 00974 if (curdbffield >= 0 && !DBFIsAttributeNULL(hdbf, igid, curdbffield)) { 00975 fldType = DBFGetFieldInfo ( hdbf, curdbffield, fldName, &fldWidth, &fldDecimals ) ; 00976 switch (fldType) { 00977 case (FTString): 00978 gid.mParentID = DBFReadStringAttribute ( hdbf, igid, curdbffield ); 00979 break ; 00980 default: break ; 00981 } 00982 } 00983 00984 curdbffield = DBFGetFieldIndex ( hdbf, "ela" ) ; 00985 if (curdbffield >= 0 && !DBFIsAttributeNULL(hdbf, igid, curdbffield)) { 00986 fldType = DBFGetFieldInfo ( hdbf, curdbffield, fldName, &fldWidth, &fldDecimals ) ; 00987 switch (fldType) { 00988 case (FTDouble): 00989 case (FTInteger): 00990 gid.mELA = (float)DBFReadDoubleAttribute ( hdbf, igid, curdbffield ); 00991 break ; 00992 case (FTString): 00993 gid.mELA = strtod(DBFReadStringAttribute ( hdbf, igid, curdbffield ), NULL) ; 00994 break ; 00995 default: break ; 00996 } 00997 } 00998 00999 curdbffield = DBFGetFieldIndex ( hdbf, "ela_desc" ) ; 01000 if (curdbffield >= 0 && !DBFIsAttributeNULL(hdbf, igid, curdbffield)) { 01001 fldType = DBFGetFieldInfo ( hdbf, curdbffield, fldName, &fldWidth, &fldDecimals ) ; 01002 switch (fldType) { 01003 case (FTDouble): 01004 case (FTInteger): 01005 case (FTString): 01006 gid.mELADesc = DBFReadStringAttribute ( hdbf, igid, curdbffield ); 01007 break ; 01008 default: break ; 01009 } 01010 } 01011 } 01012 } 01013 01014 gid.mLon = shpobj->padfX[0]; 01015 gid.mLat = shpobj->padfY[0]; 01016 // gid.mHeight = shpobj->padfZ[0]; // <---- NOT SUPPORTING ELEVATION YET 01017 01018 SHPDestroyObject( shpobj ); 01019 01020 mGData->getGIDData().addGID( gid ); 01021 01022 } 01023 01024 SHPClose( hshp ); 01025 DBFClose( hdbf ); 01026 01027 01028 // TODO: check these - are they correct for this function? 01029 mOpen = true; 01030 mViewSet->repaintViews() ; 01031 mConfigDlg->refreshAll() ; 01032 emit finishedIngestion() ; 01033 01034 } 01035 01036 void GLIMSProject::importSegmentsFromShapefile( ) { 01037 int nrec = 0, ndbfrec = 0, dbffields = 0 ; 01038 int indgid = -1, indldf = -1, i = 0 ; 01039 std::string fname; 01040 01041 // get shapefile filename 01042 QString qfname = QFileDialog::getOpenFileName(QString::null, "*.shp", 0, "Open Segments Shapefile"); 01043 if ( qfname.isNull() ) 01044 return; 01045 fname = (const char*)qfname; 01046 01047 // load shapefile 01048 SHPHandle hshp = SHPOpen( fname.c_str(), "rb" ); 01049 if ( !hshp ) { 01050 return; 01051 } 01052 01053 SHPGetInfo( hshp, &nrec, NULL, NULL, NULL ); 01054 01055 01056 SHPObject *shpobj ; 01057 01058 // ----------------------------- 01059 // DBF FILE READ 01060 01061 DBFHandle hdbf ; 01062 hdbf = DBFOpen( fname.c_str(), "rb" ); 01063 01064 ndbfrec = DBFGetRecordCount( hdbf ); 01065 dbffields = DBFGetFieldCount( hdbf ) ; 01066 bool ldfFound = false ; 01067 std::string gidid ; 01068 01069 // iterate through each object in the shape/dbf files 01070 for ( int irec=0; irec < nrec; irec++ ) { 01071 01072 // read from DBF file if there's a record for current shape 01073 if (ndbfrec > 0 && irec < ndbfrec) { 01074 std::string glactype, type, label; 01075 std::string lmat, rmat, lfeat, rfeat ; 01076 int stylecnt = 0; 01077 gidid = "" ; 01078 01079 // for current record in the segments DBF file, 01080 // read the attributes for generating line definitions 01081 LineDef ldf, DEFAULT_LDF; 01082 01083 int curdbffield = -1 ; 01084 01085 if (dbffields > 0) { 01086 // read attributes, load new line definition (ldf) where data can be added directly 01087 char fldName [12] ; 01088 int fldWidth ; 01089 int fldDecimals ; 01090 DBFFieldType fldType ; 01091 01092 curdbffield = DBFGetFieldIndex ( hdbf, "category" ) ; 01093 if (curdbffield >= 0 && !DBFIsAttributeNULL(hdbf, irec, curdbffield)) { 01094 ldfFound = true ; 01095 fldType = DBFGetFieldInfo ( hdbf, curdbffield, fldName, &fldWidth, &fldDecimals ) ; 01096 switch (fldType) { 01097 case (FTDouble): 01098 case (FTInteger): 01099 case (FTString): 01100 glactype = DBFReadStringAttribute( hdbf, irec, curdbffield ); 01101 break ; 01102 default: break ; 01103 } 01104 ldf.mGlacType = findIndexOfIdOrValue( glactype, GLIMSGlobals::mGlbGlacTypes ); 01105 } 01106 01107 curdbffield = DBFGetFieldIndex ( hdbf, "ID" ) ; 01108 if (curdbffield >= 0 && !DBFIsAttributeNULL(hdbf, irec, curdbffield)) { 01109 ldfFound = true ; 01110 fldType = DBFGetFieldInfo ( hdbf, curdbffield, fldName, &fldWidth, &fldDecimals ) ; 01111 switch (fldType) { 01112 case (FTDouble): 01113 case (FTInteger): 01114 case (FTString): 01115 gidid = DBFReadStringAttribute( hdbf, irec, curdbffield ); 01116 break ; 01117 default: break ; 01118 } 01119 } 01120 01121 curdbffield = DBFGetFieldIndex ( hdbf, "type" ) ; 01122 if (curdbffield >= 0 && !DBFIsAttributeNULL(hdbf, irec, curdbffield)) { 01123 ldfFound = true ; 01124 fldType = DBFGetFieldInfo ( hdbf, curdbffield, fldName, &fldWidth, &fldDecimals ) ; 01125 switch (fldType) { 01126 case (FTDouble): 01127 case (FTInteger): 01128 case (FTString): 01129 type = DBFReadStringAttribute( hdbf, irec, curdbffield ); 01130 break ; 01131 default: break ; 01132 } 01133 ldf.mType = findIndexOfIdOrValue( type, GLIMSGlobals::mGlbTypes ); 01134 } 01135 01136 curdbffield = DBFGetFieldIndex ( hdbf, "label" ) ; 01137 if (curdbffield >= 0 && !DBFIsAttributeNULL(hdbf, irec, curdbffield)) { 01138 ldfFound = true ; 01139 fldType = DBFGetFieldInfo ( hdbf, curdbffield, fldName, &fldWidth, &fldDecimals ) ; 01140 switch (fldType) { 01141 case (FTDouble): 01142 case (FTInteger): 01143 case (FTString): 01144 label = DBFReadStringAttribute( hdbf, irec, curdbffield ); 01145 break ; 01146 default: break ; 01147 } 01148 ldf.mLabel = findIndexOfIdOrValue( label, GLIMSGlobals::mGlbLbls ); 01149 } 01150 01151 curdbffield = DBFGetFieldIndex ( hdbf, "loc_unc_x" ) ; 01152 if (curdbffield >= 0 && !DBFIsAttributeNULL(hdbf, irec, curdbffield)) { 01153 ldfFound = true ; 01154 fldType = DBFGetFieldInfo ( hdbf, curdbffield, fldName, &fldWidth, &fldDecimals ) ; 01155 switch (fldType) { 01156 case (FTInteger): ; 01157 case (FTDouble): 01158 ldf.mLXUncert = (float)DBFReadDoubleAttribute( hdbf, irec, curdbffield ); 01159 break ; 01160 case (FTString): 01161 ldf.mLXUncert = strtod(DBFReadStringAttribute ( hdbf, irec, curdbffield ), NULL) ; 01162 break ; 01163 default: break ; 01164 } 01165 } 01166 01167 curdbffield = DBFGetFieldIndex ( hdbf, "loc_unc_y" ) ; 01168 if (curdbffield >= 0 && !DBFIsAttributeNULL(hdbf, irec, curdbffield)) { 01169 ldfFound = true ; 01170 fldType = DBFGetFieldInfo ( hdbf, curdbffield, fldName, &fldWidth, &fldDecimals ) ; 01171 switch (fldType) { 01172 case (FTInteger): ; 01173 case (FTDouble): 01174 ldf.mLYUncert = (float)DBFReadDoubleAttribute( hdbf, irec, curdbffield ); 01175 break ; 01176 case (FTString): 01177 ldf.mLYUncert = strtod(DBFReadStringAttribute ( hdbf, irec, curdbffield ), NULL) ; 01178 break ; 01179 default: break ; 01180 } 01181 } 01182 01183 curdbffield = DBFGetFieldIndex ( hdbf, "glob_unc_x" ) ; 01184 if (curdbffield >= 0 && !DBFIsAttributeNULL(hdbf, irec, curdbffield)) { 01185 ldfFound = true ; 01186 fldType = DBFGetFieldInfo ( hdbf, curdbffield, fldName, &fldWidth, &fldDecimals ) ; 01187 switch (fldType) { 01188 case (FTInteger): ; 01189 case (FTDouble): 01190 ldf.mGXUncert = (float)DBFReadDoubleAttribute( hdbf, irec, curdbffield ); 01191 break ; 01192 case (FTString): 01193 ldf.mGXUncert = strtod(DBFReadStringAttribute ( hdbf, irec, curdbffield ), NULL) ; 01194 break ; 01195 default: break ; 01196 } 01197 } 01198 01199 curdbffield = DBFGetFieldIndex ( hdbf, "glob_unc_y" ) ; 01200 if (curdbffield >= 0 && !DBFIsAttributeNULL(hdbf, irec, curdbffield)) { 01201 ldfFound = true ; 01202 fldType = DBFGetFieldInfo ( hdbf, curdbffield, fldName, &fldWidth, &fldDecimals ) ; 01203 switch (fldType) { 01204 case (FTInteger): ; 01205 case (FTDouble): 01206 ldf.mGYUncert = (float)DBFReadDoubleAttribute( hdbf, irec, curdbffield ); 01207 break ; 01208 case (FTString): 01209 ldf.mGYUncert = strtod(DBFReadStringAttribute ( hdbf, irec, curdbffield ), NULL) ; 01210 break ; 01211 default: break ; 01212 } 01213 } 01214 01215 curdbffield = DBFGetFieldIndex ( hdbf, "left_mat" ) ; 01216 if (curdbffield >= 0 && !DBFIsAttributeNULL(hdbf, irec, curdbffield)) { 01217 ldfFound = true ; 01218 fldType = DBFGetFieldInfo ( hdbf, curdbffield, fldName, &fldWidth, &fldDecimals ) ; 01219 switch (fldType) { 01220 case (FTDouble): 01221 case (FTInteger): 01222 case (FTString): 01223 lmat = DBFReadStringAttribute( hdbf, irec, curdbffield ); 01224 break ; 01225 default: break ; 01226 } 01227 ldf.mLMat = findIndexOfIdOrValue( lmat, GLIMSGlobals::mGlbMDF ); 01228 } 01229 01230 curdbffield = DBFGetFieldIndex ( hdbf, "right_mat" ) ; 01231 if (curdbffield >= 0 && !DBFIsAttributeNULL(hdbf, irec, curdbffield)) { 01232 ldfFound = true ; 01233 fldType = DBFGetFieldInfo ( hdbf, curdbffield, fldName, &fldWidth, &fldDecimals ) ; 01234 switch (fldType) { 01235 case (FTDouble): 01236 case (FTInteger): 01237 case (FTString): 01238 rmat = DBFReadStringAttribute( hdbf, irec, curdbffield ); 01239 break ; 01240 default: break ; 01241 } 01242 ldf.mRMat = findIndexOfIdOrValue( rmat, GLIMSGlobals::mGlbMDF ); 01243 } 01244 01245 curdbffield = DBFGetFieldIndex ( hdbf, "left_feat" ) ; 01246 if (curdbffield >= 0 && !DBFIsAttributeNULL(hdbf, irec, curdbffield)) { 01247 ldfFound = true ; 01248 fldType = DBFGetFieldInfo ( hdbf, curdbffield, fldName, &fldWidth, &fldDecimals ) ; 01249 switch (fldType) { 01250 case (FTDouble): 01251 case (FTInteger): 01252 case (FTString): 01253 lfeat = DBFReadStringAttribute( hdbf, irec, curdbffield ); 01254 break ; 01255 default: break ; 01256 } 01257 ldf.mLFeature = findIndexOfIdOrValue( lfeat, GLIMSGlobals::mGlbFtrs ); 01258 } 01259 01260 curdbffield = DBFGetFieldIndex ( hdbf, "right_feat" ) ; 01261 if (curdbffield >= 0 && !DBFIsAttributeNULL(hdbf, irec, curdbffield)) { 01262 ldfFound = true ; 01263 fldType = DBFGetFieldInfo ( hdbf, curdbffield, fldName, &fldWidth, &fldDecimals ) ; 01264 switch (fldType) { 01265 case (FTString): 01266 case (FTDouble): 01267 case (FTInteger): 01268 rfeat = DBFReadStringAttribute( hdbf, irec, curdbffield ); 01269 break ; 01270 default: break ; 01271 } 01272 ldf.mRFeature = findIndexOfIdOrValue( rfeat, GLIMSGlobals::mGlbFtrs ); 01273 } 01274 01275 01276 if (ldfFound) { 01277 // get the line definition set 01278 LineDefSet &defset = mGData->getLineData().getLDFSet(); 01279 01280 // look for a matching definition in existing line definition set, if one exists 01281 // (if not, i>=defset.size, and next block below will execute) 01282 for ( i = 0; i < (int)defset.size(); i++ ) { 01283 if ( defset[i] == ldf ) { 01284 indldf = i ; 01285 break; 01286 } 01287 } 01288 // if this is a new line definition, apply visual style to line definition 01289 if ( i >= (int)defset.size() && ldf != DEFAULT_LDF ) { 01290 ldf.mColor = stylecnt % 8; 01291 ldf.mWidth = 1+ ( (stylecnt%24) / 8); 01292 ldf.mStyle = 1+ ( (stylecnt%72) / 24); 01293 mGData->getLineData().addLDF( ldf ); 01294 indldf = i; 01295 stylecnt++; 01296 } 01297 } 01298 } 01299 01300 } 01301 01302 // find associated glacier ID 01303 if (!gidid.empty()) { 01304 // look for existing glacier ID 01305 std::vector<GlacierIDDef> &giddefset = mGData->getGIDData().getDefSet(); 01306 for ( i = 0; i < (int)giddefset.size(); i++ ) { 01307 if ( gidid == giddefset[i].toString() ) { 01308 indgid = i ; 01309 } 01310 } 01311 // if no existing glacier ID, create 01312 if (indgid == -1) { 01313 QString newstr = gidid.c_str() ; 01314 mGData->getGIDData().addGID ( GlacierIDDef(newstr) ) ; 01315 // repeat search 01316 giddefset = mGData->getGIDData().getDefSet(); 01317 for ( i = 0 ; i < (int)giddefset.size() ; i++ ) { 01318 if ( gidid == giddefset[i].toString() ) { 01319 indgid = i ; 01320 } 01321 } 01322 } 01323 } 01324 01325 01326 01327 // read new line from shapefile 01328 shpobj = SHPReadObject( hshp, irec ); 01329 if ( !shpobj || shpobj->nVertices <= 0 ) 01330 continue; 01331 01332 // start reading current record (read line node from shapefile) 01333 Node &n = *(new Node) ; 01334 n.x = shpobj->padfX[0]; 01335 n.y = shpobj->padfY[0]; 01336 n.z = shpobj->padfZ[0]; 01337 01338 // create new line from first node read from this record 01339 mGData->getLineData().addLineLL( n ); 01340 // get new line from mGData so more nodes can be added 01341 int iline = mGData->getLineData().size()-1; 01342 01343 // continue reading nodes 01344 for ( int inode = 1 ; inode < shpobj->nVertices ; inode++ ) { 01345 Node &n = *(new Node) ; 01346 n.x = shpobj->padfX[inode]; 01347 n.y = shpobj->padfY[inode]; 01348 n.z = shpobj->padfZ[inode]; 01349 01350 mGData->getLineData().addLineNodeLL( n, iline ); 01351 } 01352 01353 // apply line definition to new line if a line definition was found 01354 if (ldfFound && indldf >= 0) { 01355 mGData->getLineData().setLDF( iline, indldf ); 01356 } 01357 mGData->getLineData().setGID( iline, indgid ); 01358 01359 // end of reading record, clean-up for next round 01360 ldfFound = false ; 01361 indgid = -1 ; 01362 SHPDestroyObject( shpobj ); 01363 01364 // ----------------------------- 01365 } 01366 01367 SHPClose( hshp ); 01368 DBFClose( hdbf ); 01369 01370 // TODO: check these - are they correct for this function? 01371 mOpen = true; 01372 mViewSet->repaintViews() ; 01373 mConfigDlg->refreshAll() ; 01374 emit finishedIngestion() ; 01375 01376 01377 } 01378 01379 QString GLIMSProject::importGLIMSIngestImageInfo( ) { 01380 01381 // function vars 01382 std::string prefix = ""; 01383 std::string dir; 01384 std::string fname; 01385 DBFHandle hdbf; 01386 int pos; 01387 ImageInf imginf; 01388 01389 const int NSHPFILES = 4; 01390 const std::string shp_names[] = { 01391 "images", 01392 "glaciers", 01393 "segments", 01394 "session" 01395 }; 01396 01397 // GET ONE OF THE SHAPEFILES OF THE SET 01398 QString dirstr = QFileDialog::getOpenFileName(); 01399 01400 if ( dirstr.isNull() ) { 01401 mOpen = false; 01402 return "" ; 01403 } 01404 01405 01406 // GET THE PREFIX OF THE SHAPEFILE( AKA PROJECT NAME ) 01407 prefix = (const char*)dirstr; 01411 pos = prefix.find_last_of( '\\' ); 01412 if ( pos == -1 ) { 01413 pos = prefix.find_last_of( '/' ); 01414 } 01415 dir = prefix.substr( 0, pos + 1 ); 01416 01417 prefix = prefix.substr( pos + 1, prefix.length() - pos ); 01418 for ( int i=0; i < NSHPFILES; i++ ) { 01419 if ( (pos = prefix.find( shp_names[i] )) != -1 ) { 01420 prefix = prefix.substr( 0, pos ); 01421 break; 01422 } 01423 } 01424 01425 // CHECK SHAPFILE SET OUT. IF THIS RETURNS TRUE, THEN 01426 // THERE'S NO REASON TO TEST THE SHAPEFILES FOR BEING OPEN 01427 // OR COMPLETE LATER. 01429 if ( !checkShapefileSet( dir + prefix ) ) { 01430 QString msgdir = dir.c_str() ; 01431 QString msgprf = prefix.c_str() ; 01432 QString msg = "Invalid shapefile dataset\n" + msgdir + msgprf ; 01433 QMessageBox::information( NULL, 01434 "Ingest Import Error", 01435 msg ); 01436 mOpen = false; 01437 return "" ; 01438 } 01439 01440 //------------------------------------- 01441 // LOAD THE IMAGES SHAPE FILE 01442 fname = dir + "images.shp"; 01443 hdbf = DBFOpen( fname.c_str(), "rb" ); 01444 01445 // 2007-06-14 dls - Removed image ID references and functions 01446 //imginf.mImageID = DBFReadStringAttribute( hdbf, 0, 0 ); 01447 imginf.mInstID = DBFReadStringAttribute( hdbf, 0, 1 ); 01448 imginf.mOrigID = DBFReadStringAttribute( hdbf, 0, 2 ); 01449 imginf.mLocURL = DBFReadStringAttribute( hdbf, 0, 3 ); 01450 imginf.mAquiDateTime = DBFReadStringAttribute( hdbf, 0, 4 ); 01451 imginf.mCenterLon = DBFReadDoubleAttribute( hdbf, 0, 5 ); 01452 imginf.mCenterLat = DBFReadDoubleAttribute( hdbf, 0, 6 ); 01453 imginf.mCenterLonUnc = DBFReadDoubleAttribute( hdbf, 0, 7 ); 01454 imginf.mCenterLatUnc = DBFReadDoubleAttribute( hdbf, 0, 8 ); 01455 imginf.mImageAzim = DBFReadDoubleAttribute( hdbf, 0, 9 ); 01456 imginf.mCloudPct = DBFReadDoubleAttribute( hdbf, 0, 10 ); 01457 imginf.mSunAzim = DBFReadDoubleAttribute( hdbf, 0, 11 ); 01458 imginf.mSunElev = DBFReadDoubleAttribute( hdbf, 0, 12 ); 01459 imginf.mInstrument_zenith = DBFReadDoubleAttribute( hdbf, 0, 13 ); 01460 imginf.mInstrument_azimuth = DBFReadDoubleAttribute( hdbf, 0, 14 ); 01461 imginf.mProjection = DBFReadStringAttribute( hdbf, 0, 15 ); 01462 01463 DBFClose( hdbf ); 01464 01465 Image *img = Image::openImage( imginf.mLocURL.c_str() ); 01466 01467 while ( img == NULL ) { 01468 std::string imgloc; 01469 int type; 01470 QMessageBox::information( NULL, 01471 "Open Image Error", 01472 "Unable to locate image. Please specify" ); 01473 01474 ImageDlg *imgdlg = new ImageDlg( imgloc, type ); 01475 if ( !imgdlg->exec() ) { 01476 mOpen = false; 01477 delete imgdlg; 01478 return "" ; 01479 } 01480 delete imgdlg; 01481 img = Image::openImage( imgloc, (Image::MultiFileType)type ); 01482 } 01483 01484 setup( img ); 01485 01486 mGData->getImageInf() = imginf; 01487 01488 mLoc = dirstr ; 01489 01490 return dirstr ; 01491 } 01492 01493 void GLIMSProject::importGLIMSIngestData( ) { 01494 // function vars 01495 std::string prefix = ""; 01496 std::string dir; 01497 std::string fname; 01498 DBFHandle hdbf; 01499 SHPHandle hshp; 01500 SHPObject *shpobj; 01501 int pos; 01502 int nrec; 01503 ImageInf imginf; 01504 QString dirstr = mLoc ; 01505 01506 const int NSHPFILES = 4; 01507 const std::string shp_names[] = { 01508 "images", 01509 "glaciers", 01510 "segments", 01511 "session" 01512 }; 01513 01514 if ( dirstr.isNull() ) { 01515 mOpen = false; 01516 return; 01517 } 01518 01519 01520 // GET THE PREFIX OF THE SHAPEFILE( AKA PROJECT NAME ) 01521 prefix = (const char*)dirstr; 01525 pos = prefix.find_last_of( '\\' ); 01526 if ( pos == -1 ) { 01527 pos = prefix.find_last_of( '/' ); 01528 } 01529 dir = prefix.substr( 0, pos + 1 ); 01530 01531 prefix = prefix.substr( pos + 1, prefix.length() - pos ); 01532 for ( int i=0; i < NSHPFILES; i++ ) { 01533 if ( (pos = prefix.find( shp_names[i] )) != -1 ) { 01534 prefix = prefix.substr( 0, pos ); 01535 break; 01536 } 01537 } 01538 01539 // CHECK SHAPFILE SET OUT. IF THIS RETURNS TRUE, THEN 01540 // THERE'S NO REASON TO TEST THE SHAPEFILES FOR BEING OPEN 01541 // OR COMPLETE LATER. 01543 if ( !checkShapefileSet( dir + prefix ) ) { 01544 QString msgdir = dir.c_str() ; 01545 QString msgprf = prefix.c_str() ; 01546 QString msg = "Invalid shapefile dataset\n" + msgdir + msgprf ; 01547 QMessageBox::information( NULL, 01548 "Ingest Import Error", 01549 msg ); 01550 mOpen = false; 01551 return; 01552 } 01553 01554 01555 //------------------------------------- 01556 // LOAD THE SESSION SHAPE FILE 01557 fname = dir + "session.shp"; 01558 hdbf = DBFOpen( fname.c_str(), "rb" ); 01559 Session &ses = mGData->getSession(); 01560 01561 ses.mRC_ID = DBFReadIntegerAttribute( hdbf, 0, 0 ); 01562 ses.mDataSrc = DBFReadStringAttribute ( hdbf, 0, 1 ); 01563 ses.mProcDesc = DBFReadStringAttribute ( hdbf, 0, 2 ); 01564 ses.manlst_surn = DBFReadStringAttribute ( hdbf, 0, 3 ); 01565 ses.manlst_givn = DBFReadStringAttribute ( hdbf, 0, 4 ); 01566 ses.m3d_desc = DBFReadStringAttribute ( hdbf, 0, 5 ); 01567 ses.manaly_time = DBFReadStringAttribute ( hdbf, 0, 6 ); 01568 01569 DBFClose( hdbf ); 01570 01571 01572 //------------------------------------- 01573 // LOAD THE GLACIERS SHAPE FILE 01574 fname = dir + "glaciers.shp"; 01575 hshp = SHPOpen( fname.c_str(), "rb" ); 01576 if ( !hshp ) return; 01577 hdbf = DBFOpen( fname.c_str(), "rb" ); 01578 01579 nrec = DBFGetRecordCount( hdbf ); 01580 for ( int igid=0; igid < nrec; igid++ ) { 01581 Node n; 01582 GlacierIDDef gid; 01583 gid.mName = DBFReadStringAttribute ( hdbf, igid, 1 ); 01584 gid.mPrimCsfn = DBFReadIntegerAttribute( hdbf, igid, 2 ); 01585 gid.mForm = DBFReadIntegerAttribute( hdbf, igid, 3 ); 01586 gid.mFChar = DBFReadIntegerAttribute( hdbf, igid, 4 ); 01587 gid.mLChar = DBFReadIntegerAttribute( hdbf, igid, 5 ); 01588 gid.mDomMassSrc = DBFReadIntegerAttribute( hdbf, igid, 6 ); 01589 gid.mTongueAct = DBFReadIntegerAttribute( hdbf, igid, 7 ); 01590 gid.mWidth = DBFReadDoubleAttribute ( hdbf, igid, 8 ); 01591 gid.mLength = DBFReadDoubleAttribute ( hdbf, igid, 9 ); 01592 gid.mArea = DBFReadDoubleAttribute ( hdbf, igid, 10 ); 01593 gid.mAbzoneArea = DBFReadDoubleAttribute ( hdbf, igid, 11 ); 01594 gid.mSpeed = DBFReadDoubleAttribute ( hdbf, igid, 12 ); 01595 gid.mSnowLineElev = DBFReadDoubleAttribute ( hdbf, igid, 13 ); 01596 gid.mWGMSID = DBFReadStringAttribute ( hdbf, igid, 14 ); 01597 gid.mLocalID = DBFReadStringAttribute ( hdbf, igid, 15 ); 01598 gid.mParentID = DBFReadStringAttribute ( hdbf, igid, 16 ); 01599 01600 // dls 2006-01-07 added grabbing ela, rec status 01601 gid.mELA = DBFReadDoubleAttribute ( hdbf, igid, 17 ); 01602 gid.mELADesc = DBFReadStringAttribute ( hdbf, igid, 18 ); 01603 01604 shpobj = SHPReadObject( hshp, igid ); 01605 if ( shpobj->nVertices < 1 ) 01606 continue; 01607 01608 gid.mLon = shpobj->padfX[0]; 01609 gid.mLat = shpobj->padfY[0]; 01610 // gid.mHeight = shpobj->padfZ[0]; // <---- NOT SUPPORTING ELEVATION YET 01611 01612 SHPDestroyObject( shpobj ); 01613 01614 mGData->getGIDData().addGID( gid ); 01615 01616 } 01617 01618 01619 //------------------------------------- 01620 // LOAD THE SEGMENTS SHAPE FILE( YARG ) 01621 fname = dir + "segments.shp"; 01622 hshp = SHPOpen( fname.c_str(), "rb" ); 01623 if ( !hshp ) 01624 return; 01625 hdbf = DBFOpen( fname.c_str(), "rb" ); 01626 nrec = DBFGetRecordCount( hdbf ); 01627 std::string gidid, glactype, type, label; 01628 std::string lmat, rmat, lfeat, rfeat ; 01629 int stylecnt = 0; 01630 01631 // for each record in the segments DBF file, 01632 // read the attributes for generating line definitions 01633 for ( int ildf = 0; ildf < nrec; ildf++ ) { 01634 int indgid = 0, indldf = 0; 01635 LineDef ldf, DEFAULT_LDF; 01636 01637 // read attributes, load new line definition (ldf) where data can be added directly 01638 glactype = DBFReadStringAttribute( hdbf, ildf, 0 ); 01639 gidid = DBFReadStringAttribute( hdbf, ildf, 1 ); 01640 type = DBFReadStringAttribute( hdbf, ildf, 2 ); 01641 label = DBFReadStringAttribute( hdbf, ildf, 3 ); 01642 ldf.mLXUncert = DBFReadDoubleAttribute( hdbf, ildf, 4 ); 01643 ldf.mLYUncert = DBFReadDoubleAttribute( hdbf, ildf, 5 ); 01644 ldf.mGXUncert = DBFReadDoubleAttribute( hdbf, ildf, 6 ); 01645 ldf.mGYUncert = DBFReadDoubleAttribute( hdbf, ildf, 7 ); 01646 lmat = DBFReadStringAttribute( hdbf, ildf, 8 ); 01647 rmat = DBFReadStringAttribute( hdbf, ildf, 9 ); 01648 lfeat = DBFReadStringAttribute( hdbf, ildf, 10 ); 01649 rfeat = DBFReadStringAttribute( hdbf, ildf, 11 ); 01650 01651 // lookup predefined attributes in globals list, and add to new line definition (ldf) 01652 ldf.mGlacType = findIndex( glactype, GLIMSGlobals::mGlbGlacTypes ); 01653 ldf.mType = findIndex( type, GLIMSGlobals::mGlbTypes ); 01654 ldf.mLabel = findIndex( label, GLIMSGlobals::mGlbLbls ); 01655 ldf.mLMat = findIndex( lmat, GLIMSGlobals::mGlbMDF ); 01656 ldf.mRMat = findIndex( rmat, GLIMSGlobals::mGlbMDF ); 01657 ldf.mLFeature = findIndex( lfeat, GLIMSGlobals::mGlbFtrs ); 01658 ldf.mRFeature = findIndex( rfeat, GLIMSGlobals::mGlbFtrs ); 01659 01660 // get the line definition set 01661 LineDefSet &defset = mGData->getLineData().getLDFSet(); 01662 01663 // look for a matching definition in existing line definition set, if one exists 01664 // (if not, i>=defset.size, and next block below will execute) 01665 int i ; 01666 for ( i = 0; i < (int)defset.size(); i++ ) { 01667 if ( defset[i] == ldf ) { 01668 indldf = i ; 01669 break; 01670 } 01671 } 01672 01673 // if this is a new line definition, apply visual style to line definition 01674 if ( i >= (int)defset.size() && ldf != DEFAULT_LDF ) { 01675 ldf.mColor = stylecnt % 8; 01676 ldf.mWidth = 1+ ( (stylecnt%24) / 8); 01677 ldf.mStyle = 1+ ( (stylecnt%72) / 24); 01678 mGData->getLineData().addLDF( ldf ); 01679 indldf = i; 01680 stylecnt++; 01681 } 01682 01683 // get GID definition set (?) 01684 std::vector<GlacierIDDef> &giddefset = mGData->getGIDData().getDefSet(); 01685 for ( i=0; i < (int)giddefset.size(); i++ ) { 01686 if ( gidid == giddefset[i].toString() ) 01687 indgid = i; 01688 } 01689 01690 // read new line from shapefile 01691 shpobj = SHPReadObject( hshp, ildf ); 01692 if ( !shpobj || shpobj->nVertices <= 0 ) 01693 continue; 01694 01695 // memory leak? see what mGData->getLineData().addLineNodeLL actually does (copy or just grab pointer?) 01696 // Node n ; 01697 Node &n = *(new Node) ; 01698 n.x = shpobj->padfX[0]; 01699 n.y = shpobj->padfY[0]; 01700 n.z = shpobj->padfZ[0]; 01701 mGData->getLineData().addLineLL( n ); 01702 int iline = mGData->getLineData().size()-1; 01703 01704 for ( int inode = 1 ; inode < shpobj->nVertices ; inode++ ) { 01705 // Node n ; 01706 // memory leak? see what mGData->getLineData().addLineNodeLL actually does (copy or just grab pointer?) 01707 Node &n = *(new Node) ; 01708 n.x = shpobj->padfX[inode]; 01709 n.y = shpobj->padfY[inode]; 01710 n.z = shpobj->padfZ[inode]; 01711 01712 mGData->getLineData().addLineNodeLL( n, iline ); 01713 } 01714 01715 // apply GID and line definition to new line 01716 mGData->getLineData().setGID( iline, indgid ); 01717 mGData->getLineData().setLDF( iline, indldf ); 01718 } 01719 01720 mOpen = true; 01721 01722 mViewSet->repaintViews() ; 01723 mConfigDlg->refreshAll() ; 01724 01725 emit finishedIngestion() ; 01726 } 01727 01728 void GLIMSProject::setTimeStamp( ) { 01729 char buf[2560]; 01730 struct tm *t; 01731 const time_t local_time = time( NULL ); 01732 01733 t = gmtime( &local_time ); 01734 if ( t == NULL ) 01735 return; 01736 01737 sprintf( buf, 01738 "%d%02d%02dT%02d%02d%02d-0000", 01739 1900+t->tm_year, 01740 1+t->tm_mon, 01741 t->tm_mday, 01742 t->tm_hour, 01743 t->tm_min, 01744 t->tm_sec ); 01745 01746 mGData->getSession().manaly_time = buf; 01747 } 01748 01749 /* 01750 DBFHandle GLIMSProject::createDBFH( const char* fname, 01751 DBFHeader *head, 01752 int nent ) 01753 { 01754 DBFHandle hDBF = DBFCreate( fname ); 01755 for( int i=0; i < nent; i++ ) 01756 DBFAddField( hDBF, 01757 head[i].fieldName, 01758 head[i].type, 01759 head[i].width, 01760 head[i].nDec ); 01761 01762 return hDBF; 01763 } 01764 */ 01765 01766 bool GLIMSProject::checkShapefileSet( const std::string &prefix ) const { 01767 DBFHandle hdbf; 01768 DBFFieldType type; 01769 char *name = new char[11]; 01770 std::string test1, test2; 01771 int width; 01772 int ndec; 01773 int ncol; 01774 int icol; 01775 01776 DBFHeader imghead[] = { 01777 { "image_id", FTString, 10, 0}, 01778 { "inst_id", FTString, 10, 0}, 01779 { "orig_id", FTString, 50, 0}, 01780 { "imglocurl", FTString, 120, 0}, 01781 { "acq_time", FTString, 35, 0}, 01782 { "imgctrlon", FTDouble, 5, 5}, 01783 { "imgctrlat", FTDouble, 5, 5}, 01784 { "img_lon_unc", FTDouble, 5, 5}, 01785 { "img_lat_unc", FTDouble, 5, 5}, 01786 { "image_azim", FTDouble, 7, 4}, 01787 { "cloud_pct", FTDouble, 3, 9}, 01788 { "sun_azim", FTDouble, 3, 4}, 01789 { "sun_elev", FTDouble, 3, 4}, 01790 { "inst_zen", FTDouble, 3, 4}, 01791 { "inst_azim", FTDouble, 3, 4}, 01792 { "projection", FTString, 30, 0} 01793 }; 01794 ncol = 16; // THE NUMBER OF DBF COLUMNS ABOVE 01795 01796 // open file, fail if it doesn't exist 01797 hdbf = DBFOpen( (prefix + "images.shp").c_str(), "rb" ); 01798 if ( !hdbf ) { 01799 return false; 01800 } 01801 01802 // check data, fail if it's not correct 01803 for ( icol=0; icol < ncol; icol++ ) { 01804 type = DBFGetFieldInfo( hdbf, icol, name, &width, &ndec ); 01805 test1 = name; 01806 test2 = imghead[icol].fieldName; 01807 if ( test1.length() > 10 ) 01808 test1 = test1.substr( 0, 10 ); 01809 if ( test2.length() > 10 ) 01810 test2 = test2.substr( 0, 10 ); 01811 01812 if ( type != imghead[icol].type || 01813 test2 != test1 || 01814 // 2006-01-21 dls Took out width check, some fields are not limited in size 01815 //width != imghead[icol].width || 01816 ndec != imghead[icol].nDec ) { 01817 return false; 01818 } 01819 } 01820 DBFClose( hdbf ); 01821 01822 // TEST ****SESSION.SHP 01823 DBFHeader sesshead[] = { 01824 { "RC_ID", FTInteger, 11, 0}, 01825 { "data_src", FTString, 255, 0}, 01826 { "proc_desc", FTString, 200, 0}, 01827 { "anlst_surn", FTString, 50, 0}, 01828 { "anlst_givn", FTString, 50, 0}, 01829 { "3d_desc", FTString, 200, 0}, 01830 { "analy_time", FTString, 35, 0} 01831 }; 01832 ncol = 7; 01833 01834 // open file, fail if it doesn't exist 01835 hdbf = DBFOpen( (prefix + "session.shp").c_str(), "rb" ); 01836 if ( !hdbf ) { 01837 return false; 01838 } 01839 01840 // check data, fail if it's not correct 01841 for ( icol=0; icol < ncol; icol++ ) { 01842 type = DBFGetFieldInfo( hdbf, icol, name, &width, &ndec ); 01843 test1 = name; 01844 test2 = sesshead[icol].fieldName; 01845 if ( test1.length() > 10 ) 01846 test1 = test1.substr( 0, 10 ); 01847 if ( test2.length() > 10 ) 01848 test2 = test2.substr( 0, 10 ); 01849 01850 if ( type != sesshead[icol].type || 01851 test2 != test1 || 01852 // dls 2006-01-06 -- removed this check, some fields are not limited in size 01853 //width != sesshead[icol].width || 01854 ndec != sesshead[icol].nDec ) { 01855 return false; 01856 } 01857 } 01858 DBFClose( hdbf ); 01859 01860 // TEST ****GLACIERS.SHP 01861 DBFHeader glachead[] = { 01862 { "ID", FTString, 20, 0}, 01863 { "name", FTString, 40, 0}, 01864 { "primclass", FTInteger, 5, 0}, 01865 { "form", FTInteger, 5, 0}, 01866 { "front_char", FTInteger, 5, 0}, 01867 { "long_char", FTInteger, 5, 0}, 01868 { "mass_src", FTInteger, 5, 0}, 01869 { "tongue_act", FTInteger, 5, 0}, 01870 { "width_m", FTDouble, 5, 5}, 01871 { "length_m", FTDouble, 5, 5}, 01872 { "area_km2", FTDouble, 5, 5}, 01873 { "abarea_km2", FTDouble, 5, 5}, 01874 { "speed_myr", FTDouble, 5, 5}, 01875 { "snwln_elev", FTDouble, 5, 5}, 01876 { "wgms_id", FTString, 14, 0}, 01877 { "local_id", FTString, 20, 0}, 01878 { "parent_id", FTString, 20, 0} 01879 }; 01880 ncol = 17; 01881 01882 bool checkStatus = true ; 01883 hdbf = DBFOpen( (prefix + "glaciers.shp").c_str(), "rb" ); 01884 if ( !hdbf ) { 01885 return false; 01886 } 01887 for ( icol=0; icol < ncol; icol++ ) { 01888 type = DBFGetFieldInfo( hdbf, icol, name, &width, &ndec ); 01889 test1 = name; 01890 test2 = glachead[icol].fieldName; 01891 if ( test1.length() > 10 ) 01892 test1 = test1.substr( 0, 10 ); 01893 if ( test2.length() > 10 ) 01894 test2 = test2.substr( 0, 10 ); 01895 01896 if ( type != glachead[icol].type || 01897 test2 != test1 || 01898 // 2006-01-21 dls Took out width check, fields may not be limited in size 01899 //width != glachead[icol].width || 01900 ndec != glachead[icol].nDec ) { 01901 checkStatus = false; 01902 } 01903 } 01904 01905 // check for older version of shapefile 01906 if ( checkStatus == false ) { 01907 // TEST ****GLACIERS.SHP 01908 DBFHeader glacheadRetry[] = { 01909 { "ID", FTString, 20, 0}, 01910 { "name", FTString, 40, 0}, 01911 { "prim_class", FTInteger, 5, 0}, 01912 { "form", FTInteger, 5, 0}, 01913 { "front_char", FTInteger, 5, 0}, 01914 { "long_char", FTInteger, 5, 0}, 01915 { "mass_src", FTInteger, 5, 0}, 01916 { "tongue_act", FTInteger, 5, 0}, 01917 { "width_m", FTDouble, 5, 5}, 01918 { "length_m", FTDouble, 5, 5}, 01919 { "area_km2", FTDouble, 5, 5}, 01920 { "abarea_km2", FTDouble, 5, 5}, 01921 { "speed_myr", FTDouble, 5, 5}, 01922 { "snwln_elev", FTDouble, 5, 5}, 01923 { "wgms_id", FTString, 14, 0}, 01924 { "local_id", FTString, 20, 0}, 01925 { "parent_id", FTString, 20, 0} 01926 }; 01927 ncol = 17; 01928 01929 01930 for ( icol=0; icol < ncol; icol++ ) { 01931 type = DBFGetFieldInfo( hdbf, icol, name, &width, &ndec ); 01932 test1 = name; 01933 test2 = glacheadRetry[icol].fieldName; 01934 if ( test1.length() > 10 ) 01935 test1 = test1.substr( 0, 10 ); 01936 if ( test2.length() > 10 ) 01937 test2 = test2.substr( 0, 10 ); 01938 01939 if ( type != glacheadRetry[icol].type || 01940 test2 != test1 || 01941 width != glacheadRetry[icol].width || 01942 ndec != glacheadRetry[icol].nDec ) { 01943 return false; 01944 } 01945 } 01946 01947 } 01948 01949 DBFClose( hdbf ); 01950 01951 // TEST ****SEGMENTS.SHP 01952 DBFHeader seghead[] = { 01953 { "category", FTString, 20, 0}, 01954 { "ID", FTString, 20, 0}, 01955 { "type", FTString, 30, 0}, 01956 { "label", FTString, 32, 0}, 01957 { "loc_unc_x", FTDouble, 5, 5}, 01958 { "loc_unc_y", FTDouble, 5, 5}, 01959 { "glob_unc_x", FTDouble, 5, 5}, 01960 { "glob_unc_y", FTDouble, 5, 5}, 01961 { "left_mat", FTString, 3, 0}, 01962 { "right_mat", FTString, 3, 0}, 01963 { "left_feat", FTString, 3, 0}, 01964 { "right_feat", FTString, 3, 0} 01965 }; 01966 ncol = 11; 01967 01968 hdbf = DBFOpen( (prefix + "segments.shp").c_str(), "rb" ); 01969 if ( !hdbf ) { 01970 return false; 01971 } 01972 for ( icol=0; icol < ncol; icol++ ) { 01973 type = DBFGetFieldInfo( hdbf, icol, name, &width, &ndec ); 01974 test1 = name; 01975 test2 = seghead[icol].fieldName; 01976 if ( test1.length() > 10 ) 01977 test1 = test1.substr( 0, 10 ); 01978 if ( test2.length() > 10 ) 01979 test2 = test2.substr( 0, 10 ); 01980 01981 if ( type != seghead[icol].type || 01982 test2 != test1 || 01983 // 2006-01-21 dls Took out width check, fields may not be limited in size 01984 //width != seghead[icol].width || 01985 ndec != seghead[icol].nDec ) { 01986 return false; 01987 } 01988 } 01989 DBFClose( hdbf ); 01990 01991 delete [] name; 01992 // MADE IT ALL SEEMS GOOD 01993 return true; 01994 } 01995 01996 bool GLIMSProject::close( ) { 01997 01998 // ********************************** 01999 // PROJECT VALIDITY 02000 // Is project valid? 02001 if ( !validate() ) { 02002 int ret = QMessageBox::information( NULL, 02003 "Project Incomplete", 02004 "Your project has incomplete or invalid data. Would you like continue editing, or close your project?", 02005 "Continue Editing", 02006 "Close" ); 02007 02008 // CONTINUE: don't save the file, return 02009 // without closing project so user 02010 // continue editing 02011 if ( ret == 0 ) { 02012 return false ; 02013 } 02014 } 02015 02016 // ********************************** 02017 // SAVE? 02018 // Does the project need to be saved? 02019 if ( mNeedSave ) { 02020 int ret; 02021 ret = QMessageBox::information( NULL, 02022 "Project Not Saved", 02023 "The project is not saved. Would you like to save it?", 02024 "Yes", 02025 "No", 02026 "Cancel" ); 02027 // YES: save the file and continue 02028 if ( ret == 0 ) { 02029 save(); 02030 } 02031 02032 // CANCEL: don't save the file, return 02033 // without closing project 02034 if ( ret == 2 ) { 02035 return false ; 02036 } 02037 } 02038 02039 // ********************************** 02040 // Clean up 02041 if (mImg) { 02042 delete mImg; 02043 } 02044 if ( mConfigDlg ) { 02045 delete mConfigDlg; 02046 } 02047 if ( mValidationReport ) { 02048 delete mValidationReport; 02049 } 02050 if ( mValRepDlg ) { 02051 delete mValRepDlg; 02052 } 02053 if ( mEditor ) { 02054 delete mEditor; 02055 } 02056 if ( mLyrSet ) { 02057 delete mLyrSet; 02058 } 02059 if ( mGData ) { 02060 delete mGData; 02061 } 02062 02063 mNeedSave = false; 02064 return true ; 02065 02066 } 02067 02068 bool GLIMSProject::validate () { 02069 02070 bool reportStatus = true ; 02071 02072 // clear validation report file 02073 mValidationReport->clearReport () ; 02074 02075 // line data (segments) validation 02076 if ( !(mGData->getLineData().validate(mValidationReport)) ) { 02077 reportStatus = false ; 02078 } 02079 02080 // session validation 02081 if ( !(mGData->getSession().validate(mValidationReport)) ) { 02082 reportStatus = false ; 02083 } 02084 02085 // image information validation 02086 if ( !(mGData->getImageInf().validate(mValidationReport)) ) { 02087 reportStatus = false ; 02088 } 02089 02090 // glacier information validation 02091 if ( !(mGData->getGIDData().validate(mValidationReport)) ) { 02092 reportStatus = false ; 02093 } 02094 02095 02096 // display validation report window 02097 mValRepDlg->show() ; 02098 mValidationReport->clearReport () ; 02099 02100 emit finishedValidation () ; 02101 02102 return reportStatus ; 02103 } 02104 02105 02106 02107 02108
Home |
Search |
Disclaimers & Privacy |
Contact Us GLIMSView Maintainer: dsoltesz@usgs.gov |