[GRASS-SVN] r63441 - in grass-addons/grass7/misc: . m.surf.nnbathy m.surf.nnbathy/libnnbathy m.surf.nnbathy/r.surf.nnbathy m.surf.nnbathy/v.surf.nnbathy

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Dec 8 07:31:10 PST 2014


Author: lazaa
Date: 2014-12-08 07:31:10 -0800 (Mon, 08 Dec 2014)
New Revision: 63441

Added:
   grass-addons/grass7/misc/m.surf.nnbathy/
   grass-addons/grass7/misc/m.surf.nnbathy/Makefile
   grass-addons/grass7/misc/m.surf.nnbathy/libnnbathy/
   grass-addons/grass7/misc/m.surf.nnbathy/libnnbathy/Makefile
   grass-addons/grass7/misc/m.surf.nnbathy/libnnbathy/nnbathy.py
   grass-addons/grass7/misc/m.surf.nnbathy/r.surf.nnbathy/
   grass-addons/grass7/misc/m.surf.nnbathy/r.surf.nnbathy/Makefile
   grass-addons/grass7/misc/m.surf.nnbathy/r.surf.nnbathy/r.surf.nnbathy.html
   grass-addons/grass7/misc/m.surf.nnbathy/r.surf.nnbathy/r.surf.nnbathy.py
   grass-addons/grass7/misc/m.surf.nnbathy/v.surf.nnbathy/
   grass-addons/grass7/misc/m.surf.nnbathy/v.surf.nnbathy/Makefile
   grass-addons/grass7/misc/m.surf.nnbathy/v.surf.nnbathy/v.surf.nnbathy.html
   grass-addons/grass7/misc/m.surf.nnbathy/v.surf.nnbathy/v.surf.nnbathy.py
Log:
addons: new modules r.surf.nnbathy and v.surf.nnbathy


Added: grass-addons/grass7/misc/m.surf.nnbathy/Makefile
===================================================================
--- grass-addons/grass7/misc/m.surf.nnbathy/Makefile	                        (rev 0)
+++ grass-addons/grass7/misc/m.surf.nnbathy/Makefile	2014-12-08 15:31:10 UTC (rev 63441)
@@ -0,0 +1,12 @@
+MODULE_TOPDIR =../..
+
+SUBDIRS = \
+	r.surf.nnbathy \
+	v.surf.nnbathy \
+	libnnbathy
+
+include $(MODULE_TOPDIR)/include/Make/Dir.make
+
+default: parsubdirs
+
+install: installsubdirs


Property changes on: grass-addons/grass7/misc/m.surf.nnbathy/Makefile
___________________________________________________________________
Added: svn:mime-type
   + text/x-makefile
Added: svn:eol-style
   + native

Added: grass-addons/grass7/misc/m.surf.nnbathy/libnnbathy/Makefile
===================================================================
--- grass-addons/grass7/misc/m.surf.nnbathy/libnnbathy/Makefile	                        (rev 0)
+++ grass-addons/grass7/misc/m.surf.nnbathy/libnnbathy/Makefile	2014-12-08 15:31:10 UTC (rev 63441)
@@ -0,0 +1,22 @@
+MODULE_TOPDIR = ../../..
+
+include $(MODULE_TOPDIR)/include/Make/Other.make
+include $(MODULE_TOPDIR)/include/Make/Python.make
+
+MODULES = nnbathy
+
+ETCDIR = $(ETC)/nnbathy
+
+PYFILES := $(patsubst %,$(ETCDIR)/%.py,$(MODULES))
+PYCFILES := $(patsubst %,$(ETCDIR)/%.pyc,$(MODULES))
+
+default: $(PYFILES) $(PYCFILES)
+
+$(ETCDIR):
+	$(MKDIR) $@
+
+$(ETCDIR)/%: % | $(ETCDIR)
+	$(INSTALL_DATA) $< $@
+
+install:
+	cp -r $(ETCDIR) $(INST_DIR)


