[pktools] 169/375: support of ogr formats in apps with ogr writer

Bas Couwenberg sebastic at xs4all.nl
Wed Dec 3 21:54:10 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 1722a5d653f944d507496fa07659a465bd88ad97
Author: Pieter Kempeneers <kempenep at gmail.com>
Date:   Fri Dec 27 23:20:48 2013 +0100

    support of ogr formats in apps with ogr writer
---
 ChangeLog                        |   5 ++
 src/apps/pkascii2ogr.cc          |   6 +-
 src/apps/pkclassify_nn.cc        |   6 +-
 src/apps/pkclassify_svm.cc       |   6 +-
 src/apps/pkdiff.cc               |   6 +-
 src/apps/pkdumpimg.cc            |   5 +-
 src/apps/pkdumpogr.cc            |   2 +-
 src/apps/pkeditogr.cc            |  26 +++++++-
 src/apps/pkextract.cc            |  20 +++---
 src/apps/pkfs_nn.cc              |   8 ++-
 src/apps/pkgetmask.cc            |   3 +
 src/apps/pkpolygonize.cc         |  22 +++++--
 src/apps/pksieve.cc              |   4 +-
 src/imageclasses/ImgReaderOgr.cc |  10 +--
 src/imageclasses/ImgReaderOgr.h  |  78 ++++++++++++++++++++++-
 src/imageclasses/ImgWriterOgr.cc | 132 +++++++++++++++++++--------------------
 src/imageclasses/ImgWriterOgr.h  |  40 ++++++------
 17 files changed, 258 insertions(+), 121 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 4403d82..e859223 100755
--- a/ChangeLog
+++ b/ChangeLog
@@ -209,8 +209,13 @@ version 2.4.3
 	option msknodata to set nodata value in mask
 
 version 2.5
+ - ImgReaderOgr
+	support sqlite: read training file with small case band names b0, b1, ...
  - ImgReaderGdal and ImgWriterGdal
 	re-design of geotransform
+ - pkextract
+ - pkeditogr
+	support other ogr file formats than ESRI Shape (e.g, using option -f SQLite)
  - Filter2d.h
 	renamed mask to nodata
  - pkinfo
diff --git a/src/apps/pkascii2ogr.cc b/src/apps/pkascii2ogr.cc
index eb20f41..2169bca 100644
--- a/src/apps/pkascii2ogr.cc
+++ b/src/apps/pkascii2ogr.cc
@@ -23,10 +23,13 @@ along with pktools.  If not, see <http://www.gnu.org/licenses/>.
 #include "base/Optionpk.h"
 #include "imageclasses/ImgWriterOgr.h"
 
