20 #include "cpl_string.h" 21 #include "gdal_priv.h" 27 #include "base/Optionpk.h" 68 int main(
int argc,
char **argv) {
70 Optionpk<int> band_opt(
"b",
"band",
"band(s) to process (Default is -1: process all bands)");
71 Optionpk<std::string> mask_opt(
"m",
"mask",
"Mask raster dataset indicating pixels to be interpolated (zero valued) ");
73 Optionpk<double> distance_opt(
"d",
"distance",
"Maximum number of pixels to search in all directions to find values to interpolate from", 0);
74 Optionpk<int> iteration_opt(
"it",
"iteration",
"Number of 3x3 smoothing filter passes to run (default 0)", 0);
77 distance_opt.setHide(1);
78 iteration_opt.setHide(1);
82 doProcess=input_opt.retrieveOption(argc,argv);
83 band_opt.retrieveOption(argc,argv);
84 output_opt.retrieveOption(argc,argv);
85 mask_opt.retrieveOption(argc,argv);
86 distance_opt.retrieveOption(argc,argv);
87 iteration_opt.retrieveOption(argc,argv);
88 verbose_opt.retrieveOption(argc,argv);
90 catch(std::string predefinedString){
91 std::cout << predefinedString << std::endl;
96 cout <<
"Usage: pkfillnodata -i input.txt -m mask -o output" << endl;
98 std::cout <<
"short option -h shows basic options only, use long option --help to show all options" << std::endl;
102 assert(input_opt.size());
103 assert(mask_opt.size());
104 assert(output_opt.size());
106 GDALDataset *gds_input;
108 std::cout <<
"opening input file " << input_opt[0] << std::endl;
109 gds_input = (GDALDataset *) GDALOpen(input_opt[0].c_str(), GA_ReadOnly);
110 if(gds_input == NULL){
111 std::string errorString=
"FileOpenError";
115 GDALDataset *gds_mask;
117 std::cout <<
"opening mask file " << mask_opt[0] << std::endl;
118 gds_mask = (GDALDataset *) GDALOpen(mask_opt[0].c_str(), GA_ReadOnly );
119 if(gds_mask == NULL){
120 std::string errorString=
"FileOpenError";
123 GDALRasterBand *maskBand;
125 std::cout <<
"get mask raster band" << std::endl;
126 maskBand=gds_mask->GetRasterBand(1);
129 GDALDriver *poDriver;
130 poDriver = GetGDALDriverManager()->GetDriverByName(gds_input->GetDriver()->GetDescription());
131 if( poDriver == NULL ){
132 std::string errorString=
"FileOpenError";
136 std::cout <<
"copying input file to " << output_opt[0] << std::endl;
137 poDriver->CopyFiles(output_opt[0].c_str(),input_opt[0].c_str());
138 GDALDataset *gds_out;
139 gds_out=(GDALDataset *) GDALOpen(output_opt[0].c_str(), GA_Update);
141 if(band_opt.empty()){
143 for(
int iband=0;iband<gds_input->GetRasterCount();++iband)
144 band_opt.push_back(iband);
146 GDALRasterBand *targetBand;
147 for(
unsigned short iband=0;iband<band_opt.size();++iband){
148 targetBand=gds_out->GetRasterBand(band_opt[iband]+1);
150 std::cout <<
"copying input file to " << output_opt[0] << std::endl;
151 double dfComplete=0.0;
152 const char* pszMessage;
153 void* pProgressArg=NULL;
154 GDALProgressFunc pfnProgress=GDALTermProgress;
155 pfnProgress(dfComplete,pszMessage,pProgressArg);
156 if(GDALFillNodata(targetBand,maskBand,distance_opt[0],0,iteration_opt[0],NULL,pfnProgress,pProgressArg)!=CE_None){
157 std::cerr << CPLGetLastErrorMsg() << std::endl;
162 pfnProgress(dfComplete,pszMessage,pProgressArg);
181 GDALClose(gds_input);
184 GDALDumpOpenDatasets(stderr);
185 GDALDestroyDriverManager();