00001 #include "l7a_geotiff.h" 00002 #include <iostream> 00003 #include "TraceLog.h" 00004 00005 bool L7A_Geotiff::open( std::string fname ) { 00006 const std::string band_numbers[] = { 00007 "10", 00008 "20", 00009 "30", 00010 "40", 00011 "50", 00012 "61", 00013 "62", 00014 "70", 00015 "80" 00016 }; 00017 00018 const int nbands = 9; 00019 const int name_len = 29; 00020 00021 if ( (int)fname.length() < name_len ) 00022 return false; 00023 std::string dir = fname.substr( 0, fname.length()-name_len ); 00024 fname = fname.substr( fname.length()-name_len, name_len ); 00025 std::string pre = fname.substr( 0, 2 ); 00026 std::string mid = fname.substr( 3, 20 ); 00027 std::string end = fname.substr( 25, 4 ); 00028 std::string testname; 00029 bool opened = false; 00030 00031 QDialog *pdlg = new QDialog( NULL, NULL, true ); 00032 QVBoxLayout *vbl = new QVBoxLayout( pdlg, 10, 10 ); 00033 vbl->setAutoAdd( true ); 00034 new QLabel( "Loading Files. Please Wait.", pdlg ); 00035 QProgressBar *pbar = new QProgressBar( pdlg ); 00036 float pcnt = 0.0f; 00037 pdlg->show(); 00038 qApp->processEvents(); 00039 00040 for ( int iband=0; iband < nbands; iband++ ) { 00041 pcnt = (1.0f / 9.0f) * (float)iband; 00042 pbar->setProgress( (int)(pcnt * 100.0f) ); 00043 qApp->processEvents(); 00044 testname = dir + pre + "1" + mid + band_numbers[iband] + end; 00045 GDALFrmt *gdal = new GDALFrmt; 00046 if ( gdal->open( testname ) ) { 00047 mFormatSet.push_back( gdal ); 00048 BandInf binf = gdal->getBandInf( 0 ); 00049 binf.name = std::string( "Band " ) + band_numbers[iband]; 00050 mBandSet.push_back( binf ); 00051 opened = true; 00052 continue; 00053 } else { 00054 delete gdal; 00055 } 00056 00057 testname = dir + pre + "2" + mid + band_numbers[iband] + end; 00058 gdal = new GDALFrmt; 00059 if ( gdal->open( testname ) ) { 00060 mFormatSet.push_back( gdal ); 00061 BandInf binf = gdal->getBandInf( 0 ); 00062 binf.name = std::string( "Band " ) + band_numbers[iband]; 00063 mBandSet.push_back( binf ); 00064 opened = true; 00065 } else { 00066 delete gdal; 00067 } 00068 00069 } 00070 00071 if ((int)mBandSet.size()) { 00072 double x = mBandSet[0].width / 2; 00073 double y = mBandSet[0].height / 2; 00074 getLL( 0, x, y ); 00075 mImageInf.mCenterLat = y; 00076 mImageInf.mCenterLon = x; 00077 } 00078 mImageInf.mLocURL = fname ; 00079 00080 00081 delete pdlg; 00082 return opened; 00083 } 00084 00085 void L7A_Geotiff::getLL( int iband, double &i, double &j ) { 00086 if ( iband < 0 || iband > (int)mBandSet.size() ) 00087 return; 00088 00089 mFormatSet[iband]->getLL( iband, i, j ); 00090 } 00091 00092 void L7A_Geotiff::getXY( int iband, double &i, double &j ) { 00093 if ( iband < 0 || iband > (int)mBandSet.size() ) 00094 return; 00095 00096 mFormatSet[iband]->getXY( iband, i, j ); 00097 } 00098 00099 void* L7A_Geotiff::getBand( int iband, 00100 int x1, 00101 int y1, 00102 int w1, 00103 int h1, 00104 int w2, 00105 int h2, 00106 ScaleType st ) const { 00107 if ( iband < 0 || iband > (int)mBandSet.size() ) 00108 return NULL; 00109 00110 return mFormatSet[iband]->getBand( 0, x1, y1, w1, h1, w2, h2, st ); 00111 } 00112 00113
Home |
Search |
Disclaimers & Privacy |
Contact Us GLIMSView Maintainer: dsoltesz@usgs.gov |