pktools  2.6.3
Processing Kernel for geospatial data
pkegcs.cc
1 /**********************************************************************
2 pkegcs.cc: Utility for raster files in European Grid Coordinate System
3 Copyright (C) 2008-2014 Pieter Kempeneers
4 
5 This file is part of pktools
6 
7 pktools is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 pktools is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with pktools. If not, see <http://www.gnu.org/licenses/>.
19 ***********************************************************************/
20 #include "base/Optionpk.h"
21 #include "imageclasses/ImgReaderGdal.h"
22 #include "algorithms/Egcs.h"
23 
24 int main(int argc, char *argv[])
25 {
26  Optionpk<std::string> image_opt("i","image","input image to analyse","");
27  Optionpk<unsigned short> band_opt("b", "band", "Band specific information", 0);
28  Optionpk<std::string> cell2bb_opt("c2b","cell2bb","convert cell code to geo coordinates of boundingbox (e.g. 32-AB)","");
29  Optionpk<std::string> cell2mid_opt("c2m","cell2mid","convert cell code to centre in geo coordinates (e.g. 32-AB)","");
30  Optionpk<bool> refpixel_opt("ref", "ref", "get reference pixel (lower left corner of centre of gravity pixel)", false);
31  Optionpk<double> maskValue_opt("m", "mask", "mask value(s) for no data to calculate reference pixel in image",0);
32  Optionpk<int> dx_opt("dx","dx","resolution",250);
33  Optionpk<bool> geo2cell_opt("g2c", "geo2cell", "get cell code for coordinates in x_opt and y_opt given the resolution in dx_opt", false);
34  Optionpk<double> x_opt("x","x","x coordinate in epsg:3035",0);
35  Optionpk<double> y_opt("y","y","y coordinate in epsg:3035",0);
36 
37 
38  bool doProcess;//stop process when program was invoked with help option (-h --help)
39  try{
40  doProcess=image_opt.retrieveOption(argc,argv);
41  band_opt.retrieveOption(argc,argv);
42  cell2bb_opt.retrieveOption(argc,argv);
43  cell2mid_opt.retrieveOption(argc,argv);
44  geo2cell_opt.retrieveOption(argc,argv);
45  refpixel_opt.retrieveOption(argc,argv);
46  maskValue_opt.retrieveOption(argc,argv);
47  dx_opt.retrieveOption(argc,argv);
48  x_opt.retrieveOption(argc,argv);
49  y_opt.retrieveOption(argc,argv);
50  }
51  catch(std::string predefinedString){
52  std::cout << predefinedString << std::endl;
53  exit(0);
54  }
55  if(!doProcess){
56  std::cout << "short option -h shows basic options only, use long option --help to show all options" << std::endl;
57  exit(0);//help was invoked, stop processing
58  }
59 
60  Egcs egcs;
61  if(cell2bb_opt[0]!=""){
62  int theULX, theULY, theLRX, theLRY;
63  egcs.setLevel(egcs.cell2level(cell2bb_opt[0]));
64  egcs.cell2bb(cell2bb_opt[0],theULX,theULY,theLRX,theLRY);
65  std::cout << std::setprecision(12) << "--ulx=" << theULX << " --uly=" << theULY << " --lrx=" << theLRX << " --lry=" << theLRY << std::endl;
66  }
67  if(cell2mid_opt[0]!=""){
68  double midX, midY;
69  egcs.setLevel(egcs.cell2level(cell2mid_opt[0]));
70  egcs.cell2mid(cell2mid_opt[0],midX,midY);
71  std::cout << std::setprecision(12) << "-x=" << midX << " -y=" << midY << std::endl;
72  }
73  if(geo2cell_opt[0]){
74  egcs.setLevel(egcs.res2level(dx_opt[0]));
75  std::cout << egcs.geo2cell(x_opt[0],y_opt[0]) << std::endl;
76  }
77  if(image_opt[0]!=""){
78  ImgReaderGdal imgReader;
79  imgReader.open(image_opt[0]);
80  if(refpixel_opt[0]){
81  assert(band_opt[0]<imgReader.nrOfBand());
82  for(int inodata=0;inodata<maskValue_opt.size();++inodata)
83  imgReader.pushNoDataValue(maskValue_opt[inodata]);
84  // if(verbose_opt[0]){
85  // vector<double> noData;
86  // imgReader.getNoDataValues(noData,band_opt[0]);
87  // std::cout << "number of no data values: " << noData.size() << std::endl;
88  // }
89  double refX,refY;
90  //get centre of reference (centre of gravity) pixel in image
91  imgReader.getRefPix(refX,refY,band_opt[0]);
92  std::cout << std::setprecision(12) << "--x " << refX << " --y " << refY << std::endl;
93  egcs.setLevel(egcs.res2level(imgReader.getDeltaX()));
94  // unsigned short theLevel=egcs.getLevel(imgReader.getDeltaX());
95  // egcs.setLevel(theLevel);
96  std::cout << "cell code at level " << egcs.getLevel() << " (resolution is " << egcs.getResolution() << "): " << egcs.geo2cell(refX,refY) << std::endl;
97  }
98  }
99 }
Definition: Egcs.h:26