[pktools] 02/375: versions automatically extracted from config and support for mask values in pkinfo min/max values
Bas Couwenberg
sebastic at xs4all.nl
Wed Dec 3 21:53:52 UTC 2014
This is an automated email from the git hooks/post-receive script.
sebastic-guest pushed a commit to branch upstream-master
in repository pktools.
commit 61d71ee7e544dd81fced4f2ef6b963ab59d8e0c0
Author: Pieter Kempeneers <kempenep at gmail.com>
Date: Thu Aug 23 18:10:14 2012 +0200
versions automatically extracted from config and support for mask values in pkinfo min/max values
---
src/apps/pkascii2img.cc | 10 +-
src/apps/pkclassify_nn.cc | 6 +-
src/apps/pkclassify_nn.h | 56 ++-----
src/apps/pkcreatect.cc | 19 ++-
src/apps/pkcrop.cc | 17 +-
src/apps/pkdiff.cc | 265 +++++++++++++++++-------------
src/apps/pkdumpimg.cc | 11 +-
src/apps/pkdumpogr.cc | 13 +-
src/apps/pkegcs.cc | 11 +-
src/apps/pkextract.cc | 410 +++++++++++++++++++++++-----------------------
src/apps/pkfillnodata.cc | 12 +-
src/apps/pkfilter.cc | 43 +++--
src/apps/pkgetmask.cc | 25 ++-
src/apps/pkinfo.cc | 39 +++--
src/apps/pklas2img.cc | 13 +-
src/apps/pkmosaic.cc | 29 ++--
src/apps/pkndvi.cc | 27 +--
src/apps/pkpolygonize.cc | 37 +++--
src/apps/pkreclass.cc | 24 ++-
src/apps/pksetmask.cc | 15 +-
src/apps/pksieve.cc | 42 +++--
src/apps/pkstat.cc | 38 +++--
src/apps/pkstatogr.cc | 25 ++-
23 files changed, 665 insertions(+), 522 deletions(-)
diff --git a/src/apps/pkascii2img.cc b/src/apps/pkascii2img.cc
index 60e3673..5e56803 100644
--- a/src/apps/pkascii2img.cc
+++ b/src/apps/pkascii2img.cc
@@ -23,13 +23,19 @@ along with pktools. If not, see <http://www.gnu.org/licenses/>.
#include <assert.h>
#include "imageclasses/ImgWriterGdal.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
int main(int argc, char *argv[])
{
- Optionpk<bool> version_opt("\0","version","version 20120625, Copyright (C) 2008-2012 Pieter Kempeneers.\n\
+ std::string versionString="version ";
+ versionString+=VERSION;
+ versionString+=", Copyright (C) 2008-2012 Pieter Kempeneers.\n\
This program comes with ABSOLUTELY NO WARRANTY; for details type use option -h.\n\
This is free software, and you are welcome to redistribute it\n\
- under certain conditions; use option --license for details.",false);
+ under certain conditions; use option --license for details.";
+ Optionpk<bool> version_opt("\0","version",versionString,false);
Optionpk<bool> license_opt("lic","license","show license information",false);
Optionpk<bool> help_opt("h","help","shows this help info",false);
Optionpk<bool> todo_opt("\0","todo","introduce -uli -ulj to crop based on image coordinates",false);
diff --git a/src/apps/pkclassify_nn.cc b/src/apps/pkclassify_nn.cc
index a9ce801..1920632 100644
--- a/src/apps/pkclassify_nn.cc
+++ b/src/apps/pkclassify_nn.cc
@@ -44,9 +44,8 @@ int main(int argc, char *argv[])
Optionpk<bool> license_opt("lic","license","show license information",false);
Optionpk<bool> help_opt("h","help","shows this help info",false);
Optionpk<string> input_opt("i", "input", "input image","");
- Optionpk<string> training_opt("t", "training", "training shape file. A single shape file contains all training features for all classes. Use multiple training files for bootstrap aggregation (alternative to the bag and bsize options, where a random subset is taken from a single training file)","");
+ Optionpk<string> training_opt("t", "training", "training shape file. A single shape file contains all training features (must be set as: B0, B1, B2,...) for all classes (class numbers identified by label option). Use multiple training files for bootstrap aggregation (alternative to the bag and bsize options, where a random subset is taken from a single training file)","");
Optionpk<string> label_opt("\0", "label", "identifier for class label in training shape file. (default is label)","label");
- Optionpk<string> query_opt("q", "sql", "field name for sql query statement for selecting training pixels: select * from layer where fieldname=1 (default: empty)","");
Optionpk<unsigned short> reclass_opt("\0", "rc", "reclass code (e.g. --rc=12 --rc=23 to reclass first two classes to 12 and 23 resp.). Default is 0: do not reclass", 0);
Optionpk<unsigned int> balance_opt("\0", "balance", "balance the input data to this number of samples for each class (default 0: do not balance)", 0);
Optionpk<int> minSize_opt("m", "min", "if number of training pixels is less then min, do not take this class into account (default is 0: consider all classes", 0);
@@ -94,7 +93,6 @@ int main(int argc, char *argv[])
input_opt.retrieveOption(argc,argv);
training_opt.retrieveOption(argc,argv);
label_opt.retrieveOption(argc,argv);
- query_opt.retrieveOption(argc,argv);
reclass_opt.retrieveOption(argc,argv);
balance_opt.retrieveOption(argc,argv);
minSize_opt.retrieveOption(argc,argv);
@@ -189,7 +187,7 @@ int main(int argc, char *argv[])
if(verbose_opt[0]>=1)
cout << "reading imageShape file " << training_opt[0] << endl;
try{
- totalSamples=readDataImageShape(training_opt[ibag],trainingMap,fields,start_opt[0],end_opt[0],label_opt[0],query_opt[0],verbose_opt[0]);
+ totalSamples=readDataImageShape(training_opt[ibag],trainingMap,fields,start_opt[0],end_opt[0],label_opt[0],verbose_opt[0]);
if(trainingMap.size()<2){
string errorstring="Error: could not read at least two classes from training file";
throw(errorstring);
diff --git a/src/apps/pkclassify_nn.h b/src/apps/pkclassify_nn.h
index 4e11dea..68a547c 100644
--- a/src/apps/pkclassify_nn.h
+++ b/src/apps/pkclassify_nn.h
@@ -32,7 +32,6 @@ template<typename T> unsigned int readDataImageShape(const string &filename,
double start,
double end,
const string& label,
- const string& query="",
int verbose=false);
@@ -42,7 +41,6 @@ template<typename T> unsigned int readDataImageShape(const string &filename,
double start,
double end,
const string& label,
- const string& query,
int verbose)
{
mapPixels.clear();
@@ -54,7 +52,6 @@ template<typename T> unsigned int readDataImageShape(const string &filename,
ImgReaderOgr imgReaderShape;
try{
imgReaderShape.open(filename);
- bool queryFound=false;
//only retain bands in fields
imgReaderShape.getFields(fields);
vector<string>::iterator fit=fields.begin();
@@ -63,22 +60,16 @@ template<typename T> unsigned int readDataImageShape(const string &filename,
while(fit!=fields.end()){
if(verbose)
cout << *fit << " ";
- size_t pos=(*fit).find_first_not_of("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_ ");
- if(pos==string::npos){
- if(query!=""){
- if((*fit).find(query)!=string::npos)
- queryFound=true;
- }
- fields.erase(fit);
- }
- else{
- string fieldname=(*fit).substr(pos);
- int iband=atoi(fieldname.c_str());
- if((start||end)&&(iband<start||iband>end))
- fields.erase(fit);
- else
- ++fit;
+ // size_t pos=(*fit).find_first_not_of("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_ ");
+ if(((*fit).substr(0,1)=="B")&&((*fit).substr(1).find_first_not_of("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_ ")!=string::npos)){
+ int iband=atoi((*fit).substr(1).c_str());
+ if((start||end)&&(iband<start||iband>end))
+ fields.erase(fit);
+ else
+ ++fit;
}
+ else
+ fields.erase(fit);
}
if(verbose)
cout << endl;
@@ -89,30 +80,13 @@ template<typename T> unsigned int readDataImageShape(const string &filename,
cout << endl;
}
if(!nband){
- if(queryFound){
- ostringstream qs;
- qs << "select * from " << imgReaderShape.getLayerName() << " where " << query << "=1";
- if(verbose)
- cout << "reading with sql: " << qs.str() << endl;
- nband=imgReaderShape.readSql(mapPixels,OFTReal,fields,label,qs.str(),NULL,0,true,false);
- }
- else{
- if(verbose)
- cout << "reading data" << endl;
- nband=imgReaderShape.readData(mapPixels,OFTReal,fields,label,0,true,verbose==2);
- }
- }
- else{
- if(queryFound){
- ostringstream qs;
- qs << "select * from " << imgReaderShape.getLayerName() << " where " << query << "=1";
- if(verbose)
- cout << "reading with sql: " << qs.str() << endl;
- assert(nband==imgReaderShape.readSql(mapPixels,OFTReal,fields,label,qs.str(),NULL,0,true,false));
- }
- else
- assert(nband==imgReaderShape.readData(mapPixels,OFTReal,fields,label,0,true,false));
+ if(verbose)
+ cout << "reading data" << endl;
+ nband=imgReaderShape.readData(mapPixels,OFTReal,fields,label,0,true,verbose==2);
+
}
+ else
+ assert(nband==imgReaderShape.readData(mapPixels,OFTReal,fields,label,0,true,false));
}
catch(string e){
ostringstream estr;
diff --git a/src/apps/pkcreatect.cc b/src/apps/pkcreatect.cc
index da2aeeb..69e33dc 100644
--- a/src/apps/pkcreatect.cc
+++ b/src/apps/pkcreatect.cc
@@ -22,6 +22,10 @@ along with pktools. If not, see <http://www.gnu.org/licenses/>.
#include "imageclasses/ImgWriterGdal.h"
#include "base/Optionpk.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
using namespace std;
int main(int argc,char **argv) {
@@ -30,24 +34,27 @@ int main(int argc,char **argv) {
short green=-1;
short blue=-1;
- Optionpk<bool> version_opt("\0","version","version 20120625, Copyright (C) 2008-2012 Pieter Kempeneers.\n\
+ std::string versionString="version ";
+ versionString+=VERSION;
+ versionString+=", Copyright (C) 2008-2012 Pieter Kempeneers.\n\
This program comes with ABSOLUTELY NO WARRANTY; for details type use option -h.\n\
This is free software, and you are welcome to redistribute it\n\
- under certain conditions; use option --license for details.",false);
+ under certain conditions; use option --license for details.";
+ Optionpk<bool> version_opt("\0","version",versionString,false);
Optionpk<bool> license_opt("lic","license","show license information",false);
Optionpk<bool> help_opt("h","help","shows this help info",false);
Optionpk<bool> todo_opt("\0","todo","",false);
Optionpk<string> input_opt("i", "input", "Input image file", "");
Optionpk<string> output_opt("o", "output", "Output image file", "");
Optionpk<string> legend_opt("l", "legend", "Create legend as png file", "");
- Optionpk<short> dim_opt("d", "dim", "number of columns and rows in legend (Default is 100 cols x max-min+1 rows", 100);
+ Optionpk<short> dim_opt("dim", "dim", "number of columns and rows in legend.", 100);
Optionpk<double> min_opt("m", "min", "minimum value", 0);
Optionpk<double> max_opt("M", "max", "maximum value", 100);
- Optionpk<bool> grey_opt("g", "grey", "grey scale (default is false)", false);
+ Optionpk<bool> grey_opt("g", "grey", "grey scale", false);
Optionpk<string> colorTable_opt("ct", "ct", "color table (file with 5 columns: id R G B ALFA (0: transparent, 255: solid)", "");
Optionpk<string> oformat_opt("of", "oformat", "Output image format (see also gdal_translate). Empty string: inherit from input image", "GTiff");
Optionpk<string> option_opt("co", "co", "options: NAME=VALUE [-co COMPRESS=LZW] [-co INTERLEAVE=BAND]", "INTERLEAVE=BAND");
- Optionpk<string> description_opt("\0", "description", "Set image description", "");
+ Optionpk<string> description_opt("d", "description", "Set image description", "");
Optionpk<bool> verbose_opt("v", "verbose", "verbose", false);
version_opt.retrieveOption(argc,argv);
@@ -78,7 +85,7 @@ int main(int argc,char **argv) {
verbose_opt.retrieveOption(argc,argv);
if(help_opt[0]){
- cout << "usage: pkcreatect -i inputimage -o outputimage [OPTIONS]" << endl;
+ cout << "usage: pkcreatect [OPTIONS]" << endl;
exit(0);
}
diff --git a/src/apps/pkcrop.cc b/src/apps/pkcrop.cc
index 38a762c..c071c09 100644
--- a/src/apps/pkcrop.cc
+++ b/src/apps/pkcrop.cc
@@ -27,17 +27,22 @@ along with pktools. If not, see <http://www.gnu.org/licenses/>.
#include "base/Optionpk.h"
#include "algorithms/Egcs.h"
-using namespace std;
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
int main(int argc, char *argv[])
{
- Optionpk<bool> version_opt("\0","version","version 20120625, Copyright (C) 2008-2012 Pieter Kempeneers.\n\
+ std::string versionString="version ";
+ versionString+=VERSION;
+ versionString+=", Copyright (C) 2008-2012 Pieter Kempeneers.\n\
This program comes with ABSOLUTELY NO WARRANTY; for details type use option -h.\n\
This is free software, and you are welcome to redistribute it\n\
- under certain conditions; use option --license for details.",false);
+ under certain conditions; use option --license for details.";
+ Optionpk<bool> version_opt("\0","version",versionString,false);
Optionpk<bool> license_opt("lic","license","show license information",false);
Optionpk<bool> help_opt("h","help","shows this help info",false);
- Optionpk<bool> todo_opt("\0","todo","introduce -uli -ulj to crop based on image coordinates",false);
+ Optionpk<bool> todo_opt("\0","todo","",false);
Optionpk<string> input_opt("i", "input", "Input image file(s). If input contains multiple images, a multi-band output is created", "");
Optionpk<string> output_opt("o", "output", "Output image file", "");
Optionpk<string> projection_opt("p", "projection", "projection in EPSG format (leave blank to copy from input file, use EPSG:3035 to use European projection and to force to European grid", "");
@@ -51,14 +56,14 @@ int main(int argc, char *argv[])
Optionpk<double> dy_opt("dy", "dy", "Output resolution in y (in meter) (0.0: keep original resolution)", 0.0);
Optionpk<int> band_opt("b", "band", "band index to crop (-1: crop all bands)", -1);
Optionpk<double> scale_opt("s", "scale", "output=scale*input+offset", 1);
- Optionpk<double> offset_opt("\0", "offset", "output=scale*input+offset", 0);
+ Optionpk<double> offset_opt("off", "offset", "output=scale*input+offset", 0);
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", "");
Optionpk<string> oformat_opt("of", "oformat", "Output image format (see also gdal_translate). Empty string: inherit from input image", "");
Optionpk<string> colorTable_opt("ct", "ct", "color table (file with 5 columns: id R G B ALFA (0: transparent, 255: solid)", "");
Optionpk<string> option_opt("co", "co", "options: NAME=VALUE [-co COMPRESS=LZW] [-co INTERLEAVE=BAND]", "INTERLEAVE=BAND");
Optionpk<short> flag_opt("f", "flag", "Flag value to put in image if out of bounds.", 0);
Optionpk<string> resample_opt("r", "resampling-method", "Resampling method (near: nearest neighbour, bilinear: bi-linear interpolation).", "near");
- Optionpk<string> description_opt("\0", "description", "Set image description", "");
+ Optionpk<string> description_opt("d", "description", "Set image description", "");
Optionpk<bool> verbose_opt("v", "verbose", "verbose", false);
version_opt.retrieveOption(argc,argv);
diff --git a/src/apps/pkdiff.cc b/src/apps/pkdiff.cc
index 6ff83b7..a68f6b3 100644
--- a/src/apps/pkdiff.cc
+++ b/src/apps/pkdiff.cc
@@ -25,21 +25,26 @@ along with pktools. If not, see <http://www.gnu.org/licenses/>.
#include "Optionpk.h"
#include "algorithms/ConfusionMatrix.h"
-using namespace std;
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
int main(int argc, char *argv[])
{
- Optionpk<bool> version_opt("\0","version","version 20120625, Copyright (C) 2008-2012 Pieter Kempeneers.\n\
+ std::string versionString="version ";
+ versionString+=VERSION;
+ versionString+=", Copyright (C) 2008-2012 Pieter Kempeneers.\n\
This program comes with ABSOLUTELY NO WARRANTY; for details type use option -h.\n\
This is free software, and you are welcome to redistribute it\n\
- under certain conditions; use option --license for details.",false);
+ under certain conditions; use option --license for details.";
+ Optionpk<bool> version_opt("\0","version",versionString,false);
Optionpk<bool> license_opt("lic","license","show license information",false);
Optionpk<bool> help_opt("h","help","shows this help info",false);
- Optionpk<bool> todo_opt("\0","todo","todo: support different data types",false);
+ Optionpk<bool> todo_opt("\0","todo","todo: support different data types (now only integer type supported)",false);
Optionpk<string> input_opt("i", "input", "Input image file.", "");
Optionpk<string> reference_opt("r", "reference", "Reference image file", "");
Optionpk<string> output_opt("o", "output", "Output image file. Default is empty: no output image, only report difference or identical.", "");
- Optionpk<string> mask_opt("m", "mask", "Mask image file. A single mask is supported only, but several mask values can be used. See also mflag option. (default is empty)", "");
+ Optionpk<string> mask_opt("\0", "mask", "Mask image file. A single mask is supported only, but several mask values can be used. See also mflag option. (default is empty)", "");
Optionpk<string> colorTable_opt("\0", "ct", "color table (file with 5 columns: id R G B ALFA (0: transparent, 255: solid)", "");
Optionpk<short> valueE_opt("\0", "correct", "Value for correct pixels (0)", 0);
Optionpk<short> valueO_opt("\0", "omission", "Value for omission errors: input label > reference label (default value is 1)", 1);
@@ -112,44 +117,48 @@ int main(int argc, char *argv[])
assert(mask_opt.size()==input_opt.size());
vector<short> inputRange;
vector<short> referenceRange;
- if(class_opt.size()>1)
- inputRange=class_opt;
- else{
- try{
+ ConfusionMatrix cm;
+ int nclass=0;
+ vector<string> classNames;
+ if(confusion_opt[0]){
+ if(class_opt.size()>1)
+ inputRange=class_opt;
+ else{
+ try{
+ if(verbose_opt[0])
+ cout << "opening input image file " << input_opt[0] << endl;
+ inputReader.open(input_opt[0]);//,imagicX_opt[0],imagicY_opt[0]);
+ }
+ catch(string error){
+ cerr << error << endl;
+ exit(1);
+ }
+ inputReader.getRange(inputRange,band_opt[0]);
+ inputReader.close();
+ }
+
+ for(int iflag=0;iflag<flag_opt.size();++iflag){
+ vector<short>::iterator fit;
+ fit=find(inputRange.begin(),inputRange.end(),flag_opt[iflag]);
+ if(fit!=inputRange.end())
+ inputRange.erase(fit);
+ }
+ nclass=inputRange.size();
+ if(verbose_opt[0]){
+ cout << "nclass (inputRange.size()): " << nclass << endl;
+ cout << "input range: " << endl;
+ }
+ for(int rc=0;rc<inputRange.size();++rc){
+ classNames.push_back(type2string(inputRange[rc]));
if(verbose_opt[0])
- cout << "opening input image file " << input_opt[0] << endl;
- inputReader.open(input_opt[0]);//,imagicX_opt[0],imagicY_opt[0]);
+ cout << inputRange[rc] << endl;
}
- catch(string error){
- cerr << error << endl;
- exit(1);
+ cm.setClassNames(classNames);
+ if(verbose_opt[0]){
+ cout << "class names: " << endl;
+ for(int iclass=0;iclass<cm.nClasses();++iclass)
+ cout << iclass << " " << cm.getClass(iclass) << endl;
}
- inputReader.getRange(inputRange,band_opt[0]);
- inputReader.close();
- }
-
- for(int iflag=0;iflag<flag_opt.size();++iflag){
- vector<short>::iterator fit;
- fit=find(inputRange.begin(),inputRange.end(),flag_opt[iflag]);
- if(fit!=inputRange.end())
- inputRange.erase(fit);
- }
- int nclass=inputRange.size();
- vector<string> classNames;
- if(verbose_opt[0]){
- cout << "nclass (inputRange.size()): " << nclass << endl;
- cout << "input range: " << endl;
- }
- for(int rc=0;rc<inputRange.size();++rc){
- classNames.push_back(type2string(inputRange[rc]));
- if(verbose_opt[0])
- cout << inputRange[rc] << endl;
- }
- ConfusionMatrix cm(classNames);
- if(verbose_opt[0]){
- cout << "class names: " << endl;
- for(int iclass=0;iclass<cm.nClasses();++iclass)
- cout << iclass << " " << cm.getClass(iclass) << endl;
}
unsigned int ntotalValidation=0;
unsigned int nflagged=0;
@@ -158,11 +167,17 @@ int main(int argc, char *argv[])
vector<float> producer(nclass);
vector<unsigned int> nvalidation(nclass);
- //initialize
- for(int rc=0;rc<nclass;++rc){
- for(int ic=0;ic<nclass;++ic)
- resultClass[rc][ic]=0;
- nvalidation[rc]=0;
+ if(confusion_opt[0]){
+ resultClass.resize(nclass,nclass);
+ user.resize(nclass);
+ producer.resize(nclass);
+ nvalidation.resize(nclass);
+ //initialize
+ for(int rc=0;rc<nclass;++rc){
+ for(int ic=0;ic<nclass;++ic)
+ resultClass[rc][ic]=0;
+ nvalidation[rc]=0;
+ }
}
bool isDifferent=false;
@@ -194,7 +209,8 @@ int main(int argc, char *argv[])
cerr << error << endl;
exit(1);
}
- referenceRange=inputRange;
+ if(confusion_opt[0])
+ referenceRange=inputRange;
ImgWriterOgr ogrWriter;
OGRLayer *writeLayer;
@@ -362,16 +378,18 @@ int main(int argc, char *argv[])
if(!windowHasFlag&&isHomogeneous){
if(output_opt[0]!="")
writeFeature->SetField(labelclass_opt[0].c_str(),static_cast<int>(inputValue));
- ++ntotalValidation;
- int rc=distance(referenceRange.begin(),find(referenceRange.begin(),referenceRange.end(),referenceValue));
- int ic=distance(inputRange.begin(),find(inputRange.begin(),inputRange.end(),inputValue));
- assert(rc<nclass);
- assert(ic<nclass);
- ++nvalidation[rc];
- ++resultClass[rc][ic];
- if(verbose_opt[0]>1)
- cout << "increment: " << rc << " " << referenceRange[rc] << " " << ic << " " << inputRange[ic] << endl;
- cm.incrementResult(cm.getClass(rc),cm.getClass(ic),1);
+ if(confusion_opt[0]){
+ ++ntotalValidation;
+ int rc=distance(referenceRange.begin(),find(referenceRange.begin(),referenceRange.end(),referenceValue));
+ int ic=distance(inputRange.begin(),find(inputRange.begin(),inputRange.end(),inputValue));
+ assert(rc<nclass);
+ assert(ic<nclass);
+ ++nvalidation[rc];
+ ++resultClass[rc][ic];
+ if(verbose_opt[0]>1)
+ cout << "increment: " << rc << " " << referenceRange[rc] << " " << ic << " " << inputRange[ic] << endl;
+ cm.incrementResult(cm.getClass(rc),cm.getClass(ic),1);
+ }
if(inputValue==referenceValue){//correct
if(valueE_opt[0]!=flag_opt[0])
outputValue=valueE_opt[0];
@@ -406,17 +424,18 @@ int main(int argc, char *argv[])
if(output_opt[0]!="")
writeFeature->SetField(fs.str().c_str(),static_cast<int>(inputValue));
if(!windowJ&&!windowI){//centre pixel
- ++ntotalValidation;
- int rc=distance(referenceRange.begin(),find(referenceRange.begin(),referenceRange.end(),referenceValue));
- int ic=distance(inputRange.begin(),find(inputRange.begin(),inputRange.end(),inputValue));
- assert(rc<nclass);
- assert(ic<nclass);
- ++nvalidation[rc];
- ++resultClass[rc][ic];
- if(verbose_opt[0]>1)
- cout << "increment: " << rc << " " << referenceRange[rc] << " " << ic << " " << inputRange[ic] << endl;
- cm.incrementResult(cm.getClass(rc),cm.getClass(ic),1);
-
+ if(confusion_opt[0]){
+ ++ntotalValidation;
+ int rc=distance(referenceRange.begin(),find(referenceRange.begin(),referenceRange.end(),referenceValue));
+ int ic=distance(inputRange.begin(),find(inputRange.begin(),inputRange.end(),inputValue));
+ assert(rc<nclass);
+ assert(ic<nclass);
+ ++nvalidation[rc];
+ ++resultClass[rc][ic];
+ if(verbose_opt[0]>1)
+ cout << "increment: " << rc << " " << referenceRange[rc] << " " << ic << " " << inputRange[ic] << endl;
+ cm.incrementResult(cm.getClass(rc),cm.getClass(ic),1);
+ }
if(inputValue==referenceValue){//correct
if(valueE_opt[0]!=flag_opt[0])
outputValue=valueE_opt[0];
@@ -487,7 +506,10 @@ int main(int argc, char *argv[])
//todo: support different data types!
vector<short> lineInput(inputReader.nrOfCol());
vector<short> lineMask(maskReader.nrOfCol());
- vector<short> lineOutput(inputReader.nrOfCol());
+ vector<short> lineOutput;
+ if(output_opt[0]!="")
+ lineOutput.resize(inputReader.nrOfCol());
+
int irow=0;
int icol=0;
double oldreferencerow=-1;
@@ -505,30 +527,31 @@ int main(int argc, char *argv[])
cout << "projection of input image and reference image are different!" << endl;
}
vector<short> lineReference(referenceReader.nrOfCol());
- referenceReader.getRange(referenceRange,band_opt[0]);
- for(int iflag=0;iflag<flag_opt.size();++iflag){
- vector<short>::iterator fit;
- fit=find(referenceRange.begin(),referenceRange.end(),flag_opt[iflag]);
- if(fit!=referenceRange.end())
- referenceRange.erase(fit);
- }
- if(verbose_opt[0]){
- cout << "reference range: " << endl;
- for(int rc=0;rc<referenceRange.size();++rc)
- cout << referenceRange[rc] << endl;
- }
- if(referenceRange.size()!=inputRange.size()){
- if(confusion_opt[0]||output_opt[0]!=""){
- cout << "reference range is not equal to input range!" << endl;
- cout << "Kappa: " << 0 << endl;
- cout << "total weighted: " << 0 << endl;
+ if(confusion_opt[0]){
+ referenceReader.getRange(referenceRange,band_opt[0]);
+ for(int iflag=0;iflag<flag_opt.size();++iflag){
+ vector<short>::iterator fit;
+ fit=find(referenceRange.begin(),referenceRange.end(),flag_opt[iflag]);
+ if(fit!=referenceRange.end())
+ referenceRange.erase(fit);
}
- else
- cout << "reference range is not equal to input range!" << endl;
+ if(verbose_opt[0]){
+ cout << "reference range: " << endl;
+ for(int rc=0;rc<referenceRange.size();++rc)
+ cout << referenceRange[rc] << endl;
+ }
+ if(referenceRange.size()!=inputRange.size()){
+ if(confusion_opt[0]||output_opt[0]!=""){
+ cout << "reference range is not equal to input range!" << endl;
+ cout << "Kappa: " << 0 << endl;
+ cout << "total weighted: " << 0 << endl;
+ }
+ else
+ cout << "reference range is not equal to input range!" << endl;
cout << input_opt[0] << " and " << reference_opt[0] << " are different" << endl;
- exit(1);
+ exit(1);
+ }
}
-
for(irow=0;irow<inputReader.nrOfRow()&&!isDifferent;++irow){
//read line in lineInput, lineReference and lineMask
inputReader.readData(lineInput,GDT_Int16,irow,band_opt[0]);
@@ -561,7 +584,8 @@ int main(int argc, char *argv[])
bool flagged=false;
for(int iflag=0;iflag<flag_opt.size();++iflag){
if((lineInput[icol]==flag_opt[iflag])||(lineReference[ireference]==flag_opt[iflag])){
- lineOutput[icol]=flag_opt[iflag];
+ if(output_opt[0]!="")
+ lineOutput[icol]=flag_opt[iflag];
flagged=true;
break;
}
@@ -575,47 +599,54 @@ int main(int argc, char *argv[])
}
}
if(!flagged){
- ++ntotalValidation;
- int rc=distance(referenceRange.begin(),find(referenceRange.begin(),referenceRange.end(),lineReference[ireference]));
- int ic=distance(inputRange.begin(),find(inputRange.begin(),inputRange.end(),lineInput[icol]));
- assert(rc<nclass);
- assert(ic<nclass);
- ++nvalidation[rc];
- ++resultClass[rc][ic];
- if(verbose_opt[0]>1)
- cout << "increment: " << rc << " " << referenceRange[rc] << " " << ic << " " << inputRange[ic] << endl;
- cm.incrementResult(cm.getClass(rc),cm.getClass(ic),1);
+ if(confusion_opt[0]){
+ ++ntotalValidation;
+ int rc=distance(referenceRange.begin(),find(referenceRange.begin(),referenceRange.end(),lineReference[ireference]));
+ int ic=distance(inputRange.begin(),find(inputRange.begin(),inputRange.end(),lineInput[icol]));
+ assert(rc<nclass);
+ assert(ic<nclass);
+ ++nvalidation[rc];
+ ++resultClass[rc][ic];
+ if(verbose_opt[0]>1)
+ cout << "increment: " << rc << " " << referenceRange[rc] << " " << ic << " " << inputRange[ic] << endl;
+ cm.incrementResult(cm.getClass(rc),cm.getClass(ic),1);
+ }
if(lineInput[icol]==lineReference[ireference]){//correct
- if(valueE_opt[0]!=flag_opt[0])
- lineOutput[icol]=valueE_opt[0];
- else
- lineOutput[icol]=lineInput[icol];
+ if(output_opt[0]!=""){
+ if(valueE_opt[0]!=flag_opt[0])
+ lineOutput[icol]=valueE_opt[0];
+ else
+ lineOutput[icol]=lineInput[icol];
+ }
}
else{//error
if(output_opt[0]==""&&!confusion_opt[0]){
isDifferent=true;
break;
}
- if(lineInput[icol]<20){//forest
- if(lineReference[icol]>=20)//gain
- lineOutput[icol]=lineInput[icol]*10+1;//GAIN is 111,121,131
- else//forest type changed: mixed
- lineOutput[icol]=130;//MIXED FOREST
- }
- else if(lineReference[icol]<20){//loss
- lineOutput[icol]=20*10+lineReference[icol];//LOSS is 211 212 213
- }
- else//no forest
- lineOutput[icol]=20*10;//NON FOREST is 200
- // if(lineInput[icol]>lineReference[ireference])//1=forest,2=non-forest
+ if(output_opt[0]!=""){
+ if(lineInput[icol]<20){//forest
+ if(lineReference[icol]>=20)//gain
+ lineOutput[icol]=lineInput[icol]*10+1;//GAIN is 111,121,131
+ else//forest type changed: mixed
+ lineOutput[icol]=130;//MIXED FOREST
+ }
+ else if(lineReference[icol]<20){//loss
+ lineOutput[icol]=20*10+lineReference[icol];//LOSS is 211 212 213
+ }
+ else//no forest
+ lineOutput[icol]=20*10;//NON FOREST is 200
+ // if(lineInput[icol]>lineReference[ireference])//1=forest,2=non-forest
// lineOutput[icol]=valueO_opt[0];//omission error
// else
// lineOutput[icol]=valueC_opt[0];//commission error
+ }
}
}
else{
++nflagged;
- lineOutput[icol]=flag_opt[0];
+ if(output_opt[0]!="")
+ lineOutput[icol]=flag_opt[0];
}
}
if(output_opt[0]!=""){
diff --git a/src/apps/pkdumpimg.cc b/src/apps/pkdumpimg.cc
index 39572d1..f2900b2 100644
--- a/src/apps/pkdumpimg.cc
+++ b/src/apps/pkdumpimg.cc
@@ -26,12 +26,19 @@ along with pktools. If not, see <http://www.gnu.org/licenses/>.
#include "imageclasses/ImgWriterGdal.h"
#include "imageclasses/ImgWriterOgr.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
int main(int argc, char *argv[])
{
- Optionpk<bool> version_opt("\0","version","version 20120625, Copyright (C) 2008-2012 Pieter Kempeneers.\n\
+ std::string versionString="version ";
+ versionString+=VERSION;
+ versionString+=", Copyright (C) 2008-2012 Pieter Kempeneers.\n\
This program comes with ABSOLUTELY NO WARRANTY; for details type use option -h.\n\
This is free software, and you are welcome to redistribute it\n\
- under certain conditions; use option --license for details.",false);
+ under certain conditions; use option --license for details.";
+ Optionpk<bool> version_opt("\0","version",versionString,false);
Optionpk<bool> license_opt("lic","license","show license information",false);
Optionpk<bool> help_opt("h","help","shows this help info",false);
Optionpk<bool> todo_opt("\0","todo","introduce -uli -ulj to crop based on image coordinates",false);
diff --git a/src/apps/pkdumpogr.cc b/src/apps/pkdumpogr.cc
index d449b89..1f50032 100644
--- a/src/apps/pkdumpogr.cc
+++ b/src/apps/pkdumpogr.cc
@@ -26,12 +26,19 @@ along with pktools. If not, see <http://www.gnu.org/licenses/>.
#include "algorithms/Histogram.h"
#include "pkdumpogr.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
int main(int argc, char *argv[])
{
- Optionpk<bool> version_opt("\0","version","version 20120625, Copyright (C) 2008-2012 Pieter Kempeneers.\n\
+ std::string versionString="version ";
+ versionString+=VERSION;
+ versionString+=", Copyright (C) 2008-2012 Pieter Kempeneers.\n\
This program comes with ABSOLUTELY NO WARRANTY; for details type use option -h.\n\
This is free software, and you are welcome to redistribute it\n\
- under certain conditions; use option --license for details.",false);
+ under certain conditions; use option --license for details.";
+ Optionpk<bool> version_opt("\0","version",versionString,false);
Optionpk<bool> license_opt("lic","license","show license information",false);
Optionpk<bool> help_opt("h","help","shows this help info",false);
Optionpk<bool> todo_opt("\0","todo","",false);
@@ -64,7 +71,7 @@ int main(int argc, char *argv[])
exit(0);
}
if(help_opt[0]){
- cout << "usage: pkdumpogr -i inputimage -o outputimage [OPTIONS]" << endl;
+ cout << "usage: pkdumpogr -i input [OPTIONS]" << endl;
exit(0);
}
diff --git a/src/apps/pkegcs.cc b/src/apps/pkegcs.cc
index 2aa49a3..f8f28e6 100644
--- a/src/apps/pkegcs.cc
+++ b/src/apps/pkegcs.cc
@@ -21,14 +21,19 @@ along with pktools. If not, see <http://www.gnu.org/licenses/>.
#include "imageclasses/ImgReaderGdal.h"
#include "algorithms/Egcs.h"
-using namespace std;
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
int main(int argc, char *argv[])
{
- Optionpk<bool> version_opt("\0","version","version 20120625, Copyright (C) 2008-2012 Pieter Kempeneers.\n\
+ std::string versionString="version ";
+ versionString+=VERSION;
+ versionString+=", Copyright (C) 2008-2012 Pieter Kempeneers.\n\
This program comes with ABSOLUTELY NO WARRANTY; for details type use option -h.\n\
This is free software, and you are welcome to redistribute it\n\
- under certain conditions; use option --license for details.",false);
+ under certain conditions; use option --license for details.";
+ Optionpk<bool> version_opt("\0","version",versionString,false);
Optionpk<bool> license_opt("lic","license","show license information",false);
Optionpk<bool> help_opt("h","help","shows this help info",false);
Optionpk<string> image_opt("i","image","input image to analyse","");
diff --git a/src/apps/pkextract.cc b/src/apps/pkextract.cc
index fc98a2b..b58ca44 100644
--- a/src/apps/pkextract.cc
+++ b/src/apps/pkextract.cc
@@ -29,7 +29,9 @@ along with pktools. If not, see <http://www.gnu.org/licenses/>.
#include "base/Optionpk.h"
#include "algorithms/Histogram.h"
-using namespace std;
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
#ifndef PI
#define PI 3.1415926535897932384626433832795
@@ -38,37 +40,40 @@ using namespace std;
int main(int argc, char *argv[])
{
- Optionpk<bool> version_opt("\0","version","version 20120625, Copyright (C) 2008-2012 Pieter Kempeneers.\n\
+ std::string versionString="version ";
+ versionString+=VERSION;
+ versionString+=", Copyright (C) 2008-2012 Pieter Kempeneers.\n\
This program comes with ABSOLUTELY NO WARRANTY; for details type use option -h.\n\
This is free software, and you are welcome to redistribute it\n\
- under certain conditions; use option --license for details.",false);
+ under certain conditions; use option --license for details.";
+ Optionpk<bool> version_opt("\0","version",versionString,false);
Optionpk<bool> license_opt("lic","license","show license information",false);
Optionpk<bool> help_opt("h","help","shows this help info",false);
Optionpk<bool> todo_opt("\0","todo","",false);
Optionpk<string> image_opt("i", "image", "Input image file", "");
Optionpk<string> sample_opt("s", "sample", "Input sample file (shape) or class file (e.g. Corine CLC) if class option is set", "");
Optionpk<string> mask_opt("m", "mask", "Mask image file", "");
- Optionpk<int> invalid_opt("f", "flag", "Mask value where image is invalid. If a single mask is used, more flags can be set. If more masks are used, use one value for each mask. Default value is 1", 1);
+ Optionpk<int> invalid_opt("f", "flag", "Mask value where image is invalid. If a single mask is used, more flags can be set. If more masks are used, use one value for each mask.", 1);
Optionpk<int> class_opt("c", "class", "Class(es) to extract from input sample image. Use -1 to process every class in sample image, or 0 to extract all non-flagged pixels from sample file", 0);
Optionpk<string> output_opt("o", "output", "Output sample file (image file)", "");
Optionpk<bool> keepFeatures_opt("k", "keep", "Keep original features in output vector file", false);
- Optionpk<string> fieldname_opt("n", "fname", "Field name of output shape file (default is B)", "B");
Optionpk<string> bufferOutput_opt("bu", "bu", "Buffer output shape file", "");
- Optionpk<short> geo_opt("g", "geo", "geo coordinates (default is 1)", 1);
- Optionpk<short> down_opt("d", "down", "down sampling factor. Can be used to create grid points", 1);
- Optionpk<float> threshold_opt("t", "threshold", "threshold for selecting samples (randomly). Provide probability in percentage (>0) or absolute (<0). Use multiple threshold values (e.g. -t 80 -t 60) is more classes are to be extracted with random selection. Default value is 100: select all pixels for selected class(es)", 100);
+ Optionpk<short> geo_opt("g", "geo", "geo coordinates", 1);
+ Optionpk<short> down_opt("down", "down", "down sampling factor. Can be used to create grid points", 1);
+ Optionpk<float> threshold_opt("t", "threshold", "threshold for selecting samples (randomly). Provide probability in percentage (>0) or absolute (<0). Use multiple threshold values (e.g. -t 80 -t 60) is more classes are to be extracted with random selection. Use value 100 to select all pixels for selected class(es)", 100);
Optionpk<double> min_opt("min", "min", "minimum number of samples to select (0)", 0);
- Optionpk<short> boundary_opt("bo", "boundary", "boundary for selecting the sample (default: 1)", 1);
- Optionpk<short> rbox_opt("rb", "rbox", "rectangular boundary box (total width in m) to draw around the selected pixel. Can not combined with class option. Use multiple rbox options for multiple boundary boxes (default is 0: no box)", 0);
- Optionpk<short> cbox_opt("\0", "cbox", "circular boundary (diameter in m) to draw around the selected pixel. Can not combined with class option. Use multiple cbox options for multiple boundary boxes (default is 0: no box)", 0);
- Optionpk<short> disc_opt("\0", "circular", "circular disc kernel boundary (default is 0)", 0);
- Optionpk<string> ftype_opt("\0", "ftype", "Field type (only Real or Integer, default is Real)", "Real");
- Optionpk<string> ltype_opt("\0", "ltype", "Label type: In16 (default) or String", "Integer");
- Optionpk<string> label_opt("\0", "label", "name of the class label in the output vector file (default is label)", "label");
- Optionpk<bool> polygon_opt("l", "line", "create OGRPolygon as geometry instead of points. Only if sample option is also of polygon type. (default is 0: use OGRPoint)", 0);
- Optionpk<int> band_opt("b", "band", "band index to crop. (Default is -1: use all bands)", -1);
- Optionpk<short> rule_opt("r", "rule", "rule how to report image information per feature. 0: value at each point (or at centroid of the polygon if line is not set), 1: mean value (written to centroid of polygon if line is not set), 2: proportion classes, 3: custom, 4: minimum of polygon). (Default is 0)", 0);
- Optionpk<short> verbose_opt("v", "verbose", "verbose (default is 0)", 0);
+ Optionpk<short> boundary_opt("bo", "boundary", "boundary for selecting the sample", 1);
+ Optionpk<short> rbox_opt("rb", "rbox", "rectangular boundary box (total width in m) to draw around the selected pixel. Can not combined with class option. Use multiple rbox options for multiple boundary boxes. Use value 0 for no box)", 0);
+ Optionpk<short> cbox_opt("cbox", "cbox", "circular boundary (diameter in m) to draw around the selected pixel. Can not combined with class option. Use multiple cbox options for multiple boundary boxes. Use value 0 for no box)", 0);
+ Optionpk<short> disc_opt("circ", "circular", "circular disc kernel boundary", 0);
+ Optionpk<string> ftype_opt("ft", "ftype", "Field type (only Real or Integer)", "Real");
+ Optionpk<string> ltype_opt("lt", "ltype", "Label type: In16 or String", "Integer");
+ Optionpk<string> fieldname_opt("bn", "bname", "Field name of output shape file", "B");
+ Optionpk<string> label_opt("cn", "cname", "name of the class label in the output vector file", "label");
+ Optionpk<bool> polygon_opt("l", "line", "create OGRPolygon as geometry instead of points. Only if sample option is also of polygon type. Use 0 for OGRPoint", 0);
+ Optionpk<int> band_opt("b", "band", "band index to crop. Use -1 to use all bands)", -1);
+ Optionpk<short> rule_opt("r", "rule", "rule how to report image information per feature. 0: value at each point (or at centroid of the polygon if line is not set), 1: mean value (written to centroid of polygon if line is not set), 2: proportion classes, 3: custom, 4: minimum of polygon).", 0);
+ Optionpk<short> verbose_opt("v", "verbose", "verbose mode if > 0", 0);
version_opt.retrieveOption(argc,argv);
license_opt.retrieveOption(argc,argv);
@@ -82,7 +87,6 @@ int main(int argc, char *argv[])
class_opt.retrieveOption(argc,argv);
output_opt.retrieveOption(argc,argv);
keepFeatures_opt.retrieveOption(argc,argv);
- fieldname_opt.retrieveOption(argc,argv);
bufferOutput_opt.retrieveOption(argc,argv);
geo_opt.retrieveOption(argc,argv);
down_opt.retrieveOption(argc,argv);
@@ -94,6 +98,7 @@ int main(int argc, char *argv[])
disc_opt.retrieveOption(argc,argv);
ftype_opt.retrieveOption(argc,argv);
ltype_opt.retrieveOption(argc,argv);
+ fieldname_opt.retrieveOption(argc,argv);
label_opt.retrieveOption(argc,argv);
polygon_opt.retrieveOption(argc,argv);
band_opt.retrieveOption(argc,argv);
@@ -101,16 +106,16 @@ int main(int argc, char *argv[])
verbose_opt.retrieveOption(argc,argv);
if(version_opt[0]||todo_opt[0]){
- cout << version_opt.getHelp() << endl;
- cout << "todo: " << todo_opt.getHelp() << endl;
+ std::cout << version_opt.getHelp() << std::endl;
+ std::cout << "todo: " << todo_opt.getHelp() << std::endl;
exit(0);
}
if(license_opt[0]){
- cout << Optionpk<bool>::getGPLv3License() << endl;
+ std::cout << Optionpk<bool>::getGPLv3License() << std::endl;
exit(0);
}
if(help_opt[0]){
- cout << "usage: pkextract [OPTIONS]" << endl;
+ std::cout << "usage: pkextract -i input -s sample [OPTIONS]" << std::endl;
exit(0);
}
@@ -129,19 +134,19 @@ int main(int argc, char *argv[])
}
short theDim=boundary_opt[0];
if(verbose_opt[0]>1)
- cout << boundary_opt[0] << endl;
+ std::cout << boundary_opt[0] << std::endl;
ImgReaderGdal imgReader;
try{
imgReader.open(image_opt[0]);
}
- catch(string errorstring){
- cout << errorstring << endl;
+ catch(std::string errorstring){
+ std::cout << errorstring << std::endl;
exit(0);
}
int nband=(band_opt[0]<0)?imgReader.nrOfBand():band_opt.size();
if(fieldname_opt.size()<nband){
- string bandString=fieldname_opt[0];
+ std::string bandString=fieldname_opt[0];
fieldname_opt.clear();
fieldname_opt.resize(nband);
for(int iband=0;iband<nband;++iband){
@@ -159,7 +164,7 @@ int main(int argc, char *argv[])
maskReader.resize(mask_opt.size());
for(int imask=0;imask<mask_opt.size();++imask){
if(verbose_opt[0]>1)
- cout << "opening mask image file " << mask_opt[imask] << endl;
+ std::cout << "opening mask image file " << mask_opt[imask] << std::endl;
maskReader[imask].open(mask_opt[0]);
if(imgReader.isGeoRef())
assert(maskReader[imask].isGeoRef());
@@ -177,16 +182,16 @@ int main(int argc, char *argv[])
oldmaskrow[imask]=-1;
if(verbose_opt[0]>1)
- cout << "Number of bands in input image: " << imgReader.nrOfBand() << endl;
+ std::cout << "Number of bands in input image: " << imgReader.nrOfBand() << std::endl;
OGRFieldType fieldType;
OGRFieldType labelType;
int ogr_typecount=11;//hard coded for now!
if(verbose_opt[0]>1)
- cout << "field and label types can be: ";
+ std::cout << "field and label types can be: ";
for(int iType = 0; iType < ogr_typecount; ++iType){
if(verbose_opt[0]>1)
- cout << " " << OGRFieldDefn::GetFieldTypeName((OGRFieldType)iType);
+ std::cout << " " << OGRFieldDefn::GetFieldTypeName((OGRFieldType)iType);
if( OGRFieldDefn::GetFieldTypeName((OGRFieldType)iType) != NULL
&& EQUAL(OGRFieldDefn::GetFieldTypeName((OGRFieldType)iType),
ftype_opt[0].c_str()))
@@ -202,10 +207,10 @@ int main(int argc, char *argv[])
case OFTRealList:
case OFTString:
if(verbose_opt[0]>1)
- cout << endl << "field type is: " << OGRFieldDefn::GetFieldTypeName(fieldType) << endl;
+ std::cout << std::endl << "field type is: " << OGRFieldDefn::GetFieldTypeName(fieldType) << std::endl;
break;
default:
- cerr << "field type " << OGRFieldDefn::GetFieldTypeName(fieldType) << " not supported" << endl;
+ cerr << "field type " << OGRFieldDefn::GetFieldTypeName(fieldType) << " not supported" << std::endl;
exit(0);
break;
}
@@ -215,10 +220,10 @@ int main(int argc, char *argv[])
case OFTRealList:
case OFTString:
if(verbose_opt[0]>1)
- cout << endl << "label type is: " << OGRFieldDefn::GetFieldTypeName(labelType) << endl;
+ std::cout << std::endl << "label type is: " << OGRFieldDefn::GetFieldTypeName(labelType) << std::endl;
break;
default:
- cerr << "label type " << OGRFieldDefn::GetFieldTypeName(labelType) << " not supported" << endl;
+ cerr << "label type " << OGRFieldDefn::GetFieldTypeName(labelType) << " not supported" << std::endl;
exit(0);
break;
}
@@ -230,19 +235,19 @@ int main(int argc, char *argv[])
srandom(time(NULL));
assert(sample_opt[0]!="");
- if((sample_opt[0].find(".tif"))!=string::npos){//raster file
+ if((sample_opt[0].find(".tif"))!=std::string::npos){//raster file
if(!class_opt[0]){
- cout << "Warning: no classes selected, if classes must be extracted, set to -1 for all classes using option -c -1" << endl;
+ std::cout << "Warning: no classes selected, if classes must be extracted, set to -1 for all classes using option -c -1" << std::endl;
ImgReaderGdal classReader;
ImgWriterOgr ogrWriter;
// if(verbose_opt[0]>1){
- // cout << "reading position from " << sample_opt[0] << endl;
- // cout << "class thresholds: " << endl;
+ // std::cout << "reading position from " << sample_opt[0] << std::endl;
+ // std::cout << "class thresholds: " << std::endl;
// for(int iclass=0;iclass<class_opt.size();++iclass){
// if(threshold_opt.size()>1)
- // cout << class_opt[iclass] << ": " << threshold_opt[iclass] << endl;
+ // std::cout << class_opt[iclass] << ": " << threshold_opt[iclass] << std::endl;
// else
- // cout << class_opt[iclass] << ": " << threshold_opt[0] << endl;
+ // std::cout << class_opt[iclass] << ": " << threshold_opt[0] << std::endl;
// }
// }
classReader.open(sample_opt[0]);
@@ -259,7 +264,7 @@ int main(int argc, char *argv[])
int irow=0;
int icol=0;
if(verbose_opt[0]>1)
- cout << "extracting sample from image..." << endl;
+ std::cout << "extracting sample from image..." << std::endl;
progress=0;
pfnProgress(progress,pszMessage,pProgressArg);
for(irow=0;irow<classReader.nrOfRow();++irow){
@@ -298,8 +303,8 @@ int main(int argc, char *argv[])
sample[0]=x;
sample[1]=y;
if(verbose_opt[0]>1){
- cout.precision(12);
- cout << theClass << " " << x << " " << y << endl;
+ std::cout.precision(12);
+ std::cout << theClass << " " << x << " " << y << std::endl;
}
//find col in img
imgReader.geo2image(x,y,iimg,jimg);
@@ -390,7 +395,7 @@ int main(int argc, char *argv[])
if(valid){
for(int iband=0;iband<imgBuffer.size();++iband){
if(imgBuffer[iband].size()!=imgReader.nrOfCol()){
- cout << "Error in band " << iband << ": " << imgBuffer[iband].size() << "!=" << imgReader.nrOfCol() << endl;
+ std::cout << "Error in band " << iband << ": " << imgBuffer[iband].size() << "!=" << imgReader.nrOfCol() << std::endl;
assert(imgBuffer[iband].size()==imgReader.nrOfCol());
}
sample[iband+2]=imgBuffer[iband][static_cast<int>(iimg)];
@@ -420,31 +425,32 @@ int main(int argc, char *argv[])
progress=static_cast<float>(irow+1.0)/classReader.nrOfRow();
pfnProgress(progress,pszMessage,pProgressArg);
}//irow
+ progress=100;
+ pfnProgress(progress,pszMessage,pProgressArg);
if(writeBuffer.size()>0){
assert(ntotalvalid==writeBuffer.size());
if(verbose_opt[0]>0)
- cout << "creating image sample writer " << output_opt[0] << " with " << writeBuffer.size() << " samples (" << ntotalinvalid << " invalid)" << endl;
+ std::cout << "creating image sample writer " << output_opt[0] << " with " << writeBuffer.size() << " samples (" << ntotalinvalid << " invalid)" << std::endl;
ogrWriter.open(output_opt[0]);
char **papszOptions=NULL;
ostringstream slayer;
slayer << "training data";
- string layername=slayer.str();
+ std::string layername=slayer.str();
ogrWriter.createLayer(layername, imgReader.getProjection(), wkbPoint, papszOptions);
- string fieldname="fid";//number of the point
+ std::string fieldname="fid";//number of the point
ogrWriter.createField(fieldname,OFTInteger);
- map<string,double> pointAttributes;
+ map<std::string,double> pointAttributes;
ogrWriter.createField(label_opt[0],labelType);
for(int iband=0;iband<nband;++iband){
int theBand=(band_opt[0]<0)?iband:band_opt[iband];
ogrWriter.createField(fieldname_opt[iband],fieldType);
}
- pfnProgress(progress,pszMessage,pProgressArg);
- cout << "writing sample to " << output_opt[0] << "..." << endl;
+ std::cout << "writing sample to " << output_opt[0] << "..." << std::endl;
progress=0;
pfnProgress(progress,pszMessage,pProgressArg);
for(int isample=0;isample<writeBuffer.size();++isample){
if(verbose_opt[0]>1)
- cout << "writing sample " << isample << endl;
+ std::cout << "writing sample " << isample << std::endl;
pointAttributes[label_opt[0]]=writeBufferClass[isample];
for(int iband=0;iband<writeBuffer[0].size()-2;++iband){
int theBand=(band_opt[0]<0)?iband:band_opt[iband];
@@ -457,7 +463,7 @@ int main(int argc, char *argv[])
pointAttributes[fieldname_opt[iband]]=writeBuffer[isample][iband+2];
}
if(verbose_opt[0]>1)
- cout << "all bands written" << endl;
+ std::cout << "all bands written" << std::endl;
ogrWriter.addPoint(writeBuffer[isample][0],writeBuffer[isample][1],pointAttributes,fieldname,isample);
progress=static_cast<float>(isample+1.0)/writeBuffer.size();
pfnProgress(progress,pszMessage,pProgressArg);
@@ -465,14 +471,14 @@ int main(int argc, char *argv[])
ogrWriter.close();
}
else{
- cout << "No data found for any class " << endl;
+ std::cout << "No data found for any class " << std::endl;
}
classReader.close();
nsample=writeBuffer.size();
if(verbose_opt[0]){
- cout << "total number of samples written: " << nsample << endl;
+ std::cout << "total number of samples written: " << nsample << std::endl;
for(int iclass=0;iclass<class_opt.size();++iclass)
- cout << "class " << class_opt[iclass] << " has " << nvalid[iclass] << " samples" << endl;
+ std::cout << "class " << class_opt[iclass] << " has " << nvalid[iclass] << " samples" << std::endl;
}
}
else{//classification file
@@ -482,13 +488,13 @@ int main(int argc, char *argv[])
ImgReaderGdal classReader;
ImgWriterOgr ogrWriter;
if(verbose_opt[0]>1){
- cout << "reading position from " << sample_opt[0] << endl;
- cout << "class thresholds: " << endl;
+ std::cout << "reading position from " << sample_opt[0] << std::endl;
+ std::cout << "class thresholds: " << std::endl;
for(int iclass=0;iclass<class_opt.size();++iclass){
if(threshold_opt.size()>1)
- cout << class_opt[iclass] << ": " << threshold_opt[iclass] << endl;
+ std::cout << class_opt[iclass] << ": " << threshold_opt[iclass] << std::endl;
else
- cout << class_opt[iclass] << ": " << threshold_opt[0] << endl;
+ std::cout << class_opt[iclass] << ": " << threshold_opt[0] << std::endl;
}
}
classReader.open(sample_opt[0]);
@@ -505,7 +511,7 @@ int main(int argc, char *argv[])
int irow=0;
int icol=0;
if(verbose_opt[0]>1)
- cout << "extracting sample from image..." << endl;
+ std::cout << "extracting sample from image..." << std::endl;
progress=0;
pfnProgress(progress,pszMessage,pProgressArg);
for(irow=0;irow<classReader.nrOfRow();++irow){
@@ -542,8 +548,8 @@ int main(int argc, char *argv[])
sample[0]=x;
sample[1]=y;
if(verbose_opt[0]>1){
- cout.precision(12);
- cout << theClass << " " << x << " " << y << endl;
+ std::cout.precision(12);
+ std::cout << theClass << " " << x << " " << y << std::endl;
}
//find col in img
imgReader.geo2image(x,y,iimg,jimg);
@@ -634,7 +640,7 @@ int main(int argc, char *argv[])
if(valid){
for(int iband=0;iband<imgBuffer.size();++iband){
if(imgBuffer[iband].size()!=imgReader.nrOfCol()){
- cout << "Error in band " << iband << ": " << imgBuffer[iband].size() << "!=" << imgReader.nrOfCol() << endl;
+ std::cout << "Error in band " << iband << ": " << imgBuffer[iband].size() << "!=" << imgReader.nrOfCol() << std::endl;
assert(imgBuffer[iband].size()==imgReader.nrOfCol());
}
sample[iband+2]=imgBuffer[iband][static_cast<int>(iimg)];
@@ -668,16 +674,16 @@ int main(int argc, char *argv[])
if(writeBuffer.size()>0){
assert(ntotalvalid==writeBuffer.size());
if(verbose_opt[0]>0)
- cout << "creating image sample writer " << output_opt[0] << " with " << writeBuffer.size() << " samples (" << ntotalinvalid << " invalid)" << endl;
+ std::cout << "creating image sample writer " << output_opt[0] << " with " << writeBuffer.size() << " samples (" << ntotalinvalid << " invalid)" << std::endl;
ogrWriter.open(output_opt[0]);
char **papszOptions=NULL;
ostringstream slayer;
slayer << "training data";
- string layername=slayer.str();
+ std::string layername=slayer.str();
ogrWriter.createLayer(layername, imgReader.getProjection(), wkbPoint, papszOptions);
- string fieldname="fid";//number of the point
+ std::string fieldname="fid";//number of the point
ogrWriter.createField(fieldname,OFTInteger);
- map<string,double> pointAttributes;
+ map<std::string,double> pointAttributes;
// ogrWriter.createField(label_opt[0],OFTInteger);
ogrWriter.createField(label_opt[0],labelType);
for(int iband=0;iband<nband;++iband){
@@ -691,7 +697,7 @@ int main(int argc, char *argv[])
ogrWriter.createField(fieldname_opt[iband],fieldType);
}
pfnProgress(progress,pszMessage,pProgressArg);
- cout << "writing sample to " << output_opt[0] << "..." << endl;
+ std::cout << "writing sample to " << output_opt[0] << "..." << std::endl;
progress=0;
pfnProgress(progress,pszMessage,pProgressArg);
for(int isample=0;isample<writeBuffer.size();++isample){
@@ -713,51 +719,51 @@ int main(int argc, char *argv[])
ogrWriter.close();
}
else{
- cout << "No data found for any class " << endl;
+ std::cout << "No data found for any class " << std::endl;
}
classReader.close();
nsample=writeBuffer.size();
if(verbose_opt[0]){
- cout << "total number of samples written: " << nsample << endl;
+ std::cout << "total number of samples written: " << nsample << std::endl;
for(int iclass=0;iclass<class_opt.size();++iclass)
- cout << "class " << class_opt[iclass] << " has " << nvalid[iclass] << " samples" << endl;
+ std::cout << "class " << class_opt[iclass] << " has " << nvalid[iclass] << " samples" << std::endl;
}
}
}
else{//vector file
if(verbose_opt[0]>1)
- cout << "reading position from shape file " << sample_opt[0] << endl;
+ std::cout << "reading position from shape file " << sample_opt[0] << std::endl;
ImgReaderOgr sampleReader;
try{
sampleReader.open(sample_opt[0]);
}
- catch(string errorString){
- cout << errorString << endl;
+ catch(std::string errorString){
+ std::cout << errorString << std::endl;
exit(1);
}
if(verbose_opt[0]>1)
- cout << "creating image sample writer " << output_opt[0] << endl;
+ std::cout << "creating image sample writer " << output_opt[0] << std::endl;
ImgWriterOgr ogrWriter;
ogrWriter.open(output_opt[0]);
char **papszOptions=NULL;
ostringstream slayer;
slayer << "training data";
- string layername=slayer.str();
+ std::string layername=slayer.str();
if(polygon_opt[0]){
if(verbose_opt[0])
- cout << "create polygons" << endl;
+ std::cout << "create polygons" << std::endl;
ogrWriter.createLayer(layername, imgReader.getProjection(), wkbPolygon, papszOptions);
}
else{
if(verbose_opt[0])
- cout << "create points" << endl;
+ std::cout << "create points" << std::endl;
ogrWriter.createLayer(layername, imgReader.getProjection(), wkbPoint, papszOptions);
}
ogrWriter.copyFields(sampleReader);
- vector<string> fieldnames;
+ vector<std::string> fieldnames;
sampleReader.getFields(fieldnames);
assert(fieldnames.size()==ogrWriter.getFieldCount());
- map<string,double> pointAttributes;
+ map<std::string,double> pointAttributes;
switch(rule_opt[0]){
case(2):{//proportion for each class
for(int iclass=0;iclass<class_opt.size();++iclass){
@@ -790,7 +796,7 @@ int main(int argc, char *argv[])
else
fs << fieldname_opt[iband];
if(verbose_opt[0]>1)
- cout << "creating field " << fs.str() << endl;
+ std::cout << "creating field " << fs.str() << std::endl;
ogrWriter.createField(fs.str(),fieldType);
}
@@ -811,19 +817,19 @@ int main(int argc, char *argv[])
ImgWriterOgr boxWriter;
if(rbox_opt[0]>0||cbox_opt[0]>0){
if(verbose_opt[0]>1)
- cout << "opening box writer " << bufferOutput_opt[0] << endl;
+ std::cout << "opening box writer " << bufferOutput_opt[0] << std::endl;
boxWriter.open(bufferOutput_opt[0]);
- string layername="buffer";
+ std::string layername="buffer";
boxWriter.createLayer(layername, imgReader.getProjection(), wkbPolygon);
- string fieldname="fid";//number of the point
+ std::string fieldname="fid";//number of the point
if(verbose_opt[0]>1)
- cout << "creating field " << fieldname << endl;
+ std::cout << "creating field " << fieldname << std::endl;
// ogrWriter.createField(fieldname,OFTInteger);
boxWriter.createField(fieldname,OFTInteger);
}
while( (readFeature = readLayer->GetNextFeature()) != NULL ){
if(verbose_opt[0]>0)
- cout << "reading feature " << readFeature->GetFID() << endl;
+ std::cout << "reading feature " << readFeature->GetFID() << std::endl;
if(threshold_opt[0]>0){//percentual value
double p=static_cast<double>(random())/(RAND_MAX);
p*=100.0;
@@ -836,7 +842,7 @@ int main(int argc, char *argv[])
}
}
if(verbose_opt[0]>0)
- cout << "processing feature " << readFeature->GetFID() << endl;
+ std::cout << "processing feature " << readFeature->GetFID() << std::endl;
//get x and y from readFeature
double x,y;
OGRGeometry *poGeometry;
@@ -885,16 +891,16 @@ int main(int argc, char *argv[])
colMask=static_cast<int>(colMask);
if(static_cast<int>(colMask)<0||static_cast<int>(colMask)>=maskReader[0].nrOfCol()){
continue;
- // cerr << colMask << " out of mask col range!" << endl;
- // cerr << x << " " << y << " " << colMask << " " << rowMask << endl;
+ // cerr << colMask << " out of mask col range!" << std::endl;
+ // cerr << x << " " << y << " " << colMask << " " << rowMask << std::endl;
// assert(static_cast<int>(colMask)>=0&&static_cast<int>(colMask)<maskReader[0].nrOfCol());
}
if(static_cast<int>(rowMask)!=static_cast<int>(oldmaskrow[0])){
if(static_cast<int>(rowMask)<0||static_cast<int>(rowMask)>=maskReader[0].nrOfRow()){
continue;
- // cerr << rowMask << " out of mask row range!" << endl;
- // cerr << x << " " << y << " " << colMask << " " << rowMask << endl;
+ // cerr << rowMask << " out of mask row range!" << std::endl;
+ // cerr << x << " " << y << " " << colMask << " " << rowMask << std::endl;
// assert(static_cast<int>(rowMask)>=0&&static_cast<int>(rowMask)<imgReader.nrOfRow());
}
else{
@@ -935,11 +941,11 @@ int main(int argc, char *argv[])
vector< vector<OGRPoint*> > points;
points.resize(rbox_opt.size());
if(verbose_opt[0]>1)
- cout << "creating rectangular box for sample " << isample << ": ";
+ std::cout << "creating rectangular box for sample " << isample << ": ";
for(int ibox=0;ibox<rbox_opt.size();++ibox){
int npoint=4;
if(verbose_opt[0]>1)
- cout << ibox << " ";
+ std::cout << ibox << " ";
points[ibox].resize(npoint+1);
vector<OGRPoint> pbPoint(npoint+1);
pbPoint[0].setX(x-0.5*rbox_opt[ibox]);
@@ -955,22 +961,22 @@ int main(int argc, char *argv[])
pbPoint[3].setX(x-0.5*rbox_opt[ibox]);
pbPoint[3].setY(y-0.5*rbox_opt[ibox]);
points[ibox][3]=&(pbPoint[3]);//LL
- string fieldname="fid";//number of the point
+ std::string fieldname="fid";//number of the point
boxWriter.addRing(points[ibox],fieldname,isample);
// boxWriter.addLineString(points[ibox],fieldname,isample);
}
if(verbose_opt[0]>1)
- cout << endl;
+ std::cout << std::endl;
}
if(cbox_opt[0]>0){
vector< vector<OGRPoint*> > points;
points.resize(cbox_opt.size());
if(verbose_opt[0]>1)
- cout << "creating circular box ";
+ std::cout << "creating circular box ";
for(int ibox=0;ibox<cbox_opt.size();++ibox){
int npoint=50;
if(verbose_opt[0]>1)
- cout << ibox << " ";
+ std::cout << ibox << " ";
points[ibox].resize(npoint+1);
vector<OGRPoint> pbPoint(npoint+1);
double radius=cbox_opt[ibox]/2.0;
@@ -985,23 +991,23 @@ int main(int argc, char *argv[])
pbPoint[npoint].setX(x+radius*cos(alpha));
pbPoint[npoint].setY(y+radius*sin(alpha));
points[ibox][npoint]=&(pbPoint[npoint]);
- string fieldname="fid";//number of the point
+ std::string fieldname="fid";//number of the point
boxWriter.addRing(points[ibox],fieldname,isample);
// boxWriter.addLineString(points[ibox],fieldname,isample);
}
if(verbose_opt[0]>1)
- cout << endl;
+ std::cout << std::endl;
}
OGRFeature *writeFeature;
writeFeature = OGRFeature::CreateFeature(writeLayer->GetLayerDefn());
if(verbose_opt[0]>1)
- cout << "copying fields from points " << sample_opt[0] << endl;
+ std::cout << "copying fields from points " << sample_opt[0] << std::endl;
if(writeFeature->SetFrom(readFeature)!= OGRERR_NONE)
- cerr << "writing feature failed" << endl;
+ cerr << "writing feature failed" << std::endl;
if(verbose_opt[0]>1)
- cout << "write feature has " << writeFeature->GetFieldCount() << " fields" << endl;
+ std::cout << "write feature has " << writeFeature->GetFieldCount() << " fields" << std::endl;
vector<double> windowBuffer;
for(int windowJ=-theDim/2;windowJ<(theDim+1)/2;++windowJ){
@@ -1017,19 +1023,19 @@ int main(int argc, char *argv[])
if(static_cast<int>(i)<0||static_cast<int>(i)>=imgReader.nrOfCol())
continue;
if(verbose_opt[0]>1)
- cout << "reading image value at " << i << "," << j;
+ std::cout << "reading image value at " << i << "," << j;
for(int iband=0;iband<nband;++iband){
int theBand=(band_opt[0]<0)?iband:band_opt[iband];
imgReader.readData(value,GDT_Float64,i,j,theBand);
if(verbose_opt[0]>1)
- cout << ": " << value << endl;
+ std::cout << ": " << value << std::endl;
ostringstream fs;
if(theDim>1)
fs << fieldname_opt[iband] << "_" << windowJ << "_" << windowI;
else
fs << fieldname_opt[iband];
if(verbose_opt[0]>1)
- cout << "set field " << fs.str() << " to " << value << endl;
+ std::cout << "set field " << fs.str() << " to " << value << std::endl;
switch( fieldType ){
case OFTInteger:
writeFeature->SetField(fs.str().c_str(),static_cast<int>(value));
@@ -1065,9 +1071,9 @@ int main(int argc, char *argv[])
if(keepFeatures_opt[0])
writeFeature->SetField("origId",static_cast<int>(readFeature->GetFID()));
if(verbose_opt[0]>1)
- cout << "creating point feature" << endl;
+ std::cout << "creating point feature" << std::endl;
if(writeLayer->CreateFeature( writeFeature ) != OGRERR_NONE ){
- string errorString="Failed to create feature in shapefile";
+ std::string errorString="Failed to create feature in shapefile";
throw(errorString);
}
OGRFeature::DestroyFeature( writeFeature );
@@ -1088,7 +1094,7 @@ int main(int argc, char *argv[])
readPolygon.closeRings();
if(verbose_opt[0]>1)
- cout << "get centroid point from polygon" << endl;
+ std::cout << "get centroid point from polygon" << std::endl;
readPolygon.Centroid(&writeCentroidPoint);
double ulx,uly,lrx,lry;
@@ -1102,7 +1108,7 @@ int main(int argc, char *argv[])
else{
//get envelope
if(verbose_opt[0])
- cout << "reading envelope for polygon " << ifeature << endl;
+ std::cout << "reading envelope for polygon " << ifeature << std::endl;
OGREnvelope* psEnvelope=new OGREnvelope();
readPolygon.getEnvelope(psEnvelope);
ulx=psEnvelope->MinX;
@@ -1128,7 +1134,7 @@ int main(int argc, char *argv[])
lri=static_cast<int>(lri);
//iterate through all pixels
if(verbose_opt[0]>1)
- cout << "bounding box for polygon feature " << ifeature << ": " << uli << " " << ulj << " " << lri << " " << lrj << endl;
+ std::cout << "bounding box for polygon feature " << ifeature << ": " << uli << " " << ulj << " " << lri << " " << lrj << std::endl;
if(uli<0||lri>=imgReader.nrOfCol()||ulj<0||ulj>=imgReader.nrOfRow())
continue;
@@ -1179,8 +1185,8 @@ int main(int argc, char *argv[])
if(static_cast<int>(colMask)<0||static_cast<int>(colMask)>=maskReader[imask].nrOfCol())
continue;
// {
- // cerr << colMask << " out of mask col range!" << endl;
- // cerr << x << " " << y << " " << colMask << " " << rowMask << endl;
+ // cerr << colMask << " out of mask col range!" << std::endl;
+ // cerr << x << " " << y << " " << colMask << " " << rowMask << std::endl;
// assert(static_cast<int>(colMask)>=0&&static_cast<int>(colMask)<maskReader[imask].nrOfCol());
// }
@@ -1188,8 +1194,8 @@ int main(int argc, char *argv[])
if(static_cast<int>(rowMask)<0||static_cast<int>(rowMask)>=maskReader[imask].nrOfRow())
continue;
// {
- // cerr << rowMask << " out of mask row range!" << endl;
- // cerr << x << " " << y << " " << colMask << " " << rowMask << endl;
+ // cerr << rowMask << " out of mask row range!" << std::endl;
+ // cerr << x << " " << y << " " << colMask << " " << rowMask << std::endl;
// assert(static_cast<int>(rowMask)>=0&&static_cast<int>(rowMask)<imgReader.nrOfRow());
// }
else{
@@ -1217,8 +1223,8 @@ int main(int argc, char *argv[])
if(static_cast<int>(colMask)<0||static_cast<int>(colMask)>=maskReader[0].nrOfCol())
continue;
// {
- // cerr << colMask << " out of mask col range!" << endl;
- // cerr << x << " " << y << " " << colMask << " " << rowMask << endl;
+ // cerr << colMask << " out of mask col range!" << std::endl;
+ // cerr << x << " " << y << " " << colMask << " " << rowMask << std::endl;
// assert(static_cast<int>(colMask)>=0&&static_cast<int>(colMask)<maskReader[0].nrOfCol());
// }
@@ -1226,8 +1232,8 @@ int main(int argc, char *argv[])
if(static_cast<int>(rowMask)<0||static_cast<int>(rowMask)>=maskReader[0].nrOfRow())
continue;
// {
- // cerr << rowMask << " out of mask row range!" << endl;
- // cerr << x << " " << y << " " << colMask << " " << rowMask << endl;
+ // cerr << rowMask << " out of mask row range!" << std::endl;
+ // cerr << x << " " << y << " " << colMask << " " << rowMask << std::endl;
// assert(static_cast<int>(rowMask)>=0&&static_cast<int>(rowMask)<imgReader.nrOfRow());
// }
else{
@@ -1252,7 +1258,7 @@ int main(int argc, char *argv[])
continue;
writeRing.addPoint(&thePoint);
if(verbose_opt[0]>1)
- cout << "point is on surface:" << thePoint.getX() << "," << thePoint.getY() << endl;
+ std::cout << "point is on surface:" << thePoint.getX() << "," << thePoint.getY() << std::endl;
++nPointPolygon;
OGRFeature *writePointFeature;
if(!polygon_opt[0]){
@@ -1260,25 +1266,25 @@ int main(int argc, char *argv[])
if(rule_opt[0]!=1){//do not create in case of mean value (only create point at centroid
writePointFeature = OGRFeature::CreateFeature(writeLayer->GetLayerDefn());
if(verbose_opt[0]>1)
- cout << "copying fields from polygons " << sample_opt[0] << endl;
+ std::cout << "copying fields from polygons " << sample_opt[0] << std::endl;
if(writePointFeature->SetFrom(readFeature)!= OGRERR_NONE)
- cerr << "writing feature failed" << endl;
+ cerr << "writing feature failed" << std::endl;
writePointFeature->SetGeometry(&thePoint);
OGRGeometry *updateGeometry;
updateGeometry = writePointFeature->GetGeometryRef();
OGRPoint *poPoint = (OGRPoint *) updateGeometry;
if(verbose_opt[0]>1)
- cout << "write feature has " << writePointFeature->GetFieldCount() << " fields" << endl;
+ std::cout << "write feature has " << writePointFeature->GetFieldCount() << " fields" << std::endl;
}
}
if(verbose_opt[0]>1)
- cout << "reading image value within polygon at position " << i << "," << j;
+ std::cout << "reading image value within polygon at position " << i << "," << j;
for(int iband=0;iband<nband;++iband){
int theBand=(band_opt[0]<0)?iband:band_opt[iband];
double value=0;
imgReader.readData(value,GDT_Float64,i,j,theBand);
if(verbose_opt[0]>1)
- cout << ": " << value << endl;
+ std::cout << ": " << value << std::endl;
if(polygon_opt[0]||rule_opt[0]==1){
int iclass=0;
switch(rule_opt[0]){
@@ -1309,7 +1315,7 @@ int main(int argc, char *argv[])
// else
// fs << fieldname_opt[0] << theBand;
if(verbose_opt[0]>1)
- cout << "set field " << fieldname_opt[iband] << " to " << value << endl;
+ std::cout << "set field " << fieldname_opt[iband] << " to " << value << std::endl;
switch( fieldType ){
case OFTInteger:
writePointFeature->SetField(fieldname_opt[iband].c_str(),static_cast<int>(value));
@@ -1349,9 +1355,9 @@ int main(int argc, char *argv[])
writePointFeature->SetField("origId",static_cast<int>(readFeature->GetFID()));
//write feature
if(verbose_opt[0]>1)
- cout << "creating point feature" << endl;
+ std::cout << "creating point feature" << std::endl;
if(writeLayer->CreateFeature( writePointFeature ) != OGRERR_NONE ){
- string errorString="Failed to create feature in shapefile";
+ std::string errorString="Failed to create feature in shapefile";
throw(errorString);
}
//destroy feature
@@ -1366,7 +1372,7 @@ int main(int argc, char *argv[])
}
}
// //test
- // cout << "before write polygon" << endl;
+ // std::cout << "before write polygon" << std::endl;
if(polygon_opt[0]||rule_opt[0]==1){
//add ring to polygon
if(polygon_opt[0]){
@@ -1375,36 +1381,36 @@ int main(int argc, char *argv[])
//write geometry of writePolygon
writePolygonFeature->SetGeometry(&writePolygon);
if(writePolygonFeature->SetFrom(readFeature)!= OGRERR_NONE)
- cerr << "writing feature failed" << endl;
+ cerr << "writing feature failed" << std::endl;
if(verbose_opt[0]>1)
- cout << "copying new fields write polygon " << sample_opt[0] << endl;
+ std::cout << "copying new fields write polygon " << sample_opt[0] << std::endl;
if(verbose_opt[0]>1)
- cout << "write feature has " << writePolygonFeature->GetFieldCount() << " fields" << endl;
+ std::cout << "write feature has " << writePolygonFeature->GetFieldCount() << " fields" << std::endl;
//write polygon feature
}
else{//write mean value of polygon to centroid point (rule_opt[0]==1)
//create feature
if(verbose_opt[0]>1)
- cout << "copying fields from polygons " << sample_opt[0] << endl;
+ std::cout << "copying fields from polygons " << sample_opt[0] << std::endl;
if(writeCentroidFeature->SetFrom(readFeature)!= OGRERR_NONE)
- cerr << "writing feature failed" << endl;
+ cerr << "writing feature failed" << std::endl;
writeCentroidFeature->SetGeometry(&writeCentroidPoint);
OGRGeometry *updateGeometry;
updateGeometry = writeCentroidFeature->GetGeometryRef();
assert(wkbFlatten(updateGeometry->getGeometryType()) == wkbPoint );
if(verbose_opt[0]>1)
- cout << "write feature has " << writeCentroidFeature->GetFieldCount() << " fields" << endl;
+ std::cout << "write feature has " << writeCentroidFeature->GetFieldCount() << " fields" << std::endl;
}
switch(rule_opt[0]){
case(0)://value at each point (or at centroid of polygon if line is not set
default:{
if(verbose_opt[0])
- cout << "number of points in polygon: " << nPointPolygon << endl;
+ std::cout << "number of points in polygon: " << nPointPolygon << std::endl;
for(int index=0;index<polyValues.size();++index){
double theValue=polyValues[index];
// ostringstream fs;
if(verbose_opt[0])
- cout << "number of points in polygon: " << nPointPolygon << endl;
+ std::cout << "number of points in polygon: " << nPointPolygon << std::endl;
int theBand=(band_opt[0]<0)?index:band_opt[index];
// if(nband==1)
// fs << fieldname_opt[0];
@@ -1412,7 +1418,7 @@ int main(int argc, char *argv[])
// fs << fieldname_opt[0] << theBand;
if(verbose_opt[0]>1)
- cout << "set field " << fieldname_opt[index] << " to " << theValue << endl;
+ std::cout << "set field " << fieldname_opt[index] << " to " << theValue << std::endl;
switch( fieldType ){
case OFTInteger:
if(polygon_opt[0])
@@ -1462,7 +1468,7 @@ int main(int argc, char *argv[])
break;
}
default://not supported
- cout << "field type not supported yet..." << endl;
+ std::cout << "field type not supported yet..." << std::endl;
break;
}
}
@@ -1470,7 +1476,7 @@ int main(int argc, char *argv[])
}
case(1):{//mean value (written to centroid of polygon if line is not set
if(verbose_opt[0])
- cout << "number of points in polygon: " << nPointPolygon << endl;
+ std::cout << "number of points in polygon: " << nPointPolygon << std::endl;
for(int index=0;index<polyValues.size();++index){
double theValue=polyValues[index];
// ostringstream fs;
@@ -1481,7 +1487,7 @@ int main(int argc, char *argv[])
// else
// fs << fieldname_opt[0] << theBand;
if(verbose_opt[0]>1)
- cout << "set field " << fieldname_opt[index] << " to " << theValue << endl;
+ std::cout << "set field " << fieldname_opt[index] << " to " << theValue << std::endl;
switch( fieldType ){
case OFTInteger:
if(polygon_opt[0])
@@ -1531,7 +1537,7 @@ int main(int argc, char *argv[])
break;
}
default://not supported
- cout << "field type not supported yet..." << endl;
+ std::cout << "field type not supported yet..." << std::endl;
break;
}
}
@@ -1539,7 +1545,7 @@ int main(int argc, char *argv[])
}
case(2):{//proportion classes
if(verbose_opt[0])
- cout << "number of points in polygon: " << nPointPolygon << endl;
+ std::cout << "number of points in polygon: " << nPointPolygon << std::endl;
hist.normalize_pct(polyValues);
// hist.sum(polyValues);
for(int index=0;index<polyValues.size();++index){
@@ -1556,7 +1562,7 @@ int main(int argc, char *argv[])
case(3):{//custom
assert(polygon_opt[0]);//not implemented for points
if(verbose_opt[0])
- cout << "number of points in polygon: " << nPointPolygon << endl;
+ std::cout << "number of points in polygon: " << nPointPolygon << std::endl;
hist.normalize_pct(polyValues);
assert(polyValues.size()==2);//11:broadleaved, 12:coniferous
if(polyValues[0]>=75)//broadleaved
@@ -1567,12 +1573,12 @@ int main(int argc, char *argv[])
writePolygonFeature->SetField(label_opt[0].c_str(),static_cast<int>(13));
else{
if(verbose_opt[0]){
- cout << "No valid value in polyValues..." << endl;
+ std::cout << "No valid value in polyValues..." << std::endl;
for(int index=0;index<polyValues.size();++index){
double theValue=polyValues[index];
- cout << theValue << " ";
+ std::cout << theValue << " ";
}
- cout << endl;
+ std::cout << std::endl;
}
writePolygonFeature->SetField(label_opt[0].c_str(),static_cast<int>(20));
}
@@ -1581,20 +1587,20 @@ int main(int argc, char *argv[])
case(4):{//minimum of polygon
assert(polygon_opt[0]);//not implemented for points
if(verbose_opt[0])
- cout << "number of points in polygon: " << nPointPolygon << endl;
+ std::cout << "number of points in polygon: " << nPointPolygon << std::endl;
//search for min class
//todo: change to minClass=hist.max(class_opt) once Optionpk is implemented...
int minClass=class_opt[class_opt.size()-1];//!hard coded for now, maximum class is last entry in class_opt
for(int iclass=0;iclass<class_opt.size();++iclass){
if(polyValues[iclass]>0){
if(verbose_opt[0]>1)
- cout << class_opt[iclass] << ": " << polyValues[iclass] << endl;
+ std::cout << class_opt[iclass] << ": " << polyValues[iclass] << std::endl;
if(class_opt[iclass]<minClass)
minClass=class_opt[iclass];
}
}
if(verbose_opt[0]>0)
- cout << "minClass: " << minClass << endl;
+ std::cout << "minClass: " << minClass << std::endl;
writePolygonFeature->SetField(label_opt[0].c_str(),minClass);
break;
}
@@ -1603,9 +1609,9 @@ int main(int argc, char *argv[])
if(keepFeatures_opt[0])
writePolygonFeature->SetField("origId",static_cast<int>(readFeature->GetFID()));
if(verbose_opt[0]>1)
- cout << "creating polygon feature" << endl;
+ std::cout << "creating polygon feature" << std::endl;
if(writeLayer->CreateFeature( writePolygonFeature ) != OGRERR_NONE ){
- string errorString="Failed to create polygon feature in shapefile";
+ std::string errorString="Failed to create polygon feature in shapefile";
throw(errorString);
}
OGRFeature::DestroyFeature( writePolygonFeature );
@@ -1617,9 +1623,9 @@ int main(int argc, char *argv[])
if(keepFeatures_opt[0])
writeCentroidFeature->SetField("origId",static_cast<int>(readFeature->GetFID()));
if(verbose_opt[0]>1)
- cout << "creating point feature in centroid" << endl;
+ std::cout << "creating point feature in centroid" << std::endl;
if(writeLayer->CreateFeature( writeCentroidFeature ) != OGRERR_NONE ){
- string errorString="Failed to create point feature in shapefile";
+ std::string errorString="Failed to create point feature in shapefile";
throw(errorString);
}
OGRFeature::DestroyFeature( writeCentroidFeature );
@@ -1640,7 +1646,7 @@ int main(int argc, char *argv[])
readPolygon.closeRings();
if(verbose_opt[0]>1)
- cout << "get centroid point from polygon" << endl;
+ std::cout << "get centroid point from polygon" << std::endl;
readPolygon.Centroid(&writeCentroidPoint);
double ulx,uly,lrx,lry;
@@ -1654,7 +1660,7 @@ int main(int argc, char *argv[])
else{
//get envelope
if(verbose_opt[0])
- cout << "reading envelope for polygon " << ifeature << endl;
+ std::cout << "reading envelope for polygon " << ifeature << std::endl;
OGREnvelope* psEnvelope=new OGREnvelope();
readPolygon.getEnvelope(psEnvelope);
ulx=psEnvelope->MinX;
@@ -1680,7 +1686,7 @@ int main(int argc, char *argv[])
lri=static_cast<int>(lri);
//iterate through all pixels
if(verbose_opt[0]>1)
- cout << "bounding box for feature " << ifeature << ": " << uli << " " << ulj << " " << lri << " " << lrj << endl;
+ std::cout << "bounding box for feature " << ifeature << ": " << uli << " " << ulj << " " << lri << " " << lrj << std::endl;
if(uli<0||lri>=imgReader.nrOfCol()||ulj<0||ulj>=imgReader.nrOfRow())
continue;
@@ -1731,8 +1737,8 @@ int main(int argc, char *argv[])
if(static_cast<int>(colMask)<0||static_cast<int>(colMask)>=maskReader[imask].nrOfCol())
continue;
// {
- // cerr << colMask << " out of mask col range!" << endl;
- // cerr << x << " " << y << " " << colMask << " " << rowMask << endl;
+ // cerr << colMask << " out of mask col range!" << std::endl;
+ // cerr << x << " " << y << " " << colMask << " " << rowMask << std::endl;
// assert(static_cast<int>(colMask)>=0&&static_cast<int>(colMask)<maskReader[imask].nrOfCol());
// }
@@ -1740,8 +1746,8 @@ int main(int argc, char *argv[])
if(static_cast<int>(rowMask)<0||static_cast<int>(rowMask)>=maskReader[imask].nrOfRow())
continue;
// {
- // cerr << rowMask << " out of mask row range!" << endl;
- // cerr << x << " " << y << " " << colMask << " " << rowMask << endl;
+ // cerr << rowMask << " out of mask row range!" << std::endl;
+ // cerr << x << " " << y << " " << colMask << " " << rowMask << std::endl;
// assert(static_cast<int>(rowMask)>=0&&static_cast<int>(rowMask)<imgReader.nrOfRow());
// }
else{
@@ -1769,8 +1775,8 @@ int main(int argc, char *argv[])
if(static_cast<int>(colMask)<0||static_cast<int>(colMask)>=maskReader[0].nrOfCol())
continue;
// {
- // cerr << colMask << " out of mask col range!" << endl;
- // cerr << x << " " << y << " " << colMask << " " << rowMask << endl;
+ // cerr << colMask << " out of mask col range!" << std::endl;
+ // cerr << x << " " << y << " " << colMask << " " << rowMask << std::endl;
// assert(static_cast<int>(colMask)>=0&&static_cast<int>(colMask)<maskReader[0].nrOfCol());
// }
@@ -1778,8 +1784,8 @@ int main(int argc, char *argv[])
if(static_cast<int>(rowMask)<0||static_cast<int>(rowMask)>=maskReader[0].nrOfRow())
continue;
// {
- // cerr << rowMask << " out of mask row range!" << endl;
- // cerr << x << " " << y << " " << colMask << " " << rowMask << endl;
+ // cerr << rowMask << " out of mask row range!" << std::endl;
+ // cerr << x << " " << y << " " << colMask << " " << rowMask << std::endl;
// assert(static_cast<int>(rowMask)>=0&&static_cast<int>(rowMask)<imgReader.nrOfRow());
// }
else{
@@ -1804,7 +1810,7 @@ int main(int argc, char *argv[])
continue;
writeRing.addPoint(&thePoint);
if(verbose_opt[0]>1)
- cout << "point is on surface:" << thePoint.getX() << "," << thePoint.getY() << endl;
+ std::cout << "point is on surface:" << thePoint.getX() << "," << thePoint.getY() << std::endl;
++nPointPolygon;
OGRFeature *writePointFeature;
if(!polygon_opt[0]){
@@ -1812,25 +1818,25 @@ int main(int argc, char *argv[])
if(rule_opt[0]!=1){//do not create in case of mean value (only create point at centroid
writePointFeature = OGRFeature::CreateFeature(writeLayer->GetLayerDefn());
if(verbose_opt[0]>1)
- cout << "copying fields from polygons " << sample_opt[0] << endl;
+ std::cout << "copying fields from polygons " << sample_opt[0] << std::endl;
if(writePointFeature->SetFrom(readFeature)!= OGRERR_NONE)
- cerr << "writing feature failed" << endl;
+ cerr << "writing feature failed" << std::endl;
writePointFeature->SetGeometry(&thePoint);
OGRGeometry *updateGeometry;
updateGeometry = writePointFeature->GetGeometryRef();
OGRPoint *poPoint = (OGRPoint *) updateGeometry;
if(verbose_opt[0]>1)
- cout << "write feature has " << writePointFeature->GetFieldCount() << " fields" << endl;
+ std::cout << "write feature has " << writePointFeature->GetFieldCount() << " fields" << std::endl;
}
}
if(verbose_opt[0]>1)
- cout << "reading image value withinin polygon at position " << i << "," << j;
+ std::cout << "reading image value withinin polygon at position " << i << "," << j;
for(int iband=0;iband<nband;++iband){
int theBand=(band_opt[0]<0)?iband:band_opt[iband];
double value=0;
imgReader.readData(value,GDT_Float64,i,j,theBand);
if(verbose_opt[0]>1)
- cout << ": " << value << endl;
+ std::cout << ": " << value << std::endl;
if(polygon_opt[0]||rule_opt[0]==1){
int iclass=0;
switch(rule_opt[0]){
@@ -1861,7 +1867,7 @@ int main(int argc, char *argv[])
// else
// fs << fieldname_opt[0] << theBand;
if(verbose_opt[0]>1)
- cout << "set field " << fieldname_opt[iband] << " to " << value << endl;
+ std::cout << "set field " << fieldname_opt[iband] << " to " << value << std::endl;
switch( fieldType ){
case OFTInteger:
writePointFeature->SetField(fieldname_opt[iband].c_str(),static_cast<int>(value));
@@ -1899,9 +1905,9 @@ int main(int argc, char *argv[])
if(rule_opt[0]!=1){//do not create in case of mean value (only at centroid)
//write feature
if(verbose_opt[0]>1)
- cout << "creating point feature" << endl;
+ std::cout << "creating point feature" << std::endl;
if(writeLayer->CreateFeature( writePointFeature ) != OGRERR_NONE ){
- string errorString="Failed to create feature in shapefile";
+ std::string errorString="Failed to create feature in shapefile";
throw(errorString);
}
//destroy feature
@@ -1916,7 +1922,7 @@ int main(int argc, char *argv[])
}
}
// //test
- // cout << "before write polygon" << endl;
+ // std::cout << "before write polygon" << std::endl;
if(polygon_opt[0]||rule_opt[0]==1){
//add ring to polygon
if(polygon_opt[0]){
@@ -1925,43 +1931,43 @@ int main(int argc, char *argv[])
//write geometry of writePolygon
writePolygonFeature->SetGeometry(&writePolygon);
if(writePolygonFeature->SetFrom(readFeature)!= OGRERR_NONE)
- cerr << "writing feature failed" << endl;
+ cerr << "writing feature failed" << std::endl;
if(verbose_opt[0]>1)
- cout << "copying new fields write polygon " << sample_opt[0] << endl;
+ std::cout << "copying new fields write polygon " << sample_opt[0] << std::endl;
if(verbose_opt[0]>1)
- cout << "write feature has " << writePolygonFeature->GetFieldCount() << " fields" << endl;
+ std::cout << "write feature has " << writePolygonFeature->GetFieldCount() << " fields" << std::endl;
//write polygon feature
}
else{//write mean value of polygon to centroid point (rule_opt[0]==1)
//create feature
if(verbose_opt[0]>1)
- cout << "copying fields from polygons " << sample_opt[0] << endl;
+ std::cout << "copying fields from polygons " << sample_opt[0] << std::endl;
if(writeCentroidFeature->SetFrom(readFeature)!= OGRERR_NONE)
- cerr << "writing feature failed" << endl;
+ cerr << "writing feature failed" << std::endl;
writeCentroidFeature->SetGeometry(&writeCentroidPoint);
OGRGeometry *updateGeometry;
updateGeometry = writeCentroidFeature->GetGeometryRef();
assert(wkbFlatten(updateGeometry->getGeometryType()) == wkbPoint );
if(verbose_opt[0]>1)
- cout << "write feature has " << writeCentroidFeature->GetFieldCount() << " fields" << endl;
+ std::cout << "write feature has " << writeCentroidFeature->GetFieldCount() << " fields" << std::endl;
}
switch(rule_opt[0]){
case(0)://value at each point (or at centroid of polygon if line is not set
default:{
if(verbose_opt[0])
- cout << "number of points in polygon: " << nPointPolygon << endl;
+ std::cout << "number of points in polygon: " << nPointPolygon << std::endl;
for(int index=0;index<polyValues.size();++index){
double theValue=polyValues[index];
ostringstream fs;
if(verbose_opt[0])
- cout << "number of points in polygon: " << nPointPolygon << endl;
+ std::cout << "number of points in polygon: " << nPointPolygon << std::endl;
int theBand=(band_opt[0]<0)?index:band_opt[index];
// if(nband==1)
// fs << fieldname_opt[0];
// else
// fs << fieldname_opt[0] << theBand;
if(verbose_opt[0]>1)
- cout << "set field " << fieldname_opt[index] << " to " << theValue << endl;
+ std::cout << "set field " << fieldname_opt[index] << " to " << theValue << std::endl;
switch( fieldType ){
case OFTInteger:
if(polygon_opt[0])
@@ -2016,7 +2022,7 @@ int main(int argc, char *argv[])
}//case 0 and default
case(1):{//mean value (written to centroid of polygon if line is not set
if(verbose_opt[0])
- cout << "number of points in polygon: " << nPointPolygon << endl;
+ std::cout << "number of points in polygon: " << nPointPolygon << std::endl;
for(int index=0;index<polyValues.size();++index){
double theValue=polyValues[index];
ostringstream fs;
@@ -2027,7 +2033,7 @@ int main(int argc, char *argv[])
// else
// fs << fieldname_opt[0] << theBand;
if(verbose_opt[0]>1)
- cout << "set field " << fieldname_opt[index] << " to " << theValue << endl;
+ std::cout << "set field " << fieldname_opt[index] << " to " << theValue << std::endl;
switch( fieldType ){
case OFTInteger:
if(polygon_opt[0])
@@ -2082,7 +2088,7 @@ int main(int argc, char *argv[])
}
case(2):{//proportion classes
if(verbose_opt[0])
- cout << "number of points in polygon: " << nPointPolygon << endl;
+ std::cout << "number of points in polygon: " << nPointPolygon << std::endl;
hist.normalize_pct(polyValues);
// hist.sum(polyValues);
for(int index=0;index<polyValues.size();++index){
@@ -2099,7 +2105,7 @@ int main(int argc, char *argv[])
case(3):{//custom
assert(polygon_opt[0]);//not implemented for points
if(verbose_opt[0])
- cout << "number of points in polygon: " << nPointPolygon << endl;
+ std::cout << "number of points in polygon: " << nPointPolygon << std::endl;
hist.normalize_pct(polyValues);
assert(polyValues.size()==2);//11:broadleaved, 12:coniferous
if(polyValues[0]>=75)//broadleaved
@@ -2110,12 +2116,12 @@ int main(int argc, char *argv[])
writePolygonFeature->SetField(label_opt[0].c_str(),static_cast<int>(13));
else{
if(verbose_opt[0]){
- cout << "No valid value in polyValues..." << endl;
+ std::cout << "No valid value in polyValues..." << std::endl;
for(int index=0;index<polyValues.size();++index){
double theValue=polyValues[index];
- cout << theValue << " ";
+ std::cout << theValue << " ";
}
- cout << endl;
+ std::cout << std::endl;
}
writePolygonFeature->SetField(label_opt[0].c_str(),static_cast<int>(20));
}
@@ -2124,20 +2130,20 @@ int main(int argc, char *argv[])
case(4):{//minimum of polygon
assert(polygon_opt[0]);//not implemented for points
if(verbose_opt[0])
- cout << "number of points in polygon: " << nPointPolygon << endl;
+ std::cout << "number of points in polygon: " << nPointPolygon << std::endl;
//search for min class
//todo: change to minClass=hist.max(class_opt) once Optionpk is implemented...
int minClass=class_opt[class_opt.size()-1];//!hard coded for now, maximum class is last entry in class_opt
for(int iclass=0;iclass<class_opt.size();++iclass){
if(polyValues[iclass]>0){
if(verbose_opt[0]>1)
- cout << class_opt[iclass] << ": " << polyValues[iclass] << endl;
+ std::cout << class_opt[iclass] << ": " << polyValues[iclass] << std::endl;
if(class_opt[iclass]<minClass)
minClass=class_opt[iclass];
}
}
if(verbose_opt[0]>0)
- cout << "minClass: " << minClass << endl;
+ std::cout << "minClass: " << minClass << std::endl;
writePolygonFeature->SetField(label_opt[0].c_str(),minClass);
break;
}
@@ -2146,9 +2152,9 @@ int main(int argc, char *argv[])
if(keepFeatures_opt[0])
writePolygonFeature->SetField("origId",static_cast<int>(readFeature->GetFID()));
if(verbose_opt[0]>1)
- cout << "creating polygon feature" << endl;
+ std::cout << "creating polygon feature" << std::endl;
if(writeLayer->CreateFeature( writePolygonFeature ) != OGRERR_NONE ){
- string errorString="Failed to create polygon feature in shapefile";
+ std::string errorString="Failed to create polygon feature in shapefile";
throw(errorString);
}
OGRFeature::DestroyFeature( writePolygonFeature );
@@ -2160,9 +2166,9 @@ int main(int argc, char *argv[])
if(keepFeatures_opt[0])
writeCentroidFeature->SetField("origId",static_cast<int>(readFeature->GetFID()));
if(verbose_opt[0]>1)
- cout << "creating point feature in centroid" << endl;
+ std::cout << "creating point feature in centroid" << std::endl;
if(writeLayer->CreateFeature( writeCentroidFeature ) != OGRERR_NONE ){
- string errorString="Failed to create point feature in shapefile";
+ std::string errorString="Failed to create point feature in shapefile";
throw(errorString);
}
OGRFeature::DestroyFeature( writeCentroidFeature );
@@ -2173,7 +2179,7 @@ int main(int argc, char *argv[])
}
}
else{
- string test;
+ std::string test;
test=poGeometry->getGeometryName();
ostringstream oss;
oss << "geometry " << test << " not supported";
@@ -2181,8 +2187,8 @@ int main(int argc, char *argv[])
}
++ifeature;
}
- catch(string e){
- cout << e << endl;
+ catch(std::string e){
+ std::cout << e << std::endl;
continue;
}
}//end of getNextFeature
diff --git a/src/apps/pkfillnodata.cc b/src/apps/pkfillnodata.cc
index 5a629db..f30967b 100644
--- a/src/apps/pkfillnodata.cc
+++ b/src/apps/pkfillnodata.cc
@@ -25,12 +25,18 @@ extern "C" {
}
#include "base/Optionpk.h"
-using namespace std;
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
int main(int argc,char **argv) {
- Optionpk<bool> version_opt("\0","version","version 20120625, Copyright (C) 2008-2012 Pieter Kempeneers.\n\
+ std::string versionString="version ";
+ versionString+=VERSION;
+ versionString+=", Copyright (C) 2008-2012 Pieter Kempeneers.\n\
This program comes with ABSOLUTELY NO WARRANTY; for details type use option -h.\n\
This is free software, and you are welcome to redistribute it\n\
- under certain conditions; use option --license for details.",false);
+ under certain conditions; use option --license for details.";
+ Optionpk<bool> version_opt("\0","version",versionString,false);
Optionpk<bool> license_opt("lic","license","show license information",false);
Optionpk<bool> help_opt("h","help","shows this help info",false);
Optionpk<string> input_opt("i", "input", "Input image file (WARNING: will be overwritten with output!", "");
diff --git a/src/apps/pkfilter.cc b/src/apps/pkfilter.cc
index a9e55a4..c4c2122 100644
--- a/src/apps/pkfilter.cc
+++ b/src/apps/pkfilter.cc
@@ -31,32 +31,40 @@ along with pktools. If not, see <http://www.gnu.org/licenses/>.
#include "imageclasses/ImgReaderGdal.h"
#include "imageclasses/ImgWriterGdal.h"
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
/*------------------
Main procedure
----------------*/
int main(int argc,char **argv) {
- Optionpk<bool> version_opt("\0","version","version 20120625, Copyright (C) 2008-2012 Pieter Kempeneers.\n\
+ std::string versionString="version ";
+ versionString+=VERSION;
+ versionString+=", Copyright (C) 2008-2012 Pieter Kempeneers.\n\
This program comes with ABSOLUTELY NO WARRANTY; for details type use option -h.\n\
This is free software, and you are welcome to redistribute it\n\
- under certain conditions; use option --license for details.",false);
+ under certain conditions; use option --license for details.";
+ Optionpk<bool> version_opt("\0","version",versionString,false);
Optionpk<bool> license_opt("lic","license","show license information",false);
Optionpk<bool> help_opt("h","help","shows this help info",false);
Optionpk<bool> todo_opt("\0","todo","",false);
Optionpk<std::string> input_opt("i","input","input image file","");
Optionpk<std::string> output_opt("o", "output", "Output image file", "");
- Optionpk<bool> disc_opt("c", "circular", "circular disc kernel for dilation and erosion (default is false)", false);
- Optionpk<double> angle_opt("a", "angle", "angle used for directional filtering in dilation. Default is less than -180 (no directional effect)", -190);
+ Optionpk<bool> disc_opt("c", "circular", "circular disc kernel for dilation and erosion", false);
+ // Optionpk<double> angle_opt("a", "angle", "angle used for directional filtering in dilation. Default is less than -180 (no directional effect)", -190);
Optionpk<int> function_opt("f", "filter", "filter function (0: median, 1: variance, 2: min, 3: max, 4: sum, 5: mean, 6: minmax, 7: dilation, 8: erosion, 9: closing, 10: opening, 11: spatially homogeneous, 12: SobelX edge detection in X, 13: SobelY edge detection in Y, 14: SobelXY (not supported), 15: smooth, 16: density, 17: majority voting (only for classes), 18: forest aggregation (mixed), 19: smooth no data (mask) values), 20: threshold local filtering", 0);
- Optionpk<int> dimX_opt("dx", "dx", "filter kernel size in x, must be odd (example: 3). Default is 0", 0);
- Optionpk<int> dimY_opt("dy", "dy", "filter kernel size in y, must be odd (example: 3). Default is 0. Set dy=0 if 1-D filter must be used in band domain", 0);
+ Optionpk<int> dimX_opt("dx", "dx", "filter kernel size in x, must be odd (example: 3).", 0);
+ Optionpk<int> dimY_opt("dy", "dy", "filter kernel size in y, must be odd (example: 3).. Set dy=0 if 1-D filter must be used in band domain", 0);
Optionpk<string> option_opt("co", "co", "options: NAME=VALUE [-co COMPRESS=LZW] [-co INTERLEAVE=BAND]", "INTERLEAVE=BAND");
- Optionpk<short> class_opt("class", "class", "class value(s) to use for density, erosion, dilation, openening and closing, thresholding (default is 1)", 1);
+ Optionpk<short> class_opt("class", "class", "class value(s) to use for density, erosion, dilation, openening and closing, thresholding", 1);
Optionpk<double> threshold_opt("t", "threshold", "threshold value(s) to use for threshold filter (one for each class)", 0);
Optionpk<short> mask_opt("\0", "mask", "mask value(s) ", -1);
- Optionpk<std::string> tap_opt("tap", "tap", "text file conttaining taps used for filtering (from ul to lr). Default is empty: do not use taps. Use dimX and dimY to specify tap dimensions in x and y", "");
+ Optionpk<std::string> tap_opt("tap", "tap", "text file conttaining taps used for filtering (from ul to lr). Use dimX and dimY to specify tap dimensions in x and y. Leave empty for not using taps", "");
Optionpk<std::string> colorTable_opt("\0", "ct", "color table (file with 5 columns: id R G B ALFA (0: transparent, 255: solid)", "");
- Optionpk<short> down_opt("d", "down", "down sampling factor. Default is 1: no downsample)", 1);
- Optionpk<short> verbose_opt("v", "verbose", "verbose (default is 0)", 0);
+ Optionpk<short> down_opt("d", "down", "down sampling factor. Use value 1 for no downsampling)", 1);
+ Optionpk<short> verbose_opt("v", "verbose", "verbose mode if > 0", 0);
version_opt.retrieveOption(argc,argv);
license_opt.retrieveOption(argc,argv);
@@ -65,9 +73,7 @@ int main(int argc,char **argv) {
input_opt.retrieveOption(argc,argv);
output_opt.retrieveOption(argc,argv);
- verbose_opt.retrieveOption(argc,argv);
disc_opt.retrieveOption(argc,argv);
- angle_opt.retrieveOption(argc,argv);
function_opt.retrieveOption(argc,argv);
dimX_opt.retrieveOption(argc,argv);
dimY_opt.retrieveOption(argc,argv);
@@ -78,6 +84,7 @@ int main(int argc,char **argv) {
tap_opt.retrieveOption(argc,argv);
down_opt.retrieveOption(argc,argv);
colorTable_opt.retrieveOption(argc,argv);
+ verbose_opt.retrieveOption(argc,argv);
if(version_opt[0]||todo_opt[0]){
cout << version_opt.getHelp() << endl;
@@ -196,7 +203,7 @@ int main(int argc,char **argv) {
break;
case(Filter2d::DILATE):
if(dimY_opt[0]>0)
- filter2d.morphology(input,output,Filter2d::DILATE,dimX_opt[0],dimY_opt[0],disc_opt[0],angle_opt[0]);
+ filter2d.morphology(input,output,Filter2d::DILATE,dimX_opt[0],dimY_opt[0],disc_opt[0],-190);
else{
if(verbose_opt[0])
std::cout<< "1-D filtering: dilate" << std::endl;
@@ -205,7 +212,7 @@ int main(int argc,char **argv) {
break;
case(Filter2d::ERODE):
if(dimY_opt[0]>0)
- filter2d.morphology(input,output,Filter2d::ERODE,dimX_opt[0],dimY_opt[0],disc_opt[0],angle_opt[0]);
+ filter2d.morphology(input,output,Filter2d::ERODE,dimX_opt[0],dimY_opt[0],disc_opt[0],-190);
else{
if(verbose_opt[0])
std::cout<< "1-D filtering: dilate" << std::endl;
@@ -219,7 +226,7 @@ int main(int argc,char **argv) {
tmpout.open(tmps.str(),input);
try{
if(dimY_opt[0]>0)
- filter2d.morphology(input,tmpout,Filter2d::DILATE,dimX_opt[0],dimY_opt[0],disc_opt[0],angle_opt[0]);
+ filter2d.morphology(input,tmpout,Filter2d::DILATE,dimX_opt[0],dimY_opt[0],disc_opt[0],-190);
else
filter1d.morphology(input,tmpout,Filter::DILATE,dimX_opt[0]);
}
@@ -231,7 +238,7 @@ int main(int argc,char **argv) {
ImgReaderGdal tmpin;
tmpin.open(tmps.str());
if(dimY_opt[0]>0)
- filter2d.morphology(tmpin,output,Filter2d::ERODE,dimX_opt[0],dimY_opt[0],disc_opt[0],angle_opt[0]);
+ filter2d.morphology(tmpin,output,Filter2d::ERODE,dimX_opt[0],dimY_opt[0],disc_opt[0],-190);
else
filter1d.morphology(tmpin,output,Filter::ERODE,dimX_opt[0]);
tmpin.close();
@@ -246,14 +253,14 @@ int main(int argc,char **argv) {
ImgWriterGdal tmpout;
tmpout.open(tmps.str(),input);
if(dimY_opt[0]>0)
- filter2d.morphology(input,tmpout,Filter2d::ERODE,dimX_opt[0],dimY_opt[0],disc_opt[0],angle_opt[0]);
+ filter2d.morphology(input,tmpout,Filter2d::ERODE,dimX_opt[0],dimY_opt[0],disc_opt[0],-190);
else
filter1d.morphology(input,tmpout,Filter::ERODE,dimX_opt[0]);
tmpout.close();
ImgReaderGdal tmpin;
tmpin.open(tmps.str());
if(dimY_opt[0]>0)
- filter2d.morphology(tmpin,output,Filter2d::DILATE,dimX_opt[0],dimY_opt[0],disc_opt[0],angle_opt[0]);
+ filter2d.morphology(tmpin,output,Filter2d::DILATE,dimX_opt[0],dimY_opt[0],disc_opt[0],-190);
else
filter1d.morphology(tmpin,output,Filter::DILATE,dimX_opt[0]);
tmpin.close();
diff --git a/src/apps/pkgetmask.cc b/src/apps/pkgetmask.cc
index 3b6c221..dddbede 100644
--- a/src/apps/pkgetmask.cc
+++ b/src/apps/pkgetmask.cc
@@ -23,22 +23,29 @@ along with pktools. If not, see <http://www.gnu.org/licenses/>.
#include "imageclasses/ImgWriterGdal.h"
#include "base/Optionpk.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
using namespace std;
int main(int argc,char **argv) {
- Optionpk<bool> version_opt("\0","version","version 20120625, Copyright (C) 2008-2012 Pieter Kempeneers.\n\
+ std::string versionString="version ";
+ versionString+=VERSION;
+ versionString+=", Copyright (C) 2008-2012 Pieter Kempeneers.\n\
This program comes with ABSOLUTELY NO WARRANTY; for details type use option -h.\n\
This is free software, and you are welcome to redistribute it\n\
- under certain conditions; use option --license for details.",false);
+ under certain conditions; use option --license for details.";
+ Optionpk<bool> version_opt("\0","version",versionString,false);
Optionpk<bool> license_opt("lic","license","show license information",false);
Optionpk<bool> help_opt("h","help","shows this help info",false);
Optionpk<bool> todo_opt("\0","todo","",false);
Optionpk<string> input_opt("i", "input", "Input image file", "");
- Optionpk<short> band_opt("b", "band", "band(s) used for mask (default is 0)", 0);
- Optionpk<double> min_opt("m", "min", "Values smaller than min threshold(s) are masked as invalid. Use one threshold for each band (default 0)", 0);
- Optionpk<double> max_opt("M", "max", "Values greater than max threshold(s) are masked as invalid. Use one threshold for each band (default 0)", 0);
- Optionpk<string> operator_opt("p", "operator", "Operator: [AND,OR]. Default is OR)", "OR");
- Optionpk<unsigned short> valid_opt("t", "tvalue", "value(s) for valid pixels: between min and max (default 1)", 1);
- Optionpk<unsigned short> invalid_opt("f", "fvalue", "value(s) for invalid pixels: not between min and max (default 0)", 0);
+ Optionpk<short> band_opt("b", "band", "band(s) used for mask", 0);
+ Optionpk<double> min_opt("m", "min", "Values smaller than min threshold(s) are masked as invalid. Use one threshold for each band", 0);
+ Optionpk<double> max_opt("M", "max", "Values greater than max threshold(s) are masked as invalid. Use one threshold for each band", 0);
+ Optionpk<string> operator_opt("p", "operator", "Operator: [AND,OR].", "OR");
+ Optionpk<unsigned short> valid_opt("t", "tvalue", "value(s) for valid pixels: between min and max", 1);
+ Optionpk<unsigned short> invalid_opt("f", "fvalue", "value(s) for invalid pixels: not between min and max", 0);
Optionpk<string> output_opt("o", "output", "Output mask file", "");
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", "Byte");
Optionpk<string> oformat_opt("of", "oformat", "Output image format (see also gdal_translate). Empty string: inherit from input image", "");
@@ -75,7 +82,7 @@ int main(int argc,char **argv) {
verbose_opt.retrieveOption(argc,argv);
if(help_opt[0]){
- cout << "usage: pkgetmask -i inputimage -o outputimage [OPTIONS]" << endl;
+ cout << "usage: pkinfo -i inputimage -o outputimage [OPTIONS]" << endl;
exit(0);
}
diff --git a/src/apps/pkinfo.cc b/src/apps/pkinfo.cc
index bd0aafc..0e393e9 100644
--- a/src/apps/pkinfo.cc
+++ b/src/apps/pkinfo.cc
@@ -24,14 +24,22 @@ along with pktools. If not, see <http://www.gnu.org/licenses/>.
#include "imageclasses/ImgReaderGdal.h"
#include "imageclasses/ImgReaderOgr.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
int main(int argc, char *argv[])
{
- Optionpk<bool> version_opt("\0","version","version 20120625, Copyright (C) 2008-2012 Pieter Kempeneers.\n\
+ std::string versionString="version ";
+ versionString+=VERSION;
+ versionString+=", Copyright (C) 2008-2012 Pieter Kempeneers.\n\
This program comes with ABSOLUTELY NO WARRANTY; for details type use option -h.\n\
This is free software, and you are welcome to redistribute it\n\
- under certain conditions; use option --license for details.",false);
+ under certain conditions; use option --license for details.";
+ Optionpk<bool> version_opt("\0","version",versionString,false);
Optionpk<bool> license_opt("lic","license","show license information",false);
Optionpk<bool> help_opt("h","help","shows this help info",false);
+ Optionpk<bool> todo_opt("\0","todo","",false);
Optionpk<std::string> input_opt("i","input","input image file","");
Optionpk<bool> bbox_opt("bb", "bbox", "show bounding box ", false);
Optionpk<bool> bbox_te_opt("te", "te", "show bounding box in GDAL format: xmin ymin xmax ymax ", false);
@@ -41,19 +49,18 @@ int main(int argc, char *argv[])
Optionpk<bool> lines_opt("l", "lines", "Number of lines in image ", false);
Optionpk<bool> nband_opt("nb", "nband", "Show number of bands in image", false);
Optionpk<short> band_opt("b", "band", "Band specific information", 0);
- // Optionpk<bool> magic_opt("\0", "magic", "Show magic pixel in image ", false);
Optionpk<bool> dx_opt("dx", "dx", "get resolution in x (in m)", false);
Optionpk<bool> dy_opt("dy", "dy", "get resolution in y (in m)", false);
Optionpk<bool> minmax_opt("mm", "minmax", "Show min and max value of the image ", false);
Optionpk<bool> stat_opt("stat", "stat", "Show statistics (min,max, mean and stdDev of the image ", false);
Optionpk<double> min_opt("m", "min", "Show min value of the image (or set minimum for histogram)", 0);
Optionpk<double> max_opt("M", "max", "Show max value of the image (or set maximum for histogram)", 0);
- Optionpk<bool> relative_opt("\0", "rel", "Calculate relative histogram in percentage", false);
+ Optionpk<bool> relative_opt("rel", "rel", "Calculate relative histogram in percentage", false);
Optionpk<bool> projection_opt("p", "projection", "Show projection of the image ", false);
Optionpk<bool> geo_opt("geo", "geo", "get geotransform: ", false);
Optionpk<bool> interleave_opt("il", "interleave", "Show interleave ", false);
Optionpk<bool> filename_opt("f", "filename", "Image filename ", false);
- Optionpk<bool> cover_opt("\0", "cover", "Image covers bounding box (or x and y pos) if printed to std out ", false);
+ Optionpk<bool> cover_opt("cov", "cover", "Image covers bounding box (or x and y pos) if printed to std out ", false);
Optionpk<double> x_opt("x", "xpos", "x pos", -1);
Optionpk<double> y_opt("y", "ypos", "y pos", -1);
Optionpk<bool> read_opt("r", "read", "read row y (in projected coordinates if geo option is set, otherwise in image coordinates, 0 based)", 0);
@@ -64,16 +71,17 @@ int main(int argc, char *argv[])
Optionpk<double> uly_opt("uly", "uly", "Upper left y value bounding box (0)", 0.0);
Optionpk<double> lrx_opt("lrx", "lrx", "Lower right x value bounding box (0)", 0.0);
Optionpk<double> lry_opt("lry", "lry", "Lower right y value bounding box (0)", 0.0);
- Optionpk<bool> hist_opt("\0", "hist", "Calculate histogram. Use --rel for a relative histogram output. ", false);
- Optionpk<short> nbin_opt("\0", "nbin", "Number of bins used in histogram. Use 0 for all input values as integers", 0);
+ Optionpk<bool> hist_opt("hist", "hist", "Calculate histogram. Use --rel for a relative histogram output. ", false);
+ Optionpk<short> nbin_opt("nbin", "nbin", "Number of bins used in histogram. Use 0 for all input values as integers", 0);
Optionpk<bool> type_opt("ot", "otype", "Return data type", false);
- Optionpk<bool> description_opt("\0", "description", "Return image description", false);
- Optionpk<bool> metadata_opt("\0", "meta", "Show meta data ", false);
- Optionpk<double> maskValue_opt("\0", "mask", "mask value(s) for no data to calculate reference pixel in image (Default is 0)",0);
+ Optionpk<bool> description_opt("d", "description", "Return image description", false);
+ Optionpk<bool> metadata_opt("meta", "meta", "Show meta data ", false);
+ Optionpk<double> maskValue_opt("mask", "mask", "mask value(s) for no data to calculate reference pixel in image",0);
version_opt.retrieveOption(argc,argv);
license_opt.retrieveOption(argc,argv);
help_opt.retrieveOption(argc,argv);
+ todo_opt.retrieveOption(argc,argv);
if(version_opt[0]){
std::cout << version_opt.getHelp() << std::endl;
@@ -93,7 +101,6 @@ int main(int argc, char *argv[])
lines_opt.retrieveOption(argc,argv);
nband_opt.retrieveOption(argc,argv);
band_opt.retrieveOption(argc,argv);
- // magic_opt.retrieveOption(argc,argv);
dx_opt.retrieveOption(argc,argv);
dy_opt.retrieveOption(argc,argv);
minmax_opt.retrieveOption(argc,argv);
@@ -143,6 +150,9 @@ int main(int argc, char *argv[])
ImgReaderGdal imgReader;
for(int ifile=0;ifile<input_opt.size();++ifile){
imgReader.open(input_opt[ifile]);
+ for(int inodata=0;inodata<maskValue_opt.size();++inodata)
+ imgReader.pushNoDataValue(maskValue_opt[inodata],band_opt[0]);
+
if(filename_opt[0])
std::cout << " --input " << input_opt[ifile] << " ";
if(centre_opt[0]){
@@ -153,8 +163,6 @@ int main(int argc, char *argv[])
if(refpixel_opt[0]){
assert(band_opt[0]<imgReader.nrOfBand());
Egcs egcs;
- for(int inodata=0;inodata<maskValue_opt.size();++inodata)
- imgReader.pushNoDataValue(maskValue_opt[inodata],band_opt[0]);
double refX,refY;
//get centre of reference (centre of gravity) pixel in image
imgReader.getRefPix(refX,refY,band_opt[0]);
@@ -242,11 +250,6 @@ int main(int argc, char *argv[])
std::cout << "--rows " << imgReader.nrOfRow() << " ";
if(nband_opt[0])
std::cout << "--nband " << imgReader.nrOfBand() << " ";
- // if(magic_opt[0]){
- // double magic_x, magic_y;
- // imgReader.getMagicPixel(magic_x,magic_y);
- // std::cout << "--magic_x " << magic_x << " --magic_y " << magic_y << " ";
- // }
double minValue=0;
double maxValue=0;
double meanValue=0;
diff --git a/src/apps/pklas2img.cc b/src/apps/pklas2img.cc
index 63f2ccd..30395e3 100644
--- a/src/apps/pklas2img.cc
+++ b/src/apps/pklas2img.cc
@@ -26,13 +26,18 @@ along with pktools. If not, see <http://www.gnu.org/licenses/>.
#include "algorithms/Histogram.h"
#include "algorithms/Filter2d.h"
-using namespace std;
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
int main(int argc,char **argv) {
- Optionpk<bool> version_opt("\0","version","version 20120625, Copyright (C) 2008-2012 Pieter Kempeneers.\n\
+ std::string versionString="version ";
+ versionString+=VERSION;
+ versionString+=", Copyright (C) 2008-2012 Pieter Kempeneers.\n\
This program comes with ABSOLUTELY NO WARRANTY; for details type use option -h.\n\
This is free software, and you are welcome to redistribute it\n\
- under certain conditions; use option --license for details.",false);
+ under certain conditions; use option --license for details.";
+ Optionpk<bool> version_opt("\0","version",versionString,false);
Optionpk<bool> license_opt("lic","license","show license information",false);
Optionpk<bool> help_opt("h","help","shows this help info",false);
Optionpk<string> input_opt("i", "input", "Input las file", "");
@@ -510,6 +515,8 @@ int main(int argc,char **argv) {
pfnProgress(progress,pszMessage,pProgressArg);
}
}
+ progress=1;
+ pfnProgress(progress,pszMessage,pProgressArg);
if(verbose_opt[0])
std::cout << "closing lasReader" << std::endl;
outputWriter.close();
diff --git a/src/apps/pkmosaic.cc b/src/apps/pkmosaic.cc
index 63517a4..2091e23 100644
--- a/src/apps/pkmosaic.cc
+++ b/src/apps/pkmosaic.cc
@@ -28,17 +28,24 @@ along with pktools. If not, see <http://www.gnu.org/licenses/>.
#include "base/Optionpk.h"
#include "algorithms/Histogram.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
using namespace std;
int main(int argc, char *argv[])
{
- Optionpk<bool> version_opt("\0","version","version 20120625, Copyright (C) 2008-2012 Pieter Kempeneers.\n\
+ std::string versionString="version ";
+ versionString+=VERSION;
+ versionString+=", Copyright (C) 2008-2012 Pieter Kempeneers.\n\
This program comes with ABSOLUTELY NO WARRANTY; for details type use option -h.\n\
This is free software, and you are welcome to redistribute it\n\
- under certain conditions; use option --license for details.",false);
+ under certain conditions; use option --license for details.";
+ Optionpk<bool> version_opt("\0","version",versionString,false);
Optionpk<bool> license_opt("lic","license","show license information",false);
Optionpk<bool> help_opt("h","help","shows this help info",false);
- Optionpk<bool> todo_opt("\0","todo","introduce -uli -ulj to crop based on image coordinates",false);
+ Optionpk<bool> todo_opt("\0","todo","",false);
Optionpk<string> input_opt("i", "input", "Input image file(s). If input contains multiple images, a multi-band output is created", "");
Optionpk<string> output_opt("o", "output", "Output image file", "");
Optionpk<string> projection_opt("p", "projection", "projection in EPSG format (leave blank to copy from input file, use EPSG:3035 to use European projection and to force to European grid", "");
@@ -57,15 +64,15 @@ int main(int argc, char *argv[])
Optionpk<short> flag_opt("f", "flag", "Flag value to put in image if out of bounds.", 0);
Optionpk<unsigned short> resample_opt("r", "resample", "Resampling method (0: nearest neighbour, 1: bi-linear interpolation).", 0);
Optionpk<string> description_opt("\0", "description", "Set image description", "");
- Optionpk<int> mrule_opt("m", "mrule", "Mosaic rule for mosaic (0: overwrite, 1: max ndvi, 2: max Band, 3: min Band, 4: valid Band, 5: mean value, 6: max voting (only for byte images), 7: median, 8: (weighted) sum (default: 0)", 0);
- Optionpk<int> ruleBand_opt("\0", "rband", "band index used for the rule (for ndvi, use --ruleBand=redBand --ruleBand=nirBand (default 0)", 0);
- Optionpk<int> validBand_opt("\0", "validBand", "valid band index(es)", 0);
+ Optionpk<int> mrule_opt("m", "mrule", "Mosaic rule for mosaic (0: overwrite, 1: max ndvi, 2: max Band, 3: min Band, 4: valid Band, 5: mean value, 6: max voting (only for byte images), 7: median, 8: (weighted) sum", 0);
+ Optionpk<int> ruleBand_opt("rb", "rband", "band index used for the rule (for ndvi, use --ruleBand=redBand --ruleBand=nirBand", 0);
+ Optionpk<int> validBand_opt("vb", "validBand", "valid band index(es)", 0);
Optionpk<double> invalid_opt("t", "invalid", "invalid value for valid band", 0);
- Optionpk<double> minValue_opt("min", "min", "flag values smaller or equal to this value as invalid. Default is -99999999", -99999999);
- Optionpk<double> maxValue_opt("max", "max", "flag values larger or equal to this value as invalid. Default is 99999999", 99999999);
- Optionpk<bool> file_opt("\0", "file", "write number of observations for each pixels as additional layer in mosaic (default is false)", false);
- Optionpk<short> weight_opt("w", "weight", "Weights (type: short) for the mosaic, use one weight for each input file in same order as input files are provided). Default is 1 (equal weights).", 1);
- Optionpk<short> class_opt("c", "class", "classes for multi-band output image: each band represents the number of observations for one specific class. Default is 0 (no multi-band output image).", 0);
+ Optionpk<double> minValue_opt("min", "min", "flag values smaller or equal to this value as invalid.", -99999999);
+ Optionpk<double> maxValue_opt("max", "max", "flag values larger or equal to this value as invalid.", 99999999);
+ Optionpk<bool> file_opt("file", "file", "write number of observations for each pixels as additional layer in mosaic", false);
+ Optionpk<short> weight_opt("w", "weight", "Weights (type: short) for the mosaic, use one weight for each input file in same order as input files are provided). Use value 1 for equal weights.", 1);
+ Optionpk<short> class_opt("c", "class", "classes for multi-band output image: each band represents the number of observations for one specific class. Use value 0 for no multi-band output image).", 0);
Optionpk<bool> verbose_opt("v", "verbose", "verbose", false);
version_opt.retrieveOption(argc,argv);
diff --git a/src/apps/pkndvi.cc b/src/apps/pkndvi.cc
index 7dc0fb5..709a819 100644
--- a/src/apps/pkndvi.cc
+++ b/src/apps/pkndvi.cc
@@ -23,33 +23,40 @@ along with pktools. If not, see <http://www.gnu.org/licenses/>.
#include "imageclasses/ImgWriterGdal.h"
#include "base/Optionpk.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
using namespace std;
int main(int argc, char *argv[])
{
//command line options
- Optionpk<bool> version_opt("\0","version","version 20120625, Copyright (C) 2008-2012 Pieter Kempeneers.\n\
+ std::string versionString="version ";
+ versionString+=VERSION;
+ versionString+=", Copyright (C) 2008-2012 Pieter Kempeneers.\n\
This program comes with ABSOLUTELY NO WARRANTY; for details type use option -h.\n\
This is free software, and you are welcome to redistribute it\n\
- under certain conditions; use option --license for details.",false);
+ under certain conditions; use option --license for details.";
+ Optionpk<bool> version_opt("\0","version",versionString,false);
Optionpk<bool> license_opt("lic","license","show license information",false);
Optionpk<bool> help_opt("h","help","shows this help info",false);
Optionpk<string> input_opt("i","input","input image file","");
Optionpk<string> output_opt("o","output","output image file containing ndvi","");
Optionpk<short> band_opt("b", "band", "Bands to be used for vegetation index (see rule option)", 0);
- Optionpk<string> rule_opt("r", "rule", "Rule for index. [ndvi (b1-b0)/(b1+b0)|gvmi (b0+0.1)-(b1+0.02))/((b0+0.1)+(b1+0.02)))|vari (b1-b2)/(b1+b2-b0)|diff (b1-b0)|scale. Default is 0 (ndvi)", "ndvi");
- Optionpk<double> invalid_opt("t", "invalid", "Mask value where image is invalid. Default value is 0", 0);
+ Optionpk<string> rule_opt("r", "rule", "Rule for index. [ndvi (b1-b0)/(b1+b0)|gvmi (b0+0.1)-(b1+0.02))/((b0+0.1)+(b1+0.02)))|vari (b1-b2)/(b1+b2-b0)|diff (b1-b0)|scale.", "ndvi");
+ Optionpk<double> invalid_opt("t", "invalid", "Mask value where image is invalid.", 0);
Optionpk<int> flag_opt("f", "flag", "Flag value to put in image if not valid (0)", 0);
Optionpk<string> colorTable_opt("ct", "ct", "color table (file with 5 columns: id R G B ALFA (0: transparent, 255: solid)", "");
Optionpk<string> description_opt("d", "description", "Set image description", "");
- Optionpk<double> minmax_opt("m", "minmax", "minimum and maximum values for ndvi (limit all values smaller/larger to min/max (default 0)", 0);
- Optionpk<double> eps_opt("e", "eps", "epsilon, contraint division by zero (default is 0)", 0);
- Optionpk<double> scale_opt("s", "scale", "scale[0] is used for input, scale[1] is used for output: DN=scale[1]*ndvi+offset[1] (default is -s 1 -s 1)", 1);
- Optionpk<double> offset_opt("\0", "offset", "offset[0] is used for input, offset[1] is used for output (see also scale option (default is --offset 0 --offset 0)", 0);
+ Optionpk<double> minmax_opt("m", "minmax", "minimum and maximum values for ndvi (limit all values smaller/larger to min/max", 0);
+ Optionpk<double> eps_opt("e", "eps", "epsilon, contraint division by zero", 0);
+ Optionpk<double> scale_opt("s", "scale", "scale[0] is used for input, scale[1] is used for output: DN=scale[1]*ndvi+offset[1]", 1);
+ Optionpk<double> offset_opt("off", "offset", "offset[0] is used for input, offset[1] is used for output (see also scale option", 0);
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", "Byte");
Optionpk<string> oformat_opt("of", "oformat", "Output image format (see also gdal_translate). Empty string: inherit from input image", "GTiff");
Optionpk<string> option_opt("co", "co", "options: NAME=VALUE [-co COMPRESS=LZW] [-co INTERLEAVE=BAND]", "INTERLEAVE=BAND");
- Optionpk<short> verbose_opt("v", "verbose", "verbose (default 0)", 0);
+ Optionpk<short> verbose_opt("v", "verbose", "verbose mode if > 0", 0);
version_opt.retrieveOption(argc,argv);
license_opt.retrieveOption(argc,argv);
@@ -80,7 +87,7 @@ int main(int argc, char *argv[])
exit(0);
}
if(help_opt[0]){
- cout << "usage: pkndvi -i inputimage -o outputimage [OPTIONS]" << endl;
+ cout << "usage: pkinfo -i inputimage -o outputimage [OPTIONS]" << endl;
exit(0);
}
diff --git a/src/apps/pkpolygonize.cc b/src/apps/pkpolygonize.cc
index 036f05a..0581431 100644
--- a/src/apps/pkpolygonize.cc
+++ b/src/apps/pkpolygonize.cc
@@ -30,25 +30,41 @@ extern "C" {
#include "ogr_api.h"
}
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
using namespace std;
int main(int argc,char **argv) {
- Optionpk<bool> version_opt("\0","version","version 20120625, Copyright (C) 2008-2012 Pieter Kempeneers.\n\
+ std::string versionString="version ";
+ versionString+=VERSION;
+ versionString+=", Copyright (C) 2008-2012 Pieter Kempeneers.\n\
This program comes with ABSOLUTELY NO WARRANTY; for details type use option -h.\n\
This is free software, and you are welcome to redistribute it\n\
- under certain conditions; use option --license for details.",false);
+ under certain conditions; use option --license for details.";
+ Optionpk<bool> version_opt("\0","version",versionString,false);
Optionpk<bool> license_opt("lic","license","show license information",false);
Optionpk<bool> help_opt("h","help","shows this help info",false);
+ Optionpk<bool> todo_opt("\0","todo","",false);
Optionpk<string> input_opt("i", "input", "Input image file (WARNING: will be overwritten with output!", "");
Optionpk<string> mask_opt("m", "mask", "All pixels in the mask band with a value other than zero will be considered suitable for collection as polygons. Use input file as mask to remove background polygon! ", "");
Optionpk<string> output_opt("o", "output", "Output vector file", "");
- Optionpk<int> band_opt("b", "band", "the band to be used from input file (default is 0)", 0);
- Optionpk<string> fname_opt("n", "name", "the field name of the output layer (default is DN)", "DN");
- Optionpk<short> verbose_opt("v", "verbose", "verbose", 0);
+ Optionpk<int> band_opt("b", "band", "the band to be used from input file", 0);
+ Optionpk<string> fname_opt("n", "name", "the field name of the output layer", "DN");
+ Optionpk<short> verbose_opt("v", "verbose", "verbose mode if > 0", 0);
version_opt.retrieveOption(argc,argv);
license_opt.retrieveOption(argc,argv);
help_opt.retrieveOption(argc,argv);
+ todo_opt.retrieveOption(argc,argv);
+
+ input_opt.retrieveOption(argc,argv);
+ mask_opt.retrieveOption(argc,argv);
+ output_opt.retrieveOption(argc,argv);
+ band_opt.retrieveOption(argc,argv);
+ fname_opt.retrieveOption(argc,argv);
+ verbose_opt.retrieveOption(argc,argv);
if(version_opt[0]){
cout << version_opt.getHelp() << endl;
@@ -58,13 +74,10 @@ int main(int argc,char **argv) {
cout << Optionpk<bool>::getGPLv3License() << endl;
exit(0);
}
-
- input_opt.retrieveOption(argc,argv);
- mask_opt.retrieveOption(argc,argv);
- output_opt.retrieveOption(argc,argv);
- band_opt.retrieveOption(argc,argv);
- fname_opt.retrieveOption(argc,argv);
- verbose_opt.retrieveOption(argc,argv);
+ if(help_opt[0]){
+ cout << "usage: pkpolygonize -i inputimage -o outputimage [OPTIONS]" << endl;
+ exit(0);
+ }
GDALAllRegister();
diff --git a/src/apps/pkreclass.cc b/src/apps/pkreclass.cc
index 9d7f569..44a0003 100644
--- a/src/apps/pkreclass.cc
+++ b/src/apps/pkreclass.cc
@@ -25,30 +25,36 @@ along with pktools. If not, see <http://www.gnu.org/licenses/>.
#include "imageclasses/ImgReaderGdal.h"
#include "imageclasses/ImgWriterGdal.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
using namespace std;
int main(int argc, char *argv[])
{
- //command line options
- Optionpk<bool> version_opt("\0","version","version 20120625, Copyright (C) 2008-2012 Pieter Kempeneers.\n\
+ std::string versionString="version ";
+ versionString+=VERSION;
+ versionString+=", Copyright (C) 2008-2012 Pieter Kempeneers.\n\
This program comes with ABSOLUTELY NO WARRANTY; for details type use option -h.\n\
This is free software, and you are welcome to redistribute it\n\
- under certain conditions; use option --license for details.",false);
+ under certain conditions; use option --license for details.";
+ Optionpk<bool> version_opt("\0","version",versionString,false);
Optionpk<bool> license_opt("lic","license","show license information",false);
Optionpk<bool> help_opt("h","help","shows this help info",false);
Optionpk<bool> todo_opt("\0","todo","",false);
Optionpk<string> input_opt("i", "input", "Input image", "");
Optionpk<string> mask_opt("m", "mask", "Mask image(s)", "");
Optionpk<string> output_opt("o", "output", "Output mask file", "");
- Optionpk<unsigned short> invalid_opt("t", "invalid", "Mask value(s) where image is invalid. Use one value for each mask, or multiple values for a single mask. Default value is 1", 1);
+ Optionpk<unsigned short> invalid_opt("t", "invalid", "Mask value(s) where image is invalid. Use one value for each mask, or multiple values for a single mask.", 1);
Optionpk<int> flag_opt("f", "flag", "Flag value to put in image if not valid (0)", 0);
Optionpk<string> colorTable_opt("ct", "ct", "color table (file with 5 columns: id R G B ALFA (0: transparent, 255: solid)", "");
Optionpk<unsigned short> band_opt("b", "band", "band index to replace (other bands are copied to output)", 0);
Optionpk<string> type_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", "");
- Optionpk<string> code_opt("\0", "code", "Recode text file (2 colums: from to)", "");
+ Optionpk<string> code_opt("code", "code", "Recode text file (2 colums: from to)", "");
Optionpk<string> class_opt("c", "class", "list of classes to reclass (in combination with reclass option)", "");
Optionpk<string> reclass_opt("r", "reclass", "list of recoded class(es) (in combination with class option)", "");
- Optionpk<string> label_opt("l", "label", "Label name of the shape file to be replaced (default: label)", "label");
+ Optionpk<string> fieldname_opt("n", "fname", "field name of the shape file to be replaced", "label");
Optionpk<string> option_opt("co", "co", "options: NAME=VALUE [-co COMPRESS=LZW] [-co INTERLEAVE=BAND]", "INTERLEAVE=BAND");
Optionpk<string> description_opt("d", "description", "Set image description", "");
Optionpk<short> verbose_opt("v", "verbose", "verbose", 0);
@@ -78,13 +84,13 @@ int main(int argc, char *argv[])
output_opt.retrieveOption(argc,argv);
type_opt.retrieveOption(argc,argv);
band_opt.retrieveOption(argc,argv);
- label_opt.retrieveOption(argc,argv);
+ fieldname_opt.retrieveOption(argc,argv);
option_opt.retrieveOption(argc,argv);
description_opt.retrieveOption(argc,argv);
verbose_opt.retrieveOption(argc,argv);
if(help_opt[0]){
- cout << "usage: pkreclass -i inputimage -o outputimage [OPTIONS]" << endl;
+ cout << "usage: pkinfo -i inputimage -o outputimage [OPTIONS]" << endl;
exit(0);
}
@@ -151,7 +157,7 @@ int main(int argc, char *argv[])
for(int iField=0;iField<poFDefn->GetFieldCount();++iField){
OGRFieldDefn *poFieldDefn = poFDefn->GetFieldDefn(iField);
string fieldname=poFieldDefn->GetNameRef();
- if(fieldname==label_opt[0]){
+ if(fieldname==fieldname_opt[0]){
string fromClass=poFeature->GetFieldAsString(iField);
string toClass=fromClass;
if(codemapString.find(fromClass)!=codemapString.end())
diff --git a/src/apps/pksetmask.cc b/src/apps/pksetmask.cc
index 39b573c..619edd6 100644
--- a/src/apps/pksetmask.cc
+++ b/src/apps/pksetmask.cc
@@ -23,15 +23,22 @@ along with pktools. If not, see <http://www.gnu.org/licenses/>.
#include "imageclasses/ImgWriterGdal.h"
#include "base/Optionpk.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
using namespace std;
int main(int argc, char *argv[])
{
//command line options
- Optionpk<bool> version_opt("\0","version","version 20120625, Copyright (C) 2008-2012 Pieter Kempeneers.\n\
+ std::string versionString="version ";
+ versionString+=VERSION;
+ versionString+=", Copyright (C) 2008-2012 Pieter Kempeneers.\n\
This program comes with ABSOLUTELY NO WARRANTY; for details type use option -h.\n\
This is free software, and you are welcome to redistribute it\n\
- under certain conditions; use option --license for details.",false);
+ under certain conditions; use option --license for details.";
+ Optionpk<bool> version_opt("\0","version",versionString,false);
Optionpk<bool> license_opt("lic","license","show license information",false);
Optionpk<bool> help_opt("h","help","shows this help info",false);
Optionpk<bool> todo_opt("\0","todo","",false);
@@ -41,8 +48,8 @@ int main(int argc, char *argv[])
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", "");
Optionpk<string> oformat_opt("of", "oformat", "Output image format (see also gdal_translate). Empty string: inherit from input image", "");
Optionpk<string> option_opt("co", "co", "options: NAME=VALUE [-co COMPRESS=LZW] [-co INTERLEAVE=BAND]", "");
- Optionpk<unsigned short> invalid_opt("t", "invalid", "Mask value(s) where image is invalid. Use one value for each mask, or multiple values for a single mask. Default value is 1", 1);
- Optionpk<char> operator_opt("p", "operator", "Operator: < = > !. Use operator for each invalid option (default is =)", '=');
+ Optionpk<unsigned short> invalid_opt("t", "invalid", "Mask value(s) where image is invalid. Use one value for each mask, or multiple values for a single mask.", 1);
+ Optionpk<char> operator_opt("p", "operator", "Operator: < = > !. Use operator for each invalid option", '=');
Optionpk<int> flag_opt("f", "flag", "Flag value to put in image if not valid (0)", 0);
Optionpk<string> colorTable_opt("ct", "ct", "color table (file with 5 columns: id R G B ALFA (0: transparent, 255: solid)", "");
Optionpk<short> verbose_opt("v", "verbose", "verbose", 0);
diff --git a/src/apps/pksieve.cc b/src/apps/pksieve.cc
index e49f1c6..747557e 100644
--- a/src/apps/pksieve.cc
+++ b/src/apps/pksieve.cc
@@ -30,26 +30,43 @@ extern "C" {
#include "ogr_api.h"
}
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
using namespace std;
int main(int argc,char **argv) {
- Optionpk<bool> version_opt("\0","version","version 20120625, Copyright (C) 2008-2012 Pieter Kempeneers.\n\
+ std::string versionString="version ";
+ versionString+=VERSION;
+ versionString+=", Copyright (C) 2008-2012 Pieter Kempeneers.\n\
This program comes with ABSOLUTELY NO WARRANTY; for details type use option -h.\n\
This is free software, and you are welcome to redistribute it\n\
- under certain conditions; use option --license for details.",false);
+ under certain conditions; use option --license for details.";
+ Optionpk<bool> version_opt("\0","version",versionString,false);
Optionpk<bool> license_opt("lic","license","show license information",false);
Optionpk<bool> help_opt("h","help","shows this help info",false);
+ Optionpk<bool> todo_opt("\0","todo","",false);
Optionpk<string> input_opt("i", "input", "Input image file", "");
Optionpk<string> mask_opt("m", "mask", "Mask band indicating pixels to be interpolated (zero valued) ", "");
Optionpk<string> output_opt("o", "output", "Output image file", "");
- Optionpk<int> band_opt("b", "band", "the band to be used from input file (default is 0)", 0);
- Optionpk<int> connect_opt("c", "connect", "the connectedness: 4 directions or 8 directions (default: 8))", 8);
- Optionpk<int> size_opt("s", "size", "raster polygons with sizes smaller than this will be merged into their largest neighbour (default: 0 no sieve filter is performed)", 0);
- Optionpk<short> verbose_opt("v", "verbose", "verbose", 0);
+ Optionpk<int> band_opt("b", "band", "the band to be used from input file", 0);
+ Optionpk<int> connect_opt("c", "connect", "the connectedness: 4 directions or 8 directions", 8);
+ 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);
+ Optionpk<short> verbose_opt("v", "verbose", "verbose mode if > 0", 0);
version_opt.retrieveOption(argc,argv);
license_opt.retrieveOption(argc,argv);
help_opt.retrieveOption(argc,argv);
+ todo_opt.retrieveOption(argc,argv);
+
+ input_opt.retrieveOption(argc,argv);
+ mask_opt.retrieveOption(argc,argv);
+ output_opt.retrieveOption(argc,argv);
+ band_opt.retrieveOption(argc,argv);
+ connect_opt.retrieveOption(argc,argv);
+ size_opt.retrieveOption(argc,argv);
+ verbose_opt.retrieveOption(argc,argv);
if(version_opt[0]){
cout << version_opt.getHelp() << endl;
@@ -59,15 +76,10 @@ int main(int argc,char **argv) {
cout << Optionpk<bool>::getGPLv3License() << endl;
exit(0);
}
-
- input_opt.retrieveOption(argc,argv);
- input_opt.retrieveOption(argc,argv);
- mask_opt.retrieveOption(argc,argv);
- output_opt.retrieveOption(argc,argv);
- band_opt.retrieveOption(argc,argv);
- connect_opt.retrieveOption(argc,argv);
- size_opt.retrieveOption(argc,argv);
- verbose_opt.retrieveOption(argc,argv);
+ if(help_opt[0]){
+ cout << "usage: pksieve -i inputimage -o outputimage [OPTIONS]" << endl;
+ exit(0);
+ }
GDALAllRegister();
diff --git a/src/apps/pkstat.cc b/src/apps/pkstat.cc
index 5a9977a..ffc2f25 100644
--- a/src/apps/pkstat.cc
+++ b/src/apps/pkstat.cc
@@ -24,39 +24,45 @@ along with pktools. If not, see <http://www.gnu.org/licenses/>.
#include "base/Optionpk.h"
#include "algorithms/Histogram.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
using namespace std;
int main(int argc, char *argv[])
{
- Optionpk<bool> version_opt("\0","version","version 20120625, Copyright (C) 2008-2012 Pieter Kempeneers.\n\
+ std::string versionString="version ";
+ versionString+=VERSION;
+ versionString+=", Copyright (C) 2008-2012 Pieter Kempeneers.\n\
This program comes with ABSOLUTELY NO WARRANTY; for details type use option -h.\n\
This is free software, and you are welcome to redistribute it\n\
- under certain conditions; use option --license for details.",false);
+ under certain conditions; use option --license for details.";
+ Optionpk<bool> version_opt("\0","version",versionString,false);
Optionpk<bool> license_opt("lic","license","show license information",false);
Optionpk<bool> todo_opt("\0","todo","",false);
Optionpk<bool> help_opt("h","help","shows this help info",false);
Optionpk<string> input_opt("i","input","name of the input text file","");
- Optionpk<char> fs_opt("fs","fs","field separator. Default is space",' ');
- Optionpk<bool> output_opt("o","output","output the selected columns (default is false)",false);
- Optionpk<short> col_opt("c", "column", "column nr, starting from 0 (default is 1)", 1);
- Optionpk<int> range_opt("r", "range", "rows to start/end reading. Use -r 1 -r 10 to read first 10 rows where first row is header. Default is 0 (no header and read all rows)", 0);
- Optionpk<int> end_opt("end", "end", "row to end reading. Default is 0 (read until end)", 0);
- Optionpk<bool> num_opt("n","num","sample size",false);
+ Optionpk<char> fs_opt("fs","fs","field separator.",' ');
+ Optionpk<bool> output_opt("o","output","output the selected columns",false);
+ Optionpk<short> col_opt("c", "column", "column nr, starting from 0", 0);
+ Optionpk<int> range_opt("r", "range", "rows to start/end reading. Use -r 1 -r 10 to read first 10 rows where first row is header. Use 0 to read all rows with no header.", 0);
+ Optionpk<bool> size_opt("size","size","sample size",false);
Optionpk<bool> mean_opt("m","mean","calculate mean value",false);
Optionpk<bool> median_opt("med","median","calculate median",false);
Optionpk<bool> var_opt("var","var","calculate variance",false);
- Optionpk<bool> stdev_opt("\0","stdev","calculate standard deviation",false);
+ Optionpk<bool> stdev_opt("stdev","stdev","calculate standard deviation",false);
Optionpk<bool> sum_opt("s","sum","calculate sum of column",false);
Optionpk<bool> minmax_opt("mm","minmax","calculate minimum and maximum value",false);
Optionpk<double> min_opt("min","min","calculate minimum value",0);
Optionpk<double> max_opt("max","max","calculate maximum value",0);
Optionpk<bool> histogram_opt("hist","hist","calculate histogram",false);
Optionpk<short> nbin_opt("bin","bin","number of bins to calculate histogram",10);
- Optionpk<bool> relative_opt("rel","relative","use percentiles for histogram to calculate histogram",true);
+ Optionpk<bool> relative_opt("rel","relative","use percentiles for histogram to calculate histogram",false);
Optionpk<bool> correlation_opt("cor","correlation","calculate Pearson produc-moment correlation coefficient between two columns (defined by -c <col1> -c <col2>",false);
Optionpk<bool> rmse_opt("e","rmse","calculate root mean square error between two columns (defined by -c <col1> -c <col2>",false);
Optionpk<bool> reg_opt("reg","regression","calculate linear regression error between two columns (defined by -c <col1> -c <col2>",false);
- Optionpk<short> verbose_opt("v", "verbose", "verbose (default is 0)", 0);
+ Optionpk<short> verbose_opt("v", "verbose", "verbose mode when > 0", 0);
version_opt.retrieveOption(argc,argv);
license_opt.retrieveOption(argc,argv);
@@ -67,7 +73,7 @@ int main(int argc, char *argv[])
output_opt.retrieveOption(argc,argv);
col_opt.retrieveOption(argc,argv);
range_opt.retrieveOption(argc,argv);
- num_opt.retrieveOption(argc,argv);
+ size_opt.retrieveOption(argc,argv);
mean_opt.retrieveOption(argc,argv);
median_opt.retrieveOption(argc,argv);
var_opt.retrieveOption(argc,argv);
@@ -130,7 +136,7 @@ int main(int argc, char *argv[])
for(int icol=0;icol<col_opt.size();++icol){
if(ncol==col_opt[icol]){
double value=atof(item.c_str());
- if(value>=min_opt[0]&&value<=max_opt[0])
+ if((value>=min_opt[0]&&value<=max_opt[0])||max_opt[0]<=min_opt[0])
dataVector[icol].push_back(value);
}
}
@@ -167,7 +173,7 @@ int main(int argc, char *argv[])
itemStream >> value;
for(int icol=0;icol<col_opt.size();++icol){
if(ncol==col_opt[icol]){
- if(value>=min_opt[0]&&value<=max_opt[0])
+ if((value>=min_opt[0]&&value<=max_opt[0])||max_opt[0]<=min_opt[0])
dataVector[icol].push_back(value);
}
}
@@ -182,12 +188,14 @@ int main(int argc, char *argv[])
++nrow;
}
}
+ assert(dataVector.size());
dataFile.close();
double minValue=min_opt[0];
double maxValue=max_opt[0];
Histogram hist;
for(int icol=0;icol<col_opt.size();++icol){
- if(num_opt[0])
+ assert(dataVector[icol].size());
+ if(size_opt[0])
cout << "sample size column " << col_opt[icol] << ": " << dataVector[icol].size() << endl;
if(mean_opt[0])
cout << "mean value column " << col_opt[icol] << ": " << hist.mean(dataVector[icol]) << endl;
diff --git a/src/apps/pkstatogr.cc b/src/apps/pkstatogr.cc
index 30e3efc..69df4ac 100644
--- a/src/apps/pkstatogr.cc
+++ b/src/apps/pkstatogr.cc
@@ -25,23 +25,30 @@ along with pktools. If not, see <http://www.gnu.org/licenses/>.
#include "imageclasses/ImgReaderOgr.h"
#include "algorithms/Histogram.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
int main(int argc, char *argv[])
{
- Optionpk<bool> version_opt("\0","version","version 20120625, Copyright (C) 2008-2012 Pieter Kempeneers.\n\
+ std::string versionString="version ";
+ versionString+=VERSION;
+ versionString+=", Copyright (C) 2008-2012 Pieter Kempeneers.\n\
This program comes with ABSOLUTELY NO WARRANTY; for details type use option -h.\n\
This is free software, and you are welcome to redistribute it\n\
- under certain conditions; use option --license for details.",false);
+ under certain conditions; use option --license for details.";
+ Optionpk<bool> version_opt("\0","version",versionString,false);
Optionpk<bool> license_opt("lic","license","show license information",false);
Optionpk<bool> help_opt("h","help","shows this help info",false);
Optionpk<bool> todo_opt("\0","todo","",false);
Optionpk<string> input_opt("i", "input", "Input shape file", "");
- Optionpk<string> field_opt("f", "fields", "fields on which to calculate statistics", "");
- Optionpk<short> nbin_opt("n", "nbin", "number of bins", 0);
+ Optionpk<string> fieldname_opt("n", "fname", "fields on which to calculate statistics", "");
+ Optionpk<short> nbin_opt("nbin", "nbin", "number of bins", 0);
Optionpk<bool> min_opt("m","min","calculate minimum value",false);
Optionpk<bool> max_opt("M","max","calculate maximum value",false);
Optionpk<bool> mean_opt("mean","mean","calculate mean value",false);
Optionpk<bool> stdev_opt("stdev","stdev","calculate standard deviation",false);
- Optionpk<short> verbose_opt("v", "verbose", "verbose (Default: 0)", 0);
+ Optionpk<short> verbose_opt("v", "verbose", "verbose mode if > 0", 0);
version_opt.retrieveOption(argc,argv);
license_opt.retrieveOption(argc,argv);
@@ -49,7 +56,7 @@ int main(int argc, char *argv[])
todo_opt.retrieveOption(argc,argv);
input_opt.retrieveOption(argc,argv);
- field_opt.retrieveOption(argc,argv);
+ fieldname_opt.retrieveOption(argc,argv);
nbin_opt.retrieveOption(argc,argv);
min_opt.retrieveOption(argc,argv);
max_opt.retrieveOption(argc,argv);
@@ -84,11 +91,11 @@ int main(int argc, char *argv[])
Histogram hist;
//todo: implement ALL
- for(int ifield=0;ifield<field_opt.size();++ifield){
+ for(int ifield=0;ifield<fieldname_opt.size();++ifield){
if(verbose_opt[0])
cout << "field: " << ifield << endl;
theData.clear();
- inputReader.readData(theData,OFTReal,field_opt[ifield],0,verbose_opt[0]);
+ inputReader.readData(theData,OFTReal,fieldname_opt[ifield],0,verbose_opt[0]);
vector<int> binData;
double minimum=0;
double maximum=0;
@@ -97,7 +104,7 @@ int main(int argc, char *argv[])
double theMean=0;
double theVar=0;
hist.meanVar(theData,theMean,theVar);
- std::cout << " -f " << field_opt[ifield];
+ std::cout << " -f " << fieldname_opt[ifield];
if(mean_opt[0])
std::cout << " --mean " << theMean;
if(stdev_opt[0])
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-grass/pktools.git
More information about the Pkg-grass-devel
mailing list