[GRASS-SVN] r53392 - in grass-addons/grass7/imagery: . i.flip
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Oct 14 22:58:40 PDT 2012
Author: ychemin
Date: 2012-10-14 22:58:40 -0700 (Sun, 14 Oct 2012)
New Revision: 53392
Added:
grass-addons/grass7/imagery/i.flip/
grass-addons/grass7/imagery/i.flip/Makefile
grass-addons/grass7/imagery/i.flip/i.flip.html
grass-addons/grass7/imagery/i.flip/main.c
Log:
Added a North-South image flipping module for problems like TRMM and netCDF imports, row-based, very fast
Added: grass-addons/grass7/imagery/i.flip/Makefile
===================================================================
--- grass-addons/grass7/imagery/i.flip/Makefile (rev 0)
+++ grass-addons/grass7/imagery/i.flip/Makefile 2012-10-15 05:58:40 UTC (rev 53392)
@@ -0,0 +1,11 @@
+MODULE_TOPDIR = ../..
+
+PGM = i.flip
+
+LIBES = $(RASTERLIB) $(GISLIB) $(MATHLIB)
+DEPENDENCIES = $(RASTERDEP) $(GISDEP)
+
+include $(MODULE_TOPDIR)/include/Make/Module.make
+
+
+default: cmd
Added: grass-addons/grass7/imagery/i.flip/i.flip.html
===================================================================
--- grass-addons/grass7/imagery/i.flip/i.flip.html (rev 0)
+++ grass-addons/grass7/imagery/i.flip/i.flip.html 2012-10-15 05:58:40 UTC (rev 53392)
@@ -0,0 +1,18 @@
+<h2>DESCRIPTION</h2>
+
+<em>i.flip</em>Flips an image North-South. Initial need was for TRMM images.
+
+
+<h2>NOTES</h2>
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="i.atcorr.html">i.atcorr</a>
+</em>
+
+
+<h2>AUTHORS</h2>
+Yann Chemin, International Water Management Institute, Sri Lanka
+
+<p><i>Last changed: $Date: 2012-10-15 02:54:20 +0430 (Wed, 15 Oct 2012) $</i>
Added: grass-addons/grass7/imagery/i.flip/main.c
===================================================================
--- grass-addons/grass7/imagery/i.flip/main.c (rev 0)
+++ grass-addons/grass7/imagery/i.flip/main.c 2012-10-15 05:58:40 UTC (rev 53392)
@@ -0,0 +1,100 @@
+
+/****************************************************************************
+ *
+ * MODULE: i.vi
+ * AUTHOR(S): Yann Chemin - yann.chemin at gmail.com
+ * PURPOSE: Flips an image North-South.
+ *
+ * COPYRIGHT: (C) 2012 by the 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.
+ *
+ * Remark:
+ * Initial need for TRMM import
+ *
+ * Changelog:
+ *
+ *****************************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/glocale.h>
+
+int main(int argc, char *argv[])
+{
+ int nrows, ncols;
+ int row, col;
+ char *desc;
+ struct GModule *module;
+ struct Option *input, *output;
+ struct History history; /*metadata */
+ struct Colors colors; /*Color rules */
+
+ char *in, *out; /*in/out raster names */
+ int infd, outfd;
+ void *inrast, *outrast;
+ RASTER_MAP_TYPE data_type_input;
+ CELL val1, val2;
+
+ G_gisinit(argv[0]);
+
+ module = G_define_module();
+ G_add_keyword(_("imagery"));
+ G_add_keyword(_("flip"));
+ module->label =
+ _("Flips an image North-South.");
+ module->description = _("Flips an image North-South.");
+
+ /* Define the different options */
+ input = G_define_standard_option(G_OPT_R_INPUT);
+ output = G_define_standard_option(G_OPT_R_OUTPUT);
+
+ if (G_parser(argc, argv))
+ exit(EXIT_FAILURE);
+
+ in=input->answer;
+ out=output->answer;
+
+ /* Open input raster file */
+ infd = Rast_open_old(in, "");
+ data_type_input = Rast_map_type(in, "");
+ inrast = Rast_allocate_buf(data_type_input);
+
+ /* Create New raster file */
+ outfd = Rast_open_new(out, data_type_input);
+ outrast = Rast_allocate_buf(data_type_input);
+
+ nrows = Rast_window_rows();
+ ncols = Rast_window_cols();
+
+ /* Process pixels */
+ for (row = 0; row < nrows; row++)
+ {
+ G_percent(row, nrows, 2);
+ /* read input maps */
+ Rast_get_row(infd,inrast,(nrows-1-row),data_type_input);
+ /* process the data */
+ Rast_put_row(outfd,inrast,data_type_input);
+ }
+
+ G_free(inrast);
+ Rast_close(infd);
+ G_free(outrast);
+ Rast_close(outfd);
+
+ /* Color from 0 to +1000 in grey */
+ Rast_init_colors(&colors);
+ val1 = 0;
+ val2 = 1000;
+ Rast_add_c_color_rule(&val1, 0, 0, 0, &val2, 255, 255, 255, &colors);
+ Rast_short_history(out, "raster", &history);
+ Rast_command_history(&history);
+ Rast_write_history(out, &history);
+
+ exit(EXIT_SUCCESS);
+}
+
More information about the grass-commit
mailing list