00001
00013 #ifndef GRAMER_GEODATA_HPP
00014 #define GRAMER_GEODATA_HPP
00015
00016 #include <list>
00017 #include <vector>
00018 #include <iostream>
00019 #include <fstream>
00020 #include <string>
00021
00022 #include <boost/tokenizer.hpp>
00023 #include <boost/lexical_cast.hpp>
00024
00025 #include <gdal_priv.h>
00026 #include <ogr_spatialref.h>
00027
00028
00029 #include <gramer/Attributes.hpp>
00030
00031 #define MAX_NUMBER_OF_BANDDEFINITIONS 4
00032 #define MAX_NUMBER_OF_BANDCONDITIONS 4
00033
00035
00036
00038
00039
00041
00042
00044
00045
00052
00053
00055
00056
00057
00070
00071
00077
00078
00079
00080
00081
00083
00084
00086
00087
00094
00095
00100
00101
00103
00104 namespace jafar {
00105 namespace gramer {
00106
00107
00109 typedef enum { FUSION_OVERWRITE=0,
00110 FUSION_MEAN
00111 } FUSION_METHOD;
00112
00114 typedef enum { HT_NONE=-1,
00115 HT_SIMPLE,
00116 HT_NEARLY,
00117 HT_SIGMA
00118 } HOMOGENEOUS_TYPE;
00119
00125 static const std::string prefixedBandDefinitions[MAX_NUMBER_OF_BANDDEFINITIONS] =
00126 { "TRA", "VIS", "LOC", "COM" };
00127
00133 static const std::string prefixedBandConditions[MAX_NUMBER_OF_BANDCONDITIONS] =
00134 { "AIR", "GROUND", "SURFACE", "UNDERWATER"};
00135
00136
00137 typedef struct RasterCell {
00138
00139 int x;
00140 int y;
00141
00142 int xsize;
00143 int ysize;
00145 RasterCell()
00146 {
00147 x = 0;
00148 y = 0;
00149 xsize = 0;
00150 ysize = 0;
00151 }
00152
00154 RasterCell(int x_, int y_, int xs_=1, int ys_=1)
00155 {
00156 x = x_;
00157 y = y_;
00158 xsize = xs_;
00159 ysize = ys_;
00160 }
00161
00162
00163
00164 } RasterCell;
00165
00170 class GeoData
00171 {
00172 public:
00173
00174 static const double DEFAULT_DATA_VALUE() { return -1.0; };
00175
00176 static const double GEODATA_DEFAULT_SCALE() { return 1.0; };
00177
00179 typedef struct BandDefinition {
00180 std::string confFileSource;
00181 std::string sourceFile;
00182 std::string name;
00183 int bandNumber;
00184 std::string geoUtmZone;
00185 float geoRefX;
00186 float geoRefY;
00187 float geoRefZ;
00188 float geoPixelSizeX;
00189 float geoPixelSizeY;
00190 float geoPixelSizeZ;
00191 std::vector<std::string> otherInfo;
00192 } BandDefinition;
00193
00195 GeoData();
00196
00203 GeoData(const std::string& _conffilename, FUSION_METHOD _fmethod=FUSION_MEAN);
00204
00206
00207
00209 ~GeoData();
00210
00211 bool loadBand(BandDefinition band, const std::string& _dsfilename);
00212
00231 bool loadConfigurationFile(const std::string& conffile);
00232
00241 int isInVirtualMemory;
00242
00243
00244
00246 GDALDataset* getDataset() const;
00247
00249 void getAffineTransform(double& _utmXRoot, double& _utmYRoot, double& _cellXRes, double& _cellYRes);
00250
00254 int getxsize() const;
00255 int getysize() const;
00256
00258 double getScale() const;
00259
00261 double geoxroot() const;
00263 double geoyroot() const;
00265 double geoxend() const;
00267 double geoyend() const;
00269 double geoxres() const;
00271 double geoyres() const;
00272
00277 double getSigmaFactor();
00278
00283 double getProbabilityLag();
00284
00286
00287
00288
00292 bool getValueFromBand(BandDefinition _aband, int xindex, int yindex, double& readValue);
00293
00294
00295 double getData(const RasterCell& rect) const;
00296
00297
00298 double getData(const BandDefinition& bandDef, const RasterCell& rect) const;
00299
00300
00301
00302
00303
00304
00305
00306
00307
00309 void setScale(double _scale);
00310
00311
00314
00315
00320 void setFusingMethod(FUSION_METHOD _fmethod);
00321
00322
00323
00325
00337
00338
00339
00341 void setDecompositionLimit(double _dl);
00342
00344 void setDecompositionType(HOMOGENEOUS_TYPE ht_);
00345
00347 void setProbabilityLag(double probaLag_);
00348
00350 void setSigmaFactor(double sigmaF_);
00351
00353 void setSimulationProbaVisionLimit(double spvl_);
00354
00355
00359 bool isHomogeneous(const RasterCell& rect) const;
00360
00361
00365 bool overlaps(GeoData* _toMerge);
00366
00367
00368
00385 bool loadData(const std::string& _dsfilename);
00386
00390 bool setBandTag(int iband, BandDefinition& bandDef);
00391
00396 bool addBandToDataset(BandDefinition& inputinfo);
00397
00402 void addDataset(GDALDataset *_dataset);
00403
00415
00416
00428
00429
00431 void printInfo(bool verbose = true) const;
00432
00434 bool saveData(const std::string& outfile, const char* wFormat="GTIFF");
00435
00437
00438
00439
00441 void resetBands();
00442
00444 bool saveUtility(const std::string& outfile);
00446 bool saveEntropy(const std::string& outfile);
00448 bool savePotential(const std::string& outfile);
00449
00451 double euclideanDistance(double, double, double, double);
00452
00453 bool setUTMProjection(GDALDataset* inputDataset, int utmZone);
00454
00455
00456
00458
00460
00462
00464
00466 double getSimulationProbaVisionLimit();
00467
00468
00469 private:
00470
00472 std::string conffilename;
00473
00475 std::string dsfilename;
00476
00480 GDALDataset* dataset;
00481
00490 double refGeoTransform[6];
00491
00494 CPLErr refGeoTransformRType;
00495
00497 RasterCell rootCell;
00498
00499
00500
00508 FUSION_METHOD fmethod;
00509
00511 HOMOGENEOUS_TYPE htype;
00512
00514 double decompositionLimit;
00515
00517 double sigmaFactor;
00518
00524 double probabilityLag;
00525
00532 double simulationProbaVisionLimit;
00533
00543 std::vector<BandDefinition> geoBands;
00544
00545
00546
00550 void info(std::ostream& info, bool verbose = true) const;
00551
00552 friend std::ostream& operator<< (std::ostream& out, const GeoData& gd);
00553
00554 };
00555
00559 inline std::ostream& operator<< (std::ostream& out, const GeoData& gd) {
00560 gd.info(out,true);
00561 return out;
00562 }
00563 }
00564 }
00565
00566 #endif