Property changes on: grass-addons/grass7/misc/m.surf.nnbathy/libnnbathy/Makefile
___________________________________________________________________
Added: svn:mime-type
   + text/x-makefile
Added: svn:eol-style
   + native

Added: grass-addons/grass7/misc/m.surf.nnbathy/libnnbathy/nnbathy.py
===================================================================
--- grass-addons/grass7/misc/m.surf.nnbathy/libnnbathy/nnbathy.py	                        (rev 0)
+++ grass-addons/grass7/misc/m.surf.nnbathy/libnnbathy/nnbathy.py	2014-12-08 15:31:10 UTC (rev 63441)
@@ -0,0 +1,171 @@
+import grass.script as grass
+import os
+
+
+class Nnbathy:
+    # base class
+    def __init__(self, options):
+        self._tmpxyz = grass.tempfile()
+        self._xyzout = grass.tempfile()
+        self._tmp = grass.tempfile()
+        self._tmpcat = grass.tempfile()
+        self.options = options
+        self.region()
+        pass
+
+    def region(self):
+        # set the computive region
+        reg = grass.read_command("g.region", flags='p')
+        kv = grass.parse_key_val(reg, sep=':')
+        reg_N = float(kv['north'])
+        reg_W = float(kv['west'])
+        reg_S = float(kv['south'])
+        reg_E = float(kv['east'])
+        nsres = float(kv['nsres'])
+        ewres = float(kv['ewres'])
+
+        # set variables
+        self.cols = int(kv['cols'])
+        self.rows = int(kv['rows'])
+        self.area = (reg_N-reg_S)*(reg_E-reg_W)
+        self.ALG = 'nn'
+
+        # set the working region for nnbathy (it's cell-center oriented)
+        self.nn_n = reg_N - nsres/2
+        self.nn_s = reg_S + nsres/2
+        self.nn_w = reg_W + ewres/2
+        self.nn_e = reg_E - ewres/2
+        self.null = "NaN"
+        self.ctype = "double"
+
+    def compute(self):
+        # computing
+        grass.message('"nnbathy" is performing the interpolation now. \
+                      This may take some time...')
+        grass.verbose("Once it completes an 'All done.' \
+                      message will be printed.")
+
+        # nnbathy calling
+        fsock = open(self._xyzout, 'w')
+        grass.call(['nnbathy',
+                    '-W', '%d' % 0,
+                    '-i', '%s' % self._tmpxyz,
+                    '-x', '%d' % self.nn_w, '%d' % self.nn_e,
+                    '-y', '%d' % self.nn_n, '%d' % self.nn_s,
+                    '-P', '%s' % self.ALG,
+                    '-n', '%dx%d' % (self.cols, self.rows)],
+                   stdout=fsock)
+        fsock.close()
+
+    def create_output(self):
+        # create the output raster map
+        # convert the X,Y,Z nnbathy output into a GRASS ASCII grid
+        # then import with r.in.ascii
+        # 1 create header
+        header = open(self._tmp, 'w')
+        header.write('north: %s\nsouth: %s\neast: %s\nwest: %s\nrows: %s\ncols: %s\ntype: %s\nnull: %s\n\n' %
+                     (self.nn_n, self.nn_s, self.nn_e,  self.nn_w, self.rows, self.cols, self.ctype, self.null))
+        header.close()
+
+        # 2 do the conversion
+        grass.message("Converting nnbathy output to GRASS raster ...")
+        fin = open(self._xyzout, 'r')
+        fout = open(self._tmp, 'a')
+        cur_col = 1
+        for line in fin:
+            parts = line.split(" ")
+            if cur_col == self.cols:
+                cur_col = 0
+                fout.write(str(parts[2]))
+            else:
+                fout.write(str(parts[2]).rstrip('\n')+' ')
+            cur_col += 1
+        fin.close()
+        fout.close()
+
+        # 3 import to raster
+        grass.run_command('r.in.ascii', input=self._tmp,
+                          output=self.options['output'], quiet=True)
+        grass.message("All done. Raster map <%s> created."
+                      % self.options['output'])
+
+    def __del__(self):
+        # cleanup
+        if self._tmp:
+            os.remove(self._tmp)
+        if self._tmpxyz:
+            os.remove(self._tmpxyz)
+        if self._xyzout:
+            os.remove(self._xyzout)
+        if self._tmpcat:
+            os.remove(self._tmpcat)
+
+
+class Nnbathy_raster(Nnbathy):
+    # class for raster input
+    def __init__(self, options):
+        Nnbathy.__init__(self, options)
+        self._load(options)
+
+    def _load(self, options):
+        # load input raster
+        grass.run_command('r.stats', flags='1gn', input=options['input'],
+                          output=self._tmpxyz, quiet=True, overwrite=True)
+
+
+class Nnbathy_vector(Nnbathy):
+    # class for vector input
+    def __init__(self, options):
+        Nnbathy.__init__(self, options)
+        self._load(options)
+
+    def _load(self, options):
+        # load input vector, initial controls
+        if int(options['layer']) == 0:
+            _layer = ''
+            _column = ''
+        else:
+            _layer = int(options['layer'])
+            if options['zcolumn']:
+                _column = options['zcolumn']
+            else:
+                grass.message('Name of z column required for 2D vector maps.')
+
+        # convert vector to ASCII
+        if options['kwhere']:
+            grass.run_command("v.out.ascii", flags='r', overwrite=1,
+                              input=options['input'], output=self._tmpcat,
+                              format="point", separator="space", dp=15,
+                              where=options['kwhere'], layer=_layer,
+                              columns=_column)
+        else:
+            grass.run_command("v.out.ascii", flags='r', overwrite=1,
+                              input=options['input'], output=self._tmpcat,
+                              format="point", separator="space", dp=15,
+                              layer=_layer, columns=_column)
+
+        # edit ASCII file, crop out one column
+        if int(options['layer']) > 0:
+            fin = open(self._tmpcat, 'r')
+            fout = open(self._tmpxyz, 'w')
+            try:
+                for line in fin:
+                    parts = line.split(" ")
+                    fout.write(parts[0]+' '+parts[1]+' '+parts[3])
+            except StandardError, e:
+                grass.fatal_error("Invalid input: %s" % e)
+            fin.close()
+            fout.close()
+        else:
+            grass.message("Z coordinates are used.")
+
+
+class Nnbathy_file:
+    # class for file input
+    def __init__(self, options):
+        self.options = options
+        self._load(options)
+
+    def _load(self, options):
+        # load input file
+        self._tmpxyz = options['file']


