[GRASS-SVN] r56212 - in grass/trunk: include include/defs lib/raster

svn_grass at osgeo.org svn_grass at osgeo.org
Sun May 12 04:30:24 PDT 2013


Author: martinl
Date: 2013-05-12 04:30:24 -0700 (Sun, 12 May 2013)
New Revision: 56212

Modified:
   grass/trunk/include/defs/raster.h
   grass/trunk/include/raster.h
   grass/trunk/lib/raster/interp.c
Log:
libraster: Rast_option_to_interp_type() added


Modified: grass/trunk/include/defs/raster.h
===================================================================
--- grass/trunk/include/defs/raster.h	2013-05-12 11:07:51 UTC (rev 56211)
+++ grass/trunk/include/defs/raster.h	2013-05-12 11:30:24 UTC (rev 56212)
@@ -393,6 +393,7 @@
 		       DCELL, DCELL, DCELL, DCELL, DCELL, DCELL, DCELL, DCELL,
 		       DCELL, DCELL, DCELL, DCELL, DCELL, DCELL, DCELL,
 		       DCELL);
+int Rast_option_to_interp_type(const struct Option *);
 
 /* mask_info.c */
 char *Rast_mask_info(void);

Modified: grass/trunk/include/raster.h
===================================================================
--- grass/trunk/include/raster.h	2013-05-12 11:07:51 UTC (rev 56211)
+++ grass/trunk/include/raster.h	2013-05-12 11:30:24 UTC (rev 56212)
@@ -12,7 +12,12 @@
 #define FCELL_TYPE 1
 #define DCELL_TYPE 2
 
-/* for G_get_raster_sample(), INTERP_TYPE */
+/*! \brief Interpolation methods
+
+  For G_get_raster_sample(), INTERP_TYPE
+
+  \todo Rename to use prefix INTERP_
+*/
 #define UNKNOWN	  0
 #define NEAREST   1		/* nearest neighbor interpolation  */
 #define BILINEAR  2		/* bilinear interpolation          */

Modified: grass/trunk/lib/raster/interp.c
===================================================================
--- grass/trunk/lib/raster/interp.c	2013-05-12 11:07:51 UTC (rev 56211)
+++ grass/trunk/lib/raster/interp.c	2013-05-12 11:30:24 UTC (rev 56212)
@@ -1,19 +1,22 @@
 /*!
- * \file raster/interp.c
- *
- * \brief Raster Library - Interpolation
- *
- * (C) 2001-2009 GRASS Development Team
- *
- * This program is free software under the GNU General Public License 
- * (>=v2). Read the file COPYING that comes with GRASS for details.
- *
- * \author Original author CERL
- */
+  \file lib/raster/interp.c
+  
+  \brief Raster Library - Interpolation methods
+  
+  (C) 2001-2009,2013 GRASS Development Team
+  
+  This program is free software under the GNU General Public License
+  (>=v2). Read the file COPYING that comes with GRASS for details.
+  
+  \author Original author CERL
+*/
 
 #include <math.h>
+#include <string.h>
+
 #include <grass/gis.h>
 #include <grass/raster.h>
+#include <grass/glocale.h>
 
 DCELL Rast_interp_linear(double u, DCELL c0, DCELL c1)
 {
@@ -160,3 +163,52 @@
 
     return Rast_interp_cubic_bspline(v, c0, c1, c2, c3);
 }
+
+/*!
+  \brief Get interpolation method from the option.
+
+  Calls G_fatal_error() on unknown interpolation method.
+  
+  Supported methods:
+   - NEAREST
+   - BILINEAR
+   - CUBIC
+
+  \code
+  int interp_method
+  struct Option *opt_method;
+  
+  opt_method = G_define_standard_option(G_OPT_R_INTERP_TYPE);
+  
+  if (G_parser(argc, argv))
+      exit(EXIT_FAILURE);
+      
+  interp_method = G_option_to_interp_type(opt_method);
+  \endcode
+
+  \param option pointer to interpolation option
+  
+  \return interpolation method code
+*/
+int Rast_option_to_interp_type(const struct Option *option)
+{
+    int interp_type;
+    
+    interp_type = UNKNOWN;
+    if (option->answer) {
+        if (strcmp(option->answer, "nearest") == 0) {
+            interp_type = NEAREST;
+        }
+        else if (strcmp(option->answer, "bilinear") == 0) {
+            interp_type = BILINEAR;
+        }
+        else if (strcmp(option->answer, "bicubic") == 0) {
+            interp_type = CUBIC;
+        }
+    }
+
+    if (interp_type == UNKNOWN)
+        G_fatal_error(_("Unknown interpolation method: %s"), option->answer);
+
+    return interp_type;
+}



More information about the grass-commit mailing list