22 #include "base/Optionpk.h"
23 #include "algorithms/Egcs.h"
24 #include "imageclasses/ImgReaderGdal.h"
25 #include "imageclasses/ImgReaderOgr.h"
29 int main(
int argc,
char *argv[])
32 Optionpk<bool> bbox_opt(
"bb",
"bbox",
"Shows bounding box ",
false,0);
33 Optionpk<bool> bbox_te_opt(
"te",
"te",
"Shows bounding box in GDAL format: xmin ymin xmax ymax ",
false,0);
34 Optionpk<bool> center_opt(
"c",
"center",
"Image center in projected X,Y coordinates ",
false,0);
35 Optionpk<bool> colorTable_opt(
"ct",
"colortable",
"Shows colour table ",
false,0);
36 Optionpk<bool> samples_opt(
"ns",
"nsample",
"Number of samples in image ",
false,0);
37 Optionpk<bool> lines_opt(
"nl",
"nline",
"Number of lines in image ",
false,0);
38 Optionpk<bool> nband_opt(
"nb",
"nband",
"Show number of bands in image",
false,0);
39 Optionpk<short> band_opt(
"b",
"band",
"Band specific information", 0,0);
40 Optionpk<bool> dx_opt(
"dx",
"dx",
"Gets resolution in x (in m)",
false,0);
41 Optionpk<bool> dy_opt(
"dy",
"dy",
"Gets resolution in y (in m)",
false,0);
42 Optionpk<bool> minmax_opt(
"mm",
"minmax",
"Shows min and max value of the image ",
false,0);
43 Optionpk<bool> min_opt(
"min",
"minimum",
"Shows min value of the image ",
false,0);
44 Optionpk<bool> max_opt(
"max",
"maximum",
"Shows max value of the image ",
false,0);
45 Optionpk<bool> stat_opt(
"stats",
"statistics",
"Shows statistics (min,max, mean and stdDev of the image)",
false,0);
46 Optionpk<bool> projection_opt(
"a_srs",
"a_srs",
"Shows projection of the image ",
false,0);
47 Optionpk<bool> geo_opt(
"geo",
"geo",
"Gets geotransform ",
false,0);
48 Optionpk<bool> interleave_opt(
"il",
"interleave",
"Shows interleave ",
false,0);
49 Optionpk<bool> filename_opt(
"f",
"filename",
"Shows image filename ",
false,0);
50 Optionpk<bool> cover_opt(
"cover",
"cover",
"Print filename to stdout if current image covers the provided coordinates via bounding box, (x y) coordinates or extent of vector file",
false,0);
53 Optionpk<bool> read_opt(
"r",
"read",
"Reads row y (in projected coordinates if geo option is set, otherwise in image coordinates, 0 based)",
false,0);
54 Optionpk<bool> refpixel_opt(
"ref",
"reference",
"Gets reference pixel (lower left corner of center of gravity pixel)",
false,0);
55 Optionpk<bool> driver_opt(
"of",
"oformat",
"Gets driver description ",
false,0);
61 Optionpk<bool> type_opt(
"ot",
"otype",
"Returns data type",
false,0);
62 Optionpk<bool> description_opt(
"d",
"description",
"Returns image description",
false,0);
63 Optionpk<bool> metadata_opt(
"meta",
"meta",
"Shows meta data ",
false,0);
64 Optionpk<double> nodata_opt(
"nodata",
"nodata",
"Sets no data value(s) for calculations (nodata values in input image)");
68 doProcess=input_opt.retrieveOption(argc,argv);
69 bbox_opt.retrieveOption(argc,argv);
70 bbox_te_opt.retrieveOption(argc,argv);
71 center_opt.retrieveOption(argc,argv);
72 colorTable_opt.retrieveOption(argc,argv);
73 samples_opt.retrieveOption(argc,argv);
74 lines_opt.retrieveOption(argc,argv);
75 nband_opt.retrieveOption(argc,argv);
76 band_opt.retrieveOption(argc,argv);
77 dx_opt.retrieveOption(argc,argv);
78 dy_opt.retrieveOption(argc,argv);
79 minmax_opt.retrieveOption(argc,argv);
80 min_opt.retrieveOption(argc,argv);
81 max_opt.retrieveOption(argc,argv);
82 stat_opt.retrieveOption(argc,argv);
83 projection_opt.retrieveOption(argc,argv);
84 geo_opt.retrieveOption(argc,argv);
85 interleave_opt.retrieveOption(argc,argv);
86 filename_opt.retrieveOption(argc,argv);
87 cover_opt.retrieveOption(argc,argv);
88 x_opt.retrieveOption(argc,argv);
89 y_opt.retrieveOption(argc,argv);
90 read_opt.retrieveOption(argc,argv);
91 refpixel_opt.retrieveOption(argc,argv);
92 driver_opt.retrieveOption(argc,argv);
93 extent_opt.retrieveOption(argc,argv);
94 ulx_opt.retrieveOption(argc,argv);
95 uly_opt.retrieveOption(argc,argv);
96 lrx_opt.retrieveOption(argc,argv);
97 lry_opt.retrieveOption(argc,argv);
98 type_opt.retrieveOption(argc,argv);
99 description_opt.retrieveOption(argc,argv);
100 metadata_opt.retrieveOption(argc,argv);
101 nodata_opt.retrieveOption(argc,argv);
103 catch(std::string predefinedString){
104 std::cout << predefinedString << std::endl;
109 cout <<
"Usage: pkinfo -i input [options]" << endl;
111 std::cout <<
"short option -h shows basic options only, use long option --help to show all options" << std::endl;
126 double theULX, theULY, theLRX, theLRY;
129 if(extent_opt.size()){
130 extentReader.open(extent_opt[0]);
131 if(!(extentReader.getExtent(theULX,theULY, theLRX, theLRY))){
132 std::cerr <<
"Error: could not get extent from " << extent_opt[0] << std::endl;
135 ulx_opt.push_back(theULX);
136 uly_opt.push_back(theULY);
137 lrx_opt.push_back(theLRX);
138 lry_opt.push_back(theLRY);
139 if(input_opt.empty()){
141 std::cout << std::setprecision(12) <<
"-te " << theULX <<
" " << theLRY <<
" " << theLRX <<
" " << theULY;
143 std::cout << std::setprecision(12) <<
"--ulx=" << theULX <<
" --uly=" << theULY <<
" --lrx=" << theLRX <<
" --lry=" << theLRY <<
" ";
148 for(
int ifile=0;ifile<input_opt.size();++ifile){
149 imgReader.open(input_opt[ifile]);
150 for(
int inodata=0;inodata<nodata_opt.size();++inodata){
152 imgReader.GDALSetNoDataValue(nodata_opt[0],band_opt[0]);
153 imgReader.pushNoDataValue(nodata_opt[inodata]);
156 std::cout <<
" --input " << input_opt[ifile] <<
" ";
159 imgReader.getCenterPos(theX,theY);
160 std::cout << std::setprecision(12) <<
" -x " << theX <<
" -y " << theY <<
" ";
163 assert(band_opt[0]<imgReader.nrOfBand());
167 imgReader.getRefPix(refX,refY,band_opt[0]);
168 std::cout << std::setprecision(12) <<
"-x " << refX <<
" -y " << refY << std::endl;
169 egcs.setLevel(egcs.res2level(imgReader.getDeltaX()));
174 if(bbox_opt[0]||bbox_te_opt[0]){
175 imgReader.getBoundingBox(theULX,theULY,theLRX,theLRY);
177 std::cout << std::setprecision(12) <<
"-te " << theULX <<
" " << theLRY <<
" " << theLRX <<
" " << theULY;
179 std::cout << std::setprecision(12) <<
"--ulx=" << theULX <<
" --uly=" << theULY <<
" --lrx=" << theLRX <<
" --lry=" << theLRY <<
" ";
192 maxLRX=(theLRX>maxLRX)?theLRX:maxLRX;
193 maxULY=(theULY>maxULY)?theULY:maxULY;
194 minULX=(theULX<minULX)?theULX:minULX;
195 minLRY=(theLRY<minLRY)?theLRY:minLRY;
197 minLRX=(theLRX<minLRX)?theLRX:minLRX;
198 minULY=(theULY<minULY)?theULY:minULY;
199 maxULX=(theULX>maxULX)?theULX:maxULX;
200 maxLRY=(theLRY>maxLRY)?theLRY:maxLRY;
204 std::cout <<
"--dx " << imgReader.getDeltaX() <<
" ";
206 std::cout <<
"--dy " << imgReader.getDeltaY() <<
" ";
208 if(ulx_opt.size()&&uly_opt.size()&&lrx_opt.size()&&lry_opt.size()){
209 if(imgReader.covers(ulx_opt[0],uly_opt[0],lrx_opt[0],lry_opt[0]))
210 std::cout <<
" -i " << input_opt[ifile] <<
" ";
212 else if(x_opt.size()&&y_opt.size()){
213 if(imgReader.covers(x_opt[0],y_opt[0]))
214 std::cout <<
" -i " << input_opt[ifile] <<
" ";
217 std::cerr <<
"Error: failing extent (-e), bounding box or x and y position to define coverage" << std::endl;
221 else if(ulx_opt.size()||uly_opt.size()||lrx_opt.size()||lry_opt.size()){
222 double ulx,uly,lrx,lry;
223 imgReader.getBoundingBox(ulx,uly,lrx,lry);
225 std::cout <<
" --ulx=" << std::fixed << ulx <<
" ";
227 std::cout <<
" --uly=" << std::fixed << uly <<
" ";
229 std::cout <<
" --lrx=" << std::fixed << lrx <<
" ";
231 std::cout <<
" --lry=" << std::fixed << lry <<
" ";
233 if(colorTable_opt[0]){
234 GDALColorTable* colorTable=imgReader.getColorTable();
235 if(colorTable!=NULL){
236 for(
int index=0;index<colorTable->GetColorEntryCount();++index){
237 GDALColorEntry sEntry=*(colorTable->GetColorEntry(index));
238 std::cout << index <<
" " << sEntry.c1 <<
" " << sEntry.c2 <<
" " << sEntry.c3 <<
" " << sEntry.c4 << std::endl;
242 std::cout <<
"-ct none ";
245 std::cout <<
"--nsample " << imgReader.nrOfCol() <<
" ";
247 std::cout <<
"--nline " << imgReader.nrOfRow() <<
" ";
249 std::cout <<
"--nband " << imgReader.nrOfBand() <<
" ";
254 int nband=band_opt.size();
256 nband=imgReader.nrOfBand();
257 for(
int iband=0;iband<nband;++iband){
258 unsigned short theBand=(band_opt[0]<0)? iband : band_opt[iband];
260 assert(theBand<imgReader.nrOfBand());
261 GDALProgressFunc pfnProgress;
263 GDALRasterBand* rasterBand;
264 rasterBand=imgReader.getRasterBand(theBand);
265 rasterBand->ComputeStatistics(0,&minValue,&maxValue,&meanValue,&stdDev,pfnProgress,pProgressData);
266 std::cout <<
"-min " << minValue <<
" -max " << maxValue <<
" --mean " << meanValue <<
" --stdDev " << stdDev <<
" ";
269 if(minmax_opt[0]||min_opt[0]||max_opt[0]){
270 assert(theBand<imgReader.nrOfBand());
271 if((ulx_opt.size()||uly_opt.size()||lrx_opt.size()||lry_opt.size())&&(imgReader.covers(ulx_opt[0],uly_opt[0],lrx_opt[0],lry_opt[0]))){
272 double uli,ulj,lri,lrj;
273 imgReader.geo2image(ulx_opt[0],uly_opt[0],uli,ulj);
274 imgReader.geo2image(lrx_opt[0],lry_opt[0],lri,lrj);
275 imgReader.getMinMax(static_cast<int>(uli),static_cast<int>(lri),static_cast<int>(ulj),static_cast<int>(lrj),theBand,minValue,maxValue);
278 imgReader.getMinMax(minValue,maxValue,theBand,
true);
280 std::cout <<
"-min " << minValue <<
" -max " << maxValue <<
" ";
283 std::cout <<
"-min " << minValue <<
" ";
285 std::cout <<
"-max " << maxValue <<
" ";
289 if(projection_opt[0]){
290 if(imgReader.isGeoRef())
291 std::cout <<
" -a_srs " << imgReader.getProjection() <<
" ";
293 std::cout <<
" -a_srs none" <<
" ";
295 if(geo_opt[0]&&!read_opt[0]){
296 std::cout <<
" -geo " << std::setprecision(12) << imgReader.getGeoTransform();
298 if(interleave_opt[0]){
299 std::cout <<
" --interleave " << imgReader.getInterleave() <<
" ";
302 std::cout <<
"--otype " << GDALGetDataTypeName(imgReader.getDataType(band_opt[0])) <<
" ";
305 if(description_opt[0]){
312 std::list<std::string> metaData;
313 imgReader.getMetadata(metaData);
314 std::list<std::string>::const_iterator lit=metaData.begin();
315 std::cout <<
" --description ";
316 while(lit!=metaData.end())
317 std::cout << *(lit++) <<
" ";
320 std::cout <<
"Metadata: " << std::endl;
321 std::list<std::string> lmeta;
322 imgReader.getMetadata(lmeta);
323 std::list<std::string>::const_iterator lit=lmeta.begin();
324 while(lit!=lmeta.end()){
325 std::cout << *lit << std::endl;
338 std::cout.precision(12);
339 for(
int iband=0;iband<nband;++iband){
340 unsigned short theBand=(band_opt[0]<0)? iband : band_opt[iband];
341 std::vector<float> rowBuffer;
342 for(
int iy=0;iy<y_opt.size();++iy){
343 double theRow=y_opt[iy];
344 int ncol=(x_opt.size())? x_opt.size() : imgReader.nrOfCol();
345 for(
int ix=0;ix<ncol;++ix){
349 imgReader.geo2image(x_opt[ix],y_opt[iy],theCol,theRow);
354 assert(theRow<imgReader.nrOfRow());
355 imgReader.readData(rowBuffer,GDT_Float32, static_cast<int>(theRow), theBand);
356 assert(theCol<rowBuffer.size());
357 std::cout << rowBuffer[static_cast<int>(theCol)] <<
" ";
359 std::cout << std::endl;
364 std::cout <<
" --oformat " << imgReader.getDriverDescription() <<
" ";
367 if((bbox_opt[0]||bbox_te_opt[0])&&input_opt.size()>1){
369 std::cout << std::setprecision(12) <<
"-te " << minULX <<
" " << minLRY <<
" " << maxLRX <<
" " << maxULY;
371 std::cout <<
"union bounding box: " << std::setprecision(12) <<
"--ulx=" << minULX <<
" --uly=" << maxULY <<
" --lrx=" << maxLRX <<
" --lry=" << minLRY << std::endl;
372 if(maxULX<minLRX&&minULY>maxLRY){
374 std::cout <<
"intersect bounding box: " << std::setprecision(12) <<
"-te " << maxULX <<
" " << maxLRY <<
" " << minLRX <<
" --lry=" << minULY << std::endl;
376 std::cout <<
"intersect bounding box: " << std::setprecision(12) <<
"--ulx=" << maxULX <<
" --uly=" << minULY <<
" --lrx=" << minLRX <<
" --lry=" << maxLRY << std::endl;
379 std::cout <<
"no intersect" << std::endl;
382 std::cout << std::endl;