Property changes on: grass-addons/grass7/misc/m.surf.nnbathy/libnnbathy/nnbathy.py
___________________________________________________________________
Added: svn:mime-type
   + text/x-python
Added: svn:eol-style
   + native

Added: grass-addons/grass7/misc/m.surf.nnbathy/r.surf.nnbathy/Makefile
===================================================================
--- grass-addons/grass7/misc/m.surf.nnbathy/r.surf.nnbathy/Makefile	                        (rev 0)
+++ grass-addons/grass7/misc/m.surf.nnbathy/r.surf.nnbathy/Makefile	2014-12-08 15:31:10 UTC (rev 63441)
@@ -0,0 +1,8 @@
+MODULE_TOPDIR = ../../..
+
+PGM = r.surf.nnbathy
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script
+


Property changes on: grass-addons/grass7/misc/m.surf.nnbathy/r.surf.nnbathy/Makefile
___________________________________________________________________
Added: svn:mime-type
   + text/x-makefile
Added: svn:eol-style
   + native

Added: grass-addons/grass7/misc/m.surf.nnbathy/r.surf.nnbathy/r.surf.nnbathy.html
===================================================================
--- grass-addons/grass7/misc/m.surf.nnbathy/r.surf.nnbathy/r.surf.nnbathy.html	                        (rev 0)
+++ grass-addons/grass7/misc/m.surf.nnbathy/r.surf.nnbathy/r.surf.nnbathy.html	2014-12-08 15:31:10 UTC (rev 63441)
@@ -0,0 +1,69 @@
+<h2>DESCRIPTION</h2>
+
+<em>r.surf.nnbathy</em> is an interface between the
+external <em>nnbathy</em> utility and <em>GRASS</em>.
+<em>nnbathy</em> is a surface interpolation program provided with
+<a href="https://code.google.com/p/nn-c/">nn</a> - a natural neighbor
+interpolation library, written by Pavel Sakov.
+
+<p>
+<em>r.surf.nnbathy</em> provides 3 interpolation algorithms. According to
+<em>nn</em> library documentation these are: Delaunay interpolation
+(<b>alg=l</b>), Watson's algortithm for Sibson natural neighbor
+interpolation (<b>alg=nn</b>) and Belikov and Semenov's algorithm for
+non-Sibsonian natural neighbor interpolation (<b>alg=ns</b>). For performing
+the underlaying Delaunay triangulation in all cases <em>nnbathy</em> uses
+<em>triangle</em> software by
+<a href="http://www.cs.berkeley.edu/~jrs/">Jonathan Richard Shewchuk</a>.
+
+<p>
+The <b>output</b> raster map is a continous surface interpolated from the
+<b>raster</b> data.
+
+<h2>NOTES</h2>
+
+<em>nnbathy</em>, if built with '-DNN_SERIAL' (default as of nn 1.85), is
+able to create a grid of virtually any size. It interpolates and writes one
+output point at a time only. This eliminates the necessity to hold the whole
+output array in memory. However, even then all the input points are still
+held in the memory.
+
+<ol>
+<li>Requires <em>GRASS</em> 6 and <em>nnbathy</em> 1.76 or greater.</li>
+<li>Build <em>nnbathy</em> according to instructions provided with its source
+code and put it somewhere in your $PATH.</li>
+<li>The output raster map extent and resolution match the region settings at
+which the script was started.</li>
+<li>The output raster map non-NULL area is limited to the convex hull
+encompassing all the non-NULL input cells.</li>
+<li>The output is double precision floating point raster map (DCELL).</li>
+<li>Natural neighbor is a an <em>exact</em> interpolation algorithm, so all
+non-NULL input points have their value exactly preserved in the output.</li>
+<li>There is circa 0.2 KB memory overhead per each <em>input</em> cell.
+However, the <em>output</em> grid can be of any size, if <em>nnbathy</em> is
+built with -DNN_SERIAL switch.</li>
+<li><em>r.surf.nnbathy</em> creates 3 temporary files: ASCII x,y,z lists of
+the input points and output cells, and the output list converted into GRASS ASCII
+format. Then it makes a GRASS raster map from the latter - and only then it
+removes the 3 temp files, when the script terminates. Thus, at the script
+run time several times more disk space might be required, than the final
+GRASS raster map would actually occupy.</li>
+</ol>
+
+<h2>SEE ALSO</h2>
+
+<em>
+  <a href="v.surf.nnbathy.html">v.surf.nnbathy</a>
+</em> 
+
+
+<h2>AUTHOR</h2>
+Adam Laza (mentor: Martin Landa)<br>
+based on v.surf.nnbathy from GRASS 6 by<br>
+Hamish Bowman, Otago University, New Zealand<br>
+Based on <em>r.surf.nnbathy</em> by Maciej Sieczka<br>
+<em><a href="https://code.google.com/p/nn-c/">nnbathy</a></em>
+ written by Pavel Sakov
+
+<p>
+<i>Last changed: $Date$</i>


