[GRASS-SVN] r50536 - grass-addons/grass6/raster/r.area

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Jan 29 12:49:43 EST 2012


Author: neteler
Date: 2012-01-29 09:49:43 -0800 (Sun, 29 Jan 2012)
New Revision: 50536

Modified:
   grass-addons/grass6/raster/r.area/description.html
   grass-addons/grass6/raster/r.area/main.c
Log:
fixed missing module part; fixed description; fixed indentation

Modified: grass-addons/grass6/raster/r.area/description.html
===================================================================
--- grass-addons/grass6/raster/r.area/description.html	2012-01-29 16:29:10 UTC (rev 50535)
+++ grass-addons/grass6/raster/r.area/description.html	2012-01-29 17:49:43 UTC (rev 50536)
@@ -2,15 +2,17 @@
 <dt><b>input</b></dt>
 <dd>Name of input created with r.clump or another cell category map.</dd>
 <dt><b>treshold</b></dt>
-<dd>Remove areas smaller than treshold, set null for removing areas</dd>
+<dd>Remove areas smaller than threshold, set null for removing areas</dd>
 <dt><b>binary</b></dt>
 <dd>Output map has only 0 and 1 values. If treshold is applied small areas are emoved and replaced by 0</dd>
 
 <dt><b>output</b></dt>
-<dd>Original categories replaced with number of cells for each category. If areas belonging to category are not continuous every area belonging to the same category has the same area value.</dd>
-<p>
+<dd>Original categories replaced with number of cells for each category. If areas belonging
+to category are not continuous every area belonging to the same category has the same area value.</dd>
+
 <h2>DESCRIPTION</h2>
-<p>module can be used to remove, areas smaller than treshold, reclass according areas (similar to r.reclass area, but work in cells, not hectares and allow create more classes)</p>
+<p>module can be used to remove, areas smaller than threshold, reclass according areas
+(similar to r.reclass area, but work in cells, not hectares and allow create more classes)</p>
 
 <h2>SEE ALSO</h2>
 <em>
@@ -23,4 +25,3 @@
 <h2>AUTHOR</h2>
 Jarek  Jasiewicz
 
-

Modified: grass-addons/grass6/raster/r.area/main.c
===================================================================
--- grass-addons/grass6/raster/r.area/main.c	2012-01-29 16:29:10 UTC (rev 50535)
+++ grass-addons/grass6/raster/r.area/main.c	2012-01-29 17:49:43 UTC (rev 50536)
@@ -1,10 +1,9 @@
 /* ***************************************************************************
  *
- * MODULE:       r.fuzzy.logic
+ * MODULE:       r.area
  * AUTHOR(S):    Jarek Jasiewicz <jarekj amu.edu.pl>
- * PURPOSE:      Peroforms logical operatations on membership images created with 
- * 							 r.fuzzy or dofferent method. Use families for fuzzy logic
- * COPYRIGHT:    (C) 1999-2010 by the GRASS Development Team
+ * PURPOSE:      Module to calculate size of clumped areas
+ * COPYRIGHT:    (C) 2010 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
@@ -22,148 +21,156 @@
 int main(int argc, char *argv[])
 {
 
-	struct GModule *module;
-	struct Option *input,
-								*output,
-								*par_treshold;
-	struct Flag *flag_binary;							
-									
-	struct Cell_head cellhd;
-	struct Range range;
-  struct History history;
+    struct GModule *module;
+    struct Option *input, *output, *par_treshold;
+    struct Flag *flag_binary;
 
-	char *mapset;
-	int nrows, ncols;
-	int binary, treshold;
-	int row, col;
-	int infd, outfd;
-	int *in_buf;
-	int *out_buf;
-	CELL c_min, c_max;
-	int *ncells;
-	int i;
-	
-	
-	G_gisinit(argv[0]);
-	
-	input = G_define_standard_option(G_OPT_R_INPUT);
-  input->description = _("Map created with r.clump");
-  
-  output = G_define_standard_option(G_OPT_R_OUTPUT);
-	output->description = _("Map with area size (in cells)");
-	
-	
-	par_treshold = G_define_option();	/* input stream mask file - optional */
-  par_treshold->key = "treshold";
-  par_treshold->type = TYPE_INTEGER;
-  par_treshold->answer = "0";
-  par_treshold->description = _("Remove areas lower than (0 for none):");
-	
-	flag_binary=G_define_flag();
-	flag_binary->key = 'b';
-  flag_binary->description = _("Binary output");
-	
+    struct Cell_head cellhd;
+    struct Range range;
+    struct History history;
 
