8 #include <boost/program_options.hpp>
15 boost::program_options::variables_map
g_vm;
17 boost::program_options::options_description
g_help(
"Help");
18 boost::program_options::options_description
g_functions(
"Functions");
19 boost::program_options::options_description
g_parameters(
"Parameters");
21 boost::program_options::options_description
g_all(
"All options");
22 boost::program_options::options_description
g_hidden(
"Hidden options");
23 boost::program_options::options_description
g_visible(
"Allowed options");
29 std::cout <<
">>>> " << errorMessage <<
" <<<<" << std::endl << std::endl;
31 std::cout <<
"---------------------------" << std::endl;
37 std::ostringstream helpText;
39 if(
g_vm.count(
"help-input"))
41 helpText <<
"input" << std::endl;
42 helpText <<
"-----" << std::endl << std::endl;
43 helpText <<
"The \"input\" is a required parameter for all functions. It's the full path of the raster, including the file name and extension." << std::endl;
46 else if(
g_vm.count(
"help-info"))
48 helpText <<
"info" << std::endl;
49 helpText <<
"----" << std::endl << std::endl;
50 helpText <<
"The \"info\" function show raster informations, like:" << std::endl;
51 helpText <<
" - Raster Name" << std::endl;
52 helpText <<
" - Number of Columns" << std::endl;
53 helpText <<
" - Number of Rows" << std::endl;
54 helpText <<
" - Number of Bands" << std::endl;
55 helpText <<
" - SRID" << std::endl;
56 helpText <<
" - Resolution in X" << std::endl;
57 helpText <<
" - Resolution in Y" << std::endl;
58 helpText <<
" - Extent UR" << std::endl;
59 helpText <<
" - Extent LL" << std::endl;
60 helpText <<
"And informations about the raster bands, like:" << std::endl;
61 helpText <<
" - Min Values" << std::endl;
62 helpText <<
" - Max Values" << std::endl;
63 helpText <<
" - Mean Values" << std::endl;
64 helpText <<
" - Std Values" << std::endl;
65 helpText <<
" - Gain values" << std::endl;
66 helpText <<
" - Offset values" << std::endl << std::endl;
67 helpText <<
"Required parameters:" << std::endl;
68 helpText <<
" - input" << std::endl;
69 helpText << std::endl;
72 else if(
g_vm.count(
"help-copy"))
74 helpText <<
"copy" << std::endl;
75 helpText <<
"----" << std::endl << std::endl;
76 helpText <<
"The \"copy\" is a function that make a copy of the input raster. In this function, the output parameter is required." << std::endl << std::endl;
77 helpText <<
"Required parameters:" << std::endl;
78 helpText <<
" - input" << std::endl;
79 helpText <<
" - output" << std::endl;
80 helpText <<
"Optional parameters:" << std::endl;
81 helpText <<
" - band" << std::endl;
82 helpText <<
" - band-type" << std::endl;
83 helpText << std::endl;
86 else if(
g_vm.count(
"help-output"))
88 helpText <<
"output" << std::endl;
89 helpText <<
"------" << std::endl << std::endl;
90 helpText <<
"The \"output\" parameter is the full path of the output raster, including the file name and extension." << std::endl;
91 helpText <<
"It's used by the functions (copy, reproject, ...). Some functions overwrite the input raster if the output doesn't be declared." << std::endl;
92 helpText << std::endl;
95 else if(
g_vm.count(
"help-band"))
97 helpText <<
"band" << std::endl;
98 helpText <<
"----" << std::endl << std::endl;
99 helpText <<
"The \"band\" is a copy function parameter that receive a list of bands indexes that the user would like to copy." << std::endl;
100 helpText << std::endl;
103 else if(
g_vm.count(
"help-reproject"))
105 helpText <<
"reproject" << std::endl;
106 helpText <<
"---------" << std::endl << std::endl;
107 helpText <<
"The \"reproject\" is a function that reproject a raster based in the srid passed." << std::endl << std::endl;
108 helpText <<
"Required parameters:" << std::endl;
109 helpText <<
" - input" << std::endl;
110 helpText <<
" - srid" << std::endl;
111 helpText <<
"Optional parameters:" << std::endl;
112 helpText <<
" - output" << std::endl;
113 helpText << std::endl;
116 else if(
g_vm.count(
"help-convert"))
118 helpText <<
"convert" << std::endl;
119 helpText <<
"-------" << std::endl << std::endl;
120 helpText <<
"The \"convert\" is a function that convert a raster based in the extension passed." << std::endl;
121 helpText <<
"If you pass the \"output\", the image will have these output path (including name and extension)." << std::endl;
122 helpText <<
"Else, if you pass the \"extension\", the image will have the sabe name, but the extension passed." << std::endl;
123 helpText << std::endl;
124 helpText <<
"Required parameters:" << std::endl;
125 helpText <<
" - input" << std::endl;
126 helpText <<
" - extension or output" << std::endl;
127 helpText <<
"Optional parameters:" << std::endl;
128 helpText <<
" - band" << std::endl;
129 helpText << std::endl;
132 else if(
g_vm.count(
"help-resolution"))
134 helpText <<
"resolution" << std::endl;
135 helpText <<
"----------" << std::endl << std::endl;
136 helpText <<
"The \"resolution\" is a function that change the raster resolution based in the method and scale passed." << std::endl << std::endl;
137 helpText <<
"Required parameters:" << std::endl;
138 helpText <<
" - input" << std::endl;
139 helpText <<
" - method" << std::endl;
140 helpText <<
" - scale" << std::endl;
141 helpText <<
"Optional parameters:" << std::endl;
142 helpText <<
" - output" << std::endl;
143 helpText << std::endl;
146 else if(
g_vm.count(
"help-method"))
148 helpText <<
"method" << std::endl;
149 helpText <<
"------" << std::endl << std::endl;
150 helpText <<
"The \"method\" is a Resolution function parameter that receive a method for the function is based." << std::endl;
151 helpText <<
"The options are:" << std::endl;
152 helpText <<
" - \"1\" to use Nearest Neighbor method" << std::endl;
153 helpText <<
" - \"2\" to use Bilinear method" << std::endl;
154 helpText <<
" - \"3\" to use Bicubic method" << std::endl;
155 helpText << std::endl;
158 else if(
g_vm.count(
"help-scale"))
160 helpText <<
"scale" << std::endl;
161 helpText <<
"-----" << std::endl << std::endl;
162 helpText <<
"The \"scale\" is a Resolution function parameter that receive a scale integer for the function is based." << std::endl;
163 helpText <<
"For example: with a scale equal \"2\", all raster grid cells dimensions will be multiplied to 2." << std::endl;
164 helpText <<
" but if scale equal \"-2\", all raster grid cells dimensions will be divided to 2." << std::endl;
165 helpText << std::endl;
168 else if(
g_vm.count(
"help-extension"))
170 helpText <<
"extension" << std::endl;
171 helpText <<
"---------" << std::endl << std::endl;
172 helpText <<
"The \"extension\" is a Convert function parameter that receive a extension for the function is based." << std::endl;
173 helpText <<
"The options are:" << std::endl;
174 helpText <<
" - jpg" << std::endl;
175 helpText <<
" - png" << std::endl;
176 helpText <<
" - tif" << std::endl;
177 helpText << std::endl;
180 else if(
g_vm.count(
"help-srid"))
182 helpText <<
"srid" << std::endl;
183 helpText <<
"----" << std::endl << std::endl;
184 helpText <<
"The \"srid\" is a Reproject function parameter that receive a srid code for the function is based." << std::endl;
185 helpText << std::endl;
188 else if(
g_vm.count(
"help-trim"))
190 helpText <<
"trim" << std::endl;
191 helpText <<
"----" << std::endl << std::endl;
192 helpText <<
"The \"trim\" is a function that trim a raster based in the envelope passed." << std::endl << std::endl;
193 helpText <<
"Required parameters:" << std::endl;
194 helpText <<
" - input" << std::endl;
195 helpText <<
" - envelope" << std::endl;
196 helpText <<
"Optional parameters:" << std::endl;
197 helpText <<
" - output" << std::endl;
198 helpText << std::endl;
201 else if(
g_vm.count(
"help-envelope"))
203 helpText <<
"envelope" << std::endl;
204 helpText <<
"--------" << std::endl << std::endl;
205 helpText <<
"--envelope <llx> <lly> <urx> <urx>" << std::endl << std::endl;
206 helpText <<
"The \"envelope\" is a Trim function parameter that receive four doubles representind a envelope (box)." << std::endl;
207 helpText <<
"The order of passing parameters is:" << std::endl;
208 helpText <<
" - llx" << std::endl;
209 helpText <<
" - lly" << std::endl;
210 helpText <<
" - urx" << std::endl;
211 helpText <<
" - ury" << std::endl;
212 helpText <<
"Example: --envelope -40 -30 -20 5" << std::endl;
213 helpText << std::endl;
216 else if(
g_vm.count(
"help-band-type"))
218 helpText <<
"band type" << std::endl;
219 helpText <<
"----" << std::endl << std::endl;
220 helpText <<
"The \"band type\" is a copy function parameter that define witch type the output raster will have." << std::endl;
221 helpText <<
"(Not implemented yet!)" << std::endl;
222 helpText << std::endl;
225 else if(
g_vm.count(
"examples"))
227 helpText <<
"Use Examples" << std::endl;
228 helpText <<
"------------" << std::endl << std::endl;
229 helpText <<
"Info function" << std::endl << std::endl;
230 helpText <<
"--info --input D:\\MyRasters\\raster.tif" << std::endl;
231 helpText << std::endl <<
"Copy function" << std::endl << std::endl;
232 helpText <<
"--copy --input D:\\MyRasters\\raster.tif --output D:\\MyRasters\\raster_copy.tif" << std::endl;
233 helpText <<
"--copy --input D:\\MyRasters\\raster.tif --output D:\\MyRasters\\raster_copy.tif --band 2 3" << std::endl;
234 helpText <<
"--copy --input D:\\MyRasters\\raster.tif --output D:\\MyRasters\\raster_copy.tif --band-type 4" << std::endl;
235 helpText << std::endl <<
"Reproject function" << std::endl << std::endl;
236 helpText <<
"--reproject --input D:\\MyRasters\\raster.tif --srid 29181" << std::endl;
237 helpText <<
"--reproject --input D:\\MyRasters\\raster.tif --output D:\\MyRasters\\raster_reprojected.tif --srid 29181" << std::endl;
238 helpText << std::endl <<
"Convert function" << std::endl << std::endl;
239 helpText <<
"--convert --input D:\\MyRasters\\raster.tif --extension jpg" << std::endl;
240 helpText <<
"--convert --input D:\\MyRasters\\raster.tif" "D:\\MyRasters\\raster_converted.jpg" << std::endl;
241 helpText << std::endl <<
"Resolution function" << std::endl << std::endl;
242 helpText <<
"--resolution --input D:\\MyRasters\\raster.tif --method 1 --scale 2" << std::endl;
243 helpText <<
"--resolution --input D:\\MyRasters\\raster.tif --method 1 --scale -2" << std::endl;
244 helpText <<
"--resolution --input D:\\MyRasters\\raster.tif --output D:\\MyRasters\\raster_new.tif --method 1 --scale -2" << std::endl;
245 helpText << std::endl <<
"Trim function" << std::endl << std::endl;
246 helpText <<
"--trim --input D:\\MyRasters\\raster.tif --envelope -40 -30 -20 5" << std::endl;
247 helpText <<
"--trim --input D:\\MyRasters\\raster.tif --output D:\\MyRasters\\raster_trimmed.tif --envelope -40 -30 -20 5" << std::endl;
248 helpText << std::endl;
252 std::cout << helpText.str() << std::endl;
258 int main(
int argc,
char* argv[])
264 std::string input = std::string();
265 std::string output = std::string();
266 std::vector<int> bands = std::vector<int>();
268 std::string extension = std::string();
271 std::vector<double> envelope = std::vector<double>();
274 std::string errorMessage = std::string();
277 std::cout << std::endl <<
"TerraLib Raster Manager" << std::endl;
278 std::cout <<
"-------------------------" << std::endl << std::endl;
282 (
"info,f",
"Show Raster Informations")
283 (
"copy,p",
"Copy function")
284 (
"reproject,r",
"Reproject function")
285 (
"convert,c",
"Convert function")
286 (
"resolution,l",
"Change Resolution function")
287 (
"trim,t",
"Trim function")
288 (
"help,h",
"Terralib Raster Manager. --help-<function> or --help-<parameter>")
289 (
"examples,x",
"Show use examples")
290 (
"supported,u",
"Supported Extensions")
295 (
"input,i", boost::program_options::value<std::string>(),
"Input Raster (Required)")
296 (
"output,o", boost::program_options::value<std::string>(),
"Output Raster")
297 (
"band,b", boost::program_options::value<std::vector<int>>()->multitoken(),
"Band to copy")
298 (
"method,m", boost::program_options::value<int>(),
"Method used to change resolution (\"1\"-NearestNeighbor, \"2\"-Bilinear, \"3\"-Bicubic)")
299 (
"scale,s", boost::program_options::value<int>(),
"Scale used to change resolution")
300 (
"srid,d", boost::program_options::value<int>(),
"Srid used to reproject")
301 (
"extension,e", boost::program_options::value<std::string>(),
"Extension used to convert")
302 (
"envelope,v", boost::program_options::value<std::vector<double>>()->multitoken(),
"Envelope used to trim")
303 (
"band-type,n", boost::program_options::value<int>(),
"Type of the band")
313 (
"help-reproject",
"")
315 (
"help-resolution",
"")
317 (
"help-extension",
"")
321 (
"help-band-type",
"")
334 boost::program_options::store(boost::program_options::parse_command_line(argc, argv,
g_all),
g_vm);
335 boost::program_options::notify(
g_vm);
341 if(
g_vm.count(
"help") ||
g_vm.empty())
344 std::cout <<
"---------------------------" << std::endl;
349 input = (
g_vm.count(
"input") ?
g_vm[
"input"].as<std::string>() : std::string());
350 output = (
g_vm.count(
"output") ?
g_vm[
"output"].as<std::string>() : std::string());
351 bands = (
g_vm.count(
"band") ?
g_vm[
"band"].as<std::vector<int>>() : std::vector<int>());
352 srid = (
g_vm.count(
"srid") ?
g_vm[
"srid"].as<
int>() : -1);
353 extension = (
g_vm.count(
"extension") ?
g_vm[
"extension"].as<std::string>() : std::string());
354 method = (
g_vm.count(
"method") ?
g_vm[
"method"].as<
int>() :
int());
355 scale = (
g_vm.count(
"scale") ?
g_vm[
"scale"].as<
int>() :
int());
356 envelope = (
g_vm.count(
"envelope") ?
g_vm[
"envelope"].as<std::vector<double>>() : std::vector<double>());
357 bandType = (
g_vm.count(
"band-type") ?
g_vm[
"band-type"].as<
int>() : -1);
364 if(
g_vm.count(
"supported"))
373 showError(
"Comannd line error: input raster missing!");
377 if(!g_rm.
init(input, errorMessage))
384 if(
g_vm.count(
"info"))
386 std::ostringstream output;
392 std::cout << output.str();
397 else if(
g_vm.count(
"copy"))
401 showError(
"For copy, output is required!");
404 else if(!g_rm.
copyRaster(output, bands, bandType, errorMessage))
410 std::cout <<
"Rester Copied!" << std::endl << std::endl;
415 else if(
g_vm.count(
"reproject"))
419 showError(
"For reproject, srid is required!");
422 if(!g_rm.
reproject(output, srid, errorMessage))
428 std::cout <<
"Rester Reprojected!" << std::endl << std::endl;
433 else if(
g_vm.count(
"convert"))
435 if(extension.empty() && output.empty())
437 showError(
"For Convert, extension or output is required!");
440 if(!g_rm.
convert(output, extension, bands, errorMessage))
446 std::cout <<
"Rester Converted!" << std::endl << std::endl;
451 else if(
g_vm.count(
"resolution"))
453 if(method == 0 || scale == 0)
455 showError(
"For change Resolution, method and scale are required!");
464 std::cout <<
"Resolution Changed!" << std::endl << std::endl;
469 else if(
g_vm.count(
"trim"))
471 if(!g_rm.
trim(output, envelope, errorMessage))
477 std::cout <<
"Trim executed!" << std::endl << std::endl;
484 std::ostringstream output;
490 std::cout << output.str();
497 catch(std::exception& e)
499 std::cout <<
"The application concluded erroneously: " << e.what() << std::endl;
503 std::cout <<
"The application concluded unexpectedly!" << std::endl;
boost::program_options::options_description g_visible("Allowed options")
Which will be shown to the user.
Terralib Raster Manager Tool.
boost::program_options::options_description g_functions("Functions")
Group of functions options.
boost::program_options::variables_map g_vm
Map o options after parse.
void showError(std::string errorMessage)
void finalize()
It finalizes the TerraLib Platform.
static TerraLib & getInstance()
It returns a reference to the singleton instance.
int main(int argc, char *argv[])
boost::program_options::options_description g_hidden("Hidden options")
Which will not be shown to the user.
te::tools::rastermanager::RasterManager g_rm
Raster Manager Object.
boost::program_options::options_description g_parameters("Parameters")
Group of parameters options.
void initialize()
It initializes the TerraLib Platform.
This file contains include headers for the TerraLib Common Runtime module.
boost::program_options::options_description g_help("Help")
Group of help options.
boost::program_options::options_description g_all("All options")
All options.