Property changes on: grass-addons/grass7/misc/m.surf.nnbathy/r.surf.nnbathy/r.surf.nnbathy.html
___________________________________________________________________
Added: svn:mime-type
   + text/html
Added: svn:keywords
   + Author Date Id
Added: svn:eol-style
   + native

Added: grass-addons/grass7/misc/m.surf.nnbathy/r.surf.nnbathy/r.surf.nnbathy.py
===================================================================
--- grass-addons/grass7/misc/m.surf.nnbathy/r.surf.nnbathy/r.surf.nnbathy.py	                        (rev 0)
+++ grass-addons/grass7/misc/m.surf.nnbathy/r.surf.nnbathy/r.surf.nnbathy.py	2014-12-08 15:31:10 UTC (rev 63441)
@@ -0,0 +1,74 @@
+#!/usr/bin/env python
+############################################################################
+#
+# MODULE:     v.surf.nnbathy.py
+#
+# AUTHOR(S):  Adam Laza (mentor: Martin Landa)
+#             (based on v.surf.nnbathy from GRASS 6)
+#
+# PURPOSE:    Interpolate raster surface using the "nnbathy" natural
+#             neighbor interpolation program.
+#
+# COPYRIGHT:  (c) 2014 Adam Laza, and the GRASS Development Team
+#
+# LICENSE:    This program is free software under the GNU General Public
+#             License (>=v2). Read the file COPYING that comes with
+#             GRASS for details.
+#
+#############################################################################
+#
+# NOTES:
+#
+# 1. Requires nnbathy executable v 1.75 or later. Follow the instruction in
+#    html manual page to obtain it.
+#
+# 2. When creating the input raster map, make sure it's extents cover
+#    your whole region of interest, the cells you wish to interplate on are
+#    NULL, and the resolution is correct. Same as most GRASS raster modules
+#    this one is region sensitive too.
+
+#%Module
+#% description: Interpolates a raster map using the nnbathy natural neighbor interpolation program.
+#% keywords: vector
+#% keywords: surface
+#% keywords: interpolation
+#% keywords: natural
+#% keywords: neighbor
+#%end
+#%option G_OPT_R_INPUT
+#% key: input
+#% type: string
+#% description: Name of input raster map
+#% guisection: Input data
+#% required : yes
+#%end
+#%option G_OPT_R_OUTPUT
+#% key: output
+#% description: Name of output raster map
+#%end
+#%option
+#% key: algorithm
+#% type: string
+#% options: l,nn,ns
+#% answer: nn
+#% descriptions: l;Linear;nn;Sibson natural neighbor;ns;Non-Sibsonian natural neighbor
+#% description: Settings
+#%end
+
+import os
+import sys
+
+from grass.script.core import parser
+import grass.script as grass
+
+from nnbathy import Nnbathy_raster
+
+
+def main():
+    obj = Nnbathy_raster(options)
+    obj.compute()
+    obj.create_output()
+
+if __name__ == "__main__":
+    options, flags = parser()
+    main()


