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" 74 int main(
int argc,
char **argv) {
76 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).");
78 Optionpk<int> band_opt(
"b",
"band",
"the band to be used from input file", 0);
79 Optionpk<int> connect_opt(
"c",
"connect",
"the connectedness: 4 directions or 8 directions", 8);
80 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);
81 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",
"");
82 Optionpk<string> option_opt(
"co",
"co",
"Creation option for output file. Multiple options can be specified.");
83 Optionpk<string> colorTable_opt(
"ct",
"ct",
"color table (file with 5 columns: id R G B ALFA (0: transparent, 255: solid)");
84 Optionpk<short> verbose_opt(
"v",
"verbose",
"verbose mode if > 0", 0,2);
88 doProcess=input_opt.retrieveOption(argc,argv);
89 size_opt.retrieveOption(argc,argv);
90 output_opt.retrieveOption(argc,argv);
91 connect_opt.retrieveOption(argc,argv);
92 band_opt.retrieveOption(argc,argv);
93 mask_opt.retrieveOption(argc,argv);
94 otype_opt.retrieveOption(argc,argv);
95 option_opt.retrieveOption(argc,argv);
96 colorTable_opt.retrieveOption(argc,argv);
97 verbose_opt.retrieveOption(argc,argv);
99 catch(
string predefinedString){
100 std::cout << predefinedString << std::endl;
105 cout <<
"Usage: pksieve -i input [-s size] -o output" << endl;
107 std::cout <<
"short option -h shows basic options only, use long option --help to show all options" << std::endl;
113 double dfComplete=0.0;
114 const char* pszMessage;
115 void* pProgressArg=NULL;
116 GDALProgressFunc pfnProgress=GDALTermProgress;
117 pfnProgress(dfComplete,pszMessage,pProgressArg);
120 GDALRasterBand *maskBand=NULL;
123 cout <<
"opening mask file " << mask_opt[0] << endl;
124 maskReader.
open(mask_opt[0]);
128 assert(input_opt.size());
129 assert(output_opt.size());
131 GDALRasterBand *inputBand;
132 inputBand=inputReader.getRasterBand(band_opt[0]);
135 GDALRasterBand *outputBand=NULL;
137 cout <<
"opening output file " << output_opt[0] << endl;
138 outputWriter.
open(output_opt[0],inputReader);
139 if(colorTable_opt.size()){
140 if(colorTable_opt[0]!=
"none")
143 else if (inputReader.getColorTable()!=NULL)
148 if(GDALSieveFilter((GDALRasterBandH)inputBand, (GDALRasterBandH)maskBand, (GDALRasterBandH)outputBand, size_opt[0], connect_opt[0],NULL,pfnProgress,pProgressArg)!=CE_None)
149 cerr << CPLGetLastErrorMsg() << endl;
152 pfnProgress(dfComplete,pszMessage,pProgressArg);
158 outputWriter.
close();
void close(void)
Set the memory (in MB) to cache a number of rows in memory.
void setColorTable(const std::string &filename, int band=0)
Set the color table using an (ASCII) file with 5 columns (value R G B alpha)
void open(const std::string &filename, const ImgReaderGdal &imgSrc, const std::vector< std::string > &options=std::vector< std::string >())
Open an image for writing, copying image attributes from a source image. Image is directly written to...
GDALRasterBand * getRasterBand(int band=0) const
Get the GDAL rasterband for this dataset.
void close(void)
Close the image.
void open(const std::string &filename, const GDALAccess &readMode=GA_ReadOnly)
Open an image.