20 #include "cpl_string.h"
21 #include "gdal_priv.h"
27 #include "base/Optionpk.h"
31 int main(
int argc,
char **argv) {
33 Optionpk<int> band_opt(
"b",
"band",
"band(s) to process (Default is -1: process all bands)");
34 Optionpk<std::string> mask_opt(
"m",
"mask",
"Mask raster dataset indicating pixels to be interpolated (zero valued) ");
36 Optionpk<double> distance_opt(
"d",
"distance",
"Maximum number of pixels to search in all directions to find values to interpolate from", 0);
37 Optionpk<int> iteration_opt(
"it",
"iteration",
"Number of 3x3 smoothing filter passes to run (default 0)", 0);
40 distance_opt.setHide(1);
41 iteration_opt.setHide(1);
45 doProcess=input_opt.retrieveOption(argc,argv);
46 band_opt.retrieveOption(argc,argv);
47 output_opt.retrieveOption(argc,argv);
48 mask_opt.retrieveOption(argc,argv);
49 distance_opt.retrieveOption(argc,argv);
50 iteration_opt.retrieveOption(argc,argv);
51 verbose_opt.retrieveOption(argc,argv);
53 catch(std::string predefinedString){
54 std::cout << predefinedString << std::endl;
59 cout <<
"Usage: pkfillnodata -i input.txt -m mask -o output" << endl;
61 std::cout <<
"short option -h shows basic options only, use long option --help to show all options" << std::endl;
65 assert(input_opt.size());
66 assert(mask_opt.size());
67 assert(output_opt.size());
69 GDALDataset *gds_input;
71 std::cout <<
"opening input file " << input_opt[0] << std::endl;
72 gds_input = (GDALDataset *) GDALOpen(input_opt[0].c_str(), GA_ReadOnly);
73 if(gds_input == NULL){
74 std::string errorString=
"FileOpenError";
78 GDALDataset *gds_mask;
80 std::cout <<
"opening mask file " << mask_opt[0] << std::endl;
81 gds_mask = (GDALDataset *) GDALOpen(mask_opt[0].c_str(), GA_ReadOnly );
83 std::string errorString=
"FileOpenError";
86 GDALRasterBand *maskBand;
88 std::cout <<
"get mask raster band" << std::endl;
89 maskBand=gds_mask->GetRasterBand(1);
93 poDriver = GetGDALDriverManager()->GetDriverByName(gds_input->GetDriver()->GetDescription());
94 if( poDriver == NULL ){
95 std::string errorString=
"FileOpenError";
99 std::cout <<
"copying input file to " << output_opt[0] << std::endl;
100 poDriver->CopyFiles(output_opt[0].c_str(),input_opt[0].c_str());
101 GDALDataset *gds_out;
102 gds_out=(GDALDataset *) GDALOpen(output_opt[0].c_str(), GA_Update);
104 if(band_opt.empty()){
106 for(
int iband=0;iband<gds_input->GetRasterCount();++iband)
107 band_opt.push_back(iband);
109 GDALRasterBand *targetBand;
110 for(
unsigned short iband=0;iband<band_opt.size();++iband){
111 targetBand=gds_out->GetRasterBand(band_opt[iband]+1);
113 std::cout <<
"copying input file to " << output_opt[0] << std::endl;
114 double dfComplete=0.0;
115 const char* pszMessage;
116 void* pProgressArg=NULL;
117 GDALProgressFunc pfnProgress=GDALTermProgress;
118 pfnProgress(dfComplete,pszMessage,pProgressArg);
119 if(GDALFillNodata(targetBand,maskBand,distance_opt[0],0,iteration_opt[0],NULL,pfnProgress,pProgressArg)!=CE_None){
120 std::cerr << CPLGetLastErrorMsg() << std::endl;
125 pfnProgress(dfComplete,pszMessage,pProgressArg);
144 GDALClose(gds_input);
147 GDALDumpOpenDatasets(stderr);
148 GDALDestroyDriverManager();