22#include "base/Optionpk.h"
24#include "imageclasses/ImgWriterGdal.h"
74int 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())
186 if(projection_opt.size()){
187 assert(dx_opt.size());
188 assert(dy_opt.size());
190 cout << output_opt[0] <<
" is georeferenced." << endl;
203 cout << output_opt[0] <<
" is not georeferenced." << endl;
206 if(colorTable_opt.size()){
210 assert(data.size()==nrow);
211 for(irow=0;irow<nrow;++irow)
bool isGeoRef() const
Is this dataset georeferenced (pixel size in y must be negative) ?
CPLErr setGeoTransform(double *gt)
Set the geotransform data for this dataset.
CPLErr setProjectionProj4(const std::string &projection)
Set the projection for this dataset from user input (supports epsg:<number> format)
GDALDataType getDataType(int band=0) const
Get the GDAL datatype for this dataset.
void close(void)
Close the 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 setColorTable(const std::string &filename, int band=0)
Set the color table using an (ASCII) file with 5 columns (value R G B alpha)
void setImageDescription(const std::string &imageDescription)
Set the image description (only for GeoTiff format: TIFFTAG_IMAGEDESCRIPTION)
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...