21 #include "imageclasses/ImgReaderGdal.h" 22 #include "imageclasses/ImgWriterGdal.h" 23 #include "base/Optionpk.h" 73 int main(
int argc,
char **argv) {
82 Optionpk<short> dim_opt(
"dim",
"dim",
"number of columns and rows in legend.", 100);
86 Optionpk<string> colorTable_opt(
"ct",
"ct",
"color table (file with 5 columns: id R G B ALFA (0: transparent, 255: solid)");
87 Optionpk<string> oformat_opt(
"of",
"oformat",
"Output image format (see also gdal_translate).",
"GTiff");
88 Optionpk<string> option_opt(
"co",
"co",
"Creation option for output file. Multiple options can be specified.");
89 Optionpk<string> description_opt(
"d",
"description",
"Set image description");
92 legend_opt.setHide(1);
97 doProcess=input_opt.retrieveOption(argc,argv);
98 output_opt.retrieveOption(argc,argv);
99 legend_opt.retrieveOption(argc,argv);
100 dim_opt.retrieveOption(argc,argv);
101 min_opt.retrieveOption(argc,argv);
102 max_opt.retrieveOption(argc,argv);
103 grey_opt.retrieveOption(argc,argv);
104 colorTable_opt.retrieveOption(argc,argv);
105 description_opt.retrieveOption(argc,argv);
106 oformat_opt.retrieveOption(argc,argv);
107 option_opt.retrieveOption(argc,argv);
108 verbose_opt.retrieveOption(argc,argv);
110 catch(
string predefinedString){
111 std::cout << predefinedString << std::endl;
116 cout <<
"Usage: pkcreatect -i input.txt -o output [-ct colortable | -min value -max value]" << endl;
118 std::cout <<
"short option -h shows basic options only, use long option --help to show all options" << std::endl;
122 GDALColorTable colorTable;
123 GDALColorEntry sEntry;
124 if(colorTable_opt.empty()){
126 for(
int i=min_opt[0];i<=max_opt[0];++i){
128 sEntry.c1=255*(i-min_opt[0])/(max_opt[0]-min_opt[0]);
129 sEntry.c2=255*(i-min_opt[0])/(max_opt[0]-min_opt[0]);
130 sEntry.c3=255*(i-min_opt[0])/(max_opt[0]-min_opt[0]);
136 double delta=max_opt[0]-min_opt[0];
137 if(i<(min_opt[0]+0.25*delta)){
139 sEntry.c2=255*4*(i-min_opt[0])/delta;
141 else if(i<(min_opt[0]+0.5*delta)){
143 sEntry.c3=255*(1+4*(min_opt[0]+0.25*delta-i)/delta);
145 else if(i<(min_opt[0]+0.75*delta)){
146 sEntry.c1=255*4*(i-min_opt[0]-0.5*delta)/delta;
150 sEntry.c2=255*(1+4*(min_opt[0]+0.75*delta-i)/delta);
154 colorTable.SetColorEntry(i,&sEntry);
155 if(output_opt.empty())
156 cout << i <<
" " << sEntry.c1 <<
" " << sEntry.c2 <<
" " << sEntry.c3 <<
" " << sEntry.c4 << endl;
160 short ncol=dim_opt[0];
162 if(legend_opt.size()){
166 nrow=max_opt[0]-min_opt[0]+1;
169 vector<string> pngOption;
171 pngOption.push_back(
"");
172 legendWriter.
open(legend_opt[0],ncol,nrow,1,GDT_Byte,oformat_opt[0],option_opt);
173 if(colorTable_opt.size()){
174 if(colorTable_opt[0]!=
"none")
179 if(legend_opt.size()){
180 for(
int irow=0;irow<legendWriter.
nrOfRow();++irow){
181 vector<char> buffer(legendWriter.
nrOfCol());
182 for(
int icol=0;icol<legendWriter.
nrOfCol();++icol)
183 buffer[icol]=min_opt[0]+irow*static_cast<short>(max_opt[0]-min_opt[0]+1)/legendWriter.
nrOfRow();
194 if(input_opt.size()&&output_opt.size()){
197 if(option_opt.findSubstring(
"INTERLEAVE=")==option_opt.end()){
198 string theInterleave=
"INTERLEAVE=";
200 option_opt.push_back(theInterleave);
203 imgWriter.
open(output_opt[0],imgReader.nrOfCol(),imgReader.nrOfRow(),1,GDT_Byte,oformat_opt[0],option_opt);
206 if(colorTable_opt.size()){
207 if(colorTable_opt[0]!=
"none")
212 if(description_opt.size())
214 switch(imgReader.getDataType()){
217 for(
int irow=0;irow<imgReader.nrOfRow();++irow){
218 imgReader.readData(buffer,irow);
224 vector<short> buffer;
225 cout <<
"Warning: copying short to unsigned short without conversion, use gdal_translate -scale if needed..." << endl;
226 for(
int irow=0;irow<imgReader.nrOfRow();++irow){
227 imgReader.readData(buffer,irow,0);
233 vector<unsigned short> buffer;
234 for(
int irow=0;irow<imgReader.nrOfRow();++irow){
235 imgReader.readData(buffer,irow,0);
241 cerr <<
"data type " << imgReader.getDataType() <<
" not supported for adding a colortable" << endl;
247 if(legend_opt.size())
248 legendWriter.
close();
void setImageDescription(const std::string &imageDescription)
Set the image description (only for GeoTiff format: TIFFTAG_IMAGEDESCRIPTION)
int nrOfCol(void) const
Get the number of columns of this dataset.
void setColorTable(const std::string &filename, int band=0)
Set the color table using an (ASCII) file with 5 columns (value R G B alpha)
int nrOfRow(void) const
Get the number of rows of this dataset.
bool writeData(T &value, int col, int row, int band=0)
Write a single pixel cell value at a specific column and row for a specific band (all indices start c...
void copyGeoTransform(const ImgRasterGdal &imgSrc)
Copy geotransform information from another georeferenced image.
void open(const std::string &filename, const ImgReaderGdal &imgSrc, const std::vector< std::string > &options=std::vector< std::string >())
Open an image for writing, copying image attributes from a source image. Image is directly written to...
void close(void)
Close the image.
std::string getInterleave() const
Get the band coding (interleave)