| 1 | /********************************************************************** |
| 2 | pktestexternal: test program for Jim constructor with external data |
| 3 | Author(s): [email protected] |
| 4 | Copyright (C) 2016-2020 European Union (Joint Research Centre) |
| 5 | |
| 6 | This file is part of jiplib. |
| 7 | |
| 8 | jiplib is free software: you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation, either version 3 of the License, or |
| 11 | (at your option) any later version. |
| 12 | |
| 13 | jiplib is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with jiplib. If not, see <https://www.gnu.org/licenses/>. |
| 20 | ***********************************************************************/ |
| 21 | #include <math.h> |
| 22 | #include <string> |
| 23 | #include <fstream> |
| 24 | #include <assert.h> |
| 25 | #include "base/Optionjl.h" |
| 26 | #include "imageclasses/Jim.h" |
| 27 | |
| 28 | using namespace std; |
| 29 | |
| 30 | int main(int argc, char *argv[]) |
| 31 | { |
| 32 | Optionjl<string> input_opt("i", "input", "Input shape file"); |
| 33 | Optionjl<string> output_opt("o", "output", "Output vector dataset"); |
| 34 | Optionjl<string> attribute_opt("af", "afilter", "attribute filter"); |
| 35 | Optionjl<short> verbose_opt("v", "verbose", "verbose (Default: 0)", 0,2); |
| 36 | |
| 37 | verbose_opt.setHide(2); |
| 38 | |
| 39 | bool doProcess;//stop process when program was invoked with help option (-h --help) |
| 40 | try{ |
| 41 | doProcess=input_opt.retrieveOption(argc,argv); |
| 42 | output_opt.retrieveOption(argc,argv); |
| 43 | verbose_opt.retrieveOption(argc,argv); |
| 44 | } |
| 45 | catch(string predefinedString){ |
| 46 | std::cout << predefinedString << std::endl; |
| 47 | exit(0); |
| 48 | } |
| 49 | if(!doProcess){ |
| 50 | cout << endl; |
| 51 | cout << "Usage: pktestogr -i input [-o output]" << endl; |
| 52 | cout << endl; |
| 53 | std::cout << "short option -h shows basic options only, use long option --help to show all options" << std::endl; |
| 54 | exit(0);//help was invoked, stop processing |
| 55 | } |
| 56 | |
| 57 | if(input_opt.empty()){ |
| 58 | std::cerr << "No input file provided (use option -i). Use --help for help information" << std::endl; |
| 59 | exit(0); |
| 60 | } |
| 61 | if(output_opt.empty()){ |
| 62 | std::cerr << "No output file provided (use option -o). Use --help for help information" << std::endl; |
| 63 | exit(0); |
| 64 | } |
| 65 | |
| 66 | try{ |
| 67 | Jim inputReader(input_opt[0]); |
| 68 | std::vector<void*> vdata(inputReader.nrOfBand()); |
| 69 | for(size_t iband=0;iband<inputReader.nrOfBand();++iband) |
| 70 | vdata[iband]=inputReader.getDataPointer(iband); |
| 71 | if(verbose_opt[0]) |
| 72 | std::cout << "construct externalRaster" << std::endl; |
| 73 | Jim externalRaster; |
| 74 | externalRaster.open(vdata,inputReader.nrOfCol(),inputReader.nrOfRow(),inputReader.nrOfPlane(),inputReader.getGDALDataType()); |
| 75 | externalRaster.setExternalData(true); |
| 76 | externalRaster.setFile(output_opt[0],"GTiff"); |
| 77 | externalRaster.setProjectionProj4(inputReader.getProjection()); |
| 78 | double gt[6]; |
| 79 | inputReader.getGeoTransform(gt); |
| 80 | externalRaster.setGeoTransform(gt); |
| 81 | if(verbose_opt[0]) |
| 82 | std::cout << "write externalRaster" << std::endl; |
| 83 | externalRaster.write(); |
| 84 | if(verbose_opt[0]) |
| 85 | std::cout << "close externalRaster" << std::endl; |
| 86 | externalRaster.close(); |
| 87 | if(verbose_opt[0]) |
| 88 | std::cout << "close inputReader" << std::endl; |
| 89 | inputReader.close(); |
| 90 | } |
| 91 | catch(string errorstring){ |
| 92 | cerr << errorstring << endl; |
| 93 | } |
| 94 | } |
| 95 |