openModeller  Version 1.4.0
GdalRaster.hh
Go to the documentation of this file.
00001 
00030 #ifndef _GDAL_RASTERHH_
00031 #define _GDAL_RASTERHH_
00032 
00033 #include <openmodeller/om_defs.hh>
00034 #include <openmodeller/env_io/Header.hh>
00035 #include <openmodeller/env_io/Raster.hh>
00036 
00037 #include <string>
00038 #include <vector>
00039 
00040 class GDALDataset;
00041 class MapFormat;
00042 
00043 /****************************************************************/
00044 /************************** Raster Gdal *************************/
00045 
00051 class dllexp GdalRaster : public Raster
00052 {
00053 public:
00054 
00055   // Empty constructor
00056   GdalRaster(): f_data(0), f_size(0), f_format(-1), f_currentRow(-1), f_changed(0), f_warped_ds(0) {};
00057 
00063   void createRaster( const std::string& file, int categ = 0 );
00064 
00065   #ifdef MPI_FOUND
00066 
00071   void createRaster( const std::string& output_file_source, const std::string& file, const MapFormat& format );
00072   #else
00073 
00078   void createRaster( const std::string& file, const MapFormat& format );
00079   #endif
00080 
00084   ~GdalRaster();
00085 
00086   int iget( int x, int y, Scalar *val );
00087   int iput( int x, int y, Scalar val );
00088 
00093   int get( Coord x, Coord y, Scalar *val );
00094 
00100   int put( Coord x, Coord y, Scalar val );
00101 
00107   int put( Coord x, Coord y );
00108 
00114   int getMinMax( Scalar *min, Scalar *max );
00115 
00117   int calcMinMax( int band=0 );
00118 
00122   void finish();
00123 
00127   int deleteRaster();
00128 
00133   bool hasCustomGeotransform() { return (f_warped_ds == 0) ? false: true; }
00134 
00148   int getExtentInStandardCs( Coord *xmin, Coord *ymin, Coord *xmax, Coord *ymax );
00149 
00150 private:
00151 
00153   void open( char mode );
00154 
00156   void create( int format );
00157 
00158   void initBuffer();
00159 
00160   static void initGdal();
00161 
00167   void read ( Scalar *buf, int first_row, int num_rows );
00168 
00173   void write( Scalar *buf, int first_row, int num_rows );
00174 
00175   void loadRow( int row, bool writeOperation=false );
00176 
00177   void saveRow(); // Save the current row.
00178 
00179   GDALDataset *f_ds;
00180 
00181   Scalar *f_data; // One line data for all bands.
00182   int     f_size; // Size of one line.
00183 
00184   int     f_format; // File format used to create the raster (MapFormat::getFormat())
00185 
00186   int f_currentRow;
00187   int f_changed;
00188 
00189   // Disable copying.
00190   GdalRaster( const GdalRaster& );
00191   GdalRaster& operator=( const GdalRaster& );
00192 
00193   // Warped data set converting to standard openModeller coordinate system.
00194   // Only used when the raster cs is different from openModeller's default.
00195   GDALDataset *f_warped_ds;
00196 };
00197 
00198 #endif
00199