[pktools] 51/375: added mainpage.dox and pkeditogr.cc
Bas Couwenberg
sebastic at xs4all.nl
Wed Dec 3 21:53:57 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 599a7130815bd3296ab45411e5016e925a6a352b
Author: Pieter Kempeneers <kempenep at gmail.com>
Date: Mon Feb 4 13:26:32 2013 +0100
added mainpage.dox and pkeditogr.cc
---
Doxyfile | 2 +-
doc/createappsdox.sh | 7 +++
doc/mainpage.dox | 31 +++++++++++++
src/apps/pkeditogr.cc | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 160 insertions(+), 1 deletion(-)
diff --git a/Doxyfile b/Doxyfile
index 66e3662..568d39f 100644
--- a/Doxyfile
+++ b/Doxyfile
@@ -668,7 +668,7 @@ WARN_LOGFILE =
# directories like "/usr/src/myproject". Separate the files or directories
# with spaces.
-INPUT = doc
+INPUT =
# This tag can be used to specify the character encoding of the source files
# that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is
diff --git a/doc/createappsdox.sh b/doc/createappsdox.sh
index a125da9..d1f6985 100755
--- a/doc/createappsdox.sh
+++ b/doc/createappsdox.sh
@@ -4,10 +4,15 @@ cat > ../doc/header.dox <<EOF
\section thetool thetool
theshortdescription
+## SYNOPSIS
<code>
thesynopsis
</code>
+## DESCRIPTION ##
+thelongdescription
+
+## OPTIONS ##
- use either \`-short\` or \`--long\` options (both \`--long=value\` and \`--long value\` are supported)
- short option \`-h\` shows basic options only, long option \`--h\` shows all options
|short|long|type|default|description|
@@ -23,6 +28,8 @@ for file in ../src/apps/pk*.cc;do
sed -i "s/theshortdescription/$THESHORTDESCRIPTION/" ../doc/${THETOOL}.dox
THESYNOPSIS="${THETOOL} [OPTIONS]"
sed -i "s/thesynopsis/$THESYNOPSIS/" ../doc/${THETOOL}.dox
+ THELONGDESCRIPTION="$THESHORTDESCRIPTION more..."
+ sed -i "s/thelongdescription/$THELONGDESCRIPTION/" ../doc/${THETOOL}.dox
${THETOOL} --doxygen|sed '$d' >> ../doc/${THETOOL}.dox
done
diff --git a/doc/mainpage.dox b/doc/mainpage.dox
new file mode 100644
index 0000000..5d62a90
--- /dev/null
+++ b/doc/mainpage.dox
@@ -0,0 +1,31 @@
+\mainpage
+Introduction
+============
+pktools is a collection of programs written by Pieter Kempeneers in C++ to perform operations on raster images.
+It heavily relies on the Geospatial Data Abstraction Library (GDAL, http://www.gdal.org) and OGR. Some of the programs are similar to the gdal tools (gdalinfo, gdal_translate, gdal_merge,...) and many of the functionalities provided in pktools already exist. The reason for implementing pktools is a combination of personal preference and additional functionality.
+
+All utilities in pktools use command line options and have a built in help
+
+- use the `-h` option to get help
+- pktools ALWAYS use -i for input and -o for output (unlike GDAL utilities that commonly use last argument as output and second but last argument as input)
+
+License
+=======
+pktools is released under the GNU General Public License version3
+
+See http://www.gnu.org/licenses for more details
+
+Download
+========
+You can download the latest release
+- from http://download.savannah.gnu.org/releases/pktools/ (tar ball)
+- or by getting a copy of the Git repository
+
+~~~
+git clone git://git.savannah.nongnu.org/pktools.git
+~~~
+
+How to refer
+============
+You are welcome to refer to pktools as: http://pktools.nongnu.org (Pieter Kempeneers)
+
diff --git a/src/apps/pkeditogr.cc b/src/apps/pkeditogr.cc
new file mode 100644
index 0000000..d238267
--- /dev/null
+++ b/src/apps/pkeditogr.cc
@@ -0,0 +1,121 @@
+/**********************************************************************
+pkeditogr.cc: program to edit (rename fields) ogr fil
+Copyright (C) 2008-2013 Pieter Kempeneers
+
+This file is part of pktools
+
+pktools is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+pktools is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with pktools. If not, see <http://www.gnu.org/licenses/>.
+***********************************************************************/
+#include <assert.h>
+#include <map>
+#include "base/Optionpk.h"
+#include "imageclasses/ImgReaderOgr.h"
+#include "imageclasses/ImgWriterOgr.h"
+#include "imageclasses/ImgReaderGdal.h"
+#include "imageclasses/ImgWriterGdal.h"
+
+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> field_opt("f", "field", "output field names (number must exactly match input fields)");
+ Optionpk<short> verbose_opt("v", "verbose", "verbose", 0);
+
+ bool doProcess;//stop process when program was invoked with help option (-h --help)
+ try{
+ doProcess=input_opt.retrieveOption(argc,argv);
+ output_opt.retrieveOption(argc,argv);
+ field_opt.retrieveOption(argc,argv);
+ verbose_opt.retrieveOption(argc,argv);
+ }
+ catch(string predefinedString){
+ std::cout << predefinedString << std::endl;
+ exit(0);
+ }
+ if(!doProcess){
+ 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(verbose_opt[0])
+ cout << "opening " << input_opt[0] << " for reading " << endl;
+ ImgReaderOgr ogrReader(input_opt[0]);
+ if(verbose_opt[0])
+ cout << "opening " << output_opt[0] << " for writing " << endl;
+ //start reading features from the layer
+ if(verbose_opt[0])
+ cout << "reset reading" << endl;
+ ogrReader.getLayer()->ResetReading();
+ assert(field_opt.size()==ogrReader.getFieldCount());
+ unsigned long int ifeature=0;
+ if(verbose_opt[0])
+ cout << "going through features" << endl << flush;
+
+ ImgWriterOgr ogrWriter(output_opt[0]);
+ OGRLayer* writeLayer=ogrWriter.createLayer(output_opt[0],ogrReader.getProjection(),ogrReader.getGeometryType(),NULL);
+ std::vector<OGRFieldDefn*> readFields;
+ std::vector<OGRFieldDefn*> writeFields;
+ ogrReader.getFields(readFields);
+ writeFields=readFields;
+ try{
+ for(int ifield=0;ifield<readFields.size();++ifield){
+ writeFields[ifield]->SetName(field_opt[ifield].c_str());
+ if(writeLayer->CreateField(writeFields[ifield]) != OGRERR_NONE ){
+ ostringstream es;
+ es << "Creating field " << field_opt[ifield] << " failed";
+ string errorString=es.str();
+ throw(errorString);
+ }
+ }
+ }
+ catch(string errorString){
+ std::cerr << errorString << std::endl;
+ exit(1);
+ }
+ OGRFeature *poFeature;
+ while(true){// (poFeature = imgReaderOgr.getLayer()->GetNextFeature()) != NULL ){
+ poFeature = ogrReader.getLayer()->GetNextFeature();
+ if( poFeature == NULL )
+ break;
+ OGRFeature *poDstFeature = NULL;
+ poDstFeature=ogrWriter.createFeature();
+ if( poDstFeature->SetFrom( poFeature, TRUE ) != OGRERR_NONE ){
+ const char* fmt;
+ string errorString="Unable to translate feature %d from layer %s.\n";
+ fmt=errorString.c_str();
+ CPLError( CE_Failure, CPLE_AppDefined,
+ fmt,
+ poFeature->GetFID(), ogrWriter.getLayerName().c_str() );
+ OGRFeature::DestroyFeature( poFeature );
+ OGRFeature::DestroyFeature( poDstFeature );
+ }
+ poDstFeature->SetFID( poFeature->GetFID() );
+ OGRFeature::DestroyFeature( poFeature );
+
+ CPLErrorReset();
+ if(ogrWriter.createFeature( poDstFeature ) != OGRERR_NONE){
+ const char* fmt;
+ string errorString="Unable to translate feature %d from layer %s.\n";
+ fmt=errorString.c_str();
+ CPLError( CE_Failure, CPLE_AppDefined,
+ fmt,
+ poFeature->GetFID(), ogrWriter.getLayerName().c_str() );
+ OGRFeature::DestroyFeature( poDstFeature );
+ }
+ OGRFeature::DestroyFeature( poDstFeature );
+ }
+ if(verbose_opt[0])
+ cout << "replaced " << ifeature << " features" << endl;
+ ogrReader.close();
+ ogrWriter.close();
+}
--
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