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 6fd47420c6b92e13893bf76c11bd811eef193358
Author: Pieter Kempeneers <kempe...@gmail.com>
Date:   Mon Dec 9 21:58:08 2013 +0100

    version 2.4.3 with nodata values
---
 ChangeLog                         |  6 ++-
 configure.ac                      |  2 +-
 src/apps/pkascii2img.cc           |  2 +-
 src/apps/pkclassify_nn.cc         | 30 +++++++------
 src/apps/pkclassify_svm.cc        | 28 +++++++-----
 src/apps/pkcreatect.cc            |  2 +-
 src/apps/pkcrop.cc                | 37 ++++++++-------
 src/apps/pkdiff.cc                | 81 ++++++++++++++++-----------------
 src/apps/pkdsm2shadow.cc          | 12 ++---
 src/apps/pkdumpimg.cc             | 20 ++++-----
 src/apps/pkenhance.cc             |  4 +-
 src/apps/pkextract.cc             | 75 ++++++++++++++++---------------
 src/apps/pkfilter.cc              |  2 +-
 src/apps/pkgetmask.cc             | 40 +++++++++--------
 src/apps/pkinfo.cc                | 95 +++++++++++++++++----------------------
 src/apps/pklas2img.cc             | 23 +++++-----
 src/apps/pkmosaic.cc              | 55 ++++++++++++-----------
 src/apps/pkndvi.cc                | 13 +++---
 src/apps/pkreclass.cc             | 38 ++++++++--------
 src/apps/pksetmask.cc             | 67 ++++++++++++++-------------
 src/apps/pksieve.cc               |  2 +-
 src/imageclasses/ImgReaderGdal.cc | 16 +++++--
 22 files changed, 337 insertions(+), 313 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 4847018..347ce8d 100755
--- a/ChangeLog
+++ b/ChangeLog
@@ -170,6 +170,10 @@ version 2.4.2
        cross validation parameter can not be 1
  - pkfs_svm.cc
        cross validation parameter can not be 1
- - pkstat.cc->pkstatascii.cc
+       - pkstat.cc->pkstatascii.cc
        renamed to pkstatascii.cc to avoid confusion with raster data (e.g., 
pkinfo --stat)
        support of transposed output
+
+version 2.4.3
+       consistently use nodata, srcnodata, dstnodata and msknodata instead of 
invalid, mvalue, flag options
+
diff --git a/configure.ac b/configure.ac
index 125cea2..3be5db1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,4 +1,4 @@
-AC_INIT([pktools], [2.4.2], [kempe...@gmail.com])
+AC_INIT([pktools], [2.4.3], [kempe...@gmail.com])
 AM_INIT_AUTOMAKE([-Wall -Werror foreign])
 AC_CONFIG_MACRO_DIR([m4])
 
