[pktools] 170/375: adfgeotransform gt[5]=-dy in pkcrop and pkmosaic

Bas Couwenberg sebastic at xs4all.nl
Wed Dec 3 21:54:11 UTC 2014


This is an automated email from the git hooks/post-receive script.

sebastic-guest pushed a commit to branch upstream-master
in repository pktools.

commit 7d058c217ab8681910aa4723b57214245e7eb3f6
Author: Pieter Kempeneers <kempenep at gmail.com>
Date:   Sat Dec 28 14:34:11 2013 +0100

    adfgeotransform gt[5]=-dy in pkcrop and pkmosaic
---
 ChangeLog                         |  7 +++
 src/apps/pkclassify_nn.cc         |  2 +-
 src/apps/pkclassify_svm.cc        |  2 +-
 src/apps/pkcrop.cc                |  2 +-
 src/apps/pkinfo.cc                | 35 ++++++++++-----
 src/apps/pkmosaic.cc              |  7 ++-
 src/apps/pkndvi.cc                | 95 +++++++++++++++++++--------------------
 src/apps/pkreclass.cc             |  8 +++-
 src/apps/pkstatascii.cc           | 24 ++++++----
 src/apps/pkstatogr.cc             | 16 +++++--
 src/imageclasses/ImgReaderGdal.cc |  2 +-
 11 files changed, 118 insertions(+), 82 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index e859223..a30d37e 100755
--- a/ChangeLog
+++ b/ChangeLog
@@ -220,6 +220,13 @@ version 2.5
 	renamed mask to nodata
  - pkinfo
 	hist: corrected nan when min=max
+	min and max changed to src_min and src_max (limit source values for histogram)
+	support for options -min and -max in addition to minmax (-mm): show min and max independently
+ - pkstatascii
+	min and max changed to src_min and src_max (limit source values for histogram)
+	support for options -min and -max in addition to minmax (-mm): show min and max independently
  - pkfilter
 	corrected bug in 2d wavelet transform forward and inverse
 	renamed mask to nodata
+ - pkndvi
+	changed minmax option to min and max. Min and max values now apply to scaled values
diff --git a/src/apps/pkclassify_nn.cc b/src/apps/pkclassify_nn.cc
index 5f56f2a..147d259 100644
--- a/src/apps/pkclassify_nn.cc
+++ b/src/apps/pkclassify_nn.cc
@@ -212,7 +212,7 @@ int main(int argc, char *argv[])
         else
           totalSamples=trainingReaderBag.readDataImageShape(trainingMap,fields,start_opt[0],end_opt[0],label_opt[0],verbose_opt[0]);
         if(trainingMap.size()<2){
-          string errorstring="Error: could not read at least two classes from training file";
+          string errorstring="Error: could not read at least two classes from training file, did you provide class labels in training sample (see option label)?";
           throw(errorstring);
         }
 	trainingReaderBag.close();
diff --git a/src/apps/pkclassify_svm.cc b/src/apps/pkclassify_svm.cc
index 95c6f8a..96ee9e1 100644
--- a/src/apps/pkclassify_svm.cc
+++ b/src/apps/pkclassify_svm.cc
@@ -254,7 +254,7 @@ int main(int argc, char *argv[])
         else
           totalSamples=trainingReaderBag.readDataImageShape(trainingMap,fields,start_opt[0],end_opt[0],label_opt[0],verbose_opt[0]);
         if(trainingMap.size()<2){
-          string errorstring="Error: could not read at least two classes from training file";
+          string errorstring="Error: could not read at least two classes from training file, did you provide class labels in training sample (see option label)?";
           throw(errorstring);
         }
 	trainingReaderBag.close();
diff --git a/src/apps/pkcrop.cc b/src/apps/pkcrop.cc
index a05dfa1..b812ae8 100644
--- a/src/apps/pkcrop.cc
+++ b/src/apps/pkcrop.cc
@@ -364,7 +364,7 @@ int main(int argc, char *argv[])
       gt[2]=0;
       gt[3]=cropuly;
       gt[4]=0;
