20 #include "base/Optionpk.h" 21 #include "imageclasses/ImgReaderGdal.h" 22 #include "algorithms/Egcs.h" 52 int main(
int argc,
char *argv[])
56 Optionpk<std::string> cell2bb_opt(
"c2b",
"cell2bb",
"convert cell code to geo coordinates of boundingbox (e.g. 32-AB)",
"");
57 Optionpk<std::string> cell2mid_opt(
"c2m",
"cell2mid",
"convert cell code to centre in geo coordinates (e.g. 32-AB)",
"");
58 Optionpk<bool> refpixel_opt(
"ref",
"ref",
"get reference pixel (lower left corner of centre of gravity pixel)",
false);
59 Optionpk<double> maskValue_opt(
"m",
"mask",
"mask value(s) for no data to calculate reference pixel in image",0);
61 Optionpk<bool> geo2cell_opt(
"g2c",
"geo2cell",
"get cell code for coordinates in x_opt and y_opt given the resolution in dx_opt",
false);
68 doProcess=image_opt.retrieveOption(argc,argv);
69 band_opt.retrieveOption(argc,argv);
70 cell2bb_opt.retrieveOption(argc,argv);
71 cell2mid_opt.retrieveOption(argc,argv);
72 geo2cell_opt.retrieveOption(argc,argv);
73 refpixel_opt.retrieveOption(argc,argv);
74 maskValue_opt.retrieveOption(argc,argv);
75 dx_opt.retrieveOption(argc,argv);
76 x_opt.retrieveOption(argc,argv);
77 y_opt.retrieveOption(argc,argv);
79 catch(std::string predefinedString){
80 std::cout << predefinedString << std::endl;
84 std::cout <<
"short option -h shows basic options only, use long option --help to show all options" << std::endl;
89 if(cell2bb_opt[0]!=
""){
90 int theULX, theULY, theLRX, theLRY;
91 egcs.setLevel(egcs.cell2level(cell2bb_opt[0]));
92 egcs.cell2bb(cell2bb_opt[0],theULX,theULY,theLRX,theLRY);
93 std::cout << std::setprecision(12) <<
"--ulx=" << theULX <<
" --uly=" << theULY <<
" --lrx=" << theLRX <<
" --lry=" << theLRY << std::endl;
95 if(cell2mid_opt[0]!=
""){
97 egcs.setLevel(egcs.cell2level(cell2mid_opt[0]));
98 egcs.cell2mid(cell2mid_opt[0],midX,midY);
99 std::cout << std::setprecision(12) <<
"-x=" << midX <<
" -y=" << midY << std::endl;
102 egcs.setLevel(egcs.res2level(dx_opt[0]));
103 std::cout << egcs.geo2cell(x_opt[0],y_opt[0]) << std::endl;
105 if(image_opt[0]!=
""){
107 imgReader.
open(image_opt[0]);
109 assert(band_opt[0]<imgReader.
nrOfBand());
110 for(
int inodata=0;inodata<maskValue_opt.size();++inodata)
119 imgReader.
getRefPix(refX,refY,band_opt[0]);
120 std::cout << std::setprecision(12) <<
"--x " << refX <<
" --y " << refY << std::endl;
121 egcs.setLevel(egcs.res2level(imgReader.
getDeltaX()));
124 std::cout <<
"cell code at level " << egcs.getLevel() <<
" (resolution is " << egcs.getResolution() <<
"): " << egcs.geo2cell(refX,refY) << std::endl;
double getDeltaX(void) const
Get the pixel cell spacing in x.
int pushNoDataValue(double noDataValue)
Push a no data value for this dataset.
void getRefPix(double &refX, double &refY, int band=0)
Calculate the reference pixel as the centre of gravity pixel (weighted average of all values not taki...
void open(const std::string &filename, const GDALAccess &readMode=GA_ReadOnly)
Open an image.
int nrOfBand(void) const
Get the number of bands of this dataset.