[GRASS-SVN] r67441 - in grass-addons/grass7/imagery: . i.wi
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Dec 30 13:43:56 PST 2015
Author: ychemin
Date: 2015-12-30 13:43:56 -0800 (Wed, 30 Dec 2015)
New Revision: 67441
Added:
grass-addons/grass7/imagery/i.wi/
grass-addons/grass7/imagery/i.wi/i.wi.html
Removed:
grass-addons/grass7/imagery/i.wi/description.html
Modified:
grass-addons/grass7/imagery/Makefile
grass-addons/grass7/imagery/i.wi/Makefile
grass-addons/grass7/imagery/i.wi/main.c
Log:
Upgraded i.wi to grass v7
Modified: grass-addons/grass7/imagery/Makefile
===================================================================
--- grass-addons/grass7/imagery/Makefile 2015-12-30 21:26:26 UTC (rev 67440)
+++ grass-addons/grass7/imagery/Makefile 2015-12-30 21:43:56 UTC (rev 67441)
@@ -28,7 +28,8 @@
i.theilsen \
i.vi.mpi \
i.wavelet \
- i.water
+ i.water \
+ i.wi
include $(MODULE_TOPDIR)/include/Make/Dir.make
Modified: grass-addons/grass7/imagery/i.wi/Makefile
===================================================================
--- grass-addons/grass6/imagery/gipe/i.wi/Makefile 2015-12-30 18:03:17 UTC (rev 67438)
+++ grass-addons/grass7/imagery/i.wi/Makefile 2015-12-30 21:43:56 UTC (rev 67441)
@@ -2,13 +2,9 @@
PGM = i.wi
-LIBES = $(GISLIB)
-DEPENDENCIES = $(GISDEP)
+LIBES = $(GISLIB) $(RASTERLIB)
+DEPENDENCIES = $(GISDEP) $(RASTERDEP)
include $(MODULE_TOPDIR)/include/Make/Module.make
-ifneq ($(USE_LARGEFILES),)
- EXTRA_CFLAGS = -D_FILE_OFFSET_BITS=64
-endif
-
default: cmd
Deleted: grass-addons/grass7/imagery/i.wi/description.html
===================================================================
--- grass-addons/grass6/imagery/gipe/i.wi/description.html 2015-12-30 18:03:17 UTC (rev 67438)
+++ grass-addons/grass7/imagery/i.wi/description.html 2015-12-30 21:43:56 UTC (rev 67441)
@@ -1,26 +0,0 @@
-<h2>DESCRIPTION</h2>
-
-<em>i.wi</em> calculates water indices based on biophysical parameters.
-
-1. LSWI: Land Surface Water Index
-
-
-<h2>NOTES</h2>
-Created the module following the i.vi modular architechture to add more water indices as they come in literature.
-
-<h2>TODO</h2>
-Find other water indices and add them.
-
-<h2>SEE ALSO</h2>
-
-<em>
-<a href="i.vi.html">i.vi</a><br>
-</em>
-
-
-<h2>AUTHORS</h2>
-Yann Chemin, International Rice Research Institute, The Philippines<br>
-
-
-<p>
-<i>Last changed: $Date$</i>
Copied: grass-addons/grass7/imagery/i.wi/i.wi.html (from rev 67438, grass-addons/grass6/imagery/gipe/i.wi/description.html)
===================================================================
--- grass-addons/grass7/imagery/i.wi/i.wi.html (rev 0)
+++ grass-addons/grass7/imagery/i.wi/i.wi.html 2015-12-30 21:43:56 UTC (rev 67441)
@@ -0,0 +1,26 @@
+<h2>DESCRIPTION</h2>
+
+<em>i.wi</em> calculates water indices based on biophysical parameters.
+
+1. LSWI: Land Surface Water Index
+
+
+<h2>NOTES</h2>
+Created the module following the i.vi modular architechture to add more water indices as they come in literature.
+
+<h2>TODO</h2>
+Find other water indices and add them.
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="i.vi.html">i.vi</a><br>
+</em>
+
+
+<h2>AUTHORS</h2>
+Yann Chemin, International Rice Research Institute, The Philippines<br>
+
+
+<p>
+<i>Last changed: $Date$</i>
Modified: grass-addons/grass7/imagery/i.wi/main.c
===================================================================
--- grass-addons/grass6/imagery/gipe/i.wi/main.c 2015-12-30 18:03:17 UTC (rev 67438)
+++ grass-addons/grass7/imagery/i.wi/main.c 2015-12-30 21:43:56 UTC (rev 67441)
@@ -5,7 +5,7 @@
* AUTHOR(S): Yann Chemin - yann.chemin at gmail.com
* PURPOSE: Calculates water indices
*
- * COPYRIGHT: (C) 2008 by the GRASS Development Team
+ * COPYRIGHT: (C) 2008-2016 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
@@ -13,71 +13,50 @@
*
*****************************************************************************/
-
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <grass/gis.h>
+#include <grass/raster.h>
#include <grass/glocale.h>
double ls_wi(double nirchan, double swirchan);
int main(int argc, char *argv[])
{
struct Cell_head cellhd; /*region+header info */
-
char *mapset; /*mapset name */
-
int nrows, ncols;
-
int row, col;
-
char *wiflag; /*Switch for particular index */
-
struct GModule *module;
-
struct Option *input1, *input2, *input3, *output;
-
struct Flag *flag1;
-
struct History history; /*metadata */
-
struct Colors colors; /*Color rules */
-
-
-
- /************************************/
- /* FMEO Declarations**************** */
char *name; /*input raster name */
-
char *result; /*output raster name */
-
-
- /*File Descriptors */
int infd_nirchan, infd_swirchan;
-
int outfd;
-
char *nirchan, *swirchan;
-
int i = 0, j = 0;
-
void *inrast_nirchan, *inrast_swirchan;
DCELL * outrast;
RASTER_MAP_TYPE data_type_output = DCELL_TYPE;
RASTER_MAP_TYPE data_type_nirchan;
RASTER_MAP_TYPE data_type_swirchan;
-
-
- /************************************/
- G_gisinit(argv[0]);
+ /************************************/
+ G_gisinit(argv[0]);
module = G_define_module();
- module->keywords = _("Water index, biophysical parameters");
+ G_add_keyword(_("imagery"));
+ G_add_keyword(_("water"));
+ G_add_keyword(_("index"));
+ G_add_keyword(_("biophysical"));
module->description =
_("Water indices from nir and swir for the time being");
- /* Define the different options */
- input1 = G_define_option();
+ /* Define the different options */
+ input1 = G_define_option();
input1->key = _("winame");
input1->type = TYPE_STRING;
input1->required = YES;
@@ -95,69 +74,48 @@
output = G_define_standard_option(G_OPT_R_OUTPUT);
output->description = _("Name of the output wi layer");
-
- /********************/
- if (G_parser(argc, argv))
+ /********************/
+ if (G_parser(argc, argv))
exit(EXIT_FAILURE);
wiflag = input1->answer;
nirchan = input2->answer;
swirchan = input3->answer;
result = output->answer;
-
- /***************************************************/
- mapset = G_find_cell2(nirchan, "");
- if (mapset == NULL) {
- G_fatal_error(_("cell file [%s] not found"), nirchan);
- }
- data_type_nirchan = G_raster_map_type(nirchan, mapset);
- if ((infd_nirchan = G_open_cell_old(nirchan, mapset)) < 0)
+ /***************************************************/
+ data_type_nirchan = Rast_map_type(nirchan, mapset);
+ if ((infd_nirchan = Rast_open_old(nirchan, mapset)) < 0)
G_fatal_error(_("Cannot open cell file [%s]"), nirchan);
- if (G_get_cellhd(nirchan, mapset, &cellhd) < 0)
- G_fatal_error(_("Cannot read file header of [%s]"), nirchan);
- inrast_nirchan = G_allocate_raster_buf(data_type_nirchan);
-
-
- /***************************************************/
- mapset = G_find_cell2(swirchan, "");
- if (mapset == NULL) {
- G_fatal_error(_("cell file [%s] not found"), swirchan);
- }
- data_type_swirchan = G_raster_map_type(swirchan, mapset);
- if ((infd_swirchan = G_open_cell_old(swirchan, mapset)) < 0)
+ Rast_get_cellhd(nirchan, mapset, &cellhd);
+ inrast_nirchan = Rast_allocate_buf(data_type_nirchan);
+ /***************************************************/
+ data_type_swirchan = Rast_map_type(swirchan, mapset);
+ infd_swirchan = Rast_open_old(swirchan, mapset);
G_fatal_error(_("Cannot open cell file [%s]"), swirchan);
- if (G_get_cellhd(swirchan, mapset, &cellhd) < 0)
- G_fatal_error(_("Cannot read file header of [%s])"), swirchan);
- inrast_swirchan = G_allocate_raster_buf(data_type_swirchan);
-
-
- /***************************************************/
- G_debug(3, "number of rows %d", cellhd.rows);
- nrows = G_window_rows();
- ncols = G_window_cols();
- outrast = G_allocate_raster_buf(data_type_output);
-
- /* Create New raster files */
- if ((outfd = G_open_raster_new(result, data_type_output)) < 0)
- G_fatal_error(_("Could not open <%s>"), result);
-
- /* Process pixels */
- for (row = 0; row < nrows; row++)
- {
+ Rast_get_cellhd(swirchan, mapset, &cellhd);
+ inrast_swirchan = Rast_allocate_buf(data_type_swirchan);
+ /***************************************************/
+ G_debug(3, "number of rows %d", cellhd.rows);
+ nrows = Rast_window_rows();
+ ncols = Rast_window_cols();
+ outrast = Rast_allocate_buf(data_type_output);
+
+ /* Create New raster files */
+ outfd = Rast_open_new(result, data_type_output);
+ /* Process pixels */
+ for (row = 0; row < nrows; row++)
+ {
DCELL d;
DCELL d_nirchan;
DCELL d_swirchan;
G_percent(row, nrows, 2);
- if (G_get_raster_row
- (infd_nirchan, inrast_nirchan, row, data_type_nirchan) < 0)
- G_fatal_error(_("Could not read from <%s>"), nirchan);
- if (G_get_raster_row
- (infd_swirchan, inrast_swirchan, row, data_type_swirchan) < 0)
- G_fatal_error(_("Could not read from <%s>"), swirchan);
-
- /*process the data */
- for (col = 0; col < ncols; col++)
- {
+ Rast_get_row
+ (infd_nirchan, inrast_nirchan, row, data_type_nirchan);
+ Rast_get_row
+ (infd_swirchan, inrast_swirchan, row, data_type_swirchan);
+ /*process the data */
+ for (col = 0; col < ncols; col++)
+ {
switch (data_type_nirchan) {
case CELL_TYPE:
d_nirchan = (double)((CELL *) inrast_nirchan)[col];
@@ -180,40 +138,35 @@
d_swirchan = ((DCELL *) inrast_swirchan)[col];
break;
}
- if (G_is_d_null_value(&d_nirchan) ||
- G_is_d_null_value(&d_swirchan)) {
- G_set_d_null_value(&outrast[col], 1);
+ if (Rast_is_d_null_value(&d_nirchan) ||
+ Rast_is_d_null_value(&d_swirchan)) {
+ Rast_set_d_null_value(&outrast[col], 1);
}
else {
-
- /*calculate lswi */
- if (!strcoll(wiflag, "lswi")) {
- if (d_nirchan + d_swirchan < 0.001) {
- G_set_d_null_value(&outrast[col], 1);
- }
- else {
+ /*calculate lswi */
+ if (!strcoll(wiflag, "lswi")) {
+ if (d_nirchan + d_swirchan < 0.001) {
+ Rast_set_d_null_value(&outrast[col], 1);
+ }
+ else {
d = ls_wi(d_nirchan, d_swirchan);
((DCELL *) outrast)[col] = d;
}
}
}
- }
- if (G_put_raster_row(outfd, outrast, data_type_output) < 0)
- G_fatal_error(_("Cannot write to output raster file"));
}
- G_free(inrast_nirchan);
- G_close_cell(infd_nirchan);
- G_free(inrast_swirchan);
- G_close_cell(infd_swirchan);
- G_free(outrast);
- G_close_cell(outfd);
-
- /* Color from -1.0 to +1.0 in grey */
- G_init_colors(&colors);
- G_add_color_rule(-1.0, 0, 0, 0, 1.0, 255, 255, 255, &colors);
- G_short_history(result, "raster", &history);
- G_command_history(&history);
- G_write_history(result, &history);
+ Rast_put_row(outfd, outrast, data_type_output);
+ }
+ free(inrast_nirchan);
+ Rast_close(infd_nirchan);
+ free(inrast_swirchan);
+ Rast_close(infd_swirchan);
+ free(outrast);
+ Rast_close(outfd);
+ /* Color from -1.0 to +1.0 in grey */
+ Rast_short_history(result, "raster", &history);
+ Rast_command_history(&history);
+ Rast_write_history(result, &history);
exit(EXIT_SUCCESS);
}
More information about the grass-commit
mailing list