+using namespace std;
+
 int main(int argc, char *argv[])
 {
   Optionpk<string> input_opt("i","input","Input ASCII file");
   Optionpk<string> output_opt("o", "output", "Output file");
+  Optionpk<string> ogrformat_opt("f", "f", "Output sample file format","ESRI Shapefile");
   Optionpk<short> colX_opt("x", "x", "column number of x (0)", 0);
   Optionpk<short> colY_opt("y", "y", "column number of y (1)", 1);
   Optionpk<bool> polygon_opt("l", "line", "create OGRPolygon as geometry instead of points.  Fields are taken from first point and polygon is automatically closed (no need to repeat first point at last line). (false: use OGRPoint)", false);
@@ -41,6 +44,7 @@ int main(int argc, char *argv[])
   try{
     doProcess=input_opt.retrieveOption(argc,argv);
     output_opt.retrieveOption(argc,argv);
+    ogrformat_opt.retrieveOption(argc,argv);
     colX_opt.retrieveOption(argc,argv);
     colY_opt.retrieveOption(argc,argv);
     polygon_opt.retrieveOption(argc,argv);
@@ -97,7 +101,7 @@ int main(int argc, char *argv[])
   }
   
   ImgWriterOgr imgWriter;
-  imgWriter.open(output_opt[0]);
+  imgWriter.open(output_opt[0],ogrformat_opt[0]);
   try{
     if(polygon_opt[0])
       imgWriter.ascii2ogr(input_opt[0], "New Layer", fname_opt, ftype, colX_opt[0], colY_opt[0], theProjection, wkbPolygon, fs_opt[0]);
diff --git a/src/apps/pkclassify_nn.cc b/src/apps/pkclassify_nn.cc
index 7134308..5f56f2a 100644
--- a/src/apps/pkclassify_nn.cc
+++ b/src/apps/pkclassify_nn.cc
@@ -30,6 +30,8 @@ along with pktools.  If not, see <http://www.gnu.org/licenses/>.
 #include "floatfann.h"
 #include "myfann_cpp.h"
 
+using namespace std;
+
 int main(int argc, char *argv[])
 {
   vector<double> priors;
@@ -69,6 +71,7 @@ int main(int argc, char *argv[])
   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"); 
   Optionpk<string> active_opt("active", "active", "ogr output for active training sample."); 
+  Optionpk<string> ogrformat_opt("f", "f", "Output ogr format for active training sample","ESRI Shapefile");
   Optionpk<unsigned int> nactive_opt("na", "nactive", "number of active training points",1);
   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 class opt)."); 
@@ -110,6 +113,7 @@ int main(int argc, char *argv[])
     prob_opt.retrieveOption(argc,argv);
     entropy_opt.retrieveOption(argc,argv);
     active_opt.retrieveOption(argc,argv);
+    ogrformat_opt.retrieveOption(argc,argv);
     nactive_opt.retrieveOption(argc,argv);
     classname_opt.retrieveOption(argc,argv);
     classvalue_opt.retrieveOption(argc,argv);
@@ -145,7 +149,7 @@ int main(int argc, char *argv[])
   ImgWriterOgr activeWriter;
   if(active_opt.size()){
     ImgReaderOgr trainingReader(training_opt[0]);
-    activeWriter.open(active_opt[0]);
+    activeWriter.open(active_opt[0],ogrformat_opt[0]);
     activeWriter.createLayer(active_opt[0],trainingReader.getProjection(),wkbPoint,NULL);
     activeWriter.copyFields(trainingReader);
   }
diff --git a/src/apps/pkclassify_svm.cc b/src/apps/pkclassify_svm.cc
index 9a0426e..95c6f8a 100644
--- a/src/apps/pkclassify_svm.cc
+++ b/src/apps/pkclassify_svm.cc
@@ -40,6 +40,8 @@ namespace svm{
 
 #define Malloc(type,n) (type *)malloc((n)*sizeof(type))
 
+using namespace std;
+
 int main(int argc, char *argv[])
 {
   vector<double> priors;
@@ -85,6 +87,7 @@ int main(int argc, char *argv[])
   Optionpk<string> prob_opt("prob", "prob", "probability image."); 
   Optionpk<string> entropy_opt("entropy", "entropy", "entropy image (measure for uncertainty of classifier output"); 
   Optionpk<string> active_opt("active", "active", "ogr output for active training sample."); 
+  Optionpk<string> ogrformat_opt("f", "f", "Output ogr format for active training sample","ESRI Shapefile");
   Optionpk<unsigned int> nactive_opt("na", "nactive", "number of active training points",1);
   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 class opt)."); 
@@ -131,6 +134,7 @@ int main(int argc, char *argv[])
     prob_opt.retrieveOption(argc,argv);
     entropy_opt.retrieveOption(argc,argv);
     active_opt.retrieveOption(argc,argv);
+    ogrformat_opt.retrieveOption(argc,argv);
     nactive_opt.retrieveOption(argc,argv);
     classname_opt.retrieveOption(argc,argv);
     classvalue_opt.retrieveOption(argc,argv);
@@ -180,7 +184,7 @@ int main(int argc, char *argv[])
   if(active_opt.size()){
     prob_est_opt[0]=true;
     ImgReaderOgr trainingReader(training_opt[0]);
-    activeWriter.open(active_opt[0]);
+    activeWriter.open(active_opt[0],ogrformat_opt[0]);
     activeWriter.createLayer(active_opt[0],trainingReader.getProjection(),wkbPoint,NULL);
     activeWriter.copyFields(trainingReader);
   }
diff --git a/src/apps/pkdiff.cc b/src/apps/pkdiff.cc
index 4c6d011..23d4139 100644
--- a/src/apps/pkdiff.cc
+++ b/src/apps/pkdiff.cc
@@ -25,11 +25,14 @@ along with pktools.  If not, see <http://www.gnu.org/licenses/>.
 #include "Optionpk.h"
 #include "algorithms/ConfusionMatrix.h"
 
+using namespace std;
+
 int main(int argc, char *argv[])
 {
   Optionpk<string> input_opt("i", "input", "Input 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> ogrformat_opt("f", "f", "Output sample file format","ESRI Shapefile");
   Optionpk<string> mask_opt("m", "mask", "Mask image file. A single mask is supported only, but several mask values can be used. See also msknodata 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)");
@@ -53,6 +56,7 @@ int main(int argc, char *argv[])
   try{
     doProcess=input_opt.retrieveOption(argc,argv);
     output_opt.retrieveOption(argc,argv);
+    ogrformat_opt.retrieveOption(argc,argv);
     option_opt.retrieveOption(argc,argv);
     reference_opt.retrieveOption(argc,argv);
     mask_opt.retrieveOption(argc,argv);
@@ -216,7 +220,7 @@ int main(int argc, char *argv[])
             cout << "creating output vector file " << output_opt[0] << endl;
           assert(output_opt[0].find(".shp")!=string::npos);
           try{
-            ogrWriter.open(output_opt[iref]);
+            ogrWriter.open(output_opt[iref],ogrformat_opt[0]);
           }
           catch(string error){
             cerr << error << endl;
diff --git a/src/apps/pkdumpimg.cc b/src/apps/pkdumpimg.cc
index 2ce93f4..22f16ff 100644
--- a/src/apps/pkdumpimg.cc
+++ b/src/apps/pkdumpimg.cc
@@ -23,13 +23,16 @@ along with pktools.  If not, see <http://www.gnu.org/licenses/>.
 #include <iostream>
 #include <assert.h>
 #include "Optionpk.h"
+#include "imageclasses/ImgReaderOgr.h"
 #include "imageclasses/ImgWriterGdal.h"
-#include "imageclasses/ImgWriterOgr.h"
+// #include "imageclasses/ImgWriterOgr.h"
 
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
 
+using namespace std;
+
 int main(int argc, char *argv[])
 {
   Optionpk<std::string> input_opt("i","input","input image file","");
diff --git a/src/apps/pkdumpogr.cc b/src/apps/pkdumpogr.cc
index 42b30e1..4cf6eff 100644
--- a/src/apps/pkdumpogr.cc
+++ b/src/apps/pkdumpogr.cc
@@ -70,7 +70,7 @@ int main(int argc, char *argv[])
     vector<double> yvector;
     if(inputReader.getGeometryType()==wkbPoint)
       inputReader.readXY(xvector,yvector);
-    Vector2d<double> theData(attribute_opt.size());
+    Vector2d<std::string> theData(attribute_opt.size());
     for(int ifield=0;ifield<attribute_opt.size();++ifield){
       if(verbose_opt[0])
         cout << "field: " << ifield << endl;
diff --git a/src/apps/pkeditogr.cc b/src/apps/pkeditogr.cc
index 10ef0ce..44158ac 100644
--- a/src/apps/pkeditogr.cc
+++ b/src/apps/pkeditogr.cc
@@ -25,10 +25,13 @@ along with pktools.  If not, see <http://www.gnu.org/licenses/>.
 #include "imageclasses/ImgReaderGdal.h"
 #include "imageclasses/ImgWriterGdal.h"
 
+using namespace std;
+
 int main(int argc, char *argv[])
 {
-  Optionpk<string> input_opt("i", "input", "Input image");
-  Optionpk<string> output_opt("o", "output", "Output mask file");
+  Optionpk<string> input_opt("i", "input", "Input vector file");
+  Optionpk<string> output_opt("o", "output", "Output vector file");
+  Optionpk<string> ogrformat_opt("f", "f", "Output OGR file format","ESRI Shapefile");
   Optionpk<string> selectField_opt("select", "select", "select field (combined with like opt)");
   Optionpk<string> like_opt("like", "like", "substring(s) to be found in select field. If multiple substrings are provided, feature will be selected if one of them is found (stringent option must be false)");
   Optionpk<bool> stringent_opt("st", "stringent", "string in like option must exactly match to select feature)",false);
@@ -47,6 +50,7 @@ int main(int argc, char *argv[])
   try{
     doProcess=input_opt.retrieveOption(argc,argv);
     output_opt.retrieveOption(argc,argv);
+    ogrformat_opt.retrieveOption(argc,argv);
     selectField_opt.retrieveOption(argc,argv);
     like_opt.retrieveOption(argc,argv);
     stringent_opt.retrieveOption(argc,argv);
@@ -67,6 +71,14 @@ 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()){
+    std::cerr << "No input file provided (use option -i). Use --help for help information";
+      exit(0);//help was invoked, stop processing
+  }
+  if(output_opt.empty()){
+    std::cerr << "No output file provided (use option -o). Use --help for help information";
+      exit(0);//help was invoked, stop processing
+  }
   if(verbose_opt[0])
     cout << "opening " << input_opt[0] << " for reading " << endl;
   ImgReaderOgr ogrReader(input_opt[0]);
@@ -96,7 +108,7 @@ int main(int argc, char *argv[])
   if(verbose_opt[0])
     cout << "going through features" << endl << flush;
 
-  ImgWriterOgr ogrWriter(output_opt[0]);
+  ImgWriterOgr ogrWriter(output_opt[0],ogrformat_opt[0]);
   OGRLayer* writeLayer=ogrWriter.createLayer(output_opt[0],ogrReader.getProjection(),ogrReader.getGeometryType(),NULL);
   std::vector<OGRFieldDefn*> readFields;
   std::vector<OGRFieldDefn*> writeFields;
@@ -139,7 +151,12 @@ int main(int argc, char *argv[])
     std::cout << std::endl;
     std::cout << addname_opt.size() << " fields created" << std::endl;
   }
+  const char* pszMessage;
+  void* pProgressArg=NULL;
+  GDALProgressFunc pfnProgress=GDALTermProgress;
+  double progress=0;
   OGRFeature *poFeature;
+  unsigned long int nfeature=ogrReader.getFeatureCount();
   while((poFeature = ogrReader.getLayer()->GetNextFeature()) != NULL ){
     if(verbose_opt[0])
       std::cout << "feature " << ifeature << std::endl;
@@ -148,6 +165,7 @@ int main(int argc, char *argv[])
     if(like_opt.empty())
       doSelect=true;
     else{
+      assert(selectField_opt.size());
       int fieldIndex=poFeature->GetFieldIndex(selectField_opt[0].c_str());
       string fieldValue=poFeature->GetFieldAsString(fieldIndex);
       if(stringent_opt[0]){
@@ -247,6 +265,8 @@ int main(int argc, char *argv[])
     }
     OGRFeature::DestroyFeature( poFeature );
     OGRFeature::DestroyFeature( poDstFeature );
+    progress=static_cast<float>(ifeature+1)/nfeature;
+    pfnProgress(progress,pszMessage,pProgressArg);
   }
   if(verbose_opt[0])
     std::cout << "replaced " << ifeature << " features" << std::endl;
diff --git a/src/apps/pkextract.cc b/src/apps/pkextract.cc
index 8d3eb51..40bb55b 100644
--- a/src/apps/pkextract.cc
+++ b/src/apps/pkextract.cc
@@ -37,6 +37,8 @@ namespace rule{
   enum RULE_TYPE {point=0, mean=1, proportion=2, custom=3, minimum=4, maximum=5, maxvote=6, centroid=7};
 }
 
+using namespace std;
+
 int main(int argc, char *argv[])
 {
   Optionpk<string> image_opt("i", "image", "Input image file");
@@ -45,6 +47,7 @@ int main(int argc, char *argv[])
   Optionpk<int> msknodata_opt("msknodata", "msknodata", "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> ogrformat_opt("f", "f", "Output sample file format","ESRI Shapefile");
   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");
@@ -73,6 +76,7 @@ int main(int argc, char *argv[])
     msknodata_opt.retrieveOption(argc,argv);
     class_opt.retrieveOption(argc,argv);
     output_opt.retrieveOption(argc,argv);
+    ogrformat_opt.retrieveOption(argc,argv);
     test_opt.retrieveOption(argc,argv);
     keepFeatures_opt.retrieveOption(argc,argv);
     bufferOutput_opt.retrieveOption(argc,argv);
@@ -130,15 +134,15 @@ int main(int argc, char *argv[])
   ImgReaderGdal imgReader;
   if(image_opt.empty()){
     std::cerr << "No image file provided (use option -i). Use --help for help information";
-      exit(0);//help was invoked, stop processing
+      exit(0);
   }
   if(output_opt.empty()){
     std::cerr << "No output file provided (use option -o). Use --help for help information";
-      exit(0);//help was invoked, stop processing
+      exit(0);
   }
   if(sample_opt.empty()){
     std::cerr << "No sample file provided (use option -s). Use --help for help information";
-    exit(0);//help was invoked, stop processing
+    exit(0);
   }
   try{
     imgReader.open(image_opt[0]);
@@ -436,7 +440,7 @@ int main(int argc, char *argv[])
         assert(ntotalvalid==writeBuffer.size());
         if(verbose_opt[0]>0)
           std::cout << "creating image sample writer " << output_opt[0] << " with " << writeBuffer.size() << " samples (" << ntotalinvalid << " invalid)" << std::endl;
-        ogrWriter.open(output_opt[0]);
+        ogrWriter.open(output_opt[0],ogrformat_opt[0]);
         char     **papszOptions=NULL;
         ostringstream slayer;
         slayer << "training data";
@@ -684,7 +688,7 @@ int main(int argc, char *argv[])
         assert(ntotalvalid==writeBuffer.size());
         if(verbose_opt[0]>0)
           std::cout << "creating image sample writer " << output_opt[0] << " with " << writeBuffer.size() << " samples (" << ntotalinvalid << " invalid)" << std::endl;
-        ogrWriter.open(output_opt[0]);
+        ogrWriter.open(output_opt[0],ogrformat_opt[0]);
         char     **papszOptions=NULL;
         ostringstream slayer;
         slayer << "training data";
@@ -756,9 +760,9 @@ int main(int argc, char *argv[])
         std::cout << "creating image sample writer " << output_opt[0] << std::endl;
       ImgWriterOgr ogrWriter;
       ImgWriterOgr ogrTestWriter;
-      ogrWriter.open(output_opt[0]);
+      ogrWriter.open(output_opt[0],ogrformat_opt[0]);
       if(test_opt.size())
-	 ogrTestWriter.open(test_opt[0]);
+	ogrTestWriter.open(test_opt[0],ogrformat_opt[0]);
       char     **papszOptions=NULL;
       ostringstream slayer;
       slayer << "training data";
@@ -2394,6 +2398,8 @@ int main(int argc, char *argv[])
       if(test_opt.size())
 	ogrTestWriter.close();
     }
+  progress=1.0;
+  pfnProgress(progress,pszMessage,pProgressArg);
   imgReader.close();
 }
   
diff --git a/src/apps/pkfs_nn.cc b/src/apps/pkfs_nn.cc
index eba12e4..99bbb48 100644
--- a/src/apps/pkfs_nn.cc
+++ b/src/apps/pkfs_nn.cc
@@ -22,10 +22,10 @@ along with pktools.  If not, see <http://www.gnu.org/licenses/>.
 #include <map>
 #include <algorithm>
 #include "floatfann.h"
-#include "imageclasses/ImgReaderGdal.h"
-#include "imageclasses/ImgWriterGdal.h"
 #include "imageclasses/ImgReaderOgr.h"
-#include "imageclasses/ImgWriterOgr.h"
+// #include "imageclasses/ImgReaderGdal.h"
+// #include "imageclasses/ImgWriterGdal.h"
+// #include "imageclasses/ImgWriterOgr.h"
 #include "base/Optionpk.h"
 #include "algorithms/myfann_cpp.h"
 #include "algorithms/ConfusionMatrix.h"
@@ -35,6 +35,8 @@ along with pktools.  If not, see <http://www.gnu.org/licenses/>.
 #include <config.h>
 #endif
 
+using namespace std;
+
 #define Malloc(type,n) (type *)malloc((n)*sizeof(type))
 
 enum SelectorValue  { NA=0, SFFS=1, SFS=2, SBS=3, BFS=4 };
diff --git a/src/apps/pkgetmask.cc b/src/apps/pkgetmask.cc
index 041dd58..d7ecda2 100644
--- a/src/apps/pkgetmask.cc
+++ b/src/apps/pkgetmask.cc
@@ -143,6 +143,9 @@ int main(int argc,char **argv) {
     imgReader.getGeoTransform(gt);
     imgWriter.setGeoTransform(gt);//ulx,uly,imgReader.getDeltaX(),imgReader.getDeltaY(),0,0);
   }
+  if(nodata_opt.size())
+      imgWriter.GDALSetNoDataValue(nodata_opt[0]);
+
   vector<char> writeBuffer(imgWriter.nrOfCol());
   for(int irow=0;irow<imgReader.nrOfRow();++irow){
     for(int iband=0;iband<band_opt.size();++iband)
diff --git a/src/apps/pkpolygonize.cc b/src/apps/pkpolygonize.cc
index 04160a5..5eece54 100644
--- a/src/apps/pkpolygonize.cc
+++ b/src/apps/pkpolygonize.cc
@@ -37,9 +37,10 @@ extern "C" {
 using namespace std;
 
 int main(int argc,char **argv) {
-  Optionpk<string> input_opt("i", "input", "Input image file (WARNING: will be overwritten with output!", "");
-  Optionpk<string> mask_opt("m", "mask", "All pixels in the mask band with a value other than zero will be considered suitable for collection as polygons. Use input file as mask to remove background polygon! ", "");
-  Optionpk<string> output_opt("o", "output", "Output vector file", "");
+  Optionpk<string> input_opt("i", "input", "Input image file (WARNING: will be overwritten with output!");
+  Optionpk<string> mask_opt("m", "mask", "All pixels in the mask band with a value other than zero will be considered suitable for collection as polygons. Use input file as mask to remove background polygon! ");
+  Optionpk<string> output_opt("o", "output", "Output vector file");
+  Optionpk<string> ogrformat_opt("f", "f", "Output OGR file format","ESRI Shapefile");
   Optionpk<int> band_opt("b", "band", "the band to be used from input file", 0);
   Optionpk<string> fname_opt("n", "name", "the field name of the output layer", "DN");
   Optionpk<short> verbose_opt("v", "verbose", "verbose mode if > 0", 0);
@@ -49,6 +50,7 @@ int main(int argc,char **argv) {
     doProcess=input_opt.retrieveOption(argc,argv);
     mask_opt.retrieveOption(argc,argv);
     output_opt.retrieveOption(argc,argv);
+    ogrformat_opt.retrieveOption(argc,argv);
     band_opt.retrieveOption(argc,argv);
     fname_opt.retrieveOption(argc,argv);
     verbose_opt.retrieveOption(argc,argv);
@@ -61,6 +63,14 @@ 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()){
+    std::cerr << "No input file provided (use option -i). Use --help for help information";
+      exit(0);
+  }
+  if(output_opt.empty()){
+    std::cerr << "No output file provided (use option -o). Use --help for help information";
+      exit(0);
+  }
 
   GDALAllRegister();
 
@@ -73,7 +83,7 @@ int main(int argc,char **argv) {
 
   ImgReaderGdal maskReader;
   GDALRasterBand *maskBand=NULL;
-  if(mask_opt[0]!=""){
+  if(mask_opt.size()){
     if(verbose_opt[0])
       cout << "opening mask file " << mask_opt[0] << endl;
     maskReader.open(mask_opt[0]);
@@ -84,7 +94,7 @@ int main(int argc,char **argv) {
   GDALRasterBand  *inputBand;
   inputBand=inputReader.getRasterBand(0);
 
-  ImgWriterOgr ogrWriter(output_opt[0]);
+  ImgWriterOgr ogrWriter(output_opt[0],ogrformat_opt[0]);
   OGRLayer* theLayer=ogrWriter.createLayer(output_opt[0].substr(output_opt[0].rfind('/')+1), inputReader.getProjectionRef());
   if(verbose_opt[0])
     cout << "projection: " << inputReader.getProjection() << endl;
@@ -104,7 +114,7 @@ int main(int argc,char **argv) {
   cout << "number of features: " << OGR_L_GetFeatureCount(hOutLayer,TRUE) << endl;
   
   inputReader.close();
-  if(mask_opt[0]!="")
+  if(mask_opt.size())
     maskReader.close();
   ogrWriter.close();
 }
diff --git a/src/apps/pksieve.cc b/src/apps/pksieve.cc
index 576e97b..7d373a5 100644
--- a/src/apps/pksieve.cc
+++ b/src/apps/pksieve.cc
@@ -22,7 +22,7 @@ along with pktools.  If not, see <http://www.gnu.org/licenses/>.
 #include "gdal.h"
 #include "imageclasses/ImgReaderGdal.h"
 #include "imageclasses/ImgWriterGdal.h"
-#include "imageclasses/ImgWriterOgr.h"
+// #include "imageclasses/ImgWriterOgr.h"
 #include "base/Optionpk.h"
 #include "ogrsf_frmts.h"
 extern "C" {
@@ -40,7 +40,6 @@ int main(int argc,char **argv) {
   Optionpk<int> connect_opt("c", "connect", "the connectedness: 4 directions or 8 directions", 8);
   Optionpk<int> size_opt("s", "size", "raster polygons with sizes smaller than this will be merged into their largest neighbour. No sieve is performed if size = 0", 0);
   Optionpk<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<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);
@@ -54,7 +53,6 @@ int main(int argc,char **argv) {
     connect_opt.retrieveOption(argc,argv);
     size_opt.retrieveOption(argc,argv);
     otype_opt.retrieveOption(argc,argv);
-    oformat_opt.retrieveOption(argc,argv);
     option_opt.retrieveOption(argc,argv);
     colorTable_opt.retrieveOption(argc,argv);
     verbose_opt.retrieveOption(argc,argv);
diff --git a/src/imageclasses/ImgReaderOgr.cc b/src/imageclasses/ImgReaderOgr.cc
index ff901cb..c0d8671 100644
--- a/src/imageclasses/ImgReaderOgr.cc
+++ b/src/imageclasses/ImgReaderOgr.cc
@@ -197,7 +197,7 @@ std::ostream& operator<<(std::ostream& theOstream, ImgReaderOgr& theImageReader)
       theOstream << x << " " << y;
     for(fit=vfields.begin();fit!=vfields.end();++fit)
       theOstream << " " << *fit;
-    theOstream << endl;
+    theOstream << std::endl;
     ++ifeature;
   }
   return(theOstream);
@@ -239,7 +239,7 @@ unsigned int ImgReaderOgr::readDataImageShape(std::map<std::string,Vector2d<floa
       if(verbose)
         std::cout << *fit << " ";
       // size_t pos=(*fit).find_first_not_of("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_ ");
-      if((*fit).substr(0,1)=="B"){
+      if((*fit).substr(0,1)=="B"||(*fit).substr(0,1)=="b"){
 	if((*fit).substr(1).find_first_not_of("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_ ")!=std::string::npos){
 	  int theBand=atoi((*fit).substr(1).c_str());
 	  if(bands.size()){
@@ -256,7 +256,7 @@ unsigned int ImgReaderOgr::readDataImageShape(std::map<std::string,Vector2d<floa
 	  else
 	    ++fit;
 	}
-	else if((*fit)=="B" || (*fit)=="Band")//B is only band
+	else if((*fit)=="B" || (*fit)=="b" || (*fit)=="Band")//B is only band
 	  ++fit;
       }
       else
@@ -316,7 +316,7 @@ unsigned int ImgReaderOgr::readDataImageShape(std::map<std::string,Vector2d<floa
       if(verbose)
         std::cout << *fit << " ";
       // size_t pos=(*fit).find_first_not_of("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_ ");
-      if((*fit).substr(0,1)=="B"){
+      if((*fit).substr(0,1)=="B"||(*fit).substr(0,1)=="b"){
 	if((*fit).substr(1).find_first_not_of("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_ ")!=std::string::npos){
 	  int iband=atoi((*fit).substr(1).c_str());
 	  if((start||end)&&(iband<start||iband>end))
@@ -324,7 +324,7 @@ unsigned int ImgReaderOgr::readDataImageShape(std::map<std::string,Vector2d<floa
 	  else
 	    ++fit;
 	}
-	else if(*fit=="B" || *fit=="Band")
+	else if(*fit=="B" || *fit=="b"|| *fit=="Band")
 	  ++fit;
       }
       else
diff --git a/src/imageclasses/ImgReaderOgr.h b/src/imageclasses/ImgReaderOgr.h
index 171bcfb..0906527 100644
--- a/src/imageclasses/ImgReaderOgr.h
+++ b/src/imageclasses/ImgReaderOgr.h
@@ -503,7 +503,7 @@ template <typename T> int ImgReaderOgr::readData(std::vector<T>& data, const OGR
 }
 
 //read one field from all features
-template <typename T> int ImgReaderOgr::readData(std::vector<T>& data, const OGRFieldType& fieldType, const std::string& theField, int layer, bool verbose)
+template <typename T> inline int ImgReaderOgr::readData(std::vector<T>& data, const OGRFieldType& fieldType, const std::string& theField, int layer, bool verbose)
 {
   if(layer<0)
     layer=m_datasource->GetLayerCount()-1;
@@ -578,6 +578,82 @@ template <typename T> int ImgReaderOgr::readData(std::vector<T>& data, const OGR
   }
 }
 
+//specialization for string: read one field from all features
+template <> inline int ImgReaderOgr::readData(std::vector<std::string>& data, const OGRFieldType& fieldType, const std::string& theField, int layer, bool verbose)
+{
+  if(layer<0)
+    layer=m_datasource->GetLayerCount()-1;
+  assert(m_datasource->GetLayerCount()>layer);
+  OGRLayer  *poLayer;
+  if(verbose)
+    std::cout << "number of layers: " << m_datasource->GetLayerCount() << std::endl;
+  poLayer = m_datasource->GetLayer(layer);
+  OGRFeatureDefn *poFDefn = poLayer->GetLayerDefn();
+  int nfield=(theField!="")? poFDefn->GetFieldCount() : 1;
+  if(theField==""){
+    //read first field available 
+    if(verbose)
+      std::cout << "read first field from total of " << nfield << std::endl;
+  }
+
+  //start reading features from the layer
+  OGRFeature *poFeature;
+  if(verbose)
+    std::cout << "reset reading" << std::endl;
+  poLayer->ResetReading();
+  unsigned long int ifeature=0;
+  if(verbose)
+    std::cout << "going through features" << std::endl << std::flush;
+  while( (poFeature = poLayer->GetNextFeature()) != NULL ){
+    std::string theFeature;
+    if(verbose)
+      std::cout << "reading feature " << ifeature << std::endl << std::flush;
+    OGRGeometry *poGeometry;
+    poGeometry = poFeature->GetGeometryRef();
+    if(verbose){
+      if(poGeometry == NULL)
+        std::cerr << "no geometry defined" << std::endl << std::flush;
+      else// if(wkbFlatten(poGeometry->getGeometryType()) != wkbPoint)
+        std::cout << "poGeometry type: " << wkbFlatten(poGeometry->getGeometryType()) << std::endl;
+    }
+    // assert(poGeometry != NULL 
+    //        && wkbFlatten(poGeometry->getGeometryType()) == wkbPoint);
+    OGRPoint *poPoint = (OGRPoint *) poGeometry;
+
+    for(int iField=0;iField<nfield;++iField){
+      OGRFieldDefn *poFieldDefn = poFDefn->GetFieldDefn(iField);
+      std::string fieldname=poFieldDefn->GetNameRef();
+      if(fieldname!=theField)
+        continue;
+      switch(fieldType){
+      case(OFTInteger):
+      case(OFTReal):
+      case(OFTString):
+        theFeature=poFeature->GetFieldAsString(iField);
+      break;
+      default:
+        {
+          std::string errorstring="field type not supported in ImgReaderOgr::ReadData";
+          throw(errorstring);
+        }
+        break;
+      }
+    }
+    data.push_back(theFeature);
+    if(verbose)
+      std::cout << "feature is: " << theFeature << std::endl;
+    ++ifeature;
+  }
+  if(data.size()){
+    return data.size();
+  }
+  else{
+    std::ostringstream ess;
+    ess << "no layer in " << m_filename;
+    throw(ess.str());
+  }
+}
+
 //read data from all features  
 template <typename T> int ImgReaderOgr::readData(Vector2d<T>& data, const OGRFieldType& fieldType, std::vector<std::string>& fields, int layer, bool pos, bool verbose)
 {
diff --git a/src/imageclasses/ImgWriterOgr.cc b/src/imageclasses/ImgWriterOgr.cc
index 15172d9..15b769c 100644
--- a/src/imageclasses/ImgWriterOgr.cc
+++ b/src/imageclasses/ImgWriterOgr.cc
@@ -32,12 +32,12 @@ ImgWriterOgr::~ImgWriterOgr(void)
 {
 }
 
-ImgWriterOgr::ImgWriterOgr(const string& filename)
+ImgWriterOgr::ImgWriterOgr(const std::string& filename, const std::string& imageType)
 {
-  open(filename);
+  open(filename,imageType);
 }
 
-ImgWriterOgr::ImgWriterOgr(const string& filename, ImgReaderOgr& imgReaderOgr)
+ImgWriterOgr::ImgWriterOgr(const std::string& filename, ImgReaderOgr& imgReaderOgr)
 {
   m_filename=filename;
   setCodec(imgReaderOgr.getDriver());
@@ -45,7 +45,7 @@ ImgWriterOgr::ImgWriterOgr(const string& filename, ImgReaderOgr& imgReaderOgr)
   copyFields(imgReaderOgr);
 }
 
-ImgWriterOgr::ImgWriterOgr(const string& filename, ImgReaderOgr& imgReaderOgr, bool copyData)
+ImgWriterOgr::ImgWriterOgr(const std::string& filename, ImgReaderOgr& imgReaderOgr, bool copyData)
 {
   CPLErrorReset();
   m_filename=filename;
@@ -64,7 +64,7 @@ ImgWriterOgr::ImgWriterOgr(const string& filename, ImgReaderOgr& imgReaderOgr, b
 //       poDstFeature = OGRFeature::CreateFeature(m_datasource->GetLayer(m_datasource->GetLayerCount()-1)->GetLayerDefn());
       if( poDstFeature->SetFrom( poFeature, TRUE ) != OGRERR_NONE ){
 	const char* fmt;
-	string errorString="Unable to translate feature %d from layer %s.\n";
+	std::string errorString="Unable to translate feature %d from layer %s.\n";
 	fmt=errorString.c_str();
         CPLError( CE_Failure, CPLE_AppDefined,
                   fmt,
@@ -82,7 +82,7 @@ ImgWriterOgr::ImgWriterOgr(const string& filename, ImgReaderOgr& imgReaderOgr, b
       CPLErrorReset();
       if(createFeature( poDstFeature ) != OGRERR_NONE){
 	const char* fmt;
-	string errorString="Unable to translate feature %d from layer %s.\n";
+	std::string errorString="Unable to translate feature %d from layer %s.\n";
 	fmt=errorString.c_str();
         CPLError( CE_Failure, CPLE_AppDefined,
 		  fmt,
@@ -96,7 +96,7 @@ ImgWriterOgr::ImgWriterOgr(const string& filename, ImgReaderOgr& imgReaderOgr, b
 
 //---------------------------------------------------------------------------
 
-void ImgWriterOgr::open(const string& filename, ImgReaderOgr& imageReader)
+void ImgWriterOgr::open(const std::string& filename, ImgReaderOgr& imageReader)
 {
   m_filename=filename;
   setCodec(imageReader.getDriver());
@@ -104,7 +104,7 @@ void ImgWriterOgr::open(const string& filename, ImgReaderOgr& imageReader)
   copyFields(imageReader);
 }
 
-void ImgWriterOgr::open(const string& filename, const string& imageType)
+void ImgWriterOgr::open(const std::string& filename, const std::string& imageType)
 {
   m_filename = filename;
   setCodec(imageType);
@@ -117,20 +117,20 @@ void ImgWriterOgr::close(void)
 }
 
 //---------------------------------------------------------------------------
-void ImgWriterOgr::setCodec(const string& imageType){
+void ImgWriterOgr::setCodec(const std::string& imageType){
   //register the drivers
   OGRRegisterAll();
   //fetch the shape file driver
   OGRSFDriver *poDriver;
   poDriver = OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(imageType.c_str());
   if( poDriver == NULL ){
-    string errorString="FileOpenError";
+    std::string errorString="FileOpenError";
     throw(errorString);
   }
   //create the data source
   m_datasource=poDriver->CreateDataSource(m_filename.c_str(),NULL);
   if(m_datasource==NULL){
-    string errorString="Creation of output file failed";
+    std::string errorString="Creation of output file failed";
     throw(errorString);
   }
 }
@@ -138,26 +138,26 @@ void ImgWriterOgr::setCodec(const string& imageType){
 void ImgWriterOgr::setCodec(OGRSFDriver *poDriver){
   OGRRegisterAll();
   if( poDriver == NULL ){
-    string errorString="FileOpenError";
+    std::string errorString="FileOpenError";
     throw(errorString);
   }
   //create the data source
   m_datasource=poDriver->CreateDataSource(m_filename.c_str(),NULL);
   if(m_datasource==NULL){
-    string errorString="Creation of output file failed";
+    std::string errorString="Creation of output file failed";
     throw(errorString);
   }
 }
 
-// OGRLayer* ImgWriterOgr::copyLayer(OGRLayer* poSrcLayer, const string& layername, char** papszOptions)
+// OGRLayer* ImgWriterOgr::copyLayer(OGRLayer* poSrcLayer, const std::string& layername, char** papszOptions)
 // {
 //   return(m_datasource->CopyLayer(poSrcLayer, layername.c_str(),papszOptions));
 // }
 
-OGRLayer* ImgWriterOgr::createLayer(const string& layername, const string& theProjection, const OGRwkbGeometryType& eGType, char** papszOptions)
+OGRLayer* ImgWriterOgr::createLayer(const std::string& layername, const std::string& theProjection, const OGRwkbGeometryType& eGType, char** papszOptions)
 {
   if( !m_datasource->TestCapability( ODsCCreateLayer ) ){
-    string errorString="Test capability to create layer failed";
+    std::string errorString="Test capability to create layer failed";
     throw(errorString);
   }
   //papszOptions = CSLSetNameValue( papszOptions, "DIM", "1" );
@@ -165,7 +165,7 @@ OGRLayer* ImgWriterOgr::createLayer(const string& layername, const string& thePr
   //if no constraints on the types geometry to be written: use wkbUnknown 
   OGRLayer* poLayer;
   if(theProjection!=""){
-    if(theProjection.find("EPSPG:")!=string::npos){
+    if(theProjection.find("EPSPG:")!=std::string::npos){
       int epsg_code=atoi(theProjection.substr(theProjection.find_first_not_of("EPSG:")).c_str());
       OGRSpatialReference oSRS;
       oSRS.importFromEPSG(epsg_code);
@@ -181,14 +181,14 @@ OGRLayer* ImgWriterOgr::createLayer(const string& layername, const string& thePr
   //check if destroy is needed?!
   CSLDestroy( papszOptions );
   if( poLayer == NULL ){
-    string errorstring="Layer creation failed";
+    std::string errorstring="Layer creation failed";
     throw(errorstring);
   }
   OGRFeatureDefn *poFDefn = poLayer->GetLayerDefn();
   return poLayer;
 }
 
-void ImgWriterOgr::createField(const string& fieldname, const OGRFieldType& fieldType, int theLayer)
+void ImgWriterOgr::createField(const std::string& fieldname, const OGRFieldType& fieldType, int theLayer)
 {
   OGRFieldDefn oField( fieldname.c_str(), fieldType );
   if(fieldType==OFTString)
@@ -196,21 +196,21 @@ void ImgWriterOgr::createField(const string& fieldname, const OGRFieldType& fiel
   if(theLayer<0)
     theLayer=m_datasource->GetLayerCount()-1;//get back layer
   if(m_datasource->GetLayer(theLayer)->CreateField( &oField ) != OGRERR_NONE ){
-      ostringstream es;
+      std::ostringstream es;
       es << "Creating field " << fieldname << " failed";
-      string errorString=es.str();
+      std::string errorString=es.str();
       throw(errorString);
   }
 }
 
-int ImgWriterOgr::getFields(vector<string>& fields, int layer) const
+int ImgWriterOgr::getFields(std::vector<std::string>& fields, int layer) const
 {
   if(layer<0)
     layer=m_datasource->GetLayerCount()-1;
   assert(m_datasource->GetLayerCount()>layer);
   OGRLayer  *poLayer;
   if((poLayer = m_datasource->GetLayer(layer))==NULL){
-    string errorstring="Could not get layer";
+    std::string errorstring="Could not get layer";
     throw(errorstring);
   }
   OGRFeatureDefn *poFDefn = poLayer->GetLayerDefn();
@@ -223,14 +223,14 @@ int ImgWriterOgr::getFields(vector<string>& fields, int layer) const
   return(fields.size());
 }
 
-int ImgWriterOgr::getFields(vector<OGRFieldDefn*>& fields, int layer) const
+int ImgWriterOgr::getFields(std::vector<OGRFieldDefn*>& fields, int layer) const
 {
   if(layer<0)
     layer=m_datasource->GetLayerCount()-1;
   assert(m_datasource->GetLayerCount()>layer);
   OGRLayer  *poLayer;
   if((poLayer = m_datasource->GetLayer(layer))==NULL){
-    string errorstring="Could not get layer";
+    std::string errorstring="Could not get layer";
     throw(errorstring);
   }
   OGRFeatureDefn *poFDefn = poLayer->GetLayerDefn();
@@ -248,65 +248,65 @@ void ImgWriterOgr::copyFields(const ImgReaderOgr& imgReaderOgr, int theLayer){
   if(theLayer<0)
     theLayer=m_datasource->GetLayerCount()-1;//get back layer
   //get fields from imgReaderOgr
-  vector<OGRFieldDefn*> fields;
+  std::vector<OGRFieldDefn*> fields;
   
   imgReaderOgr.getFields(fields);
 //   OGRFeatureDefn *poFDefn = poLayer->GetLayerDefn();
   for(int iField=0;iField<fields.size();++iField){
     if(m_datasource->GetLayer(theLayer)->CreateField(fields[iField]) != OGRERR_NONE ){
-      ostringstream es;
+      std::ostringstream es;
       es << "Creating field " << fields[iField]->GetNameRef() << " failed";
-      string errorString=es.str();
+      std::string errorString=es.str();
       throw(errorString);
     }
   }
 }
 
-void ImgWriterOgr::addPoint(double x, double y, const map<string,double>& pointAttributes, string fieldName, const string& theId){
+void ImgWriterOgr::addPoint(double x, double y, const std::map<std::string,double>& pointAttributes, std::string fieldName, const std::string& theId){
   OGRFeature *poFeature;
   poFeature=createFeature();
   OGRPoint pt;
   poFeature->SetField( fieldName.c_str(), theId.c_str());
-  for(map<string,double>::const_iterator mit=pointAttributes.begin();mit!=pointAttributes.end();++mit){
+  for(std::map<std::string,double>::const_iterator mit=pointAttributes.begin();mit!=pointAttributes.end();++mit){
     poFeature->SetField((mit->first).c_str(), mit->second);
   }
   pt.setX(x);
   pt.setY(y);
   poFeature->SetGeometry( &pt );
   if(createFeature(poFeature)!=OGRERR_NONE){
-    string errorString="Failed to create feature in shapefile";
+    std::string errorString="Failed to create feature in shapefile";
     throw(errorString);
   }
   OGRFeature::DestroyFeature( poFeature );
 }
 
-void ImgWriterOgr::addPoint(double x, double y, const map<string,double>& pointAttributes, string fieldName, int theId){
+void ImgWriterOgr::addPoint(double x, double y, const std::map<std::string,double>& pointAttributes, std::string fieldName, int theId){
   OGRFeature *poFeature;
   poFeature = createFeature();
   OGRPoint pt;
   if(pointAttributes.size()+1!=poFeature->GetFieldCount()){
-    ostringstream ess;
-    ess << "Failed to add feature: " << pointAttributes.size() << " !=" << poFeature->GetFieldCount() << endl;
+    std::ostringstream ess;
+    ess << "Failed to add feature: " << pointAttributes.size() << " !=" << poFeature->GetFieldCount() << std::endl;
     throw(ess.str());
   }
   assert(pointAttributes.size()+1==poFeature->GetFieldCount());
   poFeature->SetField( fieldName.c_str(), theId);
   int fid=0;
-  for(map<string,double>::const_iterator mit=pointAttributes.begin();mit!=pointAttributes.end();++mit){
+  for(std::map<std::string,double>::const_iterator mit=pointAttributes.begin();mit!=pointAttributes.end();++mit){
     poFeature->SetField((mit->first).c_str(),mit->second);
   }
   pt.setX(x);
   pt.setY(y);
   poFeature->SetGeometry( &pt );
   if(createFeature(poFeature)!=OGRERR_NONE){
-    string errorString="Failed to create feature in shapefile";
+    std::string errorString="Failed to create feature in shapefile";
     throw(errorString);
   }
   OGRFeature::DestroyFeature( poFeature );
 }
 
-//add a line string (polygon), caller is responsible to close the line (end point=start point)
-void ImgWriterOgr::addLineString(vector<OGRPoint*>& points, const string& fieldName, int theId){
+//add a line std::string (polygon), caller is responsible to close the line (end point=start point)
+void ImgWriterOgr::addLineString(std::vector<OGRPoint*>& points, const std::string& fieldName, int theId){
   OGRFeature *poFeature;
   poFeature = createFeature();
   poFeature->SetStyleString("PEN(c:#FF0000,w:5px)");//see also http://www.gdal.org/ogr/ogr_feature_style.html
@@ -316,18 +316,18 @@ void ImgWriterOgr::addLineString(vector<OGRPoint*>& points, const string& fieldN
   for(int ip=0;ip<points.size();++ip)
     theLineString.setPoint(ip,points[ip]);
   if(poFeature->SetGeometry( &theLineString )!=OGRERR_NONE){
-    string errorString="Failed to set line OGRLineString as feature geometry";
+    std::string errorString="Failed to set line OGRLineString as feature geometry";
     throw(errorString);
   }
   if(createFeature(poFeature)!=OGRERR_NONE){
-    string errorString="Failed to create feature in shapefile";
+    std::string errorString="Failed to create feature in shapefile";
     throw(errorString);
   }
   OGRFeature::DestroyFeature( poFeature );
 }
 
 //add a ring (polygon), caller is responsible to close the line (end point=start point)?
-void ImgWriterOgr::addRing(vector<OGRPoint*>& points, const string& fieldName, int theId){
+void ImgWriterOgr::addRing(std::vector<OGRPoint*>& points, const std::string& fieldName, int theId){
   OGRFeature *poFeature;
   poFeature = createFeature();
   poFeature->SetStyleString("PEN(c:#FF0000,w:5px)");//see also http://www.gdal.org/ogr/ogr_feature_style.html
@@ -344,19 +344,19 @@ void ImgWriterOgr::addRing(vector<OGRPoint*>& points, const string& fieldName, i
   // SetSpatialFilter(&thePolygon)
   poFeature->SetGeometry( &thePolygon );
   if(createFeature(poFeature)!=OGRERR_NONE){
-    string errorString="Failed to create feature in shapefile";
+    std::string errorString="Failed to create feature in shapefile";
     throw(errorString);
     OGRFeature::DestroyFeature( poFeature );
   }
   if(poFeature->SetGeometry( &thePolygon )!=OGRERR_NONE){
-    string errorString="Failed to set polygon as feature geometry";
+    std::string errorString="Failed to set polygon as feature geometry";
     throw(errorString);
   }
   OGRFeature::DestroyFeature( poFeature );
 }
 
 //add a line string (polygon), caller is responsible to close the line (end point=start point)
-void ImgWriterOgr::addLineString(vector<OGRPoint*>& points, const string& fieldName, const string& theId){
+void ImgWriterOgr::addLineString(std::vector<OGRPoint*>& points, const std::string& fieldName, const std::string& theId){
   OGRFeature *poFeature;
   poFeature = createFeature();
   poFeature->SetField( fieldName.c_str(), theId.c_str());
@@ -365,11 +365,11 @@ void ImgWriterOgr::addLineString(vector<OGRPoint*>& points, const string& fieldN
   for(int ip=0;ip<points.size();++ip)
     theLineString.setPoint(ip,points[ip]);
   if(poFeature->SetGeometry( &theLineString )!=OGRERR_NONE){
-    string errorString="Failed to set line OGRLineString as feature geometry";
+    std::string errorString="Failed to set line OGRLineString as feature geometry";
     throw(errorString);
   }
   if(createFeature(poFeature)!=OGRERR_NONE){
-    string errorString="Failed to create feature in shapefile";
+    std::string errorString="Failed to create feature in shapefile";
     throw(errorString);
   }
   OGRFeature::DestroyFeature( poFeature );
@@ -390,7 +390,7 @@ int ImgWriterOgr::getFieldCount(int layer) const
   assert(m_datasource->GetLayerCount()>layer);
   OGRLayer  *poLayer;
   if((poLayer = m_datasource->GetLayer(layer))==NULL){
-    string errorstring="Could not get layer";
+    std::string errorstring="Could not get layer";
     throw(errorstring);
   }
   OGRFeatureDefn *poFDefn = poLayer->GetLayerDefn();
@@ -402,7 +402,7 @@ int ImgWriterOgr::getFeatureCount() const
   return(getLayer()->GetFeatureCount());
 }
 
-int ImgWriterOgr::ascii2ogr(const string& filename, const string &layername, const vector<string>& fieldName, const vector<OGRFieldType>& fieldType, short colX, short colY, const string& theProjection, const OGRwkbGeometryType& eGType, const char fs)
+int ImgWriterOgr::ascii2ogr(const std::string& filename, const std::string &layername, const std::vector<std::string>& fieldName, const std::vector<OGRFieldType>& fieldType, short colX, short colY, const std::string& theProjection, const OGRwkbGeometryType& eGType, const char fs)
 {
   char     **papszOptions=NULL;
   createLayer(layername, theProjection, eGType, papszOptions);
@@ -416,8 +416,8 @@ int ImgWriterOgr::ascii2ogr(const string& filename, const string &layername, con
     createField(fieldName[ifield],fieldType[ifield]);
   //create a local OGRFeature, set attributes and attach geometry before trying to write it to the layer. It is imperative that this feature be instantiated from the OGRFeatureDefn associated with the layer it will be written to.
   //todo: try to open and catch if failure...
-  ifstream fpoints(filename.c_str(),ios::in);
-  string line;
+  std::ifstream fpoints(filename.c_str(),std::ios::in);
+  std::string line;
   OGRPolygon thePolygon;
   OGRLinearRing theRing;
   OGRPoint firstPoint;
@@ -427,15 +427,15 @@ int ImgWriterOgr::ascii2ogr(const string& filename, const string &layername, con
 
 
   if(fs>' '&&fs<='~'){//field separator is a regular character (minimum ASCII code is space, maximum ASCII code is tilde)
-    string csvRecord;
+    std::string csvRecord;
     while(getline(fpoints,csvRecord)){//read a line
       OGRFeature *pointFeature;
       if(eGType==wkbPoint)
         pointFeature=createFeature();
       OGRPoint thePoint;
       bool skip=false;
-      istringstream csvstream(csvRecord);
-      string value;
+      std::istringstream csvstream(csvRecord);
+      std::string value;
       int colId=0;
       int fieldId=0;
       while(getline(csvstream,value,fs)){//read a column
@@ -471,14 +471,14 @@ int ImgWriterOgr::ascii2ogr(const string& filename, const string &layername, con
         ++colId;
       }
       if(colId!=fieldId+2){
-        ostringstream ess;
+        std::ostringstream ess;
         ess << "Error: colId = " << colId << " is different from fieldId+2 = " << fieldId;
         throw(ess.str());
       }
       if(eGType==wkbPoint){
         pointFeature->SetGeometry( &thePoint );
         if(createFeature(pointFeature)!=OGRERR_NONE){
-          string errorString="Failed to create feature in shapefile";
+          std::string errorString="Failed to create feature in shapefile";
           throw(errorString);
           OGRFeature::DestroyFeature( pointFeature );
         }
@@ -498,8 +498,8 @@ int ImgWriterOgr::ascii2ogr(const string& filename, const string &layername, con
         pointFeature=createFeature();
       OGRPoint thePoint;
       bool skip=false;
-      istringstream ist(line);
-      string value;
+      std::istringstream ist(line);
+      std::string value;
       int colId=0;
       int fieldId=0;
       while(ist >> value){
@@ -535,14 +535,14 @@ int ImgWriterOgr::ascii2ogr(const string& filename, const string &layername, con
         ++colId;
       }
       if(colId!=fieldId+2){
-        ostringstream ess;
+        std::ostringstream ess;
         ess << "Error: colId = " << colId << " is different from fieldId+2 = " << fieldId;
         throw(ess.str());
       }
       if(eGType==wkbPoint){
         pointFeature->SetGeometry( &thePoint );
         if(createFeature(pointFeature)!=OGRERR_NONE){
-          string errorString="Failed to create feature in shapefile";
+          std::string errorString="Failed to create feature in shapefile";
           throw(errorString);
           OGRFeature::DestroyFeature( pointFeature );
         }
@@ -561,7 +561,7 @@ int ImgWriterOgr::ascii2ogr(const string& filename, const string &layername, con
     // SetSpatialFilter(&thePolygon)
     polyFeature->SetGeometry( &thePolygon );
     if(createFeature(polyFeature)!=OGRERR_NONE){
-      string errorString="Failed to create feature in shapefile";
+      std::string errorString="Failed to create feature in shapefile";
       throw(errorString);
       OGRFeature::DestroyFeature( polyFeature );
     }
@@ -576,24 +576,24 @@ int ImgWriterOgr::addData(const ImgReaderGdal& imgReader, int theLayer, bool ver
     theLayer=m_datasource->GetLayerCount()-1;//get back layer
   assert(m_datasource->GetLayerCount()>theLayer);
   if(verbose)
-    cout << "number of layers: " << m_datasource->GetLayerCount() << endl;
+    std::cout << "number of layers: " << m_datasource->GetLayerCount() << std::endl;
   if(verbose)
-    cout << "get layer " << theLayer << endl;
+    std::cout << "get layer " << theLayer << std::endl;
   poLayer = m_datasource->GetLayer(theLayer);
   //start reading features from the layer
   OGRFeature *poFeature;
   if(verbose)
-    cout << "reset reading" << endl;
+    std::cout << "reset reading" << std::endl;
   poLayer->ResetReading();
   for(int iband=0;iband<imgReader.nrOfBand();++iband){
-    ostringstream fs;
+    std::ostringstream fs;
     fs << "band" << iband;
     createField(fs.str(),OFTReal);
   }
   OGRFeatureDefn *poFDefn = poLayer->GetLayerDefn();
   int nfield=poFDefn->GetFieldCount();
   if(verbose)
-    cout << "new number of fields: " << nfield << endl;
+    std::cout << "new number of fields: " << nfield << std::endl;
   while( (poFeature = poLayer->GetNextFeature()) != NULL ){
     OGRGeometry *poGeometry;
     poGeometry = poFeature->GetGeometryRef();
@@ -606,7 +606,7 @@ int ImgWriterOgr::addData(const ImgReaderGdal& imgReader, int theLayer, bool ver
       double imgData;
       imgReader.readData(imgData,GDT_Float64,x,y,iband);
       //todo: put imgdata in field
-      ostringstream fs;
+      std::ostringstream fs;
       fs << "band" << iband;
       poFeature->SetField(fs.str().c_str(),imgData);
     }
diff --git a/src/imageclasses/ImgWriterOgr.h b/src/imageclasses/ImgWriterOgr.h
index 004a1d7..b48099a 100644
--- a/src/imageclasses/ImgWriterOgr.h
+++ b/src/imageclasses/ImgWriterOgr.h
@@ -31,34 +31,32 @@ along with pktools.  If not, see <http://www.gnu.org/licenses/>.
 #include "ImgWriterGdal.h"
 #include "ImgReaderOgr.h"
 
-using namespace std;
-
 //--------------------------------------------------------------------------
 class ImgWriterOgr
 {
 public:
   ImgWriterOgr(void);
-  ImgWriterOgr(const string& filename);
-  ImgWriterOgr(const string& filename, ImgReaderOgr& imgReaderOgr);
-  ImgWriterOgr(const string& filename, ImgReaderOgr& imgReaderOgr, bool copyData);
+  ImgWriterOgr(const std::string& filename, const std::string& imageType="ESRI Shapefile");
+  ImgWriterOgr(const std::string& filename, ImgReaderOgr& imgReaderOgr);
+  ImgWriterOgr(const std::string& filename, ImgReaderOgr& imgReaderOgr, bool copyData);
   ~ImgWriterOgr(void);
-  void open(const string& filename, ImgReaderOgr& imgReaderOgr);
-  void open(const string& filename, const string& imageType="ESRI Shapefile");
+  void open(const std::string& filename, ImgReaderOgr& imgReaderOgr);
+  void open(const std::string& filename, const std::string& imageType="ESRI Shapefile");
   void close(void);
-  int ascii2ogr(const string& filename, const string &layername, const vector<string>& fieldName, const vector<OGRFieldType>& fieldType, short colX=1, short colY=2, const string& theProjection="", const OGRwkbGeometryType& eGType=wkbPoint, const char fs=' ');
-  OGRLayer* createLayer(const string& layername="New layer", const string& theProjection="", const OGRwkbGeometryType& eGType=wkbUnknown, char** papszOptions=NULL);
-  OGRLayer* copyLayer(OGRLayer* poSrcLayer, const string& layername, char** papszOptions=NULL);
-  void createField(const string& fieldname, const OGRFieldType& fieldType, int theLayer=-1);//default: get back layer
+  int ascii2ogr(const std::string& filename, const std::string &layername, const std::vector<std::string>& fieldName, const std::vector<OGRFieldType>& fieldType, short colX=1, short colY=2, const std::string& theProjection="", const OGRwkbGeometryType& eGType=wkbPoint, const char fs=' ');
+  OGRLayer* createLayer(const std::string& layername="New layer", const std::string& theProjection="", const OGRwkbGeometryType& eGType=wkbUnknown, char** papszOptions=NULL);
+  OGRLayer* copyLayer(OGRLayer* poSrcLayer, const std::string& layername, char** papszOptions=NULL);
+  void createField(const std::string& fieldname, const OGRFieldType& fieldType, int theLayer=-1);//default: get back layer
   OGRLayer* getLayer(int layer=0) const {return m_datasource->GetLayer(layer);};
-  string getLayerName(int layer=0){return m_datasource->GetLayer(layer)->GetLayerDefn()->GetName();};
-  int getFields(vector<string>& fields, int layer=0) const;
-  int getFields(vector<OGRFieldDefn*>& fields, int layer=0) const;
+  std::string getLayerName(int layer=0){return m_datasource->GetLayer(layer)->GetLayerDefn()->GetName();};
+  int getFields(std::vector<std::string>& fields, int layer=0) const;
+  int getFields(std::vector<OGRFieldDefn*>& fields, int layer=0) const;
   void copyFields(const ImgReaderOgr& imgReaderOgr, int theLayer=-1);//default: get back layer
-  void addLineString(vector<OGRPoint*>& points, const string& fieldName, const string& theId);
-  void addRing(vector<OGRPoint*>& points, const string& fieldName, int theId);
-  void addLineString(vector<OGRPoint*>& points, const string& fieldName, int theId);
-  void addPoint(double x, double y, const map<string,double>& pointAttributes, string fieldName, const string& theId);
-  void addPoint(double x, double y, const map<string,double>& pointAttributes, string fieldName, int theId);
+  void addLineString(std::vector<OGRPoint*>& points, const std::string& fieldName, const std::string& theId);
+  void addRing(std::vector<OGRPoint*>& points, const std::string& fieldName, int theId);
+  void addLineString(std::vector<OGRPoint*>& points, const std::string& fieldName, int theId);
+  void addPoint(double x, double y, const std::map<std::string,double>& pointAttributes, std::string fieldName, const std::string& theId);
+  void addPoint(double x, double y, const std::map<std::string,double>& pointAttributes, std::string fieldName, int theId);
   int addData(const ImgReaderGdal& imgReader, int layer=-1, bool verbose=false);
   OGRFeature* createFeature();
   OGRErr createFeature(OGRFeature* theFeature);
@@ -68,12 +66,12 @@ public:
   OGRSFDriver* getDriver(void) const {return m_datasource->GetDriver();};
 
 protected:
-  void setCodec(const string& imageType);
+  void setCodec(const std::string& imageType);
   void setCodec(OGRSFDriver *poDriver);
   
 //   OGRLayer* getLayer(int layer=-1);
     
-  string m_filename;
+  std::string m_filename;
   OGRDataSource *m_datasource;
 //   vector<OGRLayer*> m_layers;
 };

-- 
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