22 #include "base/Optionpk.h" 24 #include "imageclasses/ImgWriterGdal.h" 74 int main(
int argc,
char *argv[])
78 Optionpk<string> dataType_opt(
"ot",
"otype",
"Data type for output image ({Byte/Int16/UInt16/UInt32/Int32/Float32/Float64/CInt16/CInt32/CFloat32/CFloat64}). Empty string: inherit type from input image",
"Byte");
79 Optionpk<string> imageType_opt(
"of",
"oformat",
"image type string (see also gdal_translate)",
"GTiff");
80 Optionpk<string> option_opt(
"co",
"co",
"Creation option for output file. Multiple options can be specified.");
81 Optionpk<double> ulx_opt(
"ulx",
"ulx",
"Upper left x value bounding box (in geocoordinates if georef is true)", 0.0);
82 Optionpk<double> uly_opt(
"uly",
"uly",
"Upper left y value bounding box (in geocoordinates if georef is true)", 0.0);
85 Optionpk<string> projection_opt(
"a_srs",
"a_srs",
"Override the projection for the output file");
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> description_opt(
"d",
"description",
"Set image description");
92 doProcess=input_opt.retrieveOption(argc,argv);
93 output_opt.retrieveOption(argc,argv);
94 dataType_opt.retrieveOption(argc,argv);
95 imageType_opt.retrieveOption(argc,argv);
96 option_opt.retrieveOption(argc,argv);
97 ulx_opt.retrieveOption(argc,argv);
98 uly_opt.retrieveOption(argc,argv);
99 dx_opt.retrieveOption(argc,argv);
100 dy_opt.retrieveOption(argc,argv);
101 colorTable_opt.retrieveOption(argc,argv);
102 projection_opt.retrieveOption(argc,argv);
103 description_opt.retrieveOption(argc,argv);
104 verbose_opt.retrieveOption(argc,argv);
106 catch(
string predefinedString){
107 std::cout << predefinedString << std::endl;
112 cout <<
"Usage: pkascii2img -i input.txt -o output" << endl;
114 std::cout <<
"short option -h shows basic options only, use long option --help to show all options" << std::endl;
118 assert(input_opt.size());
119 assert(output_opt.size());
121 ifstream ifile(input_opt[0].c_str(),ios::in);
127 string interleave=
"BAND";
128 vector< vector<double> > data;
132 while(getline(ifile,line)){
135 istringstream ist(line);
137 row.push_back(value);
145 for(
int icol=0;icol<row.size();++icol)
146 cout << row[icol] <<
" ";
155 cout <<
"nrow: " << nrow << endl;
156 cout <<
"ncol: " << ncol << endl;
159 catch(
string theError){
160 cout << theError << endl;
163 GDALDataType dataType=GDT_Unknown;
165 cout <<
"possible output data types: ";
166 for(
int iType = 0; iType < GDT_TypeCount; ++iType){
168 cout <<
" " << GDALGetDataTypeName((GDALDataType)iType);
169 if( GDALGetDataTypeName((GDALDataType)iType) != NULL
170 && EQUAL(GDALGetDataTypeName((GDALDataType)iType),
171 dataType_opt[0].c_str()))
172 dataType=(GDALDataType) iType;
177 if(dataType==GDT_Unknown)
178 cout <<
"Unknown output pixel type: " << dataType_opt[0] << endl;
180 cout <<
"Output pixel type: " << GDALGetDataTypeName(dataType) << endl;
183 imgWriter.open(output_opt[0],ncol,nrow,1,dataType,imageType_opt[0],option_opt);
184 if(description_opt.size())
185 imgWriter.setImageDescription(description_opt[0]);
186 if(projection_opt.size()){
187 assert(dx_opt.size());
188 assert(dy_opt.size());
190 cout << output_opt[0] <<
" is georeferenced." << endl;
198 imgWriter.setGeoTransform(gt);
199 imgWriter.setProjectionProj4(projection_opt[0]);
203 cout << output_opt[0] <<
" is not georeferenced." << endl;
204 assert(!imgWriter.isGeoRef());
206 if(colorTable_opt.size()){
207 assert(imgWriter.getDataType()==GDT_Byte);
208 imgWriter.setColorTable(colorTable_opt[0]);
210 assert(data.size()==nrow);
211 for(irow=0;irow<nrow;++irow)
212 imgWriter.writeData(data[irow],irow);