-      gt[5]=dy;
+      gt[5]=-dy;
       imgWriter.setGeoTransform(gt);
       if(projection_opt.size()){
 	if(verbose_opt[0])
diff --git a/src/apps/pkinfo.cc b/src/apps/pkinfo.cc
index 2aa9b6f..60f7d90 100644
--- a/src/apps/pkinfo.cc
+++ b/src/apps/pkinfo.cc
@@ -38,15 +38,17 @@ int main(int argc, char *argv[])
   Optionpk<bool>  dx_opt("dx", "dx", "Gets resolution in x (in m)", false,0);
   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>  min_opt("min", "min", "Shows min value of the image ", false,0);
+  Optionpk<bool>  max_opt("max", "max", "Shows 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 (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<double>  src_min_opt("src_min", "src_min", "Sets minimum for histogram (does not calculate min value: use -mm instead)");
+  Optionpk<double>  src_max_opt("src_max", "src_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", "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<bool>  cover_opt("cover", "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);
@@ -78,9 +80,11 @@ int main(int argc, char *argv[])
     dx_opt.retrieveOption(argc,argv);
     dy_opt.retrieveOption(argc,argv);
     minmax_opt.retrieveOption(argc,argv);
-    stat_opt.retrieveOption(argc,argv);
     min_opt.retrieveOption(argc,argv);
     max_opt.retrieveOption(argc,argv);
+    stat_opt.retrieveOption(argc,argv);
+    src_min_opt.retrieveOption(argc,argv);
+    src_max_opt.retrieveOption(argc,argv);
     relative_opt.retrieveOption(argc,argv);
     projection_opt.retrieveOption(argc,argv);
     geo_opt.retrieveOption(argc,argv);
@@ -262,7 +266,7 @@ int main(int argc, char *argv[])
       std::cout << "--min " << minValue << " --max " << maxValue << " --mean " << meanValue << " --stdDev " << stdDev << " ";
     }
 
-    if(minmax_opt[0]){
+    if(minmax_opt[0]||min_opt[0]||max_opt[0]){
       assert(band_opt[0]<imgReader.nrOfBand());
       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]))){
 	double uli,ulj,lri,lrj;
@@ -272,7 +276,14 @@ int main(int argc, char *argv[])
       }
       else
 	imgReader.getMinMax(minValue,maxValue,band_opt[0],true);
-      std::cout << "--min " << minValue << " --max " << maxValue << " ";
+      if(minmax_opt[0])
+	std::cout << "--min " << minValue << " --max " << maxValue << " ";
+      else{
+	if(min_opt[0])
+	  std::cout << "--min " << minValue << " ";
+	if(max_opt[0])
+	  std::cout << "--max " << maxValue << " ";
+      }
     }
     if(relative_opt[0])
       hist_opt[0]=true;
@@ -285,10 +296,10 @@ int main(int argc, char *argv[])
       //todo: optimize such that getMinMax is only called once...
       imgReader.getMinMax(minValue,maxValue,band_opt[0]);
       