Property changes on: grass-addons/grass7/misc/m.surf.nnbathy/r.surf.nnbathy/r.surf.nnbathy.py
___________________________________________________________________
Added: svn:mime-type
   + text/x-python
Added: svn:eol-style
   + native

Added: grass-addons/grass7/misc/m.surf.nnbathy/v.surf.nnbathy/Makefile
===================================================================
--- grass-addons/grass7/misc/m.surf.nnbathy/v.surf.nnbathy/Makefile	                        (rev 0)
+++ grass-addons/grass7/misc/m.surf.nnbathy/v.surf.nnbathy/Makefile	2014-12-08 15:31:10 UTC (rev 63441)
@@ -0,0 +1,8 @@
+MODULE_TOPDIR = ../../..
+
+PGM = v.surf.nnbathy
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script
+


Property changes on: grass-addons/grass7/misc/m.surf.nnbathy/v.surf.nnbathy/Makefile
___________________________________________________________________
Added: svn:mime-type
   + text/x-makefile
Added: svn:eol-style
   + native

Added: grass-addons/grass7/misc/m.surf.nnbathy/v.surf.nnbathy/v.surf.nnbathy.html
===================================================================
--- grass-addons/grass7/misc/m.surf.nnbathy/v.surf.nnbathy/v.surf.nnbathy.html	                        (rev 0)
+++ grass-addons/grass7/misc/m.surf.nnbathy/v.surf.nnbathy/v.surf.nnbathy.html	2014-12-08 15:31:10 UTC (rev 63441)
@@ -0,0 +1,69 @@
+<h2>DESCRIPTION</h2>
+
+<em>v.surf.nnbathy</em> is an interface between the
+external <em>nnbathy</em> utility and <em>GRASS</em>.
+<em>nnbathy</em> is a surface interpolation program provided with
+<a href="https://code.google.com/p/nn-c/">nn</a> - a natural neighbor
+interpolation library, written by Pavel Sakov.
+
+<p>
+<em>v.surf.nnbathy</em> provides 3 interpolation algorithms. According to
+<em>nn</em> library documentation these are: Delaunay interpolation
+(<b>alg=l</b>), Watson's algortithm for Sibson natural neighbor
+interpolation (<b>alg=nn</b>) and Belikov and Semenov's algorithm for
+non-Sibsonian natural neighbor interpolation (<b>alg=ns</b>). For performing
+the underlaying Delaunay triangulation in all cases <em>nnbathy</em> uses
+<em>triangle</em> software by
+<a href="http://www.cs.berkeley.edu/~jrs/">Jonathan Richard Shewchuk</a>.
+
+<p>
+The <b>output</b> raster map is a continous surface interpolated from the
+<b>input</b> or <b>file</b> data.
+
+<h2>NOTES</h2>
+
+<em>nnbathy</em>, if built with '-DNN_SERIAL' (default as of nn 1.85), is
+able to create a grid of virtually any size. It interpolates and writes one
+output point at a time only. This eliminates the necessity to hold the whole
+output array in memory. However, even then all the input points are still
+held in the memory.
+
+<ol>
+<li>Requires <em>GRASS</em> 6 and <em>nnbathy</em> 1.76 or greater.</li>
+<li>Build <em>nnbathy</em> according to instructions provided with its source
+code and put it somewhere in your $PATH.</li>
+<li>The output raster map extent and resolution match the region settings at
+which the script was started.</li>
+<li>The output raster map non-NULL area is limited to the convex hull
+encompassing all the non-NULL input cells.</li>
+<li>The output is double precision floating point raster map (DCELL).</li>
+<li>Natural neighbor is a an <em>exact</em> interpolation algorithm, so all
+non-NULL input points have their value exactly preserved in the output.</li>
+<li>There is circa 0.2 KB memory overhead per each <em>input</em> cell.
+However, the <em>output</em> grid can be of any size, if <em>nnbathy</em> is
+built with -DNN_SERIAL switch.</li>
+<li><em>v.surf.nnbathy</em> creates 4 temporary files: ASCII x,y,z lists of
+the input points and output cells, and the output list converted into GRASS ASCII
+format. Then it makes a GRASS raster map from the latter - and only then it
+removes the 3 temp files, when the script terminates. Thus, at the script
+run time several times more disk space might be required, than the final
+GRASS raster map would actually occupy.</li>
+</ol>
+
+<h2>SEE ALSO</h2>
+
+<em>
+  <a href="r.surf.nnbathy.html">r.surf.nnbathy</a>
+</em> 
+
+
+<h2>AUTHOR</h2>
+Adam Laza (mentor: Martin Landa)<br>
+based on v.surf.nnbathy from GRASS 6 by<br>
+Hamish Bowman, Otago University, New Zealand<br>
+Based on <em>r.surf.nnbathy</em> by Maciej Sieczka<br>
+<em><a href="https://code.google.com/p/nn-c/">nnbathy</a></em>
+ written by Pavel Sakov
+
+<p>
+<i>Last changed: $Date$</i>


