00001 #ifndef __HDFEOSFRMT_H 00002 #define __HDFEOSFRMT_H 00003 00004 #include "imageformat.h" 00005 #include "odlparser.h" 00006 00007 #include <hdf.h> 00008 #include <mfhdf.h> 00009 #include <HdfEosDef.h> 00010 #include <proj_api.h> 00011 00012 #include <string> 00013 #include <cstring> 00014 #include <vector> 00015 #include <cmath> 00016 00017 #include "TraceLog.h" 00018 00019 #ifndef M_PI 00020 #define M_PI 3.1415926 00021 #endif 00022 00037 class HdfEosFrmt : public ImageFormat { 00038 protected: 00039 int32 mSWfid; 00040 00044 typedef enum { 00045 UNSUPPORTED, 00046 UTM 00047 } Projection ; 00048 00052 typedef struct { 00053 std::string swathname; 00054 std::string gfldname; 00055 std::vector<int32> dims; 00056 std::vector<std::string> dimnames; 00057 int32 type; 00058 void* geomap; 00059 } GeoField ; 00060 00064 typedef struct { 00065 std::string swathname; 00066 std::string fieldname; 00067 std::vector<int32> dims; 00068 std::vector<std::string> dimnames; 00069 int32 type; 00070 GeoField* geofldlat; 00071 GeoField* geofldlon; 00072 std::vector<int32> latoff; 00073 std::vector<int32> lonoff; 00074 std::vector<int32> latinc; 00075 std::vector<int32> loninc; 00076 } DataField ; 00077 00078 std::vector<DataField> mDFList; 00079 std::vector<GeoField> mGFList; 00080 Projection mProj; 00081 00085 void parseGeoFlds( int32 swid, std::string swname ); 00086 00090 std::string getHdfGblAttr( const std::string &fname, 00091 const std::string &attrname ) const; 00092 00101 std::string getAquiDateTime( const std::string &fname ) const; 00102 00106 std::string getProjection( const std::string &fname ) const; 00107 00111 std::string getOrigID( const std::string &fname ) const; 00112 00116 std::string getInstZenith( const std::string &fname ) const; 00117 00121 std::string getCloudPct( const std::string &fname ) const; 00122 00126 std::string getSunAzim( const std::string &fname ) const; 00127 00131 std::string getSunElev( const std::string &fname ) const; 00132 00136 std::string getImageAzim( const std::string &fname ) const; 00137 00138 00146 //std::string getImageID( const std::string &fname ) const; 00147 00152 std::string getInstID( const std::string &fname ) const; 00153 00158 std::string getInstAz( const std::string &fname ) const; 00159 00160 00164 void getBandMetaData( ) const; 00165 00166 std::vector<std::string> 00167 splitList( char *clist, char delim ) { 00168 int l, r; 00169 std::vector<std::string> ret; 00170 std::string list = clist; 00171 l = 0; 00172 while ( l < (int)list.length()-1 ) { 00173 r = list.find( delim, l ); 00174 if ( r == -1 ) r = list.length(); 00175 ret.push_back( list.substr( l, r-l ) ); 00176 l = r+1; 00177 } 00178 return ret; 00179 } 00180 00181 template<class DType> 00182 void findrange( int32 swid, 00183 std::string field, 00184 DType &lwr, 00185 DType &upr, 00186 std::vector<int32> dims ); 00187 00188 template<class DType> 00189 void maxmin( DType* data, int sz, DType &lwr, DType &upr ) { 00190 for ( int i=0; i < sz; i++ ) { 00191 if ( lwr > data[i] ) 00192 lwr = data[i]; 00193 if ( upr < data[i] ) 00194 upr = data[i]; 00195 } 00196 } 00197 00198 template<class DType> 00199 void bilinterp( DType *map, 00200 std::vector<int32> dims, 00201 std::vector<int32> offset, 00202 std::vector<int32> inc, 00203 int x, 00204 int y, 00205 double &res ); 00206 00207 void getGeoFields( int iband ); 00208 void getIntersect( int &track, 00209 int &p1, 00210 int p2, 00211 int iband, 00212 double searchVal, 00213 bool isLon, 00214 bool horizontal=true ); 00215 00216 void trackLineTo( int &x, 00217 int &y, 00218 int iband, 00219 double trackVal, 00220 double searchVal ); 00221 00222 /* 00223 void getULCorners( ); 00224 void xyToLL( int iband, double &x, double &y ); 00225 void xyToMeter( int iband, double &x, double &y ); 00226 void meterToLL( int iband, double &x, double &y ); 00227 void llToMeter( int iband, double &lon, double &lat ); 00228 void llToXY( int iband, double &lon, double &lat ); 00229 projPJ createProj( int iband ); 00230 */ 00231 00232 bool between( double a, double b, double c ) { 00233 if ( a < b ) 00234 return( c > a && c < b ); 00235 else 00236 return( c < a && c > b ); 00237 } 00238 00239 public: 00240 ~HdfEosFrmt( ); 00241 00253 virtual bool open( std:: string fname ); 00254 00255 virtual void getLL( int iband, double &i, double &j, bool toWGS84 ); 00256 virtual void getLL( int iband, double &i, double &j ) { 00257 if ( iband >= 0 && iband < (int)mBandSet.size() && 00258 mBandSet[iband].proj != "" ) { 00259 xyToLL( iband, i, j ); 00260 return; 00261 } 00262 getLL( iband, i, j, true ); 00263 } 00264 00265 virtual void getXY( int iband, double &i, double &j ); 00266 virtual void* getBand( int iband, 00267 int x1, 00268 int y1, 00269 int w1, 00270 int h1, 00271 int w2, 00272 int h2, 00273 ScaleType = SCALE_BI ) const; 00274 }; 00275 00276 #endif 00277 00278 00279 00280 00281
Home |
Search |
Disclaimers & Privacy |
Contact Us GLIMSView Maintainer: dsoltesz@usgs.gov |