-      if(min_opt.size())
-        minValue=min_opt[0];
-      if(max_opt.size())
-        maxValue=max_opt[0];
+      if(src_min_opt.size())
+        minValue=src_min_opt[0];
+      if(src_max_opt.size())
+        maxValue=src_max_opt[0];
       unsigned long int nsample=imgReader.getHistogram(output,minValue,maxValue,nbin,band_opt[0]);
       std::cout.precision(10);
       for(int bin=0;bin<nbin;++bin){
@@ -312,11 +323,11 @@ int main(int argc, char *argv[])
     }
     else{
       int minCol,minRow;
-      if(min_opt.size()){
+      if(src_min_opt.size()){
         assert(band_opt[0]<imgReader.nrOfBand());
         std::cout << "--min " << imgReader.getMin(minCol, minRow,band_opt[0]);
       }
-      if(max_opt.size()){
+      if(src_max_opt.size()){
         assert(band_opt[0]<imgReader.nrOfBand());
         assert(band_opt[0]<imgReader.nrOfBand());
         std::cout << "--max " << imgReader.getMax(minCol, minRow,band_opt[0]);
diff --git a/src/apps/pkmosaic.cc b/src/apps/pkmosaic.cc
index 4be22b3..d2aa332 100644
--- a/src/apps/pkmosaic.cc
+++ b/src/apps/pkmosaic.cc
@@ -382,7 +382,10 @@ int main(int argc, char *argv[])
   }
   else
     nwriteBand=(file_opt[0])? bands.size()+1:bands.size();
-  assert(output_opt.size());
+  if(output_opt.empty()){
+    std::cerr << "No output file provided (use option -o). Use --help for help information" << std::endl;
+    exit(0);
+  }
   if(verbose_opt[0])
     cout << "open output image " << output_opt[0] << " with " << nwriteBand << " bands" << endl << flush;
   try{
@@ -401,7 +404,7 @@ int main(int argc, char *argv[])
   gt[2]=0;
   gt[3]=maxULY;
   gt[4]=0;
-  gt[5]=dy;
+  gt[5]=-dy;
   imgWriter.setGeoTransform(gt);
   // imgWriter.setGeoTransform(minULX,maxULY,dx,dy,0,0);
   if(projection_opt.size()){
diff --git a/src/apps/pkndvi.cc b/src/apps/pkndvi.cc
index bb989fc..3cf338f 100644
--- a/src/apps/pkndvi.cc
+++ b/src/apps/pkndvi.cc
@@ -36,10 +36,13 @@ int main(int argc, char *argv[])
   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);
+  Optionpk<double> min_opt("min", "min", "minimum value for ndvi after scaling (set all values smaller than min to min)", 0);
+  Optionpk<double> max_opt("max", "max", "maximum value for ndvi after scaling (limit all values to max)");
   Optionpk<double> eps_opt("e", "eps", "epsilon, contraint division by zero", 0);
-  Optionpk<double> scale_opt("s", "scale", "scale[0] is used for input, scale[1] is used for output: DN=scale[1]*ndvi+offset[1]", 1);
-  Optionpk<double> offset_opt("off", "offset", "offset[0] is used for input, offset[1] is used for output (see also scale option", 0);
+  Optionpk<double> src_scale_opt("src_s", "src_scale", "scale used for input, scale[1] is used for output: DN=scale[1]*ndvi+offset[1]", 1);
+  Optionpk<double> dst_scale_opt("dst_s", "src_scale", "scale used for output: DN=dst_s*ndvi+dst_offset", 1);
+  Optionpk<double> src_offset_opt("src_o", "src_offset", "offset used for input", 0);
+  Optionpk<double> dst_offset_opt("dst_o", "dst_offset", "offset is used for output: DN=dst_s*ndvi+dst_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", "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", "Creation option for output file. Multiple options can be specified.");
@@ -55,10 +58,13 @@ int main(int argc, char *argv[])
     nodata_opt.retrieveOption(argc,argv);
     colorTable_opt.retrieveOption(argc,argv);
     description_opt.retrieveOption(argc,argv);
-    minmax_opt.retrieveOption(argc,argv);
+    min_opt.retrieveOption(argc,argv);
+    max_opt.retrieveOption(argc,argv);
     eps_opt.retrieveOption(argc,argv);
-    scale_opt.retrieveOption(argc,argv);
-    offset_opt.retrieveOption(argc,argv);
+    src_scale_opt.retrieveOption(argc,argv);
+    src_offset_opt.retrieveOption(argc,argv);
+    dst_scale_opt.retrieveOption(argc,argv);
+    dst_offset_opt.retrieveOption(argc,argv);
     otype_opt.retrieveOption(argc,argv);
     oformat_opt.retrieveOption(argc,argv);
     option_opt.retrieveOption(argc,argv);
@@ -73,26 +79,15 @@ int main(int argc, char *argv[])
     exit(0);//help was invoked, stop processing
   }
 
-  assert(input_opt.size());
-  assert(output_opt.size());
-
-  if(scale_opt.size()<2){
-    if(input_opt.size()<2)
-      scale_opt.push_back(1);
-    else
-      scale_opt.push_back(scale_opt[0]);
+  if(input_opt.empty()){
+    std::cerr << "No input file provided (use option -i). Use --help for help information" << std::endl;
+    exit(0);
   }
-  if(verbose_opt[0])
-    std::cout << scale_opt;
-  if(offset_opt.size()<2){
-    if(input_opt.size()<2)
-      offset_opt.push_back(0);
-    else
-      offset_opt.push_back(offset_opt[0]);
+  if(output_opt.empty()){
+    std::cerr << "No output file provided (use option -o). Use --help for help information" << std::endl;
+    exit(0);
   }
 
-  if(verbose_opt[0])
-    std::cout << offset_opt;
   int reqBand=0;
   if(rule_opt[0]=="scale")
     reqBand=1;
@@ -205,7 +200,7 @@ int main(int argc, char *argv[])
     }
     assert(invalid_opt.size()==nodata_opt.size());
     for(icol=0;icol<inputReader[0].nrOfCol();++icol){
-      double ndvi=minmax_opt[0];
+      double ndvi=min_opt[0];
       double flagValue=nodata_opt[0];
       bool valid=true;
       for(int iflag=0;valid&&iflag<invalid_opt.size();++iflag){
@@ -232,43 +227,43 @@ int main(int argc, char *argv[])
           //Normalized Pigment Chlorophyll index (NPCI Penuelas1994): b0=R_430, b1=R_680
           //Structure Intensive Pigment index (SIPI Penuelas 1995): b0=R_450, b1=R_800
           //Lichtenthaler index 1 (Lic1 Lichtenthaler1996): b0=R_680, b2=R_800
-          denom=(lineInput[1][icol]-offset_opt[0])/scale_opt[0]-(lineInput[0][icol]-offset_opt[0])/scale_opt[0];
-          nom=(lineInput[1][icol]-offset_opt[0])/scale_opt[0]+(lineInput[0][icol]-offset_opt[0])/scale_opt[0];
+          denom=(lineInput[1][icol]-src_offset_opt[0])/src_scale_opt[0]-(lineInput[0][icol]-src_offset_opt[0])/src_scale_opt[0];
+          nom=(lineInput[1][icol]-src_offset_opt[0])/src_scale_opt[0]+(lineInput[0][icol]-src_offset_opt[0])/src_scale_opt[0];
         }
         else if(rule_opt[0]=="ndvi2"){//normalized difference with different wavelengths used in denom and nom
           //Example of indices addressed by ndvi2
           //Structure Intensive Pigment index (SIPI Penuelas 1995): b0=R_450, b1=R_800, b2=R_650, b=R_800
           //Vogelmann index 2 (Vog2 Vogelmann1993): b0=R_747, b1=R_735, b2=R_715, b3=R_726
           //Vogelmann index 3 (Vog3 Vogelmann1993): b0=R_747, b1=R_734, b2=R_715, b3=R_720
-          denom=(lineInput[1][icol]-offset_opt[0])/scale_opt[0]-(lineInput[0][icol]-offset_opt[0])/scale_opt[0];
-          nom=(lineInput[2][icol]-offset_opt[0])/scale_opt[0]+(lineInput[3][icol]-offset_opt[0])/scale_opt[0];
+          denom=(lineInput[1][icol]-src_offset_opt[0])/src_scale_opt[0]-(lineInput[0][icol]-src_offset_opt[0])/src_scale_opt[0];
+          nom=(lineInput[2][icol]-src_offset_opt[0])/src_scale_opt[0]+(lineInput[3][icol]-src_offset_opt[0])/src_scale_opt[0];
         }
         else if(rule_opt[0]=="gvmi"){
-          denom=((lineInput[0][icol]-offset_opt[0])/scale_opt[0]+0.1)-((lineInput[1][icol]-offset_opt[0])/scale_opt[0]+0.02);
-          nom=((lineInput[0][icol]-offset_opt[0])/scale_opt[0]+0.1)+((lineInput[1][icol]-offset_opt[0])/scale_opt[0]+0.02);
+          denom=((lineInput[0][icol]-src_offset_opt[0])/src_scale_opt[0]+0.1)-((lineInput[1][icol]-src_offset_opt[0])/src_scale_opt[0]+0.02);
+          nom=((lineInput[0][icol]-src_offset_opt[0])/src_scale_opt[0]+0.1)+((lineInput[1][icol]-src_offset_opt[0])/src_scale_opt[0]+0.02);
         }
         else if(rule_opt[0]=="vari"){
-          denom=(lineInput[1][icol]-offset_opt[0])/scale_opt[0]-(lineInput[2][icol]-offset_opt[0])/scale_opt[0];
-          nom=(lineInput[1][icol]-offset_opt[0])/scale_opt[0]+(lineInput[2][icol]-offset_opt[0])/scale_opt[0]-(lineInput[0][icol]-offset_opt[0])/scale_opt[0];
+          denom=(lineInput[1][icol]-src_offset_opt[0])/src_scale_opt[0]-(lineInput[2][icol]-src_offset_opt[0])/src_scale_opt[0];
+          nom=(lineInput[1][icol]-src_offset_opt[0])/src_scale_opt[0]+(lineInput[2][icol]-src_offset_opt[0])/src_scale_opt[0]-(lineInput[0][icol]-src_offset_opt[0])/src_scale_opt[0];
         }
         else if(rule_opt[0]=="osavi"){//structural index (Rondeaux1996): //b0=R_670, b1=R_800
-          denom=(1.0+0.16)*(lineInput[1][icol]-offset_opt[0])/scale_opt[0]-(lineInput[0][icol]-offset_opt[0])/scale_opt[0];
-          nom=(lineInput[1][icol]-offset_opt[0])/scale_opt[0]+(lineInput[0][icol]-offset_opt[0])/scale_opt[0]+0.16;
+          denom=(1.0+0.16)*(lineInput[1][icol]-src_offset_opt[0])/src_scale_opt[0]-(lineInput[0][icol]-src_offset_opt[0])/src_scale_opt[0];
+          nom=(lineInput[1][icol]-src_offset_opt[0])/src_scale_opt[0]+(lineInput[0][icol]-src_offset_opt[0])/src_scale_opt[0]+0.16;
         }
         else if(rule_opt[0]=="mcari"){//chlorophyll index (Daughtry2000): b0=R_550, b1=R_670, b2=R_700
-          denom=((lineInput[2][icol]-offset_opt[0])/scale_opt[0]-(lineInput[1][icol]-offset_opt[0])/scale_opt[0]-0.2*((lineInput[2][icol]-offset_opt[0])/scale_opt[0]-(lineInput[0][icol]-offset_opt[0])/scale_opt[0]))*(lineInput[2][icol]-offset_opt[0])/scale_opt[0];
-          nom=(lineInput[1][icol]-offset_opt[0])/scale_opt[0];
+          denom=((lineInput[2][icol]-src_offset_opt[0])/src_scale_opt[0]-(lineInput[1][icol]-src_offset_opt[0])/src_scale_opt[0]-0.2*((lineInput[2][icol]-src_offset_opt[0])/src_scale_opt[0]-(lineInput[0][icol]-src_offset_opt[0])/src_scale_opt[0]))*(lineInput[2][icol]-src_offset_opt[0])/src_scale_opt[0];
+          nom=(lineInput[1][icol]-src_offset_opt[0])/src_scale_opt[0];
         }
         else if(rule_opt[0]=="tcari"){//chlorophyll index (Haboudane2002): b0=R_550, b1=R_670, B2=R_700
-          denom=3*((lineInput[1][icol]-offset_opt[0])/scale_opt[0]*(lineInput[2][icol]-offset_opt[0])/scale_opt[0]-(lineInput[1][icol]-offset_opt[0])/scale_opt[0]-0.2*((lineInput[2][icol]-offset_opt[0])/scale_opt[0]-(lineInput[0][icol]-offset_opt[0])/scale_opt[0])*(lineInput[2][icol]-offset_opt[0])/scale_opt[0]);
-          nom=(lineInput[1][icol]-offset_opt[0])/scale_opt[0];
+          denom=3*((lineInput[1][icol]-src_offset_opt[0])/src_scale_opt[0]*(lineInput[2][icol]-src_offset_opt[0])/src_scale_opt[0]-(lineInput[1][icol]-src_offset_opt[0])/src_scale_opt[0]-0.2*((lineInput[2][icol]-src_offset_opt[0])/src_scale_opt[0]-(lineInput[0][icol]-src_offset_opt[0])/src_scale_opt[0])*(lineInput[2][icol]-src_offset_opt[0])/src_scale_opt[0]);
+          nom=(lineInput[1][icol]-src_offset_opt[0])/src_scale_opt[0];
         }
         else if(rule_opt[0]=="diff"){
-          denom=(lineInput[1][icol]-offset_opt[0])/scale_opt[0]-(lineInput[0][icol]-offset_opt[0])/scale_opt[0];
+          denom=(lineInput[1][icol]-src_offset_opt[0])/src_scale_opt[0]-(lineInput[0][icol]-src_offset_opt[0])/src_scale_opt[0];
           nom=1.0;
         }
         else if(rule_opt[0]=="scale"){
-          denom=(lineInput[0][icol]-offset_opt[0])/scale_opt[0];
+          denom=(lineInput[0][icol]-src_offset_opt[0])/src_scale_opt[0];
           nom=1.0;
         }
         else if(rule_opt[0]=="ratio"){
@@ -285,8 +280,8 @@ int main(int argc, char *argv[])
           //Vogelmann index 1 (Vog1 Vogelmann1993): b0=R_740, b1=R_720
           //Gitelson and Merzlyak 1 (GM1 Gitelson1997): b0=R_750 b1=R_550
           //Gitelson and Merzlyak (GM2 Gitelson1997) b0=R_750 b1=R_700
-          denom=(lineInput[0][icol]-offset_opt[0])/scale_opt[0];
-          nom=(lineInput[1][icol]-offset_opt[0])/scale_opt[0];
+          denom=(lineInput[0][icol]-src_offset_opt[0])/src_scale_opt[0];
+          nom=(lineInput[1][icol]-src_offset_opt[0])/src_scale_opt[0];
         }
         else{
           std::cout << "Error: rule " << rule_opt[0] << " not supported" << std::endl;
@@ -294,24 +289,24 @@ int main(int argc, char *argv[])
         }
         if(nom>eps_opt[0]||nom<-eps_opt[0])
         ndvi=denom/nom;
-        if(ndvi<minmax_opt[0])
-          ndvi=minmax_opt[0];
-        else if(minmax_opt.size()>1){
-          if(ndvi>minmax_opt[1])
-            ndvi=minmax_opt[1];
-        }
         switch(theType){
         case(GDT_Byte):
         case(GDT_Int16):
         case(GDT_UInt16):
         case(GDT_UInt32):
         case(GDT_Int32):
-          lineOutput[icol]=static_cast<int>(0.5+ndvi*scale_opt[1]+offset_opt[1]);
+          lineOutput[icol]=static_cast<int>(0.5+ndvi*dst_scale_opt[0]+dst_offset_opt[0]);
           break;
         default:
-          lineOutput[icol]=ndvi*scale_opt[1]+offset_opt[1];
+          lineOutput[icol]=ndvi*dst_scale_opt[0]+dst_offset_opt[0];
         break;
         }
+        if(lineOutput[icol]<min_opt[0])
+          lineOutput[icol]=min_opt[0];
+        else if(max_opt.size()){
+          if(lineOutput[icol]>max_opt[0])
+            lineOutput[icol]=max_opt[0];
+        }
       }
       else
         lineOutput[icol]=flagValue;
diff --git a/src/apps/pkreclass.cc b/src/apps/pkreclass.cc
index 71cd8f2..2247a2a 100644
--- a/src/apps/pkreclass.cc
+++ b/src/apps/pkreclass.cc
@@ -71,8 +71,12 @@ int main(int argc, char *argv[])
     std::cout << "short option -h shows basic options only, use long option --help to show all options" << std::endl;
     exit(0);//help was invoked, stop processing
   }
-  if(input_opt.empty()||output_opt.empty()){
-    std::cout << "input or output files are missing, provide input (-i) and output (-o) files. Use -h or --help for more help information" << std::endl;
+  if(input_opt.empty()){
+    std::cerr << "No input file provided (use option -i). Use --help for help information" << std::endl;
+    exit(0);
+  }
+  if(output_opt.empty()){
+    std::cerr << "No output file provided (use option -o). Use --help for help information" << std::endl;
     exit(0);
   }
     
diff --git a/src/apps/pkstatascii.cc b/src/apps/pkstatascii.cc
index 6d6643d..7e9a233 100644
--- a/src/apps/pkstatascii.cc
+++ b/src/apps/pkstatascii.cc
@@ -48,8 +48,10 @@ int main(int argc, char *argv[])
   Optionpk<bool> stdev_opt("stdev","stdev","calculate standard deviation",false);
   Optionpk<bool> sum_opt("sum","sum","calculate sum of column",false);
   Optionpk<bool> minmax_opt("mm","minmax","calculate minimum and maximum value",false);
-  Optionpk<double> min_opt("min","min","set minimum value",0);
-  Optionpk<double> max_opt("max","max","set maximum value",0);
+  Optionpk<bool> min_opt("min","min","calculate minimum value",false);
+  Optionpk<bool> max_opt("max","max","calculate maximum value",false);
+  Optionpk<double> src_min_opt("src_min","src_min","start reading source from this minimum value",0);
+  Optionpk<double> src_max_opt("src_max","src_max","stop reading source from this maximum value",0);
   Optionpk<bool> histogram_opt("hist","hist","calculate histogram",false);
   Optionpk<bool> histogram2d_opt("hist2d","hist2d","calculate 2-dimensional histogram based on two columns",false);
   Optionpk<short> nbin_opt("nbin","nbin","number of bins to calculate histogram",0);
@@ -84,6 +86,8 @@ int main(int argc, char *argv[])
     minmax_opt.retrieveOption(argc,argv);
     min_opt.retrieveOption(argc,argv);
     max_opt.retrieveOption(argc,argv);
+    src_min_opt.retrieveOption(argc,argv);
+    src_max_opt.retrieveOption(argc,argv);
     histogram_opt.retrieveOption(argc,argv);
     histogram2d_opt.retrieveOption(argc,argv);
     nbin_opt.retrieveOption(argc,argv);
@@ -125,8 +129,8 @@ int main(int argc, char *argv[])
     asciiReader.setMaxRow(range_opt[1]);
   asciiReader.readData(dataVector,col_opt);
   assert(dataVector.size());
-  double minValue=min_opt[0];
-  double maxValue=max_opt[0];
+  double minValue=src_min_opt[0];
+  double maxValue=src_max_opt[0];
   if(histogram_opt[0]){
     if(nbin_opt[0]<1){
       std::cerr << "Warning: number of bins not defined, calculating bins from min and max value" << std::endl;
@@ -135,10 +139,10 @@ int main(int argc, char *argv[])
       nbin_opt[0]=maxValue-minValue+1;
     }
   }
-  double minX=min_opt[0];
-  double minY=(min_opt.size()==2)? min_opt[1] : min_opt[0];
-  double maxX=max_opt[0];
-  double maxY=(max_opt.size()==2)? max_opt[1] : max_opt[0];
+  double minX=src_min_opt[0];
+  double minY=(src_min_opt.size()==2)? src_min_opt[1] : src_min_opt[0];
+  double maxX=src_max_opt[0];
+  double maxY=(src_max_opt.size()==2)? src_max_opt[1] : src_max_opt[0];
   if(histogram2d_opt[0]){
     assert(col_opt.size()==2);
     if(nbin_opt[0]<1){
@@ -181,6 +185,10 @@ int main(int argc, char *argv[])
       cout << "min value column " << col_opt[icol] << ": " << stat.min(dataVector[icol]) << endl;
       cout << "max value column " << col_opt[icol] << ": " << stat.max(dataVector[icol]) << endl;
     }
+    if(min_opt[0])
+      cout << "min value column " << col_opt[icol] << ": " << stat.min(dataVector[icol]) << endl;
+    if(max_opt[0])
+      cout << "max value column " << col_opt[icol] << ": " << stat.max(dataVector[icol]) << endl;
     if(histogram_opt[0]){
       //todo: support kernel density function and estimate sigma as in practical estimate of the bandwith in http://en.wikipedia.org/wiki/Kernel_density_estimation
       double sigma=0;
diff --git a/src/apps/pkstatogr.cc b/src/apps/pkstatogr.cc
index 81d8ec1..a088185 100644
--- a/src/apps/pkstatogr.cc
+++ b/src/apps/pkstatogr.cc
@@ -30,8 +30,10 @@ int main(int argc, char *argv[])
   Optionpk<std::string> input_opt("i", "input", "Input shape file", "");
   Optionpk<std::string> fieldname_opt("n", "fname", "fields on which to calculate statistics", "");
   Optionpk<bool> minmax_opt("mm","minmax","calculate minimum and maximum value",false);
-  Optionpk<double> min_opt("min","min","set minimum value",0);
-  Optionpk<double> max_opt("max","max","set maximum value",0);
+  Optionpk<bool> min_opt("min","min","calculate minimum value",0);
+  Optionpk<bool> max_opt("max","max","calculate maximum value",0);
+  Optionpk<double> src_min_opt("min","min","set minimum value",0);
+  Optionpk<double> src_max_opt("max","max","set maximum value",0);
   Optionpk<bool> histogram_opt("hist","hist","calculate histogram",false);
   Optionpk<short> nbin_opt("nbin", "nbin", "number of bins", 0);
   Optionpk<bool> relative_opt("rel","relative","use percentiles for histogram to calculate histogram",false);
@@ -48,6 +50,8 @@ int main(int argc, char *argv[])
     minmax_opt.retrieveOption(argc,argv);
     min_opt.retrieveOption(argc,argv);
     max_opt.retrieveOption(argc,argv);
+    src_min_opt.retrieveOption(argc,argv);
+    src_max_opt.retrieveOption(argc,argv);
     histogram_opt.retrieveOption(argc,argv);
     nbin_opt.retrieveOption(argc,argv);
     relative_opt.retrieveOption(argc,argv);
@@ -85,8 +89,8 @@ int main(int argc, char *argv[])
     theData.clear();
     inputReader.readData(theData,OFTReal,fieldname_opt[ifield],0,verbose_opt[0]);
     std::vector<double> binData;
-    double minValue=min_opt[0];
-    double maxValue=max_opt[0];
+    double minValue=src_min_opt[0];
+    double maxValue=src_max_opt[0];
     if(histogram_opt[0]){
       if(nbin_opt[0]<1){
         if(maxValue<=minValue)
@@ -116,6 +120,10 @@ int main(int argc, char *argv[])
         std::cout << " -min " << stat.min(theData);
         std::cout << " -max " << stat.max(theData);
       }
+      if(min_opt[0])
+        std::cout << " -min " << stat.min(theData);
+      if(max_opt[0])
+        std::cout << " -max " << stat.max(theData);
       if(median_opt[0])
         std::cout << " -median " << stat.median(theData);
       if(size_opt[0])
diff --git a/src/imageclasses/ImgReaderGdal.cc b/src/imageclasses/ImgReaderGdal.cc
index f7d970a..9d0a9a9 100644
--- a/src/imageclasses/ImgReaderGdal.cc
+++ b/src/imageclasses/ImgReaderGdal.cc
@@ -143,7 +143,7 @@ std::string ImgReaderGdal::getGeoTransform() const
   double gt[6];// { 444720, 30, 0, 3751320, 0, -30 };
   m_gds->GetGeoTransform(gt);
   std::ostringstream s;
-  s << "[" << gt[0] << "," << gt[1] << "," << gt[2] << "," << gt[3] << "," << gt[4] << "," << -gt[5] << "]";
+  s << "[" << gt[0] << "," << gt[1] << "," << gt[2] << "," << gt[3] << "," << gt[4] << "," << gt[5] << "]";
   return(s.str());
   // if(!isGeoRef())
   //   return("");

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



More information about the Pkg-grass-devel mailing list