| pktools 2.6.7 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/******************************************************************************/
51 using namespace std;
52 int main(int argc, char *argv[])
53{
54 Optionpk<std::string> image_opt("i","image","input image to analyse","");
55 Optionpk<unsigned short> band_opt("b", "band", "Band specific information", 0);
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);
60 Optionpk<int> dx_opt("dx","dx","resolution",250);
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);
62 Optionpk<double> x_opt("x","x","x coordinate in epsg:3035",0);
63 Optionpk<double> y_opt("y","y","y coordinate in epsg:3035",0);
64
65
66 bool doProcess;//stop process when program was invoked with help option (-h --help)
67 try{
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);
78 }
79 catch(std::string predefinedString){
80 std::cout << predefinedString << std::endl;
81 exit(0);
82 }
83 if(!doProcess){
84 std::cout << "short option -h shows basic options only, use long option --help to show all options" << std::endl;
85 exit(0);//help was invoked, stop processing
86 }
87
88 Egcs egcs;
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;
94 }
95 if(cell2mid_opt[0]!=""){
96 double midX, midY;
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;
100 }
101 if(geo2cell_opt[0]){
102 egcs.setLevel(egcs.res2level(dx_opt[0]));
103 std::cout << egcs.geo2cell(x_opt[0],y_opt[0]) << std::endl;
104 }
105 if(image_opt[0]!=""){
106 ImgReaderGdal imgReader;
107 imgReader.open(image_opt[0]);
108 if(refpixel_opt[0]){
109 assert(band_opt[0]<imgReader.nrOfBand());
110 for(int inodata=0;inodata<maskValue_opt.size();++inodata)
111 imgReader.pushNoDataValue(maskValue_opt[inodata]);
112 // if(verbose_opt[0]){
113 // vector<double> noData;
114 // imgReader.getNoDataValues(noData,band_opt[0]);
115 // std::cout << "number of no data values: " << noData.size() << std::endl;
116 // }
117 double refX,refY;
118 //get centre of reference (centre of gravity) pixel in image
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()));
122 // unsigned short theLevel=egcs.getLevel(imgReader.getDeltaX());
123 // egcs.setLevel(theLevel);
124 std::cout << "cell code at level " << egcs.getLevel() << " (resolution is " << egcs.getResolution() << "): " << egcs.geo2cell(refX,refY) << std::endl;
125 }
126 }
127}
Egcs
Definition: Egcs.h:27
ImgRasterGdal::nrOfBand
int nrOfBand(void) const
Get the number of bands of this dataset.
Definition: ImgRasterGdal.h:102
ImgRasterGdal::getDeltaX
double getDeltaX(void) const
Get the pixel cell spacing in x.
Definition: ImgRasterGdal.h:152
ImgRasterGdal::pushNoDataValue
int pushNoDataValue(double noDataValue)
Push a no data value for this dataset.
Definition: ImgRasterGdal.cc:492
ImgReaderGdal
Definition: ImgReaderGdal.h:37
ImgReaderGdal::open
void open(const std::string &filename, const GDALAccess &readMode=GA_ReadOnly)
Open an image.
Definition: ImgReaderGdal.cc:36
ImgReaderGdal::getRefPix
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...
Definition: ImgReaderGdal.cc:398
Optionpk
Definition: Optionpk.h:107