[GRASS-SVN] r60389 - grass-addons/grass7/raster/r.area
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed May 21 05:21:06 PDT 2014
Author: zarch
Date: 2014-05-21 05:21:06 -0700 (Wed, 21 May 2014)
New Revision: 60389
Modified:
grass-addons/grass7/raster/r.area/main.c
Log:
Add lesser and greater options
Modified: grass-addons/grass7/raster/r.area/main.c
===================================================================
--- grass-addons/grass7/raster/r.area/main.c 2014-05-21 09:51:19 UTC (rev 60388)
+++ grass-addons/grass7/raster/r.area/main.c 2014-05-21 12:21:06 UTC (rev 60389)
@@ -25,7 +25,7 @@
{
struct GModule *module;
- struct Option *input, *output, *par_threshold;
+ struct Option *input, *output, *lesser, *greater;
struct Flag *flag_binary;
struct Cell_head cellhd;
@@ -34,7 +34,7 @@
char *mapset;
int nrows, ncols;
- int binary, threshold;
+ int binary, les, grt, gt;
int row, col;
int infd, outfd;
CELL *in_buf;
@@ -50,7 +50,7 @@
G_add_keyword(_("statistics"));
G_add_keyword(_("area"));
module->description =
- _("Calculates area of clumped areas and remove areas smaller than given threshold.");
+ _("Cacullates area of clumped areas and remove areas smaller than given threshold.");
input = G_define_standard_option(G_OPT_R_INPUT);
input->description = _("Map created with r.clump");
@@ -58,35 +58,42 @@
output = G_define_standard_option(G_OPT_R_OUTPUT);
output->description = _("Map with area size (in cells)");
- par_threshold = G_define_option(); /* input stream mask file - optional */
- par_threshold->key = "threshold";
- par_threshold->type = TYPE_INTEGER;
- par_threshold->answer = "0";
- par_threshold->description = _("Remove areas lower than (0 for none):");
+ lesser = G_define_option(); /* input stream mask file - optional */
+ lesser->key = "lesser";
+ lesser->type = TYPE_INTEGER;
+ lesser->answer = "0";
+ lesser->description = _("Remove areas lower than (0 for none):");
+ greater = G_define_option(); /* input stream mask file - optional */
+ greater->key = "greater";
+ greater->type = TYPE_INTEGER;
+ greater->answer = "-1";
+ greater->description = _("Remove areas greater than (-1 for none):");
+
flag_binary = G_define_flag();
flag_binary->key = 'b';
flag_binary->description = _("Binary output");
if (G_parser(argc, argv))
- exit(EXIT_FAILURE);
+ exit(EXIT_FAILURE);
-
- threshold = atof(par_threshold->answer);
binary = (flag_binary->answer != 0);
mapset = (char *)G_find_raster2(input->answer, "");
if (mapset == NULL)
- G_fatal_error(_("Raster map <%s> not found"), input->answer);
+ G_fatal_error(_("Raster map <%s> not found"), input->answer);
infd = Rast_open_old(input->answer, mapset);
Rast_get_cellhd(input->answer, mapset, &cellhd);
+ les = atof(lesser->answer);
+ grt = atof(greater->answer);
+ gt = grt > 0 ? grt : cellhd.rows * cellhd.cols;
if (Rast_map_type(input->answer, mapset) != CELL_TYPE)
- G_fatal_error(_("<%s> is not of type CELL, probably not crated with r.clump"),
- input->answer);
+ G_fatal_error(_("<%s> is not of type CELL, probably not crated with r.clump"),
+ input->answer);
Rast_init_range(&range);
Rast_read_range(input->answer, mapset, &range);
@@ -101,28 +108,28 @@
G_message(_("Reading..."));
for (row = 0; row < nrows; row++) {
- G_percent(row, nrows, 2);
- Rast_get_row(infd, in_buf, row, CELL_TYPE);
+ G_percent(row, nrows, 2);
+ Rast_get_row(infd, in_buf, row, CELL_TYPE);
- for (col = 0; col < ncols; col++) {
- if (!Rast_is_c_null_value(&in_buf[col])) {
- if (in_buf[col] < c_min || in_buf[col] > c_max)
- G_fatal_error(_("Value at row %d, col %d out of range: %d"),
- row, col, in_buf[col]);
- ncells[in_buf[col]]++;
- }
- }
- } /* end for row */
+ for (col = 0; col < ncols; col++) {
+ if (!Rast_is_c_null_value(&in_buf[col])) {
+ if (in_buf[col] < c_min || in_buf[col] > c_max)
+ G_fatal_error(_("Value at row %d, col %d out of range: %d"),
+ row, col, in_buf[col]);
+ ncells[in_buf[col]]++;
+ }
+ }
+ } /* end for row */
- if (threshold) {
- for (i = 1; i < c_max; ++i)
- if (ncells[i] < threshold)
- ncells[i] = -1;
+ if (les) {
+ for (i = 1; i < c_max; ++i)
+ if (ncells[i] < les || ncells[i] > gt)
+ ncells[i] = -1;
}
if (binary) {
- for (i = 1; i < c_max; ++i)
- ncells[i] = ncells[i] < threshold ? -1 : 1;
+ for (i = 1; i < c_max; ++i)
+ ncells[i] = ncells[i] < les ? -1 : 1;
}
outfd = Rast_open_new(output->answer, CELL_TYPE);
@@ -130,22 +137,21 @@
G_message(_("Writing..."));
for (row = 0; row < nrows; row++) {
- G_percent(row, nrows, 2);
+ G_percent(row, nrows, 2);
- Rast_get_row(infd, in_buf, row, CELL_TYPE);
+ Rast_get_row(infd, in_buf, row, CELL_TYPE);
- for (col = 0; col < ncols; col++) {
- if (Rast_is_c_null_value(&in_buf[col]) ||
- ncells[in_buf[col]] == -1)
- if (binary)
- out_buf[col] = 0;
- else
- Rast_set_c_null_value(&out_buf[col], 1);
- else
- out_buf[col] = ncells[in_buf[col]];
- }
- Rast_put_row(outfd, out_buf, CELL_TYPE);
- } /* end for row */
+ for (col = 0; col < ncols; col++) {
+ if (Rast_is_c_null_value(&in_buf[col]) || ncells[in_buf[col]] == -1)
+ if (binary)
+ out_buf[col] = 0;
+ else
+ Rast_set_c_null_value(&out_buf[col], 1);
+ else
+ out_buf[col] = ncells[in_buf[col]];
+ }
+ Rast_put_row(outfd, out_buf, CELL_TYPE);
+ } /* end for row */
G_free(ncells);
G_free(in_buf);
More information about the grass-commit
mailing list