20 #ifndef _IMGWRITERGDAL_H_
21 #define _IMGWRITERGDAL_H_
27 #include "gdal_priv.h"
28 #include "ImgRasterGdal.h"
29 #include "ImgReaderGdal.h"
30 #include "ImgReaderOgr.h"
38 void open(
const std::string& filename);
39 void open(
const std::string& filename,
const ImgReaderGdal& imgSrc,
const std::vector<std::string>& options=std::vector<std::string>());
40 void open(
const std::string& filename,
int ncol,
int nrow,
int nband,
const GDALDataType& dataType,
const std::string& imageType,
const std::vector<std::string>& options=std::vector<std::string>());
44 void setProjection(
const std::string& projection);
45 std::string setProjectionProj4(
const std::string& projection);
47 void setImageDescription(
const std::string& imageDescription){m_gds->SetMetadataItem(
"TIFFTAG_IMAGEDESCRIPTION",imageDescription.c_str());};
48 void setGeoTransform(
double* gt);
50 template<
typename T>
bool writeData(T& value,
const GDALDataType& dataType,
int col,
int row,
int band=0)
const;
51 template<
typename T>
bool writeData(std::vector<T>& buffer,
const GDALDataType& dataType ,
int minCol,
int maxCol,
int row,
int band=0)
const;
52 template<
typename T>
bool writeData(std::vector<T>& buffer,
const GDALDataType& dataType,
int row,
int band=0)
const;
53 bool writeData(
void* pdata,
const GDALDataType& dataType,
int band=0)
const;
54 template<
typename T>
bool writeDataBlock(
Vector2d<T>& buffer,
const GDALDataType& dataType ,
int minCol,
int maxCol,
int minRow,
int maxRow,
int band=0)
const;
57 void setColorTable(
const std::string& filename,
int band=0);
58 void setColorTable(GDALColorTable* colorTable,
int band=0);
59 void setMetadata(
char** metadata);
60 void rasterizeOgr(
ImgReaderOgr& ogrReader,
const std::vector<double>& burnValues=std::vector<double>(),
const std::vector<std::string>& layernames=std::vector<std::string>());
63 void setCodec(
const GDALDataType& dataType,
const std::string& imageType);
73 std::vector<std::string> m_options;
76 template<
typename T>
bool ImgWriterGdal::writeData(T& value,
const GDALDataType& dataType,
int col,
int row,
int band)
const
79 GDALRasterBand *poBand;
80 if(band>=nrOfBand()+1){
82 s <<
"band (" << band <<
") exceeds nrOfBand (" << nrOfBand() <<
")";
85 poBand = m_gds->GetRasterBand(band+1);
88 s <<
"col (" << col <<
") exceeds nrOfCol (" << nrOfCol() <<
")";
93 s <<
"col (" << col <<
") is negative";
98 s <<
"row (" << row <<
") exceeds nrOfRow (" << nrOfRow() <<
")";
102 std::ostringstream s;
103 s <<
"row (" << row <<
") is negative";
106 poBand->RasterIO(GF_Write,col,row,1,1,&value,1,1,dataType,0,0);
110 template<
typename T>
bool ImgWriterGdal::writeData(std::vector<T>& buffer,
const GDALDataType& dataType,
int minCol,
int maxCol,
int row,
int band)
const
113 GDALRasterBand *poBand;
114 if(band>=nrOfBand()+1){
115 std::ostringstream s;
116 s <<
"band (" << band <<
") exceeds nrOfBand (" << nrOfBand() <<
")";
119 poBand = m_gds->GetRasterBand(band+1);
120 if(buffer.size()!=maxCol-minCol+1){
121 std::string errorstring=
"invalid buffer size";
124 if(minCol>=nrOfCol()){
125 std::ostringstream s;
126 s <<
"minCol (" << minCol <<
") exceeds nrOfCol (" << nrOfCol() <<
")";
130 std::ostringstream s;
131 s <<
"mincol (" << minCol <<
") is negative";
134 if(maxCol>=nrOfCol()){
135 std::ostringstream s;
136 s <<
"maxCol (" << maxCol <<
") exceeds nrOfCol (" << nrOfCol() <<
")";
140 std::ostringstream s;
141 s <<
"maxCol (" << maxCol <<
") is less than minCol (" << minCol <<
")";
146 std::ostringstream s;
147 s <<
"row (" << row <<
") exceeds nrOfRow (" << nrOfRow() <<
")";
151 std::ostringstream s;
152 s <<
"row (" << row <<
") is negative";
155 poBand->RasterIO(GF_Write,minCol,row,buffer.size(),1,&(buffer[0]),buffer.size(),1,dataType,0,0);
159 template<
typename T>
bool ImgWriterGdal::writeData(std::vector<T>& buffer,
const GDALDataType& dataType,
int row,
int band)
const
162 GDALRasterBand *poBand;
163 if(band>=nrOfBand()+1){
164 std::ostringstream s;
165 s <<
"band (" << band <<
") exceeds nrOfBand (" << nrOfBand() <<
")";
168 poBand = m_gds->GetRasterBand(band+1);
169 if(buffer.size()!=nrOfCol()){
170 std::string errorstring=
"invalid buffer size";
174 std::ostringstream s;
175 s <<
"row (" << row <<
") exceeds nrOfRow (" << nrOfRow() <<
")";
178 poBand->RasterIO(GF_Write,0,row,buffer.size(),1,&(buffer[0]),buffer.size(),1,dataType,0,0);
182 template<
typename T>
bool ImgWriterGdal::writeDataBlock(
Vector2d<T>& buffer,
const GDALDataType& dataType ,
int minCol,
int maxCol,
int minRow,
int maxRow,
int band)
const
185 GDALRasterBand *poBand;
186 if(band>=nrOfBand()+1){
187 std::ostringstream s;
188 s <<
"band (" << band <<
") exceeds nrOfBand (" << nrOfBand() <<
")";
191 poBand = m_gds->GetRasterBand(band+1);
192 assert(buffer.size()==maxRow-minRow+1);
193 for(
int irow=minRow;irow<=maxRow;++irow)
194 writeData(buffer[irow-minRow], dataType, minCol, maxCol, irow, band);
198 #endif // _IMGWRITERGDAL_H_