pktools  2.6.6
Processing Kernel for geospatial data
ImgRasterGdal.h
1 /**********************************************************************
2 ImgRasterGdal.h: class to read raster files using GDAL API library
3 Copyright (C) 2008-2012 Pieter Kempeneers
4 
5 This file is part of pktools
6 
7 pktools is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 pktools is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with pktools. If not, see <http://www.gnu.org/licenses/>.
19 ***********************************************************************/
20 #ifndef _IMGRASTERGDAL_H_
21 #define _IMGRASTERGDAL_H_
22 
23 #include <fstream>
24 #include <sstream>
25 #include <string>
26 #include <vector>
27 #include <list>
28 #include <algorithm>
29 #include <assert.h>
30 #include "gdal_priv.h"
31 
32 enum RESAMPLE { NEAR = 0, BILINEAR = 1, BICUBIC = 2 };
33 
34 //--------------------------------------------------------------------------
36 {
37 public:
38  ImgRasterGdal(void);
39  virtual ~ImgRasterGdal(void){};
40 
41  virtual void close(void);
42  std::string getFileName() const {return m_filename;};
43  int nrOfCol(void) const { return m_ncol;};
44  int nrOfRow(void) const { return m_nrow;};
45  int nrOfBand(void) const { return m_nband;};
46  bool isGeoRef() const {double gt[6];getGeoTransform(gt);if(gt[5]<0) return true;else return false;};
47  std::string getProjection(void) const;
48  std::string getProjectionRef(void) const;
49  std::string getGeoTransform() const;
50  void getGeoTransform(double* gt) const;
51  bool getBoundingBox (double& ulx, double& uly, double& lrx, double& lry) const;
52  bool getCenterPos(double& x, double& y) const;
53  double getUlx() const {double ulx, uly, lrx,lry;getBoundingBox(ulx,uly,lrx,lry);return(ulx);};
54  double getUly() const {double ulx, uly, lrx,lry;getBoundingBox(ulx,uly,lrx,lry);return(uly);};
55  double getLrx() const {double ulx, uly, lrx,lry;getBoundingBox(ulx,uly,lrx,lry);return(lrx);};
56  double getLry() const {double ulx, uly, lrx,lry;getBoundingBox(ulx,uly,lrx,lry);return(lry);};
57 
58  int getNoDataValues(std::vector<double>& noDataValues) const;
59  bool isNoData(double value) const{if(m_noDataValues.empty()) return false;else return find(m_noDataValues.begin(),m_noDataValues.end(),value)!=m_noDataValues.end();};
60  int pushNoDataValue(double noDataValue);
61  int setNoData(const std::vector<double> nodata){m_noDataValues=nodata; return(m_noDataValues.size());};
62  CPLErr GDALSetNoDataValue(double noDataValue, int band=0) {return getRasterBand(band)->SetNoDataValue(noDataValue);};
63  bool covers(double x, double y) const;
64  bool covers(double ulx, double uly, double lrx, double lry) const;
65  bool geo2image(double x, double y, double& i, double& j) const;
66  bool image2geo(double i, double j, double& x, double& y) const;
67  double getDeltaX(void) const {double gt[6];getGeoTransform(gt);return gt[1];};
68  double getDeltaY(void) const {double gt[6];getGeoTransform(gt);return -gt[5];};
69 
70  GDALDataType getDataType(int band=0) const;
71  GDALRasterBand* getRasterBand(int band=0);
72  GDALColorTable* getColorTable(int band=0) const;
73  std::string getDriverDescription() const;
74  std::string getImageType() const{return getDriverDescription();};
75 // std::string getImageType() const{return "GTiff";};
76  std::string getInterleave() const;
77  std::string getCompression() const;
78  GDALDataset* getDataset(){return m_gds;};
79  char** getMetadata();
80  char** getMetadata() const;
81  void getMetadata(std::list<std::string>& metadata) const;
82 
83  std::string getDescription() const;
84  std::string getMetadataItem() const;
85  std::string getImageDescription() const;
86 
87  friend class ImgReaderGdal;
88  friend class ImgWriterGdal;
89 
90 protected:
91  std::string m_filename;
92  GDALDataset *m_gds;
93  int m_ncol;
94  int m_nrow;
95  int m_nband;
96  double m_gt[6];
97  std::vector<double> m_noDataValues;
98 };
99 
100 #endif // _IMGRASTERGDAL_H_