-	 	if (G_parser(argc, argv))
+    char *mapset;
+    int nrows, ncols;
+    int binary, treshold;
+    int row, col;
+    int infd, outfd;
+    int *in_buf;
+    int *out_buf;
+    CELL c_min, c_max;
+    int *ncells;
+    int i;
+
+
+    G_gisinit(argv[0]);
+
+    /* Set description */
+    module = G_define_module();
+    module->keywords = _("raster");
+    module->description = _("Calculates size of clumped areas.");
+
+    input = G_define_standard_option(G_OPT_R_INPUT);
+    input->description = _("Map created with r.clump");
+
+    output = G_define_standard_option(G_OPT_R_OUTPUT);
+    output->description = _("Map with area size (in cells)");
+
+
+    par_treshold = G_define_option();	/* input stream mask file - optional */
+    par_treshold->key = "treshold";
+    par_treshold->type = TYPE_INTEGER;
+    par_treshold->answer = "0";
+    par_treshold->description = _("Remove areas lower than (0 for none):");
+
+    flag_binary = G_define_flag();
+    flag_binary->key = 'b';
+    flag_binary->description = _("Binary output");
+
+
+    if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
-	
-	
-	treshold = atof(par_treshold->answer);
-	binary = (flag_binary->answer != 0);
-	mapset = G_find_cell2(input->answer, "");
-	
-	  if (mapset == NULL)
+
+
+    treshold = atof(par_treshold->answer);
+    binary = (flag_binary->answer != 0);
+    mapset = G_find_cell2(input->answer, "");
+
+    if (mapset == NULL)
 	G_fatal_error(_("Raster map <%s> not found"), input->answer);
-	
-	  if ((infd = G_open_cell_old(input->answer, mapset)) < 0)
+
+    if ((infd = G_open_cell_old(input->answer, mapset)) < 0)
 	G_fatal_error(_("Unable to open raster map <%s>"), input->answer);
-	
-	  if (G_get_cellhd(input->answer, mapset, &cellhd) < 0)
+
+    if (G_get_cellhd(input->answer, mapset, &cellhd) < 0)
 	G_fatal_error(_("Unable to read file header of <%s>"), input->answer);