Property changes on: grass-addons/grass7/misc/m.surf.nnbathy/v.surf.nnbathy/v.surf.nnbathy.html
___________________________________________________________________
Added: svn:mime-type
   + text/html
Added: svn:keywords
   + Author Date Id
Added: svn:eol-style
   + native

Added: grass-addons/grass7/misc/m.surf.nnbathy/v.surf.nnbathy/v.surf.nnbathy.py
===================================================================
--- grass-addons/grass7/misc/m.surf.nnbathy/v.surf.nnbathy/v.surf.nnbathy.py	                        (rev 0)
+++ grass-addons/grass7/misc/m.surf.nnbathy/v.surf.nnbathy/v.surf.nnbathy.py	2014-12-08 15:31:10 UTC (rev 63441)
@@ -0,0 +1,113 @@
+#!/usr/bin/env python
+############################################################################
+#
+# MODULE:     v.surf.nnbathy.py
+#
+# AUTHOR(S):  Adam Laza (mentor: Martin Landa)
+#             (based on v.surf.nnbathy from GRASS 6)
+#
+# PURPOSE:    Interpolate raster surface using the "nnbathy" natural
+#             neighbor interpolation program.
+#
+# COPYRIGHT:  (c) 2014 Adam Laza, and the GRASS Development Team
+#
+# LICENSE:    This program is free software under the GNU General Public
+#             License (>=v2). Read the file COPYING that comes with
+#             GRASS for details.
+#
+#############################################################################
+#
+# NOTES:
+#
+# 1. Requires nnbathy executable v 1.75 or later. Follow the instruction in
+#    html manual page to obtain it.
+#
+# 2. When creating the input raster map, make sure it's extents cover
+#    your whole region of interest, the cells you wish to interplate on are
+#    NULL, and the resolution is correct. Same as most GRASS raster modules
+#    this one is region sensitive too.
+
+#%Module
+#% description: Interpolates a raster map using the nnbathy natural neighbor interpolation program.
+#% keywords: vector
+#% keywords: surface
+#% keywords: interpolation
+#% keywords: natural
+#% keywords: neighbor
+#%end
+#%option G_OPT_V_INPUT
+#% key: input
+#% type: string
+#% description: Name of input vector points map
+#% guisection: Input data
+#% required : no
+#%end
+#%option G_OPT_V_FIELD
+#% key: layer
+#% label: Layer number
+#% description: If set to 0, z coordinates are used. (3D vector only)
+#% guisection: Selection
+#%end
+#%option G_OPT_F_INPUT
+#% key: file
+#% description: Containing x,y,z data as three space separated columns
+#% guisection: Input data
+#% required : no
+#%end
+#%option G_OPT_R_OUTPUT
+#% key: output
+#% description: Name of output raster map
+#%end
+#%option G_OPT_DB_COLUMN
+#% key: zcolumn
+#% description: Name of the attribute column with values to be used for approximation (if layer>0)
+#% guisection: Settings
+#%end
+#%option G_OPT_DB_WHERE
+#% key: kwhere
+#% type: string
+#% label: WHERE conditions of SQL query statement without 'where' keyword
+#% guisection: Selection
+#%end
+#%option
+#% key: algorithm
+#% type: string
+#% options: l,nn,ns
+#% answer: nn
+#% descriptions: l;Linear;nn;Sibson natural neighbor;ns;Non-Sibsonian natural neighbor
+#% description: Settings
+#%end
+
+import sys
+import os
+
+from grass.script.core import parser
+import grass.script as grass
+
+from nnbathy import Nnbathy_vector, Nnbathy_file
+
+
+def main():
+    # initial controls
+    if (options['input'] and options['file']):
+        grass.fatal("Please specify either the 'input' \
+                    or 'file' option, not both.")
+
+    if not(options['input'] or options['file']):
+        grass.message("Please specify either the 'input' or 'file' option.")
+
+    if (options['file'] and os.path.isfile(options['file'])):
+        grass.message("File "+options['file']+" does not exist.")
+
+    # vector or file input?
+    if (options['input']):
+        obj = Nnbathy_vector(options)
+    else:
+        obj = Nnbathy_file(options)
+
+    obj.compute()
+    obj.create_output()
+
+if __name__ == "__main__":
+    options, flags = parser()
+    main()


Property changes on: grass-addons/grass7/misc/m.surf.nnbathy/v.surf.nnbathy/v.surf.nnbathy.py
___________________________________________________________________
Added: svn:mime-type
   + text/x-python
Added: svn:eol-style
   + native



More information about the grass-commit mailing list