[GRASS-SVN] r67440 - in grass-addons/grass7/imagery: . i.water
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Dec 30 13:26:26 PST 2015
Author: ychemin
Date: 2015-12-30 13:26:26 -0800 (Wed, 30 Dec 2015)
New Revision: 67440
Added:
grass-addons/grass7/imagery/i.water/
grass-addons/grass7/imagery/i.water/i.water.html
Removed:
grass-addons/grass7/imagery/i.water/description.html
Modified:
grass-addons/grass7/imagery/Makefile
grass-addons/grass7/imagery/i.water/Makefile
grass-addons/grass7/imagery/i.water/main.c
Log:
Upgraded i.water to grass v7
Modified: grass-addons/grass7/imagery/Makefile
===================================================================
--- grass-addons/grass7/imagery/Makefile 2015-12-30 21:08:03 UTC (rev 67439)
+++ grass-addons/grass7/imagery/Makefile 2015-12-30 21:26:26 UTC (rev 67440)
@@ -27,7 +27,8 @@
i.spec.unmix \
i.theilsen \
i.vi.mpi \
- i.wavelet
+ i.wavelet \
+ i.water
include $(MODULE_TOPDIR)/include/Make/Dir.make
Modified: grass-addons/grass7/imagery/i.water/Makefile
===================================================================
--- grass-addons/grass6/imagery/gipe/i.water/Makefile 2015-12-30 18:03:17 UTC (rev 67438)
+++ grass-addons/grass7/imagery/i.water/Makefile 2015-12-30 21:26:26 UTC (rev 67440)
@@ -2,13 +2,9 @@
PGM = i.water
-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.water/description.html
===================================================================
--- grass-addons/grass6/imagery/gipe/i.water/description.html 2015-12-30 18:03:17 UTC (rev 67438)
+++ grass-addons/grass7/imagery/i.water/description.html 2015-12-30 21:26:26 UTC (rev 67440)
@@ -1,32 +0,0 @@
-<h2>DESCRIPTION</h2>
-
-<em>i.water</em> calculates a water layer after Xiao et al (2005) and Roy et al (2005).
-
-<h2>REFERENCES</h2>
-
-Xiao X., Boles S., Liu J., Zhuang D., Frokling S., Li C., Salas W., Moore III B. (2005). Mapping paddy rice agriculture in southern China using multi-temporal MODIS images. Remote Sensing of Environment 95:480-492.
-
-
-Roy D.P., Jin Y., Lewis P.E., Justice C.O. (2005). Prototyping a global algorithm for systematic fire-affected area mapping using MODIS time series data. Remote Sensing of Environment 97:137-162.
-
-<h2>NOTES</h2>
-
-<h2>TODO</h2>
-
-
-<h2>SEE ALSO</h2>
-
-<em>
-<a href="r.sun.html">r.sun</a><br>
-<a href="i.albedo.html">i.albedo</a><br>
-<a href="i.vi.html">i.vi</a><br>
-</em>
-
-
-<h2>AUTHORS</h2>
-
-Yann Chemin, International Rice Research Insitute, The Philippines<br>
-
-
-<p>
-<i>Last changed: $Date$</i>
Copied: grass-addons/grass7/imagery/i.water/i.water.html (from rev 67438, grass-addons/grass6/imagery/gipe/i.water/description.html)
===================================================================
--- grass-addons/grass7/imagery/i.water/i.water.html (rev 0)
+++ grass-addons/grass7/imagery/i.water/i.water.html 2015-12-30 21:26:26 UTC (rev 67440)
@@ -0,0 +1,32 @@
+<h2>DESCRIPTION</h2>
+
+<em>i.water</em> calculates a water layer after Xiao et al (2005) and Roy et al (2005).
+
+<h2>REFERENCES</h2>
+
+Xiao X., Boles S., Liu J., Zhuang D., Frokling S., Li C., Salas W., Moore III B. (2005). Mapping paddy rice agriculture in southern China using multi-temporal MODIS images. Remote Sensing of Environment 95:480-492.
+
+
+Roy D.P., Jin Y., Lewis P.E., Justice C.O. (2005). Prototyping a global algorithm for systematic fire-affected area mapping using MODIS time series data. Remote Sensing of Environment 97:137-162.
+
+<h2>NOTES</h2>
+
+<h2>TODO</h2>
+
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="r.sun.html">r.sun</a><br>
+<a href="i.albedo.html">i.albedo</a><br>
+<a href="i.vi.html">i.vi</a><br>
+</em>
+
+
+<h2>AUTHORS</h2>
+
+Yann Chemin, International Rice Research Insitute, The Philippines<br>
+
+
+<p>
+<i>Last changed: $Date$</i>
Modified: grass-addons/grass7/imagery/i.water/main.c
===================================================================
--- grass-addons/grass6/imagery/gipe/i.water/main.c 2015-12-30 18:03:17 UTC (rev 67438)
+++ grass-addons/grass7/imagery/i.water/main.c 2015-12-30 21:26:26 UTC (rev 67440)
@@ -7,7 +7,7 @@
* two versions, 1) generic (albedo,ndvi)
* 2) Modis (surf_refl_7,ndvi)
*
- * 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
@@ -20,9 +20,9 @@
#include <stdlib.h>
#include <string.h>
#include <grass/gis.h>
+#include <grass/raster.h>
#include <grass/glocale.h>
double water(double albedo, double ndvi);
-
double water_modis(double surf_ref_7, double ndvi);
int main(int argc, char *argv[])
@@ -50,7 +50,9 @@
/************************************/
G_gisinit(argv[0]);
module = G_define_module();
- module->keywords = _("water, detection");
+ G_add_keyword(_("imagery"));
+ G_add_keyword(_("water"));
+ G_add_keyword(_("detection"));
module->description = _("Water detection, 1 if found, 0 if not");
/* Define the different options */
@@ -62,7 +64,7 @@
input2->required = NO;
input2->description = _("Name of the Albedo layer [-]");
input3 = G_define_standard_option(G_OPT_R_INPUT);
- input3->key = "Modref7";
+ input3->key = "modref7";
input3->required = NO;
input3->description =
_("Name of the Modis surface reflectance band 7 layer [-]");
@@ -83,49 +85,34 @@
result1 = output1->answer;
/***************************************************/
- mapset = G_find_cell2(ndvi, "");
- if (mapset == NULL) {
- G_fatal_error(_("cell file [%s] not found"), ndvi);
- }
- data_type_ndvi = G_raster_map_type(ndvi, mapset);
- if ((infd_ndvi = G_open_cell_old(ndvi, mapset)) < 0)
+ data_type_ndvi = Rast_map_type(ndvi, mapset);
+ if ((infd_ndvi = Rast_open_old(ndvi, mapset)) < 0)
G_fatal_error(_("Cannot open cell file [%s]"), ndvi);
- if (G_get_cellhd(ndvi, mapset, &cellhd) < 0)
- G_fatal_error(_("Cannot read file header of [%s])"), ndvi);
- inrast_ndvi = G_allocate_raster_buf(data_type_ndvi);
+ Rast_get_cellhd(ndvi, mapset, &cellhd);
+ inrast_ndvi = Rast_allocate_buf(data_type_ndvi);
/***************************************************/
if (input2->answer) {
- mapset = G_find_cell2(albedo, "");
- if (mapset == NULL) {
- G_fatal_error(_("cell file [%s] not found"), albedo);
- }
- data_type_albedo = G_raster_map_type(albedo, mapset);
- if ((infd_albedo = G_open_cell_old(albedo, mapset)) < 0)
+ data_type_albedo = Rast_map_type(albedo, mapset);
+ if ((infd_albedo = Rast_open_old(albedo, mapset)) < 0)
G_fatal_error(_("Cannot open cell file [%s]"), albedo);
- if (G_get_cellhd(albedo, mapset, &cellhd) < 0)
- G_fatal_error(_("Cannot read file header of [%s]"), albedo);
- inrast_albedo = G_allocate_raster_buf(data_type_albedo);
+ Rast_get_cellhd(albedo, mapset, &cellhd);
+ inrast_albedo = Rast_allocate_buf(data_type_albedo);
}
/***************************************************/
if (input3->answer) {
- mapset = G_find_cell2(ref7, "");
- if (mapset == NULL) {
- G_fatal_error(_("Cell file [%s] not found"), ref7);
- }
- data_type_ref7 = G_raster_map_type(ref7, mapset);
- if ((infd_ref7 = G_open_cell_old(ref7, mapset)) < 0)
+ data_type_ref7 = Rast_map_type(ref7, mapset);
+ if ((infd_ref7 = Rast_open_old(ref7, mapset)) < 0)
G_fatal_error(_("Cannot open cell file [%s]"), ref7);
- if (G_get_cellhd(ref7, mapset, &cellhd) < 0)
- G_fatal_error(_("Cannot read file header of [%s]"), ref7);
- inrast_ref7 = G_allocate_raster_buf(data_type_ref7);
+ Rast_get_cellhd(ref7, mapset, &cellhd);
+ inrast_ref7 = Rast_allocate_buf(data_type_ref7);
}
/***************************************************/
G_debug(3, "number of rows %d", cellhd.rows);
- nrows = G_window_rows();
- ncols = G_window_cols();
- outrast1 = G_allocate_raster_buf(data_type_output);
+ nrows = Rast_window_rows();
+ ncols = Rast_window_cols();
+ outrast1 = Rast_allocate_buf(data_type_output);
/* Create New raster files */
- if ((outfd1 = G_open_raster_new(result1, data_type_output)) < 0)
+ if ((outfd1 = Rast_open_new(result1, data_type_output)) < 0)
G_fatal_error(_("Could not open <%s>"), result1);
/* Process pixels */
for (row = 0; row < nrows; row++)
@@ -136,18 +123,13 @@
DCELL d_ref7;
G_percent(row, nrows, 2);
/* read input maps */
- if (G_get_raster_row(infd_ndvi, inrast_ndvi, row, data_type_ndvi)
- < 0)
- G_fatal_error(_("Could not read from <%s>"), ndvi);
+ Rast_get_row(infd_ndvi, inrast_ndvi, row, data_type_ndvi);
if (input2->answer) {
- if (G_get_raster_row
- (infd_albedo, inrast_albedo, row, data_type_albedo) < 0)
- G_fatal_error(_("Could not read from <%s>"), albedo);
+ Rast_get_row
+ (infd_albedo, inrast_albedo, row, data_type_albedo);
}
if (input3->answer) {
- if (G_get_raster_row(infd_ref7, inrast_ref7, row, data_type_ref7)
- < 0)
- G_fatal_error(_("Could not read from <%s>"), ref7);
+ Rast_get_row(infd_ref7, inrast_ref7, row, data_type_ref7);
}
/*process the data */
for (col = 0; col < ncols; col++)
@@ -189,17 +171,15 @@
break;
}
}
- if (G_is_d_null_value(&d_ndvi) ||
- (input2->answer && G_is_d_null_value(&d_albedo)) ||
- (input3->answer && G_is_d_null_value(&d_ref7))) {
- G_set_c_null_value(&outrast1[col], 1);
+ if (Rast_is_d_null_value(&d_ndvi) ||
+ (input2->answer && Rast_is_d_null_value(&d_albedo)) ||
+ (input3->answer && Rast_is_d_null_value(&d_ref7))) {
+ Rast_set_c_null_value(&outrast1[col], 1);
}
else {
-
-
- /************************************/
- /* calculate water detection */
- if (input2->answer) {
+ /************************************/
+ /* calculate water detection */
+ if (input2->answer) {
d = water(d_albedo, d_ndvi);
}
else if (input3->answer) {
@@ -207,25 +187,24 @@
}
outrast1[col] = d;
}
- }
- if (G_put_raster_row(outfd1, outrast1, data_type_output) < 0)
- G_fatal_error(_("Cannot write to output raster file"));
}
- G_free(inrast_ndvi);
- G_close_cell(infd_ndvi);
+ Rast_put_row(outfd1, outrast1, data_type_output);
+ }
+ free(inrast_ndvi);
+ Rast_close(infd_ndvi);
if (input2->answer) {
- G_free(inrast_albedo);
- G_close_cell(infd_albedo);
+ free(inrast_albedo);
+ Rast_close(infd_albedo);
}
if (input3->answer) {
- G_free(inrast_ref7);
- G_close_cell(infd_ref7);
+ free(inrast_ref7);
+ Rast_close(infd_ref7);
}
- G_free(outrast1);
- G_close_cell(outfd1);
- G_short_history(result1, "raster", &history);
- G_command_history(&history);
- G_write_history(result1, &history);
+ free(outrast1);
+ Rast_close(outfd1);
+ Rast_short_history(result1, "raster", &history);
+ Rast_command_history(&history);
+ Rast_write_history(result1, &history);
exit(EXIT_SUCCESS);
}
More information about the grass-commit
mailing list