-	
-		if (G_raster_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_init_range(&range);
-	G_read_range(input->answer,mapset,&range);
-	G_get_range_min_max(&range, &c_min, &c_max);
-	
-	in_buf = G_allocate_raster_buf(CELL_TYPE);
-	
-	nrows = G_window_rows();
-	ncols = G_window_cols();
 
-	ncells=G_calloc(c_max+1,sizeof(int));
-		
-	G_message(_("Reading..."));
-	for (row = 0; row < nrows; row++) {
-		G_percent(row, nrows, 2);
-		
-		if (G_get_raster_row(infd, in_buf, row, CELL_TYPE)<0) {
-			G_close_cell(infd);
-			G_fatal_error(_("Cannot to read <%s> at row <%d>"), output->answer,row);
-		}
-				
-		for (col = 0; col < ncols; col++) {
-				
-				if(!G_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(treshold) {
-				for (i=1;i<c_max+1;++i)
-			if(ncells[i]<treshold)
-    ncells[i]=-1;
-		}
-		
-		if(binary) {
-				for (i=1;i<c_max+1;++i)
-			ncells[i]= ncells[i]<treshold ? -1 : 1;
-		}
-    
-    
-		if ((outfd = G_open_raster_new(output->answer, CELL_TYPE)) < 0)
+    if (G_raster_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_init_range(&range);
+    G_read_range(input->answer, mapset, &range);
+    G_get_range_min_max(&range, &c_min, &c_max);
+
+    in_buf = G_allocate_raster_buf(CELL_TYPE);
+
+    nrows = G_window_rows();
+    ncols = G_window_cols();
+
+    ncells = G_calloc(c_max + 1, sizeof(int));
+
+    G_message(_("Reading..."));
+    for (row = 0; row < nrows; row++) {
+	G_percent(row, nrows, 2);
+
+	if (G_get_raster_row(infd, in_buf, row, CELL_TYPE) < 0) {
+	    G_close_cell(infd);
+	    G_fatal_error(_("Cannot to read <%s> at row <%d>"),
+			  output->answer, row);
+	}
+
+	for (col = 0; col < ncols; col++) {
+
+	    if (!G_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 (treshold) {
+	for (i = 1; i < c_max + 1; ++i)
+	    if (ncells[i] < treshold)
+		ncells[i] = -1;
+    }
+
+    if (binary) {
+	for (i = 1; i < c_max + 1; ++i)
+	    ncells[i] = ncells[i] < treshold ? -1 : 1;
+    }
+
+
+    if ((outfd = G_open_raster_new(output->answer, CELL_TYPE)) < 0)
 	G_fatal_error(_("Unable to create raster map <%s>"), output->answer);
-	  	
-	out_buf = G_allocate_raster_buf(CELL_TYPE);
 
-  G_message(_("Writing..."));
-	for (row = 0; row < nrows; row++) {
-		G_percent(row, nrows, 2);
-				
-		if (G_get_raster_row(infd, in_buf, row, CELL_TYPE)<0) {
-			G_close_cell(infd);
-			G_fatal_error(_("Cannot to read <%s> at row <%d>"), output->answer,row);
-		}
-		
-		for (col = 0; col < ncols; col++) {
-				if(G_is_c_null_value(&in_buf[col]) || ncells[in_buf[col]]==-1)
-						if(binary)
-					out_buf[col]=0;
-						else
-					G_set_c_null_value(&out_buf[col],1);
-				else
-			out_buf[col] = ncells[in_buf[col]];
-		}
-	
-			if (G_put_raster_row(outfd, out_buf, CELL_TYPE) < 0)
-	   G_fatal_error(_("Failed writing raster map <%s>"), output->answer);
-	} /* end for row */
-  
-  G_free(ncells);
-  G_free(in_buf);
-	G_close_cell(infd);
-	G_free(out_buf);
-	G_close_cell(outfd);
+    out_buf = G_allocate_raster_buf(CELL_TYPE);
 
-	G_short_history(output->answer, "raster", &history);
-	G_command_history(&history);
-	G_write_history(output->answer, &history);
-	
-	G_message(_("Done!"));
-	exit(EXIT_SUCCESS);
+    G_message(_("Writing..."));
+    for (row = 0; row < nrows; row++) {
+	G_percent(row, nrows, 2);
+
+	if (G_get_raster_row(infd, in_buf, row, CELL_TYPE) < 0) {
+	    G_close_cell(infd);
+	    G_fatal_error(_("Cannot to read <%s> at row <%d>"),
+			  output->answer, row);
+	}
+
+	for (col = 0; col < ncols; col++) {
+	    if (G_is_c_null_value(&in_buf[col]) || ncells[in_buf[col]] == -1)
+		if (binary)
+		    out_buf[col] = 0;
+		else
+		    G_set_c_null_value(&out_buf[col], 1);
+	    else
+		out_buf[col] = ncells[in_buf[col]];
+	}
+
+	if (G_put_raster_row(outfd, out_buf, CELL_TYPE) < 0)
+	    G_fatal_error(_("Failed writing raster map <%s>"),
+			  output->answer);
+    }				/* end for row */
+
+    G_free(ncells);
+    G_free(in_buf);
+    G_close_cell(infd);
+    G_free(out_buf);
+    G_close_cell(outfd);
+
+    G_short_history(output->answer, "raster", &history);
+    G_command_history(&history);
+    G_write_history(output->answer, &history);
+
+    G_message(_("Done!"));
+    exit(EXIT_SUCCESS);
 }



More information about the grass-commit mailing list