20 #include "cpl_string.h"
21 #include "gdal_priv.h"
23 #include "imageclasses/ImgReaderGdal.h"
24 #include "imageclasses/ImgWriterGdal.h"
26 #include "base/Optionpk.h"
27 #include "ogrsf_frmts.h"
35 int main(
int argc,
char **argv) {
37 Optionpk<string> mask_opt(
"m",
"mask",
"Use the first band of the specified file as a validity mask (zero is invalid, non-zero is valid).");
39 Optionpk<int> band_opt(
"b",
"band",
"the band to be used from input file", 0);
40 Optionpk<int> connect_opt(
"c",
"connect",
"the connectedness: 4 directions or 8 directions", 8);
41 Optionpk<int> size_opt(
"s",
"size",
"raster polygons with sizes smaller than this will be merged into their largest neighbour. No sieve is performed if size = 0", 0);
42 Optionpk<string> otype_opt(
"ot",
"otype",
"Data type for output image ({Byte/Int16/UInt16/UInt32/Int32/Float32/Float64/CInt16/CInt32/CFloat32/CFloat64}). Empty string: inherit type from input image",
"");
43 Optionpk<string> option_opt(
"co",
"co",
"Creation option for output file. Multiple options can be specified.");
44 Optionpk<string> colorTable_opt(
"ct",
"ct",
"color table (file with 5 columns: id R G B ALFA (0: transparent, 255: solid)");
45 Optionpk<short> verbose_opt(
"v",
"verbose",
"verbose mode if > 0", 0,2);
49 doProcess=input_opt.retrieveOption(argc,argv);
50 size_opt.retrieveOption(argc,argv);
51 output_opt.retrieveOption(argc,argv);
52 connect_opt.retrieveOption(argc,argv);
53 band_opt.retrieveOption(argc,argv);
54 mask_opt.retrieveOption(argc,argv);
55 otype_opt.retrieveOption(argc,argv);
56 option_opt.retrieveOption(argc,argv);
57 colorTable_opt.retrieveOption(argc,argv);
58 verbose_opt.retrieveOption(argc,argv);
60 catch(
string predefinedString){
61 std::cout << predefinedString << std::endl;
66 cout <<
"Usage: pksieve -i input [-s size] -o output" << endl;
68 std::cout <<
"short option -h shows basic options only, use long option --help to show all options" << std::endl;
74 double dfComplete=0.0;
75 const char* pszMessage;
76 void* pProgressArg=NULL;
77 GDALProgressFunc pfnProgress=GDALTermProgress;
78 pfnProgress(dfComplete,pszMessage,pProgressArg);
81 GDALRasterBand *maskBand=NULL;
84 cout <<
"opening mask file " << mask_opt[0] << endl;
85 maskReader.open(mask_opt[0]);
86 maskBand = maskReader.getRasterBand(0);
89 assert(input_opt.size());
90 assert(output_opt.size());
92 GDALRasterBand *inputBand;
93 inputBand=inputReader.getRasterBand(band_opt[0]);
96 GDALRasterBand *outputBand=NULL;
98 cout <<
"opening output file " << output_opt[0] << endl;
99 outputWriter.open(output_opt[0],inputReader);
100 if(colorTable_opt.size()){
101 if(colorTable_opt[0]!=
"none")
102 outputWriter.setColorTable(colorTable_opt[0]);
104 else if (inputReader.getColorTable()!=NULL)
105 outputWriter.setColorTable(inputReader.getColorTable());
106 outputBand = outputWriter.getRasterBand(0);
109 if(GDALSieveFilter((GDALRasterBandH)inputBand, (GDALRasterBandH)maskBand, (GDALRasterBandH)outputBand, size_opt[0], connect_opt[0],NULL,pfnProgress,pProgressArg)!=CE_None)
110 cerr << CPLGetLastErrorMsg() << endl;
113 pfnProgress(dfComplete,pszMessage,pProgressArg);
119 outputWriter.close();