diff --git a/src/apps/pkascii2img.cc b/src/apps/pkascii2img.cc
index 9d90bed..643c0d5 100644
--- a/src/apps/pkascii2img.cc
+++ b/src/apps/pkascii2img.cc
@@ -30,7 +30,7 @@ int main(int argc, char *argv[])
   Optionpk<string> output_opt("o", "output", "Output image file");
   Optionpk<string> dataType_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> imageType_opt("of", "oformat", "image type string (see also 
gdal_translate)", "GTiff");
-  Optionpk<string> option_opt("co", "co", "options: NAME=VALUE [-co 
COMPRESS=LZW] [-co INTERLEAVE=BAND]");
+  Optionpk<string> option_opt("co", "co", "Creation option for output file. 
Multiple options can be specified.");
   Optionpk<double> ulx_opt("ulx", "ulx", "Upper left x value bounding box (in 
geocoordinates if georef is true)", 0.0);
   Optionpk<double> uly_opt("uly", "uly", "Upper left y value bounding box (in 
geocoordinates if georef is true)", 0.0);
   Optionpk<double> dx_opt("dx", "dx", "Output resolution in x (in meter)");
diff --git a/src/apps/pkclassify_nn.cc b/src/apps/pkclassify_nn.cc
index 4946700..147c639 100644
--- a/src/apps/pkclassify_nn.cc
+++ b/src/apps/pkclassify_nn.cc
@@ -60,12 +60,12 @@ int main(int argc, char *argv[])
   Optionpk<int> bagSize_opt("bs", "bsize", "Percentage of features used from 
available training features for each bootstrap aggregation (one size for all 
classes, or a different size for each class respectively", 100);
   Optionpk<string> classBag_opt("cb", "classbag", "output for each individual 
bootstrap aggregation (default is blank)"); 
   Optionpk<string> mask_opt("m", "mask", "mask image (see also mvalue option 
(default is no mask)"); 
-  Optionpk<short> maskValue_opt("mv", "mvalue", "mask value(s) not to consider 
for classification (use negative values if only these values should be taken 
into account). Values will be taken over in classification image. Default is 
0", 0);
-  Optionpk<unsigned short> flag_opt("f", "flag", "flag to put where image is 
invalid. Default is 0", 0);
+  Optionpk<short> mask_nodata_opt("mask_nodata", "mask_nodata", "mask value(s) 
not to consider for classification (use negative values if only these values 
should be taken into account). Values will be taken over in classification 
image. Default is 0", 0);
+  Optionpk<unsigned short> nodata_opt("nodata", "nodata", "nodata value to put 
where image is masked as nodata", 0);
   Optionpk<string> output_opt("o", "output", "output classification image"); 
   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<string> option_opt("co", "co", "Creation option for output file. 
Multiple options can be specified.");
   Optionpk<string> colorTable_opt("ct", "ct", "colour table in ascii format 
having 5 columns: id R G B ALFA (0: transparent, 255: solid)"); 
   Optionpk<string> prob_opt("\0", "prob", "probability image. Default is no 
probability image"); 
   Optionpk<string> entropy_opt("entropy", "entropy", "entropy image (measure 
for uncertainty of classifier output"); 
@@ -101,8 +101,8 @@ int main(int argc, char *argv[])
     bagSize_opt.retrieveOption(argc,argv);
     classBag_opt.retrieveOption(argc,argv);
     mask_opt.retrieveOption(argc,argv);
-    maskValue_opt.retrieveOption(argc,argv);
-    flag_opt.retrieveOption(argc,argv);
+    mask_nodata_opt.retrieveOption(argc,argv);
+    nodata_opt.retrieveOption(argc,argv);
     output_opt.retrieveOption(argc,argv);
     otype_opt.retrieveOption(argc,argv);
     oformat_opt.retrieveOption(argc,argv);
@@ -640,21 +640,25 @@ int main(int argc, char *argv[])
         cout << "opening class image for writing output " << output_opt[0] << 
endl;
       if(classBag_opt.size()){
         
classImageBag.open(output_opt[0],ncol,nrow,nbag,GDT_Byte,imageType,option_opt);
+       classImageBag.GDALSetNoDataValue(nodata_opt[0]);
         classImageBag.copyGeoTransform(testImage);
         classImageBag.setProjection(testImage.getProjection());
       }
       
classImageOut.open(output_opt[0],ncol,nrow,1,GDT_Byte,imageType,option_opt);
+      classImageOut.GDALSetNoDataValue(nodata_opt[0]);
       classImageOut.copyGeoTransform(testImage);
       classImageOut.setProjection(testImage.getProjection());
       if(colorTable_opt.size())
         classImageOut.setColorTable(colorTable_opt[0],0);
       if(prob_opt.size()){
         
probImage.open(prob_opt[0],ncol,nrow,nclass,GDT_Byte,imageType,option_opt);
+       probImage.GDALSetNoDataValue(nodata_opt[0]);
         probImage.copyGeoTransform(testImage);
         probImage.setProjection(testImage.getProjection());
       }
       if(entropy_opt.size()){
         
entropyImage.open(entropy_opt[0],ncol,nrow,1,GDT_Byte,imageType,option_opt);
+       entropyImage.GDALSetNoDataValue(nodata_opt[0]);
         entropyImage.copyGeoTransform(testImage);
         entropyImage.setProjection(testImage.getProjection());
       }
@@ -753,17 +757,17 @@ int main(int argc, char *argv[])
         bool masked=false;
         if(!lineMask.empty()){
           short theMask=0;
-          for(short ivalue=0;ivalue<maskValue_opt.size();++ivalue){
-            if(maskValue_opt[ivalue]>=0){//values set in maskValue_opt are 
invalid
-              if(lineMask[icol]==maskValue_opt[ivalue]){
+          for(short ivalue=0;ivalue<mask_nodata_opt.size();++ivalue){
+            if(mask_nodata_opt[ivalue]>=0){//values set in mask_nodata_opt are 
invalid
+              if(lineMask[icol]==mask_nodata_opt[ivalue]){
                 theMask=lineMask[icol];
                 masked=true;
                 break;
               }
             }
-            else{//only values set in maskValue_opt are valid
-              if(lineMask[icol]!=-maskValue_opt[ivalue]){
-                  theMask=(flag_opt.size()==maskValue_opt.size())? 
flag_opt[ivalue] : flag_opt[0];// lineMask[icol];
+            else{//only values set in mask_nodata_opt are valid
+              if(lineMask[icol]!=-mask_nodata_opt[ivalue]){
+                  theMask=(nodata_opt.size()==mask_nodata_opt.size())? 
nodata_opt[ivalue] : nodata_opt[0];// lineMask[icol];
                 masked=true;
               }
               else{
@@ -790,8 +794,8 @@ int main(int argc, char *argv[])
         if(!valid){
           if(classBag_opt.size())
             for(int ibag=0;ibag<nbag;++ibag)
-              classBag[ibag][icol]=flag_opt[0];
-          classOut[icol]=flag_opt[0];
+              classBag[ibag][icol]=nodata_opt[0];
+          classOut[icol]=nodata_opt[0];
           continue;//next column
         }
         for(int iclass=0;iclass<nclass;++iclass)
diff --git a/src/apps/pkclassify_svm.cc b/src/apps/pkclassify_svm.cc
index 0b62975..e9bd63d 100644
--- a/src/apps/pkclassify_svm.cc
+++ b/src/apps/pkclassify_svm.cc
@@ -77,11 +77,11 @@ int main(int argc, char *argv[])
   Optionpk<int> bagSize_opt("bs", "bsize", "Percentage of features used from 
available training features for each bootstrap aggregation (one size for all 
classes, or a different size for each class respectively", 100);
   Optionpk<string> classBag_opt("cb", "classbag", "output for each individual 
bootstrap aggregation");
   Optionpk<string> mask_opt("m", "mask", "mask image (see also mvalue 
option"); 
-  Optionpk<short> maskValue_opt("mv", "mvalue", "mask value(s) not to consider 
for classification (use negative values if only these values should be taken 
into account). Values will be taken over in classification image.", 0);
-  Optionpk<unsigned short> flag_opt("f", "flag", "flag to put where image is 
invalid.", 0);
+  Optionpk<short> mask_nodata_opt("mask_nodata", "mask_nodata", "mask value(s) 
not to consider for classification (use negative values if only these values 
should be taken into account). Values will be taken over in classification 
image.", 0);
+  Optionpk<unsigned short> nodata_opt("nodata", "nodata", "nodata value to put 
where image is masked as nodata", 0);
   Optionpk<string> output_opt("o", "output", "output classification 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<string> option_opt("co", "co", "Creation option for output file. 
Multiple options can be specified.");
   Optionpk<string> colorTable_opt("ct", "ct", "colour table in ascii format 
having 5 columns: id R G B ALFA (0: transparent, 255: solid)"); 
   Optionpk<string> prob_opt("prob", "prob", "probability image."); 
   Optionpk<string> entropy_opt("entropy", "entropy", "entropy image (measure 
for uncertainty of classifier output"); 
@@ -123,8 +123,8 @@ int main(int argc, char *argv[])
     bagSize_opt.retrieveOption(argc,argv);
     classBag_opt.retrieveOption(argc,argv);
     mask_opt.retrieveOption(argc,argv);
-    maskValue_opt.retrieveOption(argc,argv);
-    flag_opt.retrieveOption(argc,argv);
+    mask_nodata_opt.retrieveOption(argc,argv);
+    nodata_opt.retrieveOption(argc,argv);
     output_opt.retrieveOption(argc,argv);
     oformat_opt.retrieveOption(argc,argv);
     colorTable_opt.retrieveOption(argc,argv);
@@ -628,21 +628,25 @@ int main(int argc, char *argv[])
         std::cout << "opening class image for writing output " << 
output_opt[0] << std::endl;
       if(classBag_opt.size()){
         
classImageBag.open(output_opt[0],ncol,nrow,nbag,GDT_Byte,imageType,option_opt);
+       classImageBag.GDALSetNoDataValue(nodata_opt[0]);
         classImageBag.copyGeoTransform(testImage);
         classImageBag.setProjection(testImage.getProjection());
       }
       
classImageOut.open(output_opt[0],ncol,nrow,1,GDT_Byte,imageType,option_opt);
+      classImageOut.GDALSetNoDataValue(nodata_opt[0]);
       classImageOut.copyGeoTransform(testImage);
       classImageOut.setProjection(testImage.getProjection());
       if(colorTable_opt.size())
         classImageOut.setColorTable(colorTable_opt[0],0);
       if(prob_opt.size()){
         
probImage.open(prob_opt[0],ncol,nrow,nclass,GDT_Byte,imageType,option_opt);
+       probImage.GDALSetNoDataValue(nodata_opt[0]);
         probImage.copyGeoTransform(testImage);
         probImage.setProjection(testImage.getProjection());
       }
       if(entropy_opt.size()){
         
entropyImage.open(entropy_opt[0],ncol,nrow,1,GDT_Byte,imageType,option_opt);
+       entropyImage.GDALSetNoDataValue(nodata_opt[0]);
         entropyImage.copyGeoTransform(testImage);
         entropyImage.setProjection(testImage.getProjection());
       }
@@ -738,16 +742,16 @@ int main(int argc, char *argv[])
         bool masked=false;
         if(!lineMask.empty()){
           short theMask=0;
-          for(short ivalue=0;ivalue<maskValue_opt.size();++ivalue){
-            if(maskValue_opt[ivalue]>=0){//values set in maskValue_opt are 
invalid
-              if(lineMask[icol]==maskValue_opt[ivalue]){
+          for(short ivalue=0;ivalue<mask_nodata_opt.size();++ivalue){
+            if(mask_nodata_opt[ivalue]>=0){//values set in mask_nodata_opt are 
invalid
+              if(lineMask[icol]==mask_nodata_opt[ivalue]){
                 theMask=lineMask[icol];
                 masked=true;
                 break;
               }
             }
-            else{//only values set in maskValue_opt are valid
-              if(lineMask[icol]!=-maskValue_opt[ivalue]){
+            else{//only values set in mask_nodata_opt are valid
+              if(lineMask[icol]!=-mask_nodata_opt[ivalue]){
                 theMask=lineMask[icol];
                 masked=true;
               }
@@ -775,8 +779,8 @@ int main(int argc, char *argv[])
         if(!valid){
           if(classBag_opt.size())
             for(int ibag=0;ibag<nbag;++ibag)
-              classBag[ibag][icol]=flag_opt[0];
-          classOut[icol]=flag_opt[0];
+              classBag[ibag][icol]=nodata_opt[0];
+          classOut[icol]=nodata_opt[0];
           continue;//next column
         }
         for(short iclass=0;iclass<nclass;++iclass)
diff --git a/src/apps/pkcreatect.cc b/src/apps/pkcreatect.cc
index 19ba4d0..7f14e2b 100644
--- a/src/apps/pkcreatect.cc
+++ b/src/apps/pkcreatect.cc
@@ -39,7 +39,7 @@ int main(int argc,char **argv) {
   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> option_opt("co", "co", "Creation option for output file. 
Multiple options can be specified.");
   Optionpk<string>  description_opt("d", "description", "Set image 
description");
   Optionpk<bool>  verbose_opt("v", "verbose", "verbose", false);
 
diff --git a/src/apps/pkcrop.cc b/src/apps/pkcrop.cc
index 04d2b35..e95a3ae 100644
--- a/src/apps/pkcrop.cc
+++ b/src/apps/pkcrop.cc
@@ -35,10 +35,10 @@ int main(int argc, char *argv[])
   Optionpk<string>  projection_opt("a_srs", "a_srs", "Override the projection 
for the output file (leave blank to copy from input file, use epsg:3035 to use 
European projection and force to European grid");
   Optionpk<string>  extent_opt("e", "extent", "get boundary from extent from 
polygons in vector file");
   Optionpk<bool> mask_opt("m","mask","mask values out of polygon in extent 
file to flag option (tip: for better performance, use gdal_rasterize -i -burn 0 
-l extent extent.shp output (with output the result of pkcrop)",false);
-  Optionpk<double>  ulx_opt("ulx", "ulx", "Upper left x value bounding box (in 
geocoordinates if georef is true)", 0.0);
-  Optionpk<double>  uly_opt("uly", "uly", "Upper left y value bounding box (in 
geocoordinates if georef is true)", 0.0);
-  Optionpk<double>  lrx_opt("lrx", "lrx", "Lower right x value bounding box 
(in geocoordinates if georef is true)", 0.0);
-  Optionpk<double>  lry_opt("lry", "lry", "Lower right y value bounding box 
(in geocoordinates if georef is true)", 0.0);
+  Optionpk<double>  ulx_opt("ulx", "ulx", "Upper left x value bounding box", 
0.0);
+  Optionpk<double>  uly_opt("uly", "uly", "Upper left y value bounding box", 
0.0);
+  Optionpk<double>  lrx_opt("lrx", "lrx", "Lower right x value bounding box", 
0.0);
+  Optionpk<double>  lry_opt("lry", "lry", "Lower right y value bounding box", 
0.0);
   Optionpk<double>  dx_opt("dx", "dx", "Output resolution in x (in meter) 
(empty: keep original resolution)");
   Optionpk<double>  dy_opt("dy", "dy", "Output resolution in y (in meter) 
(empty: keep original resolution)");
   Optionpk<double> cx_opt("x", "x", "x-coordinate of image center to crop (in 
meter)");
@@ -53,9 +53,9 @@ int main(int argc, char *argv[])
   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> option_opt("co", "co", "options: NAME=VALUE [-co 
COMPRESS=LZW] [-co INTERLEAVE=BAND]");
+  Optionpk<string> option_opt("co", "co", "Creation option for output file. 
Multiple options can be specified.");
   Optionpk<string>  colorTable_opt("ct", "ct", "color table (file with 5 
columns: id R G B ALFA (0: transparent, 255: solid)");
-  Optionpk<short>  flag_opt("f", "flag", "Flag value to put in image if out of 
bounds.", 0);
+  Optionpk<short>  nodata_opt("nodata", "nodata", "Nodata value to put in 
image if out of bounds.");
   Optionpk<string>  resample_opt("r", "resampling-method", "Resampling method 
(near: nearest neighbour, bilinear: bi-linear interpolation).", "near");
   Optionpk<string>  description_opt("d", "description", "Set image 
description");
   Optionpk<bool>  verbose_opt("v", "verbose", "verbose", false);
@@ -87,7 +87,7 @@ int main(int argc, char *argv[])
     ny_opt.retrieveOption(argc,argv);
     ns_opt.retrieveOption(argc,argv);
     nl_opt.retrieveOption(argc,argv);
-    flag_opt.retrieveOption(argc,argv);
+    nodata_opt.retrieveOption(argc,argv);
     resample_opt.retrieveOption(argc,argv);
     description_opt.retrieveOption(argc,argv);
     verbose_opt.retrieveOption(argc,argv);
@@ -109,6 +109,7 @@ int main(int argc, char *argv[])
     exit(0);//help was invoked, stop processing
   }
 
+  short nodataValue=nodata_opt.size()? nodata_opt[0] : 0;
   RESAMPLE theResample;
   if(resample_opt[0]=="near"){
     theResample=NEAR;
@@ -344,6 +345,10 @@ int main(int argc, char *argv[])
         imageType=oformat_opt[0];
       try{
         
imgWriter.open(output_opt[0],ncropcol,ncroprow,ncropband,theType,imageType,option_opt);
+       if(nodata_opt.size()){
+         for(int iband=0;iband<ncropband;++iband)
+           imgWriter.GDALSetNoDataValue(nodata_opt[0],iband);
+       }
       }
       catch(string errorstring){
         cout << errorstring << endl;
@@ -359,12 +364,14 @@ int main(int argc, char *argv[])
       }
       else if(imgReader.isGeoRef())
        imgWriter.setProjection(imgReader.getProjection());
-      if(colorTable_opt.size()){
-        if(colorTable_opt[0]!="none")
-          imgWriter.setColorTable(colorTable_opt[0]);
+      if(imgWriter.getDataType()==GDT_Byte){
+       if(colorTable_opt.size()){
+         if(colorTable_opt[0]!="none")
+           imgWriter.setColorTable(colorTable_opt[0]);
+       }
+       else if (imgReader.getColorTable()!=NULL)//copy colorTable from input 
image
+         imgWriter.setColorTable(imgReader.getColorTable());
       }
-      else if (imgReader.getColorTable()!=NULL)//copy colorTable from input 
image
-        imgWriter.setColorTable(imgReader.getColorTable());
     }
     double startCol=uli;
     double endCol=lri;
@@ -420,7 +427,7 @@ int main(int argc, char *argv[])
          //else if(readRow>=imgReader.nrOfRow())
          //readRow=imgReader.nrOfRow()-1;
          for(int ib=0;ib<ncropcol;++ib)
-           writeBuffer.push_back(flag_opt[0]);
+           writeBuffer.push_back(nodataValue);
        }
        else{
          try{
@@ -438,7 +445,7 @@ int main(int argc, char *argv[])
                //                 readCol=0;
                //               else if(readCol>=imgReader.nrOfCol())
                //                 readCol=imgReader.nrOfCol()-1;
-               writeBuffer.push_back(flag_opt[0]);
+               writeBuffer.push_back(nodataValue);
              }
              else{
                 bool valid=true;
@@ -467,7 +474,7 @@ int main(int argc, char *argv[])
                   }
                 }
                 if(!valid)
-                  writeBuffer.push_back(flag_opt[0]);
+                  writeBuffer.push_back(nodataValue);
                 else{
                   double theScale=1;
                   double theOffset=0;
diff --git a/src/apps/pkdiff.cc b/src/apps/pkdiff.cc
index e8c7036..54d1fb5 100644
--- a/src/apps/pkdiff.cc
+++ b/src/apps/pkdiff.cc
@@ -28,28 +28,25 @@ along with pktools.  If not, see 
<http://www.gnu.org/licenses/>.
 int main(int argc, char *argv[])
 {
   Optionpk<string> input_opt("i", "input", "Input image file.");
-  Optionpk<string> reference_opt("r", "reference", "Reference image file");
+  Optionpk<string> reference_opt("ref", "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> colorTable_opt("ct", "ct", "color table (file with 5 
columns: id R G B ALFA (0: transparent, 255: solid)", "");
+  Optionpk<string> mask_opt("m", "mask", "Mask image file. A single mask is 
supported only, but several mask values can be used. See also mask_nodata 
option. (default is empty)");
+  Optionpk<int> masknodata_opt("msknodata", "msknodata", "Mask value(s) where 
image is invalid. Use negative value for valid data (example: use -t -1: if 
only -1 is valid value)", 0);
+  Optionpk<string> colorTable_opt("ct", "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);
   Optionpk<short> valueC_opt("\0", "commission", "Value for commission errors: 
input label < reference label (default value is 2)", 2);
-  Optionpk<short> flag_opt("f", "flag", "No value flag(s)", 0);
-  Optionpk<int> invalid_opt("t", "invalid", "Mask value(s) where image is 
invalid. Use negative value for valid data (example: use -t -1: if only -1 is 
valid value)", 0);
-  //  Optionpk<short> mflag_opt("t", "mflag", "Mask value(s) for invalid data 
(positive value), or for valid data (negative value). Default is 0", 0);
+  Optionpk<short> nodata_opt("nodata", "nodata", "No value flag(s)", 0);
   Optionpk<short> band_opt("b", "band", "Band to extract (0)", 0);
   Optionpk<bool> confusion_opt("cm", "confusion", "create confusion matrix (to 
std out) (default value is 0)", false);
-  Optionpk<short> lzw_opt("\0", "lzw", "compression (default value is 1)", 1);
   Optionpk<string> labelref_opt("lr", "lref", "name of the reference label in 
case reference is shape file(default is label)", "label");
   Optionpk<string> labelclass_opt("lc", "lclass", "name of the classified 
label in case output is shape file (default is class)", "class");
-  // Optionpk<short> class_opt("c", "class", "numeric classes used (must cover 
range in input and reference raster image. Leave empty if range must be read 
from first input image (default)", 0);
   Optionpk<short> boundary_opt("\0", "boundary", "boundary for selecting the 
sample (default: 1)", 1);
   Optionpk<bool> disc_opt("\0", "circular", "use circular disc kernel 
boundary)", false);
   Optionpk<bool> homogeneous_opt("\0", "homogeneous", "only take homogeneous 
regions into account", false);
-  Optionpk<string> option_opt("co", "co", "options: NAME=VALUE [-co 
COMPRESS=LZW] [-co INTERLEAVE=BAND]");
-  Optionpk<string> classname_opt("\0", "class", "list of class names."); 
-  Optionpk<short> classvalue_opt("\0", "reclass", "list of class values (use 
same order as in classname opt."); 
+  Optionpk<string> option_opt("co", "co", "Creation option for output file. 
Multiple options can be specified.");
+  Optionpk<string> classname_opt("c", "class", "list of class names."); 
+  Optionpk<short> classvalue_opt("r", "reclass", "list of class values (use 
same order as in classname opt."); 
   Optionpk<short> verbose_opt("v", "verbose", "verbose (default value is 0)", 
0);
 
   bool doProcess;//stop process when program was invoked with help option (-h 
--help)
@@ -63,11 +60,10 @@ int main(int argc, char *argv[])
     valueE_opt.retrieveOption(argc,argv);
     valueO_opt.retrieveOption(argc,argv);
     valueC_opt.retrieveOption(argc,argv);
-    flag_opt.retrieveOption(argc,argv);
-    invalid_opt.retrieveOption(argc,argv);
+    nodata_opt.retrieveOption(argc,argv);
+    masknodata_opt.retrieveOption(argc,argv);
     band_opt.retrieveOption(argc,argv);
     confusion_opt.retrieveOption(argc,argv);
-    lzw_opt.retrieveOption(argc,argv);
     labelref_opt.retrieveOption(argc,argv);
     labelclass_opt.retrieveOption(argc,argv);
     // class_opt.retrieveOption(argc,argv);
@@ -92,8 +88,8 @@ int main(int argc, char *argv[])
 
   if(verbose_opt[0]){
     cout << "flag(s) set to";
-    for(int iflag=0;iflag<flag_opt.size();++iflag)
-      cout << " " << flag_opt[iflag];
+    for(int iflag=0;iflag<nodata_opt.size();++iflag)
+      cout << " " << nodata_opt[iflag];
     cout << endl;
   }
 
@@ -128,9 +124,9 @@ int main(int argc, char *argv[])
       inputReader.close();
     // }
   
-    for(int iflag=0;iflag<flag_opt.size();++iflag){
+    for(int iflag=0;iflag<nodata_opt.size();++iflag){
       vector<short>::iterator fit;
-      fit=find(inputRange.begin(),inputRange.end(),flag_opt[iflag]);
+      fit=find(inputRange.begin(),inputRange.end(),nodata_opt[iflag]);
       if(fit!=inputRange.end())
         inputRange.erase(fit);
     }
@@ -304,8 +300,8 @@ int main(int argc, char *argv[])
             cout << "reference value: " << referenceValue << endl;
           bool pixelFlagged=false;
           bool maskFlagged=false;
-          for(int iflag=0;iflag<flag_opt.size();++iflag){
-            if(referenceValue==flag_opt[iflag])
+          for(int iflag=0;iflag<nodata_opt.size();++iflag){
+            if(referenceValue==nodata_opt[iflag])
               pixelFlagged=true;
           }
           if(pixelFlagged)
@@ -358,24 +354,24 @@ int main(int argc, char *argv[])
               if(verbose_opt[0])
                 cout << "input value: " << inputValue << endl;
               pixelFlagged=false;
-              for(int iflag=0;iflag<flag_opt.size();++iflag){
-                if(inputValue==flag_opt[iflag]){
+              for(int iflag=0;iflag<nodata_opt.size();++iflag){
+                if(inputValue==nodata_opt[iflag]){
                   pixelFlagged=true;
                   break;
                 }
               }
-              maskFlagged=false;//(invalid_opt[ivalue]>=0)?false:true;
+              maskFlagged=false;//(masknodata_opt[ivalue]>=0)?false:true;
               if(mask_opt.size()){
                 maskReader.readData(maskValue,GDT_Int16,i,j,band_opt[0]);
-                for(int ivalue=0;ivalue<invalid_opt.size();++ivalue){
-                  if(invalid_opt[ivalue]>=0){//values set in invalid_opt are 
invalid
-                    if(maskValue==invalid_opt[ivalue]){
+                for(int ivalue=0;ivalue<masknodata_opt.size();++ivalue){
+                  if(masknodata_opt[ivalue]>=0){//values set in masknodata_opt 
are invalid
+                    if(maskValue==masknodata_opt[ivalue]){
                       maskFlagged=true;
                       break;
                     }
                   }
-                  else{//only values set in invalid_opt are valid
-                    if(maskValue!=-invalid_opt[ivalue])
+                  else{//only values set in masknodata_opt are valid
+                    if(maskValue!=-masknodata_opt[ivalue])
                       maskFlagged=true;
                     else{
                       maskFlagged=false;
@@ -420,7 +416,7 @@ int main(int argc, char *argv[])
                 }
               }
               if(inputValue==referenceValue){//correct
-                if(valueE_opt[0]!=flag_opt[0])
+                if(valueE_opt[0]!=nodata_opt[0])
                   outputValue=valueE_opt[0];
                 else
                   outputValue=inputValue;
@@ -477,7 +473,7 @@ int main(int argc, char *argv[])
                       }
                     }
                     if(inputValue==referenceValue){//correct
-                      if(valueE_opt[0]!=flag_opt[0])
+                      if(valueE_opt[0]!=nodata_opt[0])
                         outputValue=valueE_opt[0];
                       else
                         outputValue=inputValue;
@@ -521,18 +517,17 @@ int main(int argc, char *argv[])
       if(output_opt.size()){
         if(verbose_opt[0])
           cout << "opening output image " << output_opt[0] << endl;
-        string compression=(lzw_opt[0])? "LZW":"NONE";
         if(option_opt.findSubstring("INTERLEAVE=")==option_opt.end()){
           string theInterleave="INTERLEAVE=";
           theInterleave+=inputReader.getInterleave();
           option_opt.push_back(theInterleave);
         }
         
imgWriter.open(output_opt[0],inputReader.nrOfCol(),inputReader.nrOfRow(),1,inputReader.getDataType(),inputReader.getImageType(),option_opt);
-
+       imgWriter.GDALSetNoDataValue(nodata_opt[0]);
         if(inputReader.isGeoRef()){
           imgWriter.copyGeoTransform(inputReader);
         }
-        if(colorTable_opt[0]!="")
+        if(colorTable_opt.size())
           imgWriter.setColorTable(colorTable_opt[0]);
         else if(inputReader.getColorTable()!=NULL){
           if(verbose_opt[0])
@@ -574,9 +569,9 @@ int main(int argc, char *argv[])
     vector<short> lineReference(referenceReader.nrOfCol());
     if(confusion_opt[0]){
       referenceReader.getRange(referenceRange,band_opt[0]);
-      for(int iflag=0;iflag<flag_opt.size();++iflag){
+      for(int iflag=0;iflag<nodata_opt.size();++iflag){
         vector<short>::iterator fit;
-        fit=find(referenceRange.begin(),referenceRange.end(),flag_opt[iflag]);
+        
fit=find(referenceRange.begin(),referenceRange.end(),nodata_opt[iflag]);
         if(fit!=referenceRange.end())
           referenceRange.erase(fit);
       }
@@ -627,17 +622,17 @@ 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])){
+        for(int iflag=0;iflag<nodata_opt.size();++iflag){
+          
if((lineInput[icol]==nodata_opt[iflag])||(lineReference[ireference]==nodata_opt[iflag])){
             if(output_opt.size())
-              lineOutput[icol]=flag_opt[iflag];
+              lineOutput[icol]=nodata_opt[iflag];
             flagged=true;
             break;
           }
         }
         if(mask_opt.size()){
-          for(int ivalue=0;ivalue<invalid_opt.size();++ivalue){
-            if(lineMask[icol]==invalid_opt[ivalue]){
+          for(int ivalue=0;ivalue<masknodata_opt.size();++ivalue){
+            if(lineMask[icol]==masknodata_opt[ivalue]){
               flagged=true;
               break;
             }
@@ -658,14 +653,14 @@ int main(int argc, char *argv[])
           }
           if(lineInput[icol]==lineReference[ireference]){//correct
             if(output_opt.size()){
-              if(valueE_opt[0]!=flag_opt[0])
+              if(valueE_opt[0]!=nodata_opt[0])
                 lineOutput[icol]=valueE_opt[0];
               else
                 lineOutput[icol]=lineInput[icol];
             }
           }
           else{//error
-            if(output_opt[0]==""&&!confusion_opt[0]){
+            if(output_opt.empty()&&!confusion_opt[0]){
               isDifferent=true;
               break;
             }
@@ -691,7 +686,7 @@ int main(int argc, char *argv[])
         else{
           ++nflagged;
           if(output_opt.size())
-            lineOutput[icol]=flag_opt[0];
+            lineOutput[icol]=nodata_opt[0];
         }
       }
       if(output_opt.size()){
diff --git a/src/apps/pkdsm2shadow.cc b/src/apps/pkdsm2shadow.cc
index b087a50..58c25ec 100644
--- a/src/apps/pkdsm2shadow.cc
+++ b/src/apps/pkdsm2shadow.cc
@@ -34,15 +34,15 @@ along with pktools.  If not, see 
<http://www.gnu.org/licenses/>.
   Main procedure
   ----------------*/
 int main(int argc,char **argv) {
-  Optionpk<std::string> input_opt("i","input","input image file","");
-  Optionpk<std::string> output_opt("o", "output", "Output image file", "");
+  Optionpk<std::string> input_opt("i","input","input image file");
+  Optionpk<std::string> output_opt("o", "output", "Output image file");
   Optionpk<double> sza_opt("sza", "sza", "Sun zenith angle.");
   Optionpk<double> saa_opt("saa", "saa", "Sun azimuth angle (N=0 E=90 S=180 
W=270).");
   Optionpk<int> flag_opt("f", "flag", "Flag to put in image if pixel shadow", 
0);
   Optionpk<std::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<std::string> option_opt("co", "co", "options: NAME=VALUE [-co 
COMPRESS=LZW] [-co INTERLEAVE=BAND]");
+  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", "Creation option for output file. 
Multiple options can be specified.");
   Optionpk<short> verbose_opt("v", "verbose", "verbose mode if > 0", 0);
 
   bool doProcess;//stop process when program was invoked with help option (-h 
--help)
@@ -69,6 +69,8 @@ int main(int argc,char **argv) {
 
   ImgReaderGdal input;
   ImgWriterGdal output;
+  assert(input_opt.size());
+  assert(output_opt.size());
   input.open(input_opt[0]);
   // output.open(output_opt[0],input);
   GDALDataType theType=GDT_Unknown;
@@ -116,7 +118,7 @@ int main(int argc,char **argv) {
   filter2d::Filter2d filter2d;
   if(verbose_opt[0])
     std::cout<< "class values: ";
-  if(colorTable_opt[0]!="")
+  if(colorTable_opt.size())
     output.setColorTable(colorTable_opt[0]);
   
filter2d.shadowDsm(input,output,sza_opt[0],saa_opt[0],input.getDeltaX(),flag_opt[0]);
   input.close();
diff --git a/src/apps/pkdumpimg.cc b/src/apps/pkdumpimg.cc
index 50a88e1..1a74b11 100644
--- a/src/apps/pkdumpimg.cc
+++ b/src/apps/pkdumpimg.cc
@@ -45,8 +45,8 @@ int main(int argc, char *argv[])
   Optionpk<double> dx_opt("dx", "dx", "Output resolution in x (in meter) (0.0: 
keep original resolution)",0.0);
   Optionpk<double> dy_opt("dy", "dy", "Output resolution in y (in meter) (0.0: 
keep original resolution)",0.0);
   Optionpk<string> resample_opt("r", "resampling-method", "Resampling method 
(near: nearest neighbour, bilinear: bi-linear interpolation).", "near");
-  Optionpk<short> flag_opt("f", "flag", "Flag value to put in image if out of 
bounds.", 0);
-  Optionpk<double> nodata_opt("nodata", "nodata", "set no data value(s) for 
calculations (flags in input image)");
+  Optionpk<short> dstnodata_opt("dstnodata", "dstnodata", "nodata value for 
ouptut if out of bounds.", 0);
+  Optionpk<double> srcnodata_opt("srcnodata", "srcnodata", "set no data 
value(s) for input image");
   Optionpk<short> verbose_opt("v", "verbose", "verbose (Default: 0)", 0);
 
   bool doProcess;//stop process when program was invoked with help option (-h 
--help)
@@ -64,8 +64,8 @@ int main(int argc, char *argv[])
     dx_opt.retrieveOption(argc,argv);
     dy_opt.retrieveOption(argc,argv);
     resample_opt.retrieveOption(argc,argv);
-    flag_opt.retrieveOption(argc,argv);
-    nodata_opt.retrieveOption(argc,argv);
+    srcnodata_opt.retrieveOption(argc,argv);
+    dstnodata_opt.retrieveOption(argc,argv);
     verbose_opt.retrieveOption(argc,argv);
   }
   catch(string predefinedString){
@@ -101,8 +101,8 @@ int main(int argc, char *argv[])
   GDALDataType theType;
 
   ImgReaderGdal imgReader(input_opt[0]);
-  for(int inodata=0;inodata<nodata_opt.size();++inodata)
-    imgReader.pushNoDataValue(nodata_opt[inodata]);
+  for(int inodata=0;inodata<srcnodata_opt.size();++inodata)
+    imgReader.pushNoDataValue(srcnodata_opt[inodata]);
 
   ImgWriterGdal virtualWriter;//only for coordinate conversion (no output file 
defined)
   
@@ -249,15 +249,15 @@ int main(int argc, char *argv[])
           if(readCol<0||readCol>=imgReader.nrOfCol()){
             if(oformat_opt[0]=="matrix"){
               if(output_opt[0].empty())
-                std::cout << flag_opt[0] << " ";
+                std::cout << dstnodata_opt[0] << " ";
               else
-                outputStream << flag_opt[0] << " ";
+                outputStream << dstnodata_opt[0] << " ";
             }
             else{
               if(output_opt[0].empty())
-                std::cout << x << " " << y << " " << flag_opt[0] << endl;
+                std::cout << x << " " << y << " " << dstnodata_opt[0] << endl;
               else
-                outputStream << x << " " << y << " " << flag_opt[0] << endl;
+                outputStream << x << " " << y << " " << dstnodata_opt[0] << 
endl;
             }
           }
           else{
diff --git a/src/apps/pkenhance.cc b/src/apps/pkenhance.cc
index 7f904c7..09fd5da 100644
--- a/src/apps/pkenhance.cc
+++ b/src/apps/pkenhance.cc
@@ -32,7 +32,7 @@ int main(int argc,char **argv) {
   Optionpk<double> maxRef_opt("maxref", "maxref", "Sets maximum for histogram 
of reference image");
   Optionpk<double> minInput_opt("mininput", "mininput", "Sets minimum for 
histogram of input image");
   Optionpk<double> maxInput_opt("maxinput", "maxinput", "Sets maximum for 
histogram of input image");
-  Optionpk<double> nodata_opt("nodata", "nodata", "Sets no data value(s) for 
calculations (flags in input image)");
+  Optionpk<double> nodata_opt("nodata", "nodata", "Sets no data value(s) for 
calculations (nodata values in input image)");
   Optionpk<std::string> method_opt("m", "method", "enhancement method 
(histmatch)", "histmatch");
   // Optionpk<std::string> wavelet_type_opt("wt", "wavelet", "wavelet type: 
daubechies,daubechies_centered, haar, haar_centered, bspline, 
bspline_centered", "daubechies");
   // Optionpk<int> family_opt("wf", "family", "wavelet family (vanishing 
moment, see also 
http://www.gnu.org/software/gsl/manual/html_node/DWT-Initialization.html)", 4);
@@ -40,7 +40,7 @@ int main(int argc,char **argv) {
   Optionpk<short>  nbin_opt("nbin", "nbin", "Number of bins used in histogram. 
Use 0 for all input values as integers",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> option_opt("co", "co", "options: NAME=VALUE [-co 
COMPRESS=LZW] [-co INTERLEAVE=BAND]");
+  Optionpk<string> option_opt("co", "co", "Creation option for output file. 
Multiple options can be specified.");
   Optionpk<short> verbose_opt("v", "verbose", "verbose mode if > 0", 0);
 
   bool doProcess;//stop process when program was invoked with help option (-h 
--help)
diff --git a/src/apps/pkextract.cc b/src/apps/pkextract.cc
index 5129206..661afd9 100644
--- a/src/apps/pkextract.cc
+++ b/src/apps/pkextract.cc
@@ -39,15 +39,15 @@ namespace rule{
 
 int main(int argc, char *argv[])
 {
-  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.", 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 leave empty to 
extract all non-flagged pixels from sample file");
-  Optionpk<string> output_opt("o", "output", "Output sample file (image 
file)", "");
+  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> mask_nodata_opt("mask_nodata", "mask_nodata", "Mask value 
where image is invalid. If a single mask is used, more nodata values 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 leave empty to 
extract all valid data pixels from sample file");
+  Optionpk<string> output_opt("o", "output", "Output sample file (image 
file)");
   Optionpk<string> test_opt("test", "test", "Test sample file (use this option 
in combination with threshold<100 to create a training (output) and test set");
   Optionpk<bool> keepFeatures_opt("k", "keep", "Keep original features in 
output vector file", false);
-  Optionpk<string> bufferOutput_opt("bu", "bu", "Buffer output shape file", 
"");
+  Optionpk<string> bufferOutput_opt("bu", "bu", "Buffer output shape file");
   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) if more classes are to be 
extracted with random selection. Use value 100 to select all pixels for 
selected class(es)", 100);
@@ -70,7 +70,7 @@ int main(int argc, char *argv[])
     doProcess=image_opt.retrieveOption(argc,argv);
     sample_opt.retrieveOption(argc,argv);
     mask_opt.retrieveOption(argc,argv);
-    invalid_opt.retrieveOption(argc,argv);
+    mask_nodata_opt.retrieveOption(argc,argv);
     class_opt.retrieveOption(argc,argv);
     output_opt.retrieveOption(argc,argv);
     test_opt.retrieveOption(argc,argv);
@@ -128,6 +128,8 @@ int main(int argc, char *argv[])
   if(verbose_opt[0]>1)
     std::cout << "boundary: " << boundary_opt[0] << std::endl;
   ImgReaderGdal imgReader;
+  assert(image_opt.size());
+  assert(output_opt.size());
   try{
     imgReader.open(image_opt[0]);
   }
@@ -152,7 +154,7 @@ int main(int argc, char *argv[])
   if(verbose_opt[0])
     std::cout << fieldname_opt << std::endl;
   vector<ImgReaderGdal> maskReader;
-  if(mask_opt[0]!=""){
+  if(mask_opt.size()){
     maskReader.resize(mask_opt.size());
     for(int imask=0;imask<mask_opt.size();++imask){
       if(verbose_opt[0]>1)
@@ -164,7 +166,7 @@ int main(int argc, char *argv[])
   }
 
   Vector2d<int> maskBuffer;
-  if(mask_opt[0]!=""){
+  if(mask_opt.size()){
     maskBuffer.resize(mask_opt.size());
     for(int imask=0;imask<maskReader.size();++imask)
       maskBuffer[imask].resize(maskReader[imask].nrOfCol());
@@ -226,7 +228,7 @@ int main(int argc, char *argv[])
   double progress=0;
   srandom(time(NULL));
 
-  assert(sample_opt[0]!="");
+  assert(sample_opt.size());
   if((sample_opt[0].find(".tif"))!=std::string::npos){//raster file
     if(class_opt.empty()){
       std::cout << "Warning: no classes selected, if classes must be 
extracted, set to -1 for all classes using option -c -1" << std::endl;
@@ -347,10 +349,10 @@ int main(int argc, char *argv[])
                   }
                 }
                 int ivalue=0;
-                if(mask_opt.size()==invalid_opt.size())//one invalid value for 
each mask
-                  ivalue=static_cast<int>(invalid_opt[imask]);
+                if(mask_opt.size()==mask_nodata_opt.size())//one invalid value 
for each mask
+                  ivalue=static_cast<int>(mask_nodata_opt[imask]);
                 else//use same invalid value for each mask
-                  ivalue=static_cast<int>(invalid_opt[0]);
+                  ivalue=static_cast<int>(mask_nodata_opt[0]);
                 if(maskBuffer[imask][colMask]==ivalue){
                   valid=false;
                   break;
@@ -376,8 +378,8 @@ int main(int argc, char *argv[])
                     oldmaskrow[0]=rowMask;
                   }
                 }
-                for(int ivalue=0;ivalue<invalid_opt.size();++ivalue){
-                  
if(maskBuffer[0][colMask]==static_cast<int>(invalid_opt[ivalue])){
+                for(int ivalue=0;ivalue<mask_nodata_opt.size();++ivalue){
+                  
if(maskBuffer[0][colMask]==static_cast<int>(mask_nodata_opt[ivalue])){
                     valid=false;
                     break;
                   }
@@ -596,10 +598,10 @@ int main(int argc, char *argv[])
                   }
                 }
                 int ivalue=0;
-                if(mask_opt.size()==invalid_opt.size())//one invalid value for 
each mask
-                  ivalue=static_cast<int>(invalid_opt[imask]);
+                if(mask_opt.size()==mask_nodata_opt.size())//one invalid value 
for each mask
+                  ivalue=static_cast<int>(mask_nodata_opt[imask]);
                 else//use same invalid value for each mask
-                  ivalue=static_cast<int>(invalid_opt[0]);
+                  ivalue=static_cast<int>(mask_nodata_opt[0]);
                 if(maskBuffer[imask][colMask]==ivalue){
                   valid=false;
                   break;
@@ -625,8 +627,8 @@ int main(int argc, char *argv[])
                     oldmaskrow[0]=rowMask;
                   }
                 }
-                for(int ivalue=0;ivalue<invalid_opt.size();++ivalue){
-                  
if(maskBuffer[0][colMask]==static_cast<int>(invalid_opt[ivalue])){
+                for(int ivalue=0;ivalue<mask_nodata_opt.size();++ivalue){
+                  
if(maskBuffer[0][colMask]==static_cast<int>(mask_nodata_opt[ivalue])){
                     valid=false;
                     break;
                   }
@@ -842,6 +844,7 @@ int main(int argc, char *argv[])
       unsigned long int nfeature=sampleReader.getFeatureCount();
       ImgWriterOgr boxWriter;
       if(rbox_opt[0]>0||cbox_opt[0]>0){
+       assert(bufferOutput_opt.size());
        assert(test_opt.empty());//not implemented
         if(verbose_opt[0]>1)
           std::cout << "opening box writer " << bufferOutput_opt[0] << 
std::endl;
@@ -912,10 +915,10 @@ int main(int argc, char *argv[])
                 }
                 //               char ivalue=0;
                 int ivalue=0;
-                if(mask_opt.size()==invalid_opt.size())//one invalid value for 
each mask
-                  ivalue=static_cast<int>(invalid_opt[imask]);
+                if(mask_opt.size()==mask_nodata_opt.size())//one invalid value 
for each mask
+                  ivalue=static_cast<int>(mask_nodata_opt[imask]);
                 else//use same invalid value for each mask
-                  ivalue=static_cast<int>(invalid_opt[0]);
+                  ivalue=static_cast<int>(mask_nodata_opt[0]);
                 if(maskBuffer[imask][colMask]==ivalue){
                   valid=false;
                   break;
@@ -945,8 +948,8 @@ int main(int argc, char *argv[])
                     oldmaskrow[0]=rowMask;
                   }
                 }
-                for(int ivalue=0;ivalue<invalid_opt.size();++ivalue){
-                  
if(maskBuffer[0][colMask]==static_cast<int>(invalid_opt[ivalue])){
+                for(int ivalue=0;ivalue<mask_nodata_opt.size();++ivalue){
+                  
if(maskBuffer[0][colMask]==static_cast<int>(mask_nodata_opt[ivalue])){
                     valid=false;
                     break;
                   }
@@ -1264,10 +1267,10 @@ int main(int argc, char *argv[])
                       }
                       //               char ivalue=0;
                       int ivalue=0;
-                      if(mask_opt.size()==invalid_opt.size())//one invalid 
value for each mask
-                        ivalue=static_cast<int>(invalid_opt[imask]);
+                      if(mask_opt.size()==mask_nodata_opt.size())//one invalid 
value for each mask
+                        ivalue=static_cast<int>(mask_nodata_opt[imask]);
                       else//use same invalid value for each mask
-                        ivalue=static_cast<int>(invalid_opt[0]);
+                        ivalue=static_cast<int>(mask_nodata_opt[0]);
                       if(maskBuffer[imask][colMask]==ivalue){
                         valid=false;
                         break;
@@ -1299,8 +1302,8 @@ int main(int argc, char *argv[])
                           oldmaskrow[0]=rowMask;
                         }
                       }
-                      for(int ivalue=0;ivalue<invalid_opt.size();++ivalue){
-                        
if(maskBuffer[0][colMask]==static_cast<int>(invalid_opt[ivalue])){
+                      for(int ivalue=0;ivalue<mask_nodata_opt.size();++ivalue){
+                        
if(maskBuffer[0][colMask]==static_cast<int>(mask_nodata_opt[ivalue])){
                           valid=false;
                           break;
                         }
@@ -1879,10 +1882,10 @@ int main(int argc, char *argv[])
                       }
                       //               char ivalue=0;
                       int ivalue=0;
-                      if(mask_opt.size()==invalid_opt.size())//one invalid 
value for each mask
-                        ivalue=static_cast<int>(invalid_opt[imask]);
+                      if(mask_opt.size()==mask_nodata_opt.size())//one invalid 
value for each mask
+                        ivalue=static_cast<int>(mask_nodata_opt[imask]);
                       else//use same invalid value for each mask
-                        ivalue=static_cast<int>(invalid_opt[0]);
+                        ivalue=static_cast<int>(mask_nodata_opt[0]);
                       if(maskBuffer[imask][colMask]==ivalue){
                         valid=false;
                         break;
@@ -1914,8 +1917,8 @@ int main(int argc, char *argv[])
                           oldmaskrow[0]=rowMask;
                         }
                       }
-                      for(int ivalue=0;ivalue<invalid_opt.size();++ivalue){
-                        
if(maskBuffer[0][colMask]==static_cast<int>(invalid_opt[ivalue])){
+                      for(int ivalue=0;ivalue<mask_nodata_opt.size();++ivalue){
+                        
if(maskBuffer[0][colMask]==static_cast<int>(mask_nodata_opt[ivalue])){
                           valid=false;
                           break;
                         }
diff --git a/src/apps/pkfilter.cc b/src/apps/pkfilter.cc
index 6ef1e33..13995e3 100644
--- a/src/apps/pkfilter.cc
+++ b/src/apps/pkfilter.cc
@@ -61,7 +61,7 @@ int main(int argc,char **argv) {
   Optionpk<std::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). Use none to ommit color 
table");
-  Optionpk<std::string> option_opt("co", "co", "options: NAME=VALUE [-co 
COMPRESS=LZW] [-co INTERLEAVE=BAND]");
+  Optionpk<string> option_opt("co", "co", "Creation option for output file. 
Multiple options can be specified.");
   Optionpk<short> down_opt("d", "down", "down sampling factor. Use value 1 for 
no downsampling). Use value n>1 for downsampling (aggregation)", 1);
   Optionpk<string> beta_opt("beta", "beta", "ASCII file with beta for each 
class transition in Markov Random Field");
   Optionpk<double> eps_opt("eps","eps", "error marging for linear feature",0);
diff --git a/src/apps/pkgetmask.cc b/src/apps/pkgetmask.cc
index 9548f9f..91f4e4e 100644
--- a/src/apps/pkgetmask.cc
+++ b/src/apps/pkgetmask.cc
@@ -25,18 +25,18 @@ along with pktools.  If not, see 
<http://www.gnu.org/licenses/>.
 
 using namespace std;
 int main(int argc,char **argv) {
-  Optionpk<string>  input_opt("i", "input", "Input image file", "");
-  Optionpk<short>  band_opt("b", "band", "band(s) used for mask", 0);
+  Optionpk<string> input_opt("i", "input", "Input image file");
+  Optionpk<short> band_opt("b", "band", "band(s) used for mask", 0);
   Optionpk<double> min_opt("min", "min", "Values smaller than min threshold(s) 
are masked as invalid. Use one threshold for each band", 0);
   Optionpk<double> max_opt("max", "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", "");
-  Optionpk<string> option_opt("co", "co", "options: NAME=VALUE [-co 
COMPRESS=LZW] [-co INTERLEAVE=BAND]", "INTERLEAVE=BAND");
-  Optionpk<string> colorTable_opt("ct", "ct", "color table (file with 5 
columns: id R G B ALFA (0: transparent, 255: solid)", "");
+  Optionpk<string> operator_opt("p", "operator", "Operator: [AND,OR].", "OR");
+  Optionpk<unsigned short> data_opt("data", "data", "value(s) for valid 
pixels: between min and max", 1);
+  Optionpk<unsigned short> nodata_opt("nodata", "nodata", "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");
+  Optionpk<string> option_opt("co", "co", "Creation option for output file. 
Multiple options can be specified.");
+  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);
 
   bool doProcess;//stop process when program was invoked with help option (-h 
--help)
@@ -46,8 +46,8 @@ int main(int argc,char **argv) {
     min_opt.retrieveOption(argc,argv);
     max_opt.retrieveOption(argc,argv);
     operator_opt.retrieveOption(argc,argv);
-    valid_opt.retrieveOption(argc,argv);
-    invalid_opt.retrieveOption(argc,argv);
+    data_opt.retrieveOption(argc,argv);
+    nodata_opt.retrieveOption(argc,argv);
     output_opt.retrieveOption(argc,argv);
     otype_opt.retrieveOption(argc,argv);
     oformat_opt.retrieveOption(argc,argv);
@@ -88,6 +88,7 @@ int main(int argc,char **argv) {
       cout << "Output pixel type:  " << GDALGetDataTypeName(theType) << endl;
   }
 
+  assert(input_opt.size());
   ImgReaderGdal imgReader(input_opt[0]);
   assert(band_opt.size()>=0);
   assert(band_opt.size()<=imgReader.nrOfBand());
@@ -96,8 +97,8 @@ int main(int argc,char **argv) {
     min_opt.push_back(min_opt[0]);
   while(band_opt.size()>max_opt.size())
     max_opt.push_back(max_opt[0]);
-  while(min_opt.size()>valid_opt.size())
-    valid_opt.push_back(valid_opt[0]);
+  while(min_opt.size()>data_opt.size())
+    data_opt.push_back(data_opt[0]);
   assert(min_opt.size()==max_opt.size());
   if(verbose_opt[0]){
     cout << "min,max values: ";
@@ -121,15 +122,16 @@ int main(int argc,char **argv) {
       cout << "Using data type from input image: " << 
GDALGetDataTypeName(theType) << endl;
   }
   string imageType=imgReader.getImageType();
-  if(oformat_opt[0]!="")//default
+  if(oformat_opt.size())//default
     imageType=oformat_opt[0];
   if(option_opt.findSubstring("INTERLEAVE=")==option_opt.end()){
     string theInterleave="INTERLEAVE=";
     theInterleave+=imgReader.getInterleave();
     option_opt.push_back(theInterleave);
   }
+  assert(output_opt.size());
   
imgWriter.open(output_opt[0],imgReader.nrOfCol(),imgReader.nrOfRow(),1,theType,imageType,option_opt);
-  if(colorTable_opt[0]!=""){
+  if(colorTable_opt.size()){
     if(colorTable_opt[0]!="none")
       imgWriter.setColorTable(colorTable_opt[0]);
   }
@@ -147,13 +149,13 @@ int main(int argc,char **argv) {
       imgReader.readData(lineBuffer[iband],GDT_Float32,irow,band_opt[iband]);
     for(int icol=0;icol<imgReader.nrOfCol();++icol){
       bool valid=(operator_opt[0]=="OR")?false:true;
-      unsigned short validValue=valid_opt[0];
+      unsigned short validValue=data_opt[0];
       for(int ivalid=0;ivalid<min_opt.size();++ivalid){
         bool validBand=false;
       // for(int iband=0;iband<band_opt.size();++iband){
         unsigned short theBand=(band_opt.size()==min_opt.size())? ivalid:0;
         
if(lineBuffer[theBand][icol]>=min_opt[ivalid]&&lineBuffer[theBand][icol]<=max_opt[ivalid]){
-          validValue=valid_opt[ivalid];
+          validValue=data_opt[ivalid];
           validBand=true;
         }
         valid=(operator_opt[0]=="OR")?valid||validBand : valid&&validBand;
@@ -161,7 +163,7 @@ int main(int argc,char **argv) {
       if(valid)
        writeBuffer[icol]=validValue;
       else
-       writeBuffer[icol]=invalid_opt[0];
+       writeBuffer[icol]=nodata_opt[0];
     }
     imgWriter.writeData(writeBuffer,GDT_Byte,irow);
     progress=(1.0+irow)/imgWriter.nrOfRow();
diff --git a/src/apps/pkinfo.cc b/src/apps/pkinfo.cc
index 6be4183..87819f0 100644
--- a/src/apps/pkinfo.cc
+++ b/src/apps/pkinfo.cc
@@ -39,20 +39,20 @@ int main(int argc, char *argv[])
   Optionpk<bool>  dy_opt("dy", "dy", "Gets resolution in y (in m)", false,0);
   Optionpk<bool>  minmax_opt("mm", "minmax", "Shows min and max value of the 
image ", false,0);
   Optionpk<bool>  stat_opt("stat", "stat", "Shows statistics (min,max, mean 
and stdDev of the image)", false,0);
-  Optionpk<double>  min_opt("min", "min", "Sets minimum for histogram");
-  Optionpk<double>  max_opt("max", "max", "Sets maximum for histogram");
+  Optionpk<double>  min_opt("min", "min", "Sets minimum for histogram (does 
not calculate min value: use -mm instead)");
+  Optionpk<double>  max_opt("max", "max", "Sets maximum for histogram (does 
not calculate min value: use -mm instead)");
   Optionpk<bool>  relative_opt("rel", "rel", "Calculates relative histogram in 
percentage", false,0);
   Optionpk<bool>  projection_opt("a_srs", "a_srs", "Shows projection of the 
image ", false,0);
   Optionpk<bool>  geo_opt("geo", "geo", "Gets geotransform  ", false,0);
   Optionpk<bool>  interleave_opt("il", "interleave", "Shows interleave ", 
false,0);
   Optionpk<bool>  filename_opt("f", "filename", "Shows image filename ", 
false,0);
-  Optionpk<bool>  cover_opt("cov", "cover", "Image covers bounding box (or x 
and y pos) if printed to std out ", false,0);
+  Optionpk<bool>  cover_opt("cov", "cover", "Print filename to stdout if 
current image covers the provided coordinates via bounding box, (x y) 
coordinates or extent of vector file", false,0);
   Optionpk<double>  x_opt("x", "xpos", "x pos");
   Optionpk<double>  y_opt("y", "ypos", "y pos");
   Optionpk<bool>  read_opt("r", "read", "Reads row y (in projected coordinates 
if geo option is set, otherwise in image coordinates, 0 based)",false,0);
   Optionpk<bool>  refpixel_opt("ref", "ref", "Gets reference pixel (lower left 
corner of centre of gravity pixel)", false,0);
   Optionpk<bool>  driver_opt("of", "oformat", "Gets driver description ", 
false,0);
-  Optionpk<std::string>  extent_opt("e", "extent", "Gets boundary from extent 
from polygons in vector file");
+  Optionpk<std::string>  extent_opt("e", "extent", "Gets boundary from vector 
file");
   Optionpk<double>  ulx_opt("ulx", "ulx", "Upper left x value bounding box");
   Optionpk<double>  uly_opt("uly", "uly", "Upper left y value bounding box");
   Optionpk<double>  lrx_opt("lrx", "lrx", "Lower right x value bounding box");
@@ -62,7 +62,7 @@ int main(int argc, char *argv[])
   Optionpk<bool>  type_opt("ot", "otype", "Returns data type", false,0);
   Optionpk<bool>  description_opt("d", "description", "Returns image 
description", false,0);
   Optionpk<bool>  metadata_opt("meta", "meta", "Shows meta data ", false,0);
-  Optionpk<double> nodata_opt("nodata", "nodata", "Sets no data value(s) for 
calculations (flags in input image)");
+  Optionpk<double> nodata_opt("nodata", "nodata", "Sets no data value(s) for 
calculations (nodata values in input image)");
 
   bool doProcess;//stop process when program was invoked with help option (-h 
--help)
   try{
@@ -124,6 +124,27 @@ int main(int argc, char *argv[])
   double maxULX=0;
   double maxLRY=0;
   
+  double theULX, theULY, theLRX, theLRY;
+  //get bounding box from extentReader if defined
+  ImgReaderOgr extentReader;
+  if(extent_opt.size()){
+    extentReader.open(extent_opt[0]);
+    if(!(extentReader.getExtent(theULX,theULY, theLRX, theLRY))){
+      std::cerr << "Error: could not get extent from " << extent_opt[0] << 
std::endl;
+      exit(1);
+    }
+    ulx_opt.push_back(theULX);
+    uly_opt.push_back(theULY);
+    lrx_opt.push_back(theLRX);
+    lry_opt.push_back(theLRY);
+    if(input_opt.empty()){//report bounding box from extent file instead
+      if(bbox_te_opt[0])
+       std::cout << std::setprecision(12) << "-te " << theULX << " " << theLRY 
<< " " << theLRX << " " << theULY;
+      else
+       std::cout << std::setprecision(12) << "--ulx=" << theULX << " --uly=" 
<< theULY << " --lrx=" << theLRX << " --lry=" << theLRY << " ";
+    }
+  }
+
   ImgReaderGdal imgReader;
   for(int ifile=0;ifile<input_opt.size();++ifile){
     imgReader.open(input_opt[ifile]);
@@ -145,14 +166,13 @@ int main(int argc, char *argv[])
       double refX,refY;
       //get centre of reference (centre of gravity) pixel in image
       imgReader.getRefPix(refX,refY,band_opt[0]);
-      std::cout << std::setprecision(12) << "-rx " << refX << " -ry " << refY 
<< std::endl;
+      std::cout << std::setprecision(12) << "-x " << refX << " -y " << refY << 
std::endl;
       egcs.setLevel(egcs.res2level(imgReader.getDeltaX()));
       // unsigned short theLevel=egcs.getLevel(imgReader.getDeltaX());
       // egcs.setLevel(theLevel);
       //cout << "cell code at level " << egcs.getLevel() << " (resolution is " 
<< egcs.getResolution() << "): " << egcs.geo2cell(refX,refY) << endl;
     }
     if(bbox_opt[0]||bbox_te_opt[0]){
-      double theULX, theULY, theLRX, theLRY;
       imgReader.getBoundingBox(theULX,theULY,theLRX,theLRY);
       if(bbox_te_opt[0])
         std::cout << std::setprecision(12) << "-te " << theULX << " " << 
theLRY << " " << theLRX << " " << theULY;
@@ -186,23 +206,18 @@ int main(int argc, char *argv[])
     if(dy_opt[0])
       std::cout << "--dy " << imgReader.getDeltaY() << " ";
     if(cover_opt[0]){
-      //get bounding box from extentReader if defined
-      ImgReaderOgr extentReader;
-      if(extent_opt.size()){
-        extentReader.open(extent_opt[0]);
-        
if(!(extentReader.getExtent(ulx_opt[0],uly_opt[0],lrx_opt[0],lry_opt[0]))){
-          std::cerr << "Error: could not get extent from " << extent_opt[0] << 
std::endl;
-          exit(1);
-        }
-        // std::cout << "--ulx=" << ulx_opt[0] << " --uly=" << uly_opt[0] << " 
--lrx=" << lrx_opt[0] << " --lry=" << lry_opt[0] << std::endl;
+      if(ulx_opt.size()&&uly_opt.size()&&lrx_opt.size()&&lry_opt.size()){
+       if(imgReader.covers(ulx_opt[0],uly_opt[0],lrx_opt[0],lry_opt[0]))
+         std::cout << " -i " << input_opt[ifile] << " ";
+      }
+      else if(x_opt.size()&&y_opt.size()){
+       if(imgReader.covers(x_opt[0],y_opt[0]))
+         std::cout << " -i " << input_opt[ifile] << " ";
+      }
+      else{
+       std::cerr << "Error: failing extent (-e), bounding box or x and y 
position to define coverage" << std::endl;
+       exit(1);
       }
-      double theULX, theULY, theLRX, theLRY;
-      imgReader.getBoundingBox(theULX,theULY,theLRX,theLRY);
-      
if((ulx_opt.size()||uly_opt.size()||lrx_opt.size()||lry_opt.size())&&(imgReader.covers(ulx_opt[0],uly_opt[0],lrx_opt[0],lry_opt[0])))
-       std::cout << " -i " << input_opt[ifile] << " ";
-      else if(imgReader.covers(x_opt[0],y_opt[0]))
-       std::cout << " -i " << input_opt[ifile] << " ";
-
     }
     else if(ulx_opt.size()||uly_opt.size()||lrx_opt.size()||lry_opt.size()){
       double ulx,uly,lrx,lry;
@@ -259,37 +274,11 @@ int main(int argc, char *argv[])
        imgReader.getMinMax(minValue,maxValue,band_opt[0],true);
       std::cout << "--min " << minValue << " --max " << maxValue << " ";
     }
+    if(relative_opt[0])
+      hist_opt[0]=true;
     if(hist_opt[0]){
       assert(band_opt[0]<imgReader.nrOfBand());
       int nbin=nbin_opt[0];
-      // imgReader.getMinMax(minValue,maxValue,band_opt[0]);
-      // if(min_opt.size())
-      //   minValue=min_opt[0];
-      // if(max_opt.size())
-      //   maxValue=max_opt[0];
-      // if(nbin_opt[0]==0)
-      //   nbin=maxValue-minValue+1;
-      // assert(nbin>0);
-      // std::vector<unsigned long int> output(nbin);
-      // unsigned long int nsample=0;
-      // unsigned long int ninvalid=0;
-      // std::vector<double> lineBuffer(imgReader.nrOfCol());
-      // for(int i=0;i<nbin;output[i++]=0);
-      // for(int irow=0;irow<imgReader.nrOfRow();++irow){
-      //   imgReader.readData(lineBuffer,GDT_Float64,irow,band_opt[0]);
-      //   for(int icol=0;icol<imgReader.nrOfCol();++icol){
-      //     if(imgReader.isNoData(lineBuffer[icol]))
-      //       ++ninvalid;
-      //     else if(lineBuffer[icol]>maxValue)
-      //       ++ninvalid;
-      //     else if(lineBuffer[icol]<minValue)
-      //       ++ninvalid;
-      //     else if(lineBuffer[icol]==maxValue)
-      //       ++output[nbin-1];
-      //     else
-      //       
++output[static_cast<int>(static_cast<double>(lineBuffer[icol]-minValue)/(maxValue-minValue)*nbin)];
-      //   }
-      // }
       std::vector<unsigned long int> output(nbin_opt[0]);
       minValue=0;
       maxValue=0;
@@ -419,8 +408,6 @@ int main(int argc, char *argv[])
     else
       std::cout << "no intersect" << std::endl;
   }
-  if(!input_opt.size())
-    std::cerr << "No input file provided (use option -i). Use pkinfo --help 
for help information" << std::endl;
-  else if(!read_opt[0]&&!hist_opt[0])
+  if(!read_opt[0]&&!hist_opt[0])
     std::cout << std::endl;
 }
diff --git a/src/apps/pklas2img.cc b/src/apps/pklas2img.cc
index e4b3e28..e881f21 100644
--- a/src/apps/pklas2img.cc
+++ b/src/apps/pklas2img.cc
@@ -27,10 +27,8 @@ along with pktools.  If not, see 
<http://www.gnu.org/licenses/>.
 #include "algorithms/Filter2d.h"
 
 int main(int argc,char **argv) {
-  Optionpk<string> input_opt("i", "input", "Input las file", "");
-  // Optionpk<string> mask_opt("m", "mask", "mask image file", "");
-  // Optionpk<short> invalid_opt("t", "invalid", "Mask value(s) where image is 
invalid. Use multiple values for a single mask.", 0);
-  Optionpk<short> flag_opt("f", "flag", "Flag value(s) to put in image if not 
valid. Use as many flags as invalid options", 0);
+  Optionpk<string> input_opt("i", "input", "Input las file");
+  Optionpk<short> nodata_opt("nodata", "nodata", "nodata value to put in image 
if not valid", 0);
   Optionpk<string> attribute_opt("n", "name", "names of the attribute to 
select: intensity, return, nreturn, z", "z");
   Optionpk<bool> disc_opt("circ", "circular", "circular disc kernel for 
dilation and erosion", false);
   Optionpk<double> maxSlope_opt("s", "maxSlope", "Maximum slope used for 
morphological filtering", 0.0);
@@ -44,7 +42,7 @@ int main(int argc,char **argv) {
   Optionpk<string> postFilter_opt("pf", "pfilter", "post processing filter 
(etew_min,promorph (progressive morphological filter),bunting (adapted 
promorph),open,close,none).", "none");
   Optionpk<short> dimx_opt("\0", "dimX", "Dimension X of postFilter", 3);
   Optionpk<short> dimy_opt("\0", "dimY", "Dimension Y of postFilter", 3);
-  Optionpk<string> output_opt("o", "output", "Output image file", "");
+  Optionpk<string> output_opt("o", "output", "Output image file");
   Optionpk<string> projection_opt("a_srs", "a_srs", "assign the projection for 
the output file in epsg code, e.g., epsg:3035 for European LAEA projection");
   Optionpk<double> ulx_opt("\0", "ulx", "Upper left x value bounding box (in 
geocoordinates if georef is true). 0 is read from input file", 0.0);
   Optionpk<double> uly_opt("\0", "uly", "Upper left y value bounding box (in 
geocoordinates if georef is true). 0 is read from input file", 0.0);
@@ -52,10 +50,10 @@ int main(int argc,char **argv) {
   Optionpk<double> lry_opt("\0", "lry", "Lower right y value bounding box (in 
geocoordinates if georef is true). 0 is read from input file", 0.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<string> option_opt("co", "co", "Creation option for output file. 
Multiple options can be specified.");
   Optionpk<double> dx_opt("dx", "dx", "Output resolution in x (in meter)", 
1.0);
   Optionpk<double> dy_opt("dy", "dy", "Output resolution in y (in meter)", 
1.0);
-  Optionpk<string> colorTable_opt("ct", "ct", "color table (file with 5 
columns: id R G B ALFA (0: transparent, 255: solid)", "");
+  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 mode", 0);
 
   bool doProcess;//stop process when program was invoked with help option (-h 
--help)
@@ -63,7 +61,7 @@ int main(int argc,char **argv) {
     doProcess=input_opt.retrieveOption(argc,argv);
     // mask_opt.retrieveOption(argc,argv);
     // invalid_opt.retrieveOption(argc,argv);
-    flag_opt.retrieveOption(argc,argv);
+    nodata_opt.retrieveOption(argc,argv);
     attribute_opt.retrieveOption(argc,argv);
     disc_opt.retrieveOption(argc,argv);
     maxSlope_opt.retrieveOption(argc,argv);
@@ -196,13 +194,14 @@ int main(int argc,char **argv) {
   int nrow=ceil(maxULY-minLRY)/dy_opt[0];//number of rows in outputGrid
   //todo: multiple bands
   int nband=(composite_opt[0]=="profile")? nbin_opt[0] : 1;
-  if(output_opt[0]==""){
+  if(output_opt.size()){
     cerr << "Error: no output file defined" << endl;
     exit(1);
   }
   if(verbose_opt[0])
     cout << "opening output file " << output_opt[0] << endl;
   
outputWriter.open(output_opt[0],ncol,nrow,nband,theType,oformat_opt[0],option_opt);
+  outputWriter.GDALSetNoDataValue(nodata_opt[0]);
   //set projection
   outputWriter.setGeoTransform(minULX,maxULY,dx_opt[0],dy_opt[0],0,0);
   if(projection_opt.size()){
@@ -212,7 +211,7 @@ int main(int argc,char **argv) {
   }
   if(!outputWriter.isGeoRef())
     cout << "Warning: output image " << output_opt[0] << " is not 
georeferenced!" << endl;
-  if(colorTable_opt[0]!="")
+  if(colorTable_opt.size())
     outputWriter.setColorTable(colorTable_opt[0]);
 
   inputData.clear();
@@ -336,7 +335,7 @@ int main(int argc,char **argv) {
     for(int icol=0;icol<ncol;++icol){
       std::vector<float> profile;
       if(!inputData[irow][icol].size())
-        outputData[irow][icol]=(static_cast<float>((flag_opt[0])));
+        outputData[irow][icol]=(static_cast<float>((nodata_opt[0])));
       else{
         statfactory::StatFactory stat;
         if(composite_opt[0]=="min")
@@ -356,7 +355,7 @@ int main(int argc,char **argv) {
         else if(composite_opt[0]=="profile"){
           if(inputData[irow][icol].size()<2){
             for(int iband=0;iband<nband;++iband)
-              outputProfile[iband][icol]=static_cast<float>(flag_opt[0]);
+              outputProfile[iband][icol]=static_cast<float>(nodata_opt[0]);
             continue;
           }
           float min=0;
diff --git a/src/apps/pkmosaic.cc b/src/apps/pkmosaic.cc
index 8504ae4..db0ed63 100644
--- a/src/apps/pkmosaic.cc
+++ b/src/apps/pkmosaic.cc
@@ -36,28 +36,28 @@ using namespace std;
 
 int main(int argc, char *argv[])
 {
-  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>  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("a_srs", "a_srs", "Override the projection 
for the output file (leave blank to copy from input file, use epsg:3035 to use 
European projection and force to European grid");
-  Optionpk<string>  extent_opt("e", "extent", "get boundary from extent from 
polygons in vector file", "");
+  Optionpk<string>  extent_opt("e", "extent", "get boundary from extent from 
polygons in vector file");
   Optionpk<double>  ulx_opt("ulx", "ulx", "Upper left x value bounding box (in 
geocoordinates if georef is true)", 0.0);
   Optionpk<double>  uly_opt("uly", "uly", "Upper left y value bounding box (in 
geocoordinates if georef is true)", 0.0);
   Optionpk<double>  lrx_opt("lrx", "lrx", "Lower right x value bounding box 
(in geocoordinates if georef is true)", 0.0);
   Optionpk<double>  lry_opt("lry", "lry", "Lower right y value bounding box 
(in geocoordinates if georef is true)", 0.0);
   Optionpk<double>  dx_opt("dx", "dx", "Output resolution in x (in meter) 
(0.0: keep original resolution)", 0.0);
   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<int>  band_opt("b", "band", "band index(es) to crop (-1: crop all 
bands)", -1);
   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>  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", "Creation option for output file. 
Multiple options can be specified.");
+  Optionpk<short>  dstnodata_opt("dstnodata", "dstnodata", "nodata 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<string> mrule_opt("m", "mrule", "Mosaic rule for mosaic (overwrite, 
maxndvi, maxband, minband, validband, mean, maxvote (only for byte images), 
median, sum", "overwrite");
   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> srcnodata_opt("srcnodata", "srcnodata", "invalid value for 
valid band", 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);
@@ -82,13 +82,13 @@ int main(int argc, char *argv[])
     dx_opt.retrieveOption(argc,argv);
     dy_opt.retrieveOption(argc,argv);
     option_opt.retrieveOption(argc,argv);
-    flag_opt.retrieveOption(argc,argv);
+    dstnodata_opt.retrieveOption(argc,argv);
     resample_opt.retrieveOption(argc,argv);
     description_opt.retrieveOption(argc,argv);
     mrule_opt.retrieveOption(argc,argv);
     ruleBand_opt.retrieveOption(argc,argv);
     validBand_opt.retrieveOption(argc,argv);
-    invalid_opt.retrieveOption(argc,argv);
+    srcnodata_opt.retrieveOption(argc,argv);
     minValue_opt.retrieveOption(argc,argv);
     maxValue_opt.retrieveOption(argc,argv);
     file_opt.retrieveOption(argc,argv);
@@ -119,8 +119,8 @@ int main(int argc, char *argv[])
   mruleMap["median"]=mrule::median;
   mruleMap["sum"]=mrule::sum;
 
-  while(invalid_opt.size()<validBand_opt.size())
-    invalid_opt.push_back(invalid_opt[0]);
+  while(srcnodata_opt.size()<validBand_opt.size())
+    srcnodata_opt.push_back(srcnodata_opt[0]);
   while(minValue_opt.size()<validBand_opt.size())
     minValue_opt.push_back(minValue_opt[0]);
   while(maxValue_opt.size()<validBand_opt.size())
@@ -174,7 +174,7 @@ int main(int argc, char *argv[])
   double dy=dy_opt[0];
   //get bounding box from extentReader if defined
   ImgReaderOgr extentReader;
-  if(extent_opt[0]!=""){
+  if(extent_opt.size()){
     extentReader.open(extent_opt[0]);
     if(!(extentReader.getExtent(ulx_opt[0],uly_opt[0],lrx_opt[0],lry_opt[0]))){
        cerr << "Error: could not get extent from " << extent_opt[0] << endl;
@@ -196,7 +196,7 @@ int main(int argc, char *argv[])
     catch(string errorstring){
       cerr << errorstring << " " << input_opt[ifile] << endl;
     }
-    if(colorTable_opt[0]=="")
+    if(colorTable_opt.empty())
       if(imgReader.getColorTable())
         theColorTable=(imgReader.getColorTable()->Clone());
     if(projection_opt.empty())
@@ -279,7 +279,7 @@ int main(int argc, char *argv[])
           cout << "Using data type from input image: " << 
GDALGetDataTypeName(theType) << endl;
       }
 
-      if(oformat_opt[0]!="")//default
+      if(oformat_opt.size())//default
         imageType=oformat_opt[0];
       else
         imageType=imgReader.getImageType();
@@ -372,10 +372,13 @@ int main(int argc, char *argv[])
   }
   else
     nwriteBand=(file_opt[0])? bands.size()+1:bands.size();
+  assert(output_opt.size());
   if(verbose_opt[0])
     cout << "open output image " << output_opt[0] << " with " << nwriteBand << 
" bands" << endl << flush;
   try{
     
imgWriter.open(output_opt[0],ncol,nrow,nwriteBand,theType,imageType,option_opt);
+    for(int iband=0;iband<nwriteBand;++iband)
+      imgWriter.GDALSetNoDataValue(dstnodata_opt[0],iband);
   }
   catch(string error){
     cout << error << endl;
@@ -393,14 +396,14 @@ int main(int argc, char *argv[])
       cout << "projection: " << theProjection << endl;
     imgWriter.setProjection(theProjection);
   }
-    
-  if(colorTable_opt[0]!=""){
-    assert(imgWriter.getDataType()==GDT_Byte);
-    imgWriter.setColorTable(colorTable_opt[0]);
+  if(imgWriter.getDataType()==GDT_Byte){
+    if(colorTable_opt.size()){
+      if(colorTable_opt[0]!="none")
+       imgWriter.setColorTable(colorTable_opt[0]);
+    }
+    else if(theColorTable)
+      imgWriter.setColorTable(theColorTable);
   }
-  else if(theColorTable)
-    imgWriter.setColorTable(theColorTable);
-
   //create mosaic image
   if(verbose_opt[0])
      cout << "creating mosaic image" << endl;
@@ -441,7 +444,7 @@ int main(int argc, char *argv[])
       }
       else{
         for(int iband=0;iband<nband;++iband)
-          writeBuffer[iband][icol]=flag_opt[0];
+          writeBuffer[iband][icol]=dstnodata_opt[0];
       }
     }
     for(int ifile=0;ifile<input_opt.size();++ifile){
@@ -521,7 +524,7 @@ int main(int argc, char *argv[])
             upperCol=imgReader.nrOfCol()-1;
           for(int vband=0;vband<validBand_opt.size();++vband){
             
val_new=(readCol-0.5-lowerCol)*readBuffer[validBand_opt[vband]][upperCol-startCol]+(1-readCol+0.5+lowerCol)*readBuffer[validBand_opt[vband]][lowerCol-startCol];
-            
if(val_new<=minValue_opt[vband]||val_new>=maxValue_opt[vband]||val_new==invalid_opt[vband]){
+            
if(val_new<=minValue_opt[vband]||val_new>=maxValue_opt[vband]||val_new==srcnodata_opt[vband]){
               readValid=false;
               break;
             }
@@ -531,7 +534,7 @@ int main(int argc, char *argv[])
           readCol=static_cast<int>(readCol);
           for(int vband=0;vband<validBand_opt.size();++vband){
             val_new=readBuffer[validBand_opt[vband]][readCol-startCol];
-            
if(val_new<=minValue_opt[vband]||val_new>=maxValue_opt[vband]||val_new==invalid_opt[vband]){
+            
if(val_new<=minValue_opt[vband]||val_new>=maxValue_opt[vband]||val_new==srcnodata_opt[vband]){
               readValid=false;
               break;
             }
diff --git a/src/apps/pkndvi.cc b/src/apps/pkndvi.cc
index 6bb3250..bb989fc 100644
--- a/src/apps/pkndvi.cc
+++ b/src/apps/pkndvi.cc
@@ -33,7 +33,7 @@ int main(int argc, char *argv[])
   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), ndvi2 (b1-b0)/(b2+b3), gvmi 
(b0+0.1)-(b1+0.02))/((b0+0.1)+(b1+0.02))), vari (b1-b2)/(b1+b2-b0), osavi, 
mcari, tcari, diff (b1-b0), scale, ratio.", "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<int> nodata_opt("nodata", "nodata", "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", 0);
@@ -42,7 +42,7 @@ int main(int argc, char *argv[])
   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]");
+  Optionpk<string> option_opt("co", "co", "Creation option for output file. 
Multiple options can be specified.");
   Optionpk<short> verbose_opt("v", "verbose", "verbose mode if > 0", 0);
 
   bool doProcess;//stop process when program was invoked with help option (-h 
--help)
@@ -52,7 +52,7 @@ int main(int argc, char *argv[])
     band_opt.retrieveOption(argc,argv);
     rule_opt.retrieveOption(argc,argv);
     invalid_opt.retrieveOption(argc,argv);
-    flag_opt.retrieveOption(argc,argv);
+    nodata_opt.retrieveOption(argc,argv);
     colorTable_opt.retrieveOption(argc,argv);
     description_opt.retrieveOption(argc,argv);
     minmax_opt.retrieveOption(argc,argv);
@@ -150,6 +150,7 @@ int main(int argc, char *argv[])
     option_opt.push_back(theInterleave);
   }
   
outputWriter.open(output_opt[0],inputReader[0].nrOfCol(),inputReader[0].nrOfRow(),1,theType,oformat_opt[0],option_opt);
+  outputWriter.GDALSetNoDataValue(nodata_opt[0]);
 
   if(description_opt.size())
       outputWriter.setImageDescription(description_opt[0]);
@@ -202,15 +203,15 @@ int main(int argc, char *argv[])
       cerr << errorstring << endl;
       exit(1);
     }
-    assert(invalid_opt.size()==flag_opt.size());
+    assert(invalid_opt.size()==nodata_opt.size());
     for(icol=0;icol<inputReader[0].nrOfCol();++icol){
       double ndvi=minmax_opt[0];
-      double flagValue=flag_opt[0];
+      double flagValue=nodata_opt[0];
       bool valid=true;
       for(int iflag=0;valid&&iflag<invalid_opt.size();++iflag){
         for(int iband=0;iband<lineInput.size();++iband){
           if(lineInput[iband][icol]==invalid_opt[iflag]){
-            flagValue=flag_opt[iflag];
+            flagValue=nodata_opt[iflag];
             valid=false;
             break;
           }
diff --git a/src/apps/pkreclass.cc b/src/apps/pkreclass.cc
index 1d6faea..71cd8f2 100644
--- a/src/apps/pkreclass.cc
+++ b/src/apps/pkreclass.cc
@@ -29,11 +29,11 @@ using namespace std;
 
 int main(int argc, char *argv[])
 {
-  Optionpk<string>  input_opt("i", "input", "Input image");
-  Optionpk<string>  mask_opt("m", "mask", "Mask image(s)");
+  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.", 1);
-  Optionpk<int> flag_opt("f", "flag", "Flag value to put in image if not valid 
(0)", 0);
+  Optionpk<unsigned short> masknodata_opt("msknodata", "msknodata", "Mask 
value(s) where image has nodata. Use one value for each mask, or multiple 
values for a single mask.", 1);
+  Optionpk<int> nodata_opt("nodata", "nodata", "nodata 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", "");
@@ -41,7 +41,7 @@ int main(int argc, char *argv[])
   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> 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]");
+  Optionpk<string> option_opt("co", "co", "Creation option for output file. 
Multiple options can be specified.");
   Optionpk<string> description_opt("d", "description", "Set image 
description");
   Optionpk<short> verbose_opt("v", "verbose", "verbose", 0);
 
@@ -49,8 +49,8 @@ int main(int argc, char *argv[])
   try{
     doProcess=input_opt.retrieveOption(argc,argv);
     mask_opt.retrieveOption(argc,argv);
-    invalid_opt.retrieveOption(argc,argv);
-    flag_opt.retrieveOption(argc,argv);
+    masknodata_opt.retrieveOption(argc,argv);
+    nodata_opt.retrieveOption(argc,argv);
     code_opt.retrieveOption(argc,argv);
     class_opt.retrieveOption(argc,argv);
     reclass_opt.retrieveOption(argc,argv);
@@ -198,6 +198,8 @@ int main(int argc, char *argv[])
       option_opt.push_back(theInterleave);
     }
     
outputWriter.open(output_opt[0],inputReader.nrOfCol(),inputReader.nrOfRow(),inputReader.nrOfBand(),theType,inputReader.getImageType(),option_opt);
+    for(int iband=0;iband<inputReader.nrOfBand();++iband)
+      outputWriter.GDALSetNoDataValue(nodata_opt[0],iband);
     if(description_opt.size())
       outputWriter.setImageDescription(description_opt[0]);
 
@@ -223,10 +225,10 @@ int main(int argc, char *argv[])
     double ulx,uly,lrx,lry;
     inputReader.getBoundingBox(ulx,uly,lrx,lry);
     outputWriter.copyGeoTransform(inputReader);
-    assert(flag_opt.size()==invalid_opt.size());
+    assert(nodata_opt.size()==masknodata_opt.size());
     if(verbose_opt[0]&&mask_opt.size()){
-      for(int iv=0;iv<invalid_opt.size();++iv)
-        cout << invalid_opt[iv] << "->" << flag_opt[iv] << endl;
+      for(int iv=0;iv<masknodata_opt.size();++iv)
+        cout << masknodata_opt[iv] << "->" << nodata_opt[iv] << endl;
     }
 
     assert(outputWriter.nrOfCol()==inputReader.nrOfCol());
@@ -282,13 +284,13 @@ int main(int argc, char *argv[])
               oldRowMask=rowMask;
             }
             short ivalue=0;
-            if(mask_opt.size()==invalid_opt.size())//one invalid value for 
each mask
-              ivalue=invalid_opt[imask];
+            if(mask_opt.size()==masknodata_opt.size())//one invalid value for 
each mask
+              ivalue=masknodata_opt[imask];
             else//use same invalid value for each mask
-              ivalue=invalid_opt[0];
+              ivalue=masknodata_opt[0];
             if(lineMask[imask][colMask]==ivalue){
               for(int iband=0;iband<inputReader.nrOfBand();++iband)
-                lineInput[iband][icol]=flag_opt[imask];
+                lineInput[iband][icol]=nodata_opt[imask];
               masked=true;
               break;
             }
@@ -314,11 +316,11 @@ int main(int argc, char *argv[])
             }
             oldRowMask=rowMask;
           }
-          for(int ivalue=0;ivalue<invalid_opt.size();++ivalue){
-            assert(invalid_opt.size()==flag_opt.size());
-            if(lineMask[0][colMask]==invalid_opt[ivalue]){
+          for(int ivalue=0;ivalue<masknodata_opt.size();++ivalue){
+            assert(masknodata_opt.size()==nodata_opt.size());
+            if(lineMask[0][colMask]==masknodata_opt[ivalue]){
               for(int iband=0;iband<inputReader.nrOfBand();++iband)
-                lineInput[iband][icol]=flag_opt[ivalue];
+                lineInput[iband][icol]=nodata_opt[ivalue];
               masked=true;
               break;
             }
diff --git a/src/apps/pksetmask.cc b/src/apps/pksetmask.cc
index aa6e520..841d7c7 100644
--- a/src/apps/pksetmask.cc
+++ b/src/apps/pksetmask.cc
@@ -28,15 +28,15 @@ using namespace std;
 int main(int argc, char *argv[])
 {
   //command line options
-  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<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<int> 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);
+  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<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", "Creation option for output file. 
Multiple options can be specified.");
+  Optionpk<int> msknodata_opt("msknodata", "msknodata", "Mask value(s) where 
image has nodata. 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 msknodata option", '=');
+  Optionpk<int> nodata_opt("nodata", "nodata", "nodata value to put in image 
if not valid", 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);
 
@@ -48,9 +48,9 @@ int main(int argc, char *argv[])
     otype_opt.retrieveOption(argc,argv);
     oformat_opt.retrieveOption(argc,argv);
     option_opt.retrieveOption(argc,argv);
-    invalid_opt.retrieveOption(argc,argv);
+    msknodata_opt.retrieveOption(argc,argv);
     operator_opt.retrieveOption(argc,argv);
-    flag_opt.retrieveOption(argc,argv);
+    nodata_opt.retrieveOption(argc,argv);
     colorTable_opt.retrieveOption(argc,argv);
     verbose_opt.retrieveOption(argc,argv);
   }
@@ -67,17 +67,17 @@ int main(int argc, char *argv[])
      cout << "number of mask images: " << mask_opt.size() << endl;
   vector<ImgReaderGdal> maskReader(mask_opt.size()); 
   for(int imask=0;imask<mask_opt.size();++imask){
-    assert(mask_opt[imask]!="");
     if(verbose_opt[0])
       cout << "opening mask image file " << mask_opt[imask] << endl;
     maskReader[imask].open(mask_opt[imask]);
   }
+  assert(input_opt.size());
   if(verbose_opt[0])
     cout << "opening input image file " << input_opt[0] << endl;
   ImgReaderGdal inputReader;
   inputReader.open(input_opt[0]);
   string imageType=inputReader.getImageType();
-  if(oformat_opt[0]!="")//default
+  if(oformat_opt.size())//default
     imageType=oformat_opt[0];
   GDALDataType theType=GDT_Unknown;
   if(verbose_opt[0]){
@@ -95,6 +95,7 @@ int main(int argc, char *argv[])
   if(theType==GDT_Unknown)
     theType=inputReader.getDataType();
 
+  assert(output_opt.size());
   if(verbose_opt[0]){
     std::cout << std::endl << "Output data type:  " << 
GDALGetDataTypeName(theType) << std::endl;
     std::cout << "opening output image for writing: " << output_opt[0] << 
std::endl;
@@ -107,6 +108,8 @@ int main(int argc, char *argv[])
       option_opt.push_back(theInterleave);
     }
     
outputWriter.open(output_opt[0],inputReader.nrOfCol(),inputReader.nrOfRow(),inputReader.nrOfBand(),theType,imageType,option_opt);
+    for(int iband=0;iband<inputReader.nrOfBand();++iband)
+      outputWriter.GDALSetNoDataValue(nodata_opt[0],iband);
     outputWriter.setProjection(inputReader.getProjection());
     outputWriter.copyGeoTransform(inputReader);
   }
@@ -133,13 +136,13 @@ int main(int argc, char *argv[])
       assert(maskReader[imask].nrOfRow()==inputReader.nrOfRow());
     }
   }
-  assert(flag_opt.size()==invalid_opt.size());
-  assert(operator_opt.size()==invalid_opt.size()||operator_opt.size()==1);
+  assert(nodata_opt.size()==msknodata_opt.size());
+  assert(operator_opt.size()==msknodata_opt.size()||operator_opt.size()==1);
   if(verbose_opt[0]){
     cout << " mask files selected: " << mask_opt.size() << endl;
-    for(int iv=0;iv<invalid_opt.size();++iv){
-      char 
op=(operator_opt.size()==invalid_opt.size())?operator_opt[iv]:operator_opt[0];
-      cout << op << " " << invalid_opt[iv] << "->" << flag_opt[iv] << endl;
+    for(int iv=0;iv<msknodata_opt.size();++iv){
+      char 
op=(operator_opt.size()==msknodata_opt.size())?operator_opt[iv]:operator_opt[0];
+      cout << op << " " << msknodata_opt[iv] << "->" << nodata_opt[iv] << endl;
     }
   }
   
@@ -210,10 +213,10 @@ int main(int argc, char *argv[])
           else
             continue;//no coverage in this mask
          int ivalue=0;
-         if(mask_opt.size()==invalid_opt.size())//one invalid value for each 
mask
-           ivalue=invalid_opt[imask];
+         if(mask_opt.size()==msknodata_opt.size())//one invalid value for each 
mask
+           ivalue=msknodata_opt[imask];
          else//use same invalid value for each mask
-           ivalue=invalid_opt[0];
+           ivalue=msknodata_opt[0];
          char 
op=(operator_opt.size()==mask_opt.size())?operator_opt[imask]:operator_opt[0];
          switch(op){
          case('='):
@@ -238,10 +241,10 @@ int main(int argc, char *argv[])
             if(verbose_opt[0]>1)
               cout << "image masked at (col=" << icol << ",row=" << irow <<") 
with mask " << mask_opt[imask] << " and value " << ivalue << endl;
            for(int iband=0;iband<inputReader.nrOfBand();++iband){
-              if(mask_opt.size()==flag_opt.size())//one flag value for each 
mask
-                lineInput[iband][icol]=flag_opt[imask];
+              if(mask_opt.size()==nodata_opt.size())//one flag value for each 
mask
+                lineInput[iband][icol]=nodata_opt[imask];
               else                
-                lineInput[iband][icol]=flag_opt[0];
+                lineInput[iband][icol]=nodata_opt[0];
             }
             masked=false;
            break;
@@ -273,31 +276,31 @@ int main(int argc, char *argv[])
            }
             oldRowMask[0]=rowMask;
          }
-          for(int ivalue=0;ivalue<invalid_opt.size();++ivalue){
-            assert(invalid_opt.size()==flag_opt.size());
-            char 
op=(operator_opt.size()==invalid_opt.size())?operator_opt[ivalue]:operator_opt[0];
+          for(int ivalue=0;ivalue<msknodata_opt.size();++ivalue){
+            assert(msknodata_opt.size()==nodata_opt.size());
+            char 
op=(operator_opt.size()==msknodata_opt.size())?operator_opt[ivalue]:operator_opt[0];
             switch(op){
             case('='):
             default:
-              if(lineMask[0][colMask]==invalid_opt[ivalue])
+              if(lineMask[0][colMask]==msknodata_opt[ivalue])
                 masked=true;
               break;
             case('<'):
-              if(lineMask[0][colMask]<invalid_opt[ivalue])
+              if(lineMask[0][colMask]<msknodata_opt[ivalue])
                 masked=true;
               break;
             case('>'):
-              if(lineMask[0][colMask]>invalid_opt[ivalue])
+              if(lineMask[0][colMask]>msknodata_opt[ivalue])
                 masked=true;
               break;
             case('!'):
-              if(lineMask[0][colMask]!=invalid_opt[ivalue])
+              if(lineMask[0][colMask]!=msknodata_opt[ivalue])
                 masked=true;
               break;
             }
             if(masked){
               for(int iband=0;iband<inputReader.nrOfBand();++iband)
-                lineInput[iband][icol]=flag_opt[ivalue];
+                lineInput[iband][icol]=nodata_opt[ivalue];
               masked=false;
               break;
             }
diff --git a/src/apps/pksieve.cc b/src/apps/pksieve.cc
index 321c043..576e97b 100644
--- a/src/apps/pksieve.cc
+++ b/src/apps/pksieve.cc
@@ -41,7 +41,7 @@ int main(int argc,char **argv) {
   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<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<string> option_opt("co", "co", "Creation option for output file. 
Multiple options can be specified.");
   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 mode if > 0", 0);
 
diff --git a/src/imageclasses/ImgReaderGdal.cc 
b/src/imageclasses/ImgReaderGdal.cc
index c4ad030..e0579d3 100644
--- a/src/imageclasses/ImgReaderGdal.cc
+++ b/src/imageclasses/ImgReaderGdal.cc
@@ -463,6 +463,7 @@ unsigned long int 
ImgReaderGdal::getHistogram(std::vector<unsigned long int>& hi
   unsigned long int ninvalid=0;
   std::vector<double> lineBuffer(nrOfCol());
   for(int i=0;i<nbin;histvector[i++]=0);
+  double scale=static_cast<double>(nbin-1)/(maxValue-minValue);
   for(int irow=0;irow<nrOfRow();++irow){
     readData(lineBuffer,GDT_Float64,irow,theBand);
     for(int icol=0;icol<nrOfCol();++icol){
@@ -472,10 +473,17 @@ unsigned long int 
ImgReaderGdal::getHistogram(std::vector<unsigned long int>& hi
         ++ninvalid;
       else if(lineBuffer[icol]<minValue)
         ++ninvalid;
-      else if(lineBuffer[icol]==maxValue)
-        ++histvector[nbin-1];
-      else
-        
++histvector[static_cast<int>(static_cast<double>(lineBuffer[icol]-minValue)/(maxValue-minValue)*(nbin-1))];
+      else{//scale to [0:nbin]
+       int theBin=static_cast<unsigned long 
int>(scale*(lineBuffer[icol]-minValue));
+       assert(theBin>=0);
+       assert(theBin!=nbin);
+       assert(theBin<nbin);
+       ++histvector[theBin];
+      // else if(lineBuffer[icol]==maxValue)
+      //   ++histvector[nbin-1];
+      // else
+      //   
++histvector[static_cast<int>(static_cast<double>(lineBuffer[icol]-minValue)/(maxValue-minValue)*(nbin-1))];
+      }
     }
   }
   unsigned long int nvalid=nrOfCol()*nrOfRow()-ninvalid;

-- 
Alioth's /usr/local/bin/git-commit-notice on 
/srv/git.debian.org/git/pkg-grass/pktools.git

_______________________________________________
Pkg-grass-devel mailing list
Pkg-grass-devel@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-grass-devel

Reply via email to