[GRASS-SVN] r59095 - in grass/branches/releasebranch_6_4/raster/r.li: . r.li.cwed r.li.daemon r.li.dominance r.li.edgedensity r.li.mpa r.li.mps r.li.padcv r.li.padrange r.li.padsd r.li.patchdensity r.li.patchnum r.li.pielou r.li.renyi r.li.richness r.li.shannon r.li.shape r.li.simpson
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Feb 18 16:26:05 PST 2014
Author: neteler
Date: 2014-02-18 16:26:04 -0800 (Tue, 18 Feb 2014)
New Revision: 59095
Modified:
grass/branches/releasebranch_6_4/raster/r.li/description.html
grass/branches/releasebranch_6_4/raster/r.li/r.li.cwed/cwed.c
grass/branches/releasebranch_6_4/raster/r.li/r.li.cwed/description.html
grass/branches/releasebranch_6_4/raster/r.li/r.li.daemon/GenericCell.c
grass/branches/releasebranch_6_4/raster/r.li/r.li.daemon/GenericCell.h
grass/branches/releasebranch_6_4/raster/r.li/r.li.daemon/avl.c
grass/branches/releasebranch_6_4/raster/r.li/r.li.daemon/avlDefs.h
grass/branches/releasebranch_6_4/raster/r.li/r.li.daemon/avlID.c
grass/branches/releasebranch_6_4/raster/r.li/r.li.daemon/daemon.c
grass/branches/releasebranch_6_4/raster/r.li/r.li.daemon/worker.c
grass/branches/releasebranch_6_4/raster/r.li/r.li.dominance/description.html
grass/branches/releasebranch_6_4/raster/r.li/r.li.dominance/dominance.c
grass/branches/releasebranch_6_4/raster/r.li/r.li.edgedensity/description.html
grass/branches/releasebranch_6_4/raster/r.li/r.li.edgedensity/edgedensity.c
grass/branches/releasebranch_6_4/raster/r.li/r.li.mpa/description.html
grass/branches/releasebranch_6_4/raster/r.li/r.li.mpa/mpa.c
grass/branches/releasebranch_6_4/raster/r.li/r.li.mps/description.html
grass/branches/releasebranch_6_4/raster/r.li/r.li.mps/mps.c
grass/branches/releasebranch_6_4/raster/r.li/r.li.padcv/description.html
grass/branches/releasebranch_6_4/raster/r.li/r.li.padcv/padcv.c
grass/branches/releasebranch_6_4/raster/r.li/r.li.padrange/description.html
grass/branches/releasebranch_6_4/raster/r.li/r.li.padrange/padrange.c
grass/branches/releasebranch_6_4/raster/r.li/r.li.padsd/description.html
grass/branches/releasebranch_6_4/raster/r.li/r.li.padsd/padsd.c
grass/branches/releasebranch_6_4/raster/r.li/r.li.patchdensity/description.html
grass/branches/releasebranch_6_4/raster/r.li/r.li.patchdensity/main.c
grass/branches/releasebranch_6_4/raster/r.li/r.li.patchnum/description.html
grass/branches/releasebranch_6_4/raster/r.li/r.li.patchnum/main.c
grass/branches/releasebranch_6_4/raster/r.li/r.li.pielou/description.html
grass/branches/releasebranch_6_4/raster/r.li/r.li.pielou/pielou.c
grass/branches/releasebranch_6_4/raster/r.li/r.li.renyi/description.html
grass/branches/releasebranch_6_4/raster/r.li/r.li.richness/description.html
grass/branches/releasebranch_6_4/raster/r.li/r.li.richness/richness.c
grass/branches/releasebranch_6_4/raster/r.li/r.li.shannon/description.html
grass/branches/releasebranch_6_4/raster/r.li/r.li.shannon/shannon.c
grass/branches/releasebranch_6_4/raster/r.li/r.li.shape/description.html
grass/branches/releasebranch_6_4/raster/r.li/r.li.shape/main.c
grass/branches/releasebranch_6_4/raster/r.li/r.li.simpson/description.html
grass/branches/releasebranch_6_4/raster/r.li/r.li.simpson/simpson.c
Log:
r.li: trivial backports from trunk
Modified: grass/branches/releasebranch_6_4/raster/r.li/description.html
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/description.html 2014-02-19 00:24:09 UTC (rev 59094)
+++ grass/branches/releasebranch_6_4/raster/r.li/description.html 2014-02-19 00:26:04 UTC (rev 59095)
@@ -58,6 +58,7 @@
using on the areas selected on configuration file.
</ol>
+
<h2>NOTE</h2>
The <em>r.li.daemon</em> module also has a "main" function front-end
Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.cwed/cwed.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.cwed/cwed.c 2014-02-19 00:24:09 UTC (rev 59094)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.cwed/cwed.c 2014-02-19 00:26:04 UTC (rev 59095)
@@ -48,20 +48,16 @@
raster = G_define_standard_option(G_OPT_R_MAP);
- conf = G_define_option();
+ conf = G_define_standard_option(G_OPT_F_INPUT);
conf->key = "conf";
conf->description = _("Configuration file");
- conf->type = TYPE_STRING;
conf->required = YES;
- conf->gisprompt = "old_file,file,input";
- path = G_define_option();
+ path = G_define_standard_option(G_OPT_F_INPUT);
path->key = "path";
path->description =
- "Input file that contains the weight to calculate the index";
- path->type = TYPE_STRING;
+ _("Name of file that contains the weight to calculate the index");
path->required = YES;
- path->gisprompt = "old_file,file,input";
output = G_define_standard_option(G_OPT_R_OUTPUT);
@@ -84,28 +80,20 @@
double *result)
{
double indice = 0; /* the result */
-
struct Cell_head hd;
-
int i = 0;
int file_fd = -1;
int l; /*number of read byte */
int ris = 0;
-
char *mapset;
char *file;
char *strFile;
-
char row[NMAX]; /* to read the file */
-
char **bufRighe; /* contains every valid file row */
-
char separatore; /* separator to split a string */
-
long totCoppie = 0; /* number of cells pair */
long totRow = 0; /* of the file */
long tabSize = 10; /* array length */
-
Coppie *cc = NULL; /* here store the pair of cell with the weight. these information are in the file */
@@ -251,16 +239,13 @@
}
}
- /*else
- * num = 1 ---> in the line there is only 1 token
+ /* else num = 1 ---> in the line there is only 1 token
* I ignore this line
*/
-
}
-
switch (ad->data_type) {
case CELL_TYPE:
{
@@ -301,7 +286,6 @@
int calculate(int fd, struct area_entry *ad, Coppie * cc, long totCoppie,
double *result)
{
-
double indice = 0;
double somma = 0;
double area = 0;
@@ -340,7 +324,6 @@
masked = TRUE;
}
-
buf_sup = G_allocate_cell_buf();
if (buf_sup == NULL) {
G_fatal_error("malloc buf_sup failed");
@@ -358,7 +341,8 @@
G_set_c_null_value(buf_sup + ad->x, ad->cl); /*the first time buf_sup is all null */
for (j = 0; j < ad->rl; j++) { /* for each row */
- buf_corr = RLI_get_cell_raster_row(fd, j + ad->y, ad); /* read row of raster */
+ /* read row of raster */
+ buf_corr = RLI_get_cell_raster_row(fd, j + ad->y, ad);
if (j > 0) { /* not first row */
buf_sup = RLI_get_cell_raster_row(fd, j - 1 + ad->y, ad);
}
@@ -381,8 +365,8 @@
}
if (!(G_is_null_value(&corrCell, CELL_TYPE))) {
supCell = buf_sup[i + ad->x];
- /* calculate how many edge the cell has */
+ /* calculate how many edges the cell has */
if (((!G_is_null_value(&prevCell, CELL_TYPE))) &&
(corrCell != prevCell)) {
int r = 0;
@@ -414,7 +398,6 @@
mask_sup = mask_corr;
}
-
/* calcolo dell'indice */
if (area == 0)
indice = -1;
@@ -431,6 +414,7 @@
*result = indice;
if (masked) {
+ close(mask_fd);
G_free(mask_corr);
G_free(mask_sup);
}
@@ -443,7 +427,6 @@
int calculateD(int fd, struct area_entry *ad, Coppie * cc, long totCoppie,
double *result)
{
-
double indice = 0;
double somma = 0;
double area = 0;
@@ -483,7 +466,6 @@
masked = TRUE;
}
-
buf_sup = G_allocate_d_raster_buf();
if (buf_sup == NULL) {
G_fatal_error("malloc buf_sup failed");
@@ -498,7 +480,8 @@
G_set_d_null_value(buf_sup + ad->x, ad->cl); /*the first time buf_sup is all null */
for (j = 0; j < ad->rl; j++) { /* for each row */
- buf_corr = RLI_get_dcell_raster_row(fd, j + ad->y, ad); /* read row of raster */
+ /* read row of raster */
+ buf_corr = RLI_get_dcell_raster_row(fd, j + ad->y, ad);
if (j > 0) { /* not first row */
buf_sup = RLI_get_dcell_raster_row(fd, j - 1 + ad->y, ad);
}
@@ -552,7 +535,6 @@
mask_sup = mask_corr;
}
-
/* calcolo dell'indice */
if (area == 0)
indice = -1;
@@ -568,6 +550,7 @@
}
*result = indice;
if (masked) {
+ close(mask_fd);
G_free(mask_corr);
G_free(mask_sup);
}
@@ -579,7 +562,6 @@
int calculateF(int fd, struct area_entry *ad, Coppie * cc, long totCoppie,
double *result)
{
-
double indice = 0;
double somma = 0;
double area = 0;
@@ -636,10 +618,11 @@
c1.t = FCELL_TYPE;
c2.t = FCELL_TYPE;
-
for (j = 0; j < ad->rl; j++) { /* for each row */
- buf_corr = RLI_get_fcell_raster_row(fd, j + ad->y, ad); /* read row of raster */
- if (j > 0) { /* not first row */
+ /* read row of raster */
+ buf_corr = RLI_get_fcell_raster_row(fd, j + ad->y, ad);
+ if (j > 0) {
+ /* not first row */
buf_sup = RLI_get_fcell_raster_row(fd, j - 1 + ad->y, ad);
}
/*read mask if needed */
@@ -672,7 +655,6 @@
return RLI_ERRORE;
}
-
if ((!(G_is_null_value(&supCell, FCELL_TYPE))) &&
(corrCell != supCell)) {
int r = 0;
@@ -692,7 +674,6 @@
mask_sup = mask_corr;
}
-
/* calcolo dell'indice */
if (area == 0)
indice = -1;
@@ -708,6 +689,7 @@
}
*result = indice;
if (masked) {
+ close(mask_fd);
G_free(mask_corr);
G_free(mask_sup);
}
Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.cwed/description.html
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.cwed/description.html 2014-02-19 00:24:09 UTC (rev 59094)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.cwed/description.html 2014-02-19 00:26:04 UTC (rev 59095)
@@ -28,7 +28,7 @@
the <tt>$HOME/.r.li/output/</tt> folder.
<p>
<!-- TODO: verify next: -->
-If the input raster map contains only NULL values it is considered to
+If the sample area contains only NULL values it is considered to
have 0 patch and CWED=0. If Area is 0 <em>r.li.cwed</em> returns -1.
This is only possible if the map is masked.<br>
If you want to change these -1 values to NULL, run subsequently on the resulting map:
Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.daemon/GenericCell.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.daemon/GenericCell.c 2014-02-19 00:24:09 UTC (rev 59094)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.daemon/GenericCell.c 2014-02-19 00:26:04 UTC (rev 59095)
@@ -6,6 +6,7 @@
* Read the COPYING file that comes with GRASS for details.
*
*/
+
#include "GenericCell.h"
int equalsGenericCell(generic_cell c1, generic_cell c2)
Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.daemon/GenericCell.h
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.daemon/GenericCell.h 2014-02-19 00:24:09 UTC (rev 59094)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.daemon/GenericCell.h 2014-02-19 00:26:04 UTC (rev 59095)
@@ -7,12 +7,12 @@
*
*/
+#ifndef GENERICCELL_H
+#define GENERICCELL_H
+
#include <grass/gis.h>
#include <grass/glocale.h>
-#ifndef GENERICCELL_H
-#define GENERICCELL_H
-
#define GC_HIGHER 1
#define GC_EQUAL 2
#define GC_LOWER 3
Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.daemon/avl.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.daemon/avl.c 2014-02-19 00:24:09 UTC (rev 59094)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.daemon/avl.c 2014-02-19 00:26:04 UTC (rev 59095)
@@ -6,14 +6,15 @@
* Read the COPYING file that comes with GRASS for details.
*
*/
-#include <grass/gis.h>
-#include <grass/glocale.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
+#include <grass/gis.h>
+#include <grass/glocale.h>
+
#include "defs.h"
#include "avlDefs.h"
#include "avl.h"
@@ -32,7 +33,7 @@
void printAVL(avl_node * r);
-/* define function declsred in avl.h */
+/* define function declared in avl.h */
avl_tree avl_make(const generic_cell k, const long n)
{
@@ -186,6 +187,8 @@
}
+
+
static avl_node *avl_individua(const avl_tree root, const generic_cell k,
avl_node ** father, int *direction)
{
Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.daemon/avlDefs.h
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.daemon/avlDefs.h 2014-02-19 00:24:09 UTC (rev 59094)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.daemon/avlDefs.h 2014-02-19 00:26:04 UTC (rev 59095)
@@ -6,6 +6,7 @@
* Read the COPYING file that comes with GRASS for details.
*
*/
+
#define AVL_S 1
#define AVL_D 2
#define AVL_SS 11
Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.daemon/avlID.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.daemon/avlID.c 2014-02-19 00:24:09 UTC (rev 59094)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.daemon/avlID.c 2014-02-19 00:26:04 UTC (rev 59095)
@@ -7,13 +7,13 @@
*
*/
-#include <grass/gis.h>
-#include <grass/glocale.h>
-
#include <stdlib.h>
#include <fcntl.h>
#include <math.h>
+#include <grass/gis.h>
+#include <grass/glocale.h>
+
#include "defs.h"
#include "avlDefs.h"
#include "avlID.h"
@@ -30,7 +30,6 @@
void avlID_rotation_rr(avlID_node * critical);
-
avlID_tree avlID_make(const long k, const long n)
{
avlID_node *root = NULL; /* root pointer */
Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.daemon/daemon.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.daemon/daemon.c 2014-02-19 00:24:09 UTC (rev 59094)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.daemon/daemon.c 2014-02-19 00:26:04 UTC (rev 59095)
@@ -15,6 +15,7 @@
* \include
*
*/
+#include <grass/config.h>
#include <stdlib.h>
#include <stddef.h>
#include <fcntl.h>
@@ -34,6 +35,10 @@
#include <grass/glocale.h>
#include "daemon.h"
+#ifdef __MINGW32__
+#define srandom srand
+#define random rand
+#endif
int calculateIndex(char *file, int f(int, char **, struct area_entry *, double *),
char **parameters, char *raster, char *output)
@@ -73,7 +78,6 @@
if (mkfifo(reportChannelName, 0644) == -1)
G_fatal_error("Error in pipe creation");
-
/*###############################################
--------------create childs-------------------
############################################### */
@@ -132,7 +136,7 @@
if (parsed == MVWIN) {
/* struct Cell_head cellhd_r, cellhd_new;
char *mapset; */
- /* create new raster file */
+ /*creating new raster file */
mv_fd = G_open_raster_new(output, DCELL_TYPE);
if (mv_fd < 0)
G_fatal_error(_("Unable to create raster map <%s>"), output);
@@ -169,8 +173,7 @@
i++;
}
-
- /* body */
+ /*body */
while (next_Area(parsed, l, g, &m) != 0) {
int j = 0, donePid;
Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.daemon/worker.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.daemon/worker.c 2014-02-19 00:24:09 UTC (rev 59094)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.daemon/worker.c 2014-02-19 00:26:04 UTC (rev 59095)
@@ -275,6 +275,7 @@
if (write(mask_fd, buf, cl * sizeof(int)) < 0)
return NULL;
}
+
close(mask_fd);
return G_store(tmp_file);
}
Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.dominance/description.html
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.dominance/description.html 2014-02-19 00:24:09 UTC (rev 59094)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.dominance/description.html 2014-02-19 00:26:04 UTC (rev 59095)
@@ -32,8 +32,11 @@
<em>r.li.setup</em>) and saving results in <em>my_out</em>, run:
<div class="code"><pre>
r.li.dominance map=my_map conf=my_conf output=my_out
+</pre></div>
+<p>
-# forest map example:
+Forest map (Spearfish sample dataset) example:
+<div class="code"><pre>
g.region rast=landcover.30m -p
r.mapcalc "forests = if(landcover.30m >= 41 && landcover.30m <= 43,1,null())"
r.li.dominance map=forests conf=movwindow7 out=forests_dominance_mov7
Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.dominance/dominance.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.dominance/dominance.c 2014-02-19 00:24:09 UTC (rev 59094)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.dominance/dominance.c 2014-02-19 00:26:04 UTC (rev 59095)
@@ -1,13 +1,19 @@
-/*
- * \brief calculates dominance's diversity index
+/****************************************************************************
*
- * \AUTHOR: Serena Pallecchi student of Computer Science University of Pisa (Italy)
- * Commission from Faunalia Pontedera (PI) www.faunalia.it
+ * MODULE: r.li.dominance
+ * AUTHOR(S): Serena Pallecchi (original contributor)
+ * student of Computer Science University of Pisa (Italy)
+ * Commission from Faunalia Pontedera (PI) www.faunalia.it
+ * Rewrite: Markus Metz
*
- * This program is free software under the GPL (>=v2)
- * Read the COPYING file that comes with GRASS for details.
+ * PURPOSE: calculates dominance diversity index
+ * COPYRIGHT: (C) 2007-2014 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.
+ *
+ *****************************************************************************/
#include <grass/gis.h>
#include <grass/glocale.h>
@@ -21,6 +27,8 @@
#include "../r.li.daemon/avl.h"
#include "../r.li.daemon/daemon.h"
+/* template is shannon */
+
int calculate(int fd, struct area_entry *ad, double *result);
int calculateD(int fd, struct area_entry *ad, double *result);
int calculateF(int fd, struct area_entry *ad, double *result);
@@ -41,11 +49,9 @@
raster = G_define_standard_option(G_OPT_R_MAP);
- conf = G_define_option();
+ conf = G_define_standard_option(G_OPT_F_INPUT);
conf->key = "conf";
conf->description = _("Configuration file");
- conf->type = TYPE_STRING;
- conf->gisprompt = "old_file,file,input";
conf->required = YES;
output = G_define_standard_option(G_OPT_R_OUTPUT);
@@ -55,7 +61,6 @@
return calculateIndex(conf->answer, dominance, NULL, raster->answer,
output->answer);
-
}
@@ -91,22 +96,19 @@
G_fatal_error("data type unknown");
return RLI_ERRORE;
}
-
}
if (ris != RLI_OK)
- return RLI_ERRORE;
+ return RLI_ERRORE;
*result = indice;
return RLI_OK;
-
}
int calculate(int fd, struct area_entry *ad, double *result)
{
-
CELL *buf;
CELL corrCell;
CELL precCell;
@@ -266,14 +268,12 @@
return RLI_ERRORE;
}
tot = avl_to_array(albero, zero, array);
-
if (tot != m) {
- G_warning
- ("avl_to_array unaspected value. the result could be wrong");
+ G_warning("avl_to_array unexpected value. the result could be wrong");
return RLI_ERRORE;
}
- /* calculate summary */
+ /* calculate shannon */
for (i = 0; i < m; i++) {
t = (double)array[i]->tot;
percentuale = (double)(t / area);
@@ -325,9 +325,7 @@
double logaritmo;
avl_tree albero = NULL;
-
AVL_table *array;
-
generic_cell cc;
cc.t = DCELL_TYPE;
@@ -464,7 +462,6 @@
return RLI_ERRORE;
}
tot = avl_to_array(albero, zero, array);
-
if (tot != m) {
G_warning
("avl_to_array unaspected value. the result could be wrong");
@@ -478,7 +475,6 @@
logaritmo = (double)log(percentuale);
somma = somma + (percentuale * logaritmo);
}
-
G_free(array);
if (m != 0)
@@ -523,9 +519,7 @@
double logaritmo;
avl_tree albero = NULL;
-
AVL_table *array;
-
generic_cell cc;
cc.t = FCELL_TYPE;
@@ -543,8 +537,6 @@
}
G_set_f_null_value(&precCell, 1);
-
-
for (j = 0; j < ad->rl; j++) { /* for each row */
if (masked) {
if (read(mask_fd, mask_buf, (ad->cl * sizeof(int))) < 0) {
@@ -661,14 +653,12 @@
return RLI_ERRORE;
}
tot = avl_to_array(albero, zero, array);
-
if (tot != m) {
- G_warning
- ("avl_to_array unaspected value. the result could be wrong");
+ G_warning("avl_to_array unexpected value. the result could be wrong");
return RLI_ERRORE;
}
- /* calculate summary */
+ /* calculate shannon */
for (i = 0; i < m; i++) {
t = (double)array[i]->tot;
percentuale = (double)(t / area);
Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.edgedensity/description.html
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.edgedensity/description.html 2014-02-19 00:24:09 UTC (rev 59094)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.edgedensity/description.html 2014-02-19 00:26:04 UTC (rev 59095)
@@ -3,10 +3,11 @@
<em>r.li.edgedensity </em>calculates:<br>
<br>
<ul>
- <li> the density of all the edge of patch i
+ <li> the density of all edges of patch type <em>k</em>
<img alt="rliEdgeDensity formula1" src="rliEdgeDensity_formula1.png">
, or
- <li> the density of all the edge in the sampling area if i isn't specified,
+ <li> the density of all edges in the sampling area if <em>k</em> is
+ not specified,
<img alt="rliEdgeDensity formula2" src="rliEdgeDensity_formula2.png">
</ul>
<p>with:
@@ -14,7 +15,8 @@
<li><b>k</b>: patch type</li>
<li><b>m</b>: number of patch types</li>
<li><b>n</b>: number of edge segments of patch type k</li>
-<li><b>e<small><small>ik </small></small></b>:total length of edge in landscape involving patch type k</li>
+<li><b>e<small><small>ik </small></small></b>:total edge length in
+the landscape involving patch type k</li>
<li> <b>Area</b>: total landscape area</li>
</ul>
@@ -49,8 +51,11 @@
file run:<br>
<div class="code"><pre>
r.li.edgedensity map=my_map conf=my_conf output=my_out patch_type=34
+</pre></div>
+<p>
-# forest map example:
+Forest map (Spearfish sample dataset) example:
+<div class="code"><pre>
g.region rast=landcover.30m -p
r.mapcalc "forests = if(landcover.30m >= 41 && landcover.30m <= 43,1,null())"
r.li.edgedensity map=forests conf=movwindow7 out=forests_edgedens_mov7
Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.edgedensity/edgedensity.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.edgedensity/edgedensity.c 2014-02-19 00:24:09 UTC (rev 59094)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.edgedensity/edgedensity.c 2014-02-19 00:26:04 UTC (rev 59095)
@@ -40,12 +40,10 @@
raster = G_define_standard_option(G_OPT_R_MAP);
- conf = G_define_option();
+ conf = G_define_standard_option(G_OPT_F_INPUT);
conf->key = "conf";
conf->description = _("Configuration file");
- conf->type = TYPE_STRING;
conf->required = YES;
- conf->gisprompt = "old_file,file,input";
output = G_define_standard_option(G_OPT_R_OUTPUT);
@@ -72,15 +70,11 @@
}
-
int edgedensity(int fd, char **valore, struct area_entry *ad, double *result)
{
struct Cell_head hd;
-
int ris = -1;
-
char *mapset;
-
double indice = 0;
mapset = G_find_cell(ad->raster, "");
@@ -88,7 +82,6 @@
if (G_get_cellhd(ad->raster, mapset, &hd) == -1)
return RLI_ERRORE;
-
switch (ad->data_type) {
case CELL_TYPE:
{
@@ -146,6 +139,7 @@
/* open mask if needed */
if (ad->mask == 1) {
+
if ((mask_fd = open(ad->mask_name, O_RDONLY, 0755)) < 0) {
G_fatal_error("Cannot open mask file <%s>", ad->mask_name);
return RLI_ERRORE; /* FIXME: can not return from a fatal error */
@@ -184,7 +178,6 @@
if (j > 0) /* not first row */
buf_sup = RLI_get_cell_raster_row(fd, j - 1 + ad->y, ad);
-
if ((j + 1) < ad->rl) { /*not last row */
buf_inf = RLI_get_cell_raster_row(fd, 1 + j + ad->y, ad);
}
@@ -204,10 +197,9 @@
return RLI_ERRORE;
}
-
- if ((j + 1) < ad->rl) { /*not last row */
+ if ((j + 1) < ad->rl) { /* not last row */
if (read(mask_fd, mask_inf, (ad->cl * sizeof(int))) < 0) {
- G_fatal_error("reading mask_inf");
+ G_fatal_error("reading mask_inf at row j");
return RLI_ERRORE;
}
}
@@ -243,20 +235,17 @@
supCell = buf_sup[i + ad->x];
-
if (masked && mask_inf[i + ad->x] == 0)
G_set_c_null_value(&infCell, 1);
else
infCell = buf_inf[i + ad->x];
- /* calculate how many edge the cell has */
-
+ /* calculate how many edges the cell has */
if ((G_is_null_value(&prevCell, CELL_TYPE)) ||
(corrCell != prevCell)) {
bordoCorr++;
}
-
if ((G_is_null_value(&supCell, CELL_TYPE)) ||
(corrCell != supCell)) {
bordoCorr++;
@@ -267,13 +256,12 @@
bordoCorr++;
}
-
if ((G_is_null_value(&nextCell, CELL_TYPE)) ||
(corrCell != nextCell)) {
bordoCorr++;
}
- /*store the result in the tree */
+ /* store the result in the tree */
if (albero == NULL) {
c1.val.c = corrCell;
albero = avl_make(c1, bordoCorr);
@@ -309,13 +297,10 @@
}
}
}
-
bordoCorr = 0;
}
-
prevCell = buf_corr[i + ad->x];
}
-
if (masked)
mask_sup = mask_corr;
}
@@ -337,10 +322,8 @@
c1.val.c = cella;
e = (double)howManyCell(albero, c1);
somma = e;
-
}
else { /* all classes */
-
array = G_malloc(m * sizeof(AVL_tableRow));
if (array == NULL) {
G_fatal_error("malloc array failed");
@@ -349,7 +332,7 @@
tot = avl_to_array(albero, zero, array);
if (tot != m) {
G_warning
- ("avl_to_array unaspected value. the result could be wrong");
+ ("avl_to_array unexpected value. the result could be wrong");
}
for (i = 0; i < m; i++) {
e = (double)array[i]->tot;
@@ -371,7 +354,6 @@
return RLI_OK;
}
-
int calculateD(int fd, struct area_entry *ad, char **valore, double *result)
{
double indice = 0;
@@ -461,7 +443,6 @@
return RLI_ERRORE;
}
-
if ((j + 1) < ad->rl) { /*not last row */
if (read(mask_fd, mask_inf, (ad->cl * sizeof(int))) < 0) {
G_fatal_error("reading mask_inf");
@@ -481,18 +462,15 @@
G_set_d_null_value(&corrCell, 1);
for (i = 0; i < ad->cl; i++) { /* for each cell in the row */
-
area++;
corrCell = buf_corr[i + ad->x];
-
if (masked && mask_corr[i + ad->x] == 0) {
G_set_d_null_value(&corrCell, 1);
area--;
}
if (!(G_is_null_value(&corrCell, DCELL_TYPE))) {
-
if ((i + 1) == ad->cl) /*last cell of the row */
G_set_d_null_value(&nextCell, 1);
else if (masked && mask_corr[i + 1 + ad->x] == 0)
@@ -502,7 +480,6 @@
supCell = buf_sup[i + ad->x];
-
if (masked && mask_inf[i + ad->x] == 0)
G_set_d_null_value(&infCell, 1);
else
@@ -530,7 +507,7 @@
bordoCorr++;
}
- /*store the result in the tree */
+ /* store the result in the tree */
if (albero == NULL) {
c1.val.dc = corrCell;
albero = avl_make(c1, bordoCorr);
@@ -566,17 +543,12 @@
}
}
}
-
bordoCorr = 0;
-
}
-
prevCell = buf_corr[i + ad->x];
}
-
if (masked)
mask_sup = mask_corr;
-
}
/* calculate index */
@@ -605,7 +577,7 @@
tot = avl_to_array(albero, zero, array);
if (tot != m) {
G_warning
- ("avl_to_array unaspected value. the result could be wrong");
+ ("avl_to_array unexpected value. the result could be wrong");
}
for (i = 0; i < m; i++) {
e = (double)array[i]->tot;
@@ -684,7 +656,6 @@
/* for each raster row */
for (j = 0; j < ad->rl; j++) {
-
/* read row of raster */
buf_corr = RLI_get_fcell_raster_row(fd, j + ad->y, ad);
@@ -692,7 +663,6 @@
buf_sup = RLI_get_fcell_raster_row(fd, j - 1 + ad->y, ad);
if ((j + 1) < ad->rl) { /* not last row */
-
buf_inf = RLI_get_fcell_raster_row(fd, 1 + j + ad->y, ad);
}
else {
@@ -701,11 +671,10 @@
G_fatal_error("malloc mask_inf failed");
return RLI_ERRORE;
}
-
G_set_f_null_value(buf_inf + ad->x, ad->cl);
}
- /*read mask if needed */
+ /* read mask if needed */
if (masked) {
if (read(mask_fd, mask_corr, (ad->cl * sizeof(int))) < 0) {
@@ -752,14 +721,12 @@
supCell = buf_sup[i + ad->x];
-
if (masked && mask_inf[i + ad->x] == 0)
G_set_f_null_value(&infCell, 1);
else
infCell = buf_inf[i + ad->x];
/* calculate how many edge the cell has */
-
if ((G_is_null_value(&prevCell, FCELL_TYPE)) ||
(corrCell != prevCell)) {
bordoCorr++;
@@ -780,7 +747,7 @@
bordoCorr++;
}
- /*store the result in the tree */
+ /* store the result in the tree */
if (albero == NULL) {
c1.val.c = corrCell;
albero = avl_make(c1, bordoCorr);
@@ -816,17 +783,12 @@
}
}
}
-
bordoCorr = 0;
-
}
-
prevCell = buf_corr[i + ad->x];
}
-
if (masked)
mask_sup = mask_corr;
-
}
/* calculate index */
@@ -869,6 +831,7 @@
*result = indice;
if (masked) {
+ close(mask_fd);
G_free(mask_inf);
G_free(mask_corr);
}
Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.mpa/description.html
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.mpa/description.html 2014-02-19 00:24:09 UTC (rev 59094)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.mpa/description.html 2014-02-19 00:26:04 UTC (rev 59095)
@@ -35,8 +35,11 @@
<em>r.li.setup</em>) and saving results in <em>my_out</em>, run:
<div class="code"><pre>
r.li.mpa map=my_map conf=my_conf output=my_out
+</pre></div>
+<p>
-# forest map example:
+Forest map (Spearfish sample dataset) example:
+<div class="code"><pre>
g.region rast=landcover.30m -p
r.mapcalc "forests = if(landcover.30m >= 41 && landcover.30m <= 43,1,null())"
r.li.mpa map=forests conf=movwindow7 out=forests_mpa_mov7
Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.mpa/mpa.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.mpa/mpa.c 2014-02-19 00:24:09 UTC (rev 59094)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.mpa/mpa.c 2014-02-19 00:26:04 UTC (rev 59095)
@@ -40,12 +40,10 @@
raster = G_define_standard_option(G_OPT_R_MAP);
- conf = G_define_option();
+ conf = G_define_standard_option(G_OPT_F_INPUT);
conf->key = "conf";
conf->description = _("Configuration file");
- conf->type = TYPE_STRING;
conf->required = YES;
- conf->gisprompt = "old_file,file,input";
output = G_define_standard_option(G_OPT_R_OUTPUT);
@@ -55,26 +53,20 @@
return calculateIndex(conf->answer, meanPixelAttribute, NULL,
raster->answer, output->answer);
-
-
}
int meanPixelAttribute(int fd, char **par, struct area_entry *ad, double *result)
{
char *mapset;
-
int ris = 0;
-
double indice = 0;
-
struct Cell_head hd;
mapset = G_find_cell(ad->raster, "");
if (G_get_cellhd(ad->raster, mapset, &hd) == -1)
return RLI_ERRORE;
-
switch (ad->data_type) {
case CELL_TYPE:
{
@@ -102,14 +94,12 @@
return RLI_ERRORE;
}
-
*result = indice;
return RLI_OK;
}
-
int calculate(int fd, struct area_entry *ad, double *result)
{
CELL *buf;
@@ -122,7 +112,6 @@
double indice = 0;
double somma = 0;
-
/* open mask if needed */
if (ad->mask == 1) {
if ((mask_fd = open(ad->mask_name, O_RDONLY, 0755)) < 0) {
@@ -142,7 +131,6 @@
buf = RLI_get_cell_raster_row(fd, j + ad->y, ad); /*read raster row */
if (masked) { /*read mask row if needed */
-
if (read(mask_fd, mask_buf, (ad->cl * sizeof(int))) < 0) {
G_fatal_error("mask read failed");
return RLI_ERRORE;
@@ -161,7 +149,6 @@
}
}
-
if (area == 0)
indice = (double)-1;
else
@@ -169,11 +156,14 @@
*result = indice;
if (masked) {
+ close(mask_fd);
G_free(mask_buf);
}
+
return RLI_OK;
}
+
int calculateD(int fd, struct area_entry *ad, double *result)
{
DCELL *buf;
@@ -186,7 +176,6 @@
double indice = 0;
double somma = 0;
-
/* open mask if needed */
if (ad->mask == 1) {
if ((mask_fd = open(ad->mask_name, O_RDONLY, 0755)) < 0) {
@@ -207,7 +196,6 @@
buf = RLI_get_dcell_raster_row(fd, j + ad->y, ad); /*read raster row */
if (masked) { /*read mask row if needed */
-
if (read(mask_fd, mask_buf, (ad->cl * sizeof(int))) < 0) {
G_fatal_error("mask read failed");
return RLI_ERRORE;
@@ -226,7 +214,6 @@
}
}
-
if (area == 0)
indice = (double)-1;
else
@@ -234,8 +221,10 @@
*result = indice;
if (masked) {
+ close(mask_fd);
G_free(mask_buf);
}
+
return RLI_OK;
}
@@ -251,7 +240,6 @@
double indice = 0;
double somma = 0;
-
/* open mask if needed */
if (ad->mask == 1) {
if ((mask_fd = open(ad->mask_name, O_RDONLY, 0755)) < 0) {
@@ -267,12 +255,10 @@
}
-
for (j = 0; j < ad->rl; j++) { /*for each raster row */
buf = RLI_get_fcell_raster_row(fd, j + ad->y, ad); /*read raster row */
if (masked) { /*read mask row if needed */
-
if (read(mask_fd, mask_buf, (ad->cl * sizeof(int))) < 0) {
G_fatal_error("mask read failed");
return RLI_ERRORE;
@@ -292,7 +278,6 @@
}
}
-
if (area == 0)
indice = (double)-1;
else
@@ -300,7 +285,9 @@
*result = indice;
if (masked) {
+ close(mask_fd);
G_free(mask_buf);
}
+
return RLI_OK;
}
Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.mps/description.html
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.mps/description.html 2014-02-19 00:24:09 UTC (rev 59094)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.mps/description.html 2014-02-19 00:26:04 UTC (rev 59095)
@@ -1,8 +1,13 @@
<h2>DESCRIPTION</h2>
-<em>r.li.mps</em> (mean patch size) calculates the mean size of the patches
-in the sampling area as:<br>
+<em>r.li.mps</em> (mean patch size) calculates the mean size of the
+patches in the sampling area as:<br>
+<!--
<img src="rlimps_formula.png" alt="rliMps formula"><br>
+-->
+<div class="code"><pre>
+MPS = A / Npatch
+</pre></div>
with:
<ul>
@@ -10,6 +15,12 @@
<li><b>Npatch</b>: number of patches</li>
</ul>
+The unit of the mean size is hectare.
+
+<p>
+This index is calculated using a 4 neighbour algorithm, diagonal cells
+are ignored when tracing a patch.
+
<h2>NOTES</h2>
Do not use absolute path names for the <b>output</b> map/file.
@@ -32,8 +43,11 @@
<em>r.li.setup</em>) and saving results in <em>my_out</em>, run:
<div class="code"><pre>
r.li.mps map=my_map conf=my_conf output=my_out
+</pre></div>
+<p>
-# forest map example:
+Forest map (Spearfish sample dataset) example:
+<div class="code"><pre>
g.region rast=landcover.30m -p
r.mapcalc "forests = if(landcover.30m >= 41 && landcover.30m <= 43,1,null())"
r.li.mps map=forests conf=movwindow7 out=forests_mps_mov7
Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.mps/mps.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.mps/mps.c 2014-02-19 00:24:09 UTC (rev 59094)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.mps/mps.c 2014-02-19 00:26:04 UTC (rev 59095)
@@ -1,13 +1,18 @@
-/*
- * \brief calculates mean patch size index
+/****************************************************************************
*
- * \AUTHOR: Serena Pallecchi student of Computer Science University of Pisa (Italy)
- * Commission from Faunalia Pontedera (PI) www.faunalia.it
+ * MODULE: r.li.patchnum
+ * AUTHOR(S): Serena Pallecchi (original contributor)
+ * student of Computer Science University of Pisa (Italy)
+ * Commission from Faunalia Pontedera (PI) www.faunalia.it
*
- * This program is free software under the GPL (>=v2)
- * Read the COPYING file that comes with GRASS for details.
+ * PURPOSE: calculates mean patch size index
+ * COPYRIGHT: (C) 2007-2014 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.
+ *
+ *****************************************************************************/
#include <stdlib.h>
#include <fcntl.h>
@@ -40,12 +45,10 @@
raster = G_define_standard_option(G_OPT_R_MAP);
- conf = G_define_option();
+ conf = G_define_standard_option(G_OPT_F_INPUT);
conf->key = "conf";
conf->description = _("Configuration file");
- conf->type = TYPE_STRING;
conf->required = YES;
- conf->gisprompt = "old_file,file,input";
output = G_define_standard_option(G_OPT_R_OUTPUT);
@@ -54,7 +57,6 @@
return calculateIndex(conf->answer, meanPatchSize, NULL, raster->answer,
output->answer);
-
}
@@ -93,7 +95,7 @@
}
if (ris != RLI_OK)
- return RLI_ERRORE;
+ return RLI_ERRORE;
*result = indice;
Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.padcv/description.html
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.padcv/description.html 2014-02-19 00:24:09 UTC (rev 59094)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.padcv/description.html 2014-02-19 00:26:04 UTC (rev 59095)
@@ -1,15 +1,15 @@
<h2>DESCRIPTION</h2>
-<em>r.li.padcv</em> (patch area distribution coefficient of variation) calculates
-as:<br>
-<img src="rlipadcv_formula1.png" alt="rlipadcv formula"> <br>
+<em>r.li.padcv</em> calculates the coefficient of variation of patch
+area sizes in hectares as:<br>
+<img src="rlipadcv_formula1.png" alt="r.li.padcv formula"> <br>
with:<br>
<ul>
<li><b>SD</b>: standard deviation of patch area size
<img src="rlipadcv_formula2.png"> </li>
<li><b>MPS</b>: mean patch area size </li>
<li><b>a<small><small>i</small></small></b>: area of patch i</li>
- <li><b>N<small>patch</small></b>: number of patch</li>
+ <li><b>N<small>patch</small></b>: number of patches</li>
</ul>
<h2>NOTES</h2>
@@ -33,8 +33,11 @@
<em>r.li.setup</em>) and saving results in <em>my_out</em>, run:
<div class="code"><pre>
r.li.padcv map=my_map conf=my_conf output=my_out
+</pre></div>
+<p>
-# forest map example:
+Forest map (Spearfish sample dataset) example:
+<div class="code"><pre>
g.region rast=landcover.30m -p
r.mapcalc "forests = if(landcover.30m >= 41 && landcover.30m <= 43,1,null())"
r.li.padcv map=forests conf=movwindow7 out=forests_padcv_mov7
Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.padcv/padcv.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.padcv/padcv.c 2014-02-19 00:24:09 UTC (rev 59094)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.padcv/padcv.c 2014-02-19 00:26:04 UTC (rev 59095)
@@ -1,13 +1,19 @@
-/*
- * \brief calculates coefficient of variation of patch area
+/****************************************************************************
*
- * \AUTHOR: Serena Pallecchi student of Computer Science University of Pisa (Italy)
- * Commission from Faunalia Pontedera (PI) www.faunalia.it
+ * MODULE: r.li.padcv
+ * AUTHOR(S): Serena Pallecchi (original contributor)
+ * student of Computer Science University of Pisa (Italy)
+ * Commission from Faunalia Pontedera (PI) www.faunalia.it
+ * Fixes: Markus Neteler <neteler itc.it>
*
- * This program is free software under the GPL (>=v2)
- * Read the COPYING file that comes with GRASS for details.
+ * PURPOSE: calculates coefficient of variation of patch areas
+ * COPYRIGHT: (C) 2007-2014 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.
+ *
+ *****************************************************************************/
#include <stdlib.h>
#include <fcntl.h>
@@ -40,18 +46,15 @@
/* define options */
raster = G_define_standard_option(G_OPT_R_MAP);
- conf = G_define_option();
+ conf = G_define_standard_option(G_OPT_F_INPUT);
conf->key = "conf";
conf->description = _("Configuration file");
- conf->gisprompt = "old_file,file,input";
- conf->type = TYPE_STRING;
conf->required = YES;
output = G_define_standard_option(G_OPT_R_OUTPUT);
if (G_parser(argc, argv))
exit(EXIT_FAILURE);
-
return calculateIndex(conf->answer, patchAreaDistributionCV, NULL,
raster->answer, output->answer);
}
@@ -87,8 +90,8 @@
G_fatal_error("data type unknown");
return RLI_ERRORE;
}
+ }
- }
if (ris != RLI_OK) {
*result = -1;
return RLI_ERRORE;
@@ -99,6 +102,7 @@
return RLI_OK;
}
+
int calculate(int fd, struct area_entry *ad, double *result)
{
CELL *buf;
Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.padrange/description.html
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.padrange/description.html 2014-02-19 00:24:09 UTC (rev 59094)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.padrange/description.html 2014-02-19 00:26:04 UTC (rev 59095)
@@ -1,14 +1,18 @@
<h2>DESCRIPTION</h2>
-<em>r.li.padrange</em> (patch area distribution range) calculates
-as:<br>
-<img src="rlipadrange_formula.png" alt="rlipadrange formula"> <br>
+<em>r.li.padrange</em> calculates the range of patch area sizes in
+hectares as:<br>
+<img src="rlipadrange_formula.png" alt="r.li.padrange formula"> <br>
with:<br>
<ul>
<li><b>a<small><small>max</small></small></b>: max patch area size</li>
<li><b>a<small><small>min</small></small></b>: min patch area size</li>
</ul>
+<p>
+This index is calculated using a 4 neighbour algorithm, diagonal cells
+are ignored when tracing a patch.
+
<h2>NOTES</h2>
Do not use absolute path names for the <b>output</b> map/file.
@@ -31,8 +35,11 @@
<em>r.li.setup</em>) and saving results in <em>my_out</em>, run:
<div class="code"><pre>
r.li.padrange map=my_map conf=my_conf output=my_out
+</pre></div>
+<p>
-# forest map example:
+Forest map (Spearfish sample dataset) example:
+<div class="code"><pre>
g.region rast=landcover.30m -p
r.mapcalc "forests = if(landcover.30m >= 41 && landcover.30m <= 43,1,null())"
r.li.padrange map=forests conf=movwindow7 out=forests_padrange_mov7
Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.padrange/padrange.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.padrange/padrange.c 2014-02-19 00:24:09 UTC (rev 59094)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.padrange/padrange.c 2014-02-19 00:26:04 UTC (rev 59095)
@@ -1,21 +1,27 @@
-/*
- * \brief calculates range of patch area size
+/****************************************************************************
*
- * \AUTHOR: Serena Pallecchi student of Computer Science University of Pisa (Italy)
- * Commission from Faunalia Pontedera (PI) www.faunalia.it
+ * MODULE: r.li.padrange
+ * AUTHOR(S): Serena Pallecchi (original contributor)
+ * student of Computer Science University of Pisa (Italy)
+ * Commission from Faunalia Pontedera (PI) www.faunalia.it
+ * Fixes: Markus Neteler <neteler itc.it>
*
- * This program is free software under the GPL (>=v2)
- * Read the COPYING file that comes with GRASS for details.
+ * PURPOSE: calculates calculates standard deviation of patch areas
+ * COPYRIGHT: (C) 2007-2014 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.
+ *
+ *****************************************************************************/
-#include <grass/gis.h>
-#include <grass/glocale.h>
-
#include <stdlib.h>
#include <fcntl.h>
#include <math.h>
+#include <grass/gis.h>
+#include <grass/glocale.h>
+
#include "../r.li.daemon/defs.h"
#include "../r.li.daemon/avlDefs.h"
#include "../r.li.daemon/avlID.h"
@@ -39,13 +45,14 @@
/* define options */
raster = G_define_standard_option(G_OPT_R_MAP);
- conf = G_define_option();
+
+ conf = G_define_standard_option(G_OPT_F_INPUT);
conf->key = "conf";
conf->description = _("Configuration file");
- conf->gisprompt = "old_file,file,input";
- conf->type = TYPE_STRING;
conf->required = YES;
+
output = G_define_standard_option(G_OPT_R_OUTPUT);
+
if (G_parser(argc, argv))
exit(EXIT_FAILURE);
return calculateIndex(conf->answer, patchAreaDistributionRANGE, NULL,
@@ -65,13 +72,11 @@
return RLI_ERRORE;
switch (ad->data_type) {
case CELL_TYPE:
-
{
ris = calculate(fd, ad, &indice);
break;
}
case DCELL_TYPE:
-
{
ris = calculateD(fd, ad, &indice);
break;
@@ -82,7 +87,6 @@
break;
}
default:
-
{
G_fatal_error("data type unknown");
return RLI_ERRORE;
@@ -92,7 +96,9 @@
*result = -1;
return RLI_ERRORE;
}
+
*result = indice;
+
return RLI_OK;
}
@@ -123,16 +129,11 @@
long *mask_patch_sup;
long *mask_patch_corr;
-
double indice = 0;
double rk = 0;
-
avlID_tree albero = NULL;
-
avlID_table *array = NULL;
-
generic_cell gc;
-
gc.t = CELL_TYPE;
/* open mask if needed */
@@ -482,8 +483,6 @@
}
}
-
-
rk = area_max - area_min;
indice = rk;
Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.padsd/description.html
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.padsd/description.html 2014-02-19 00:24:09 UTC (rev 59094)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.padsd/description.html 2014-02-19 00:26:04 UTC (rev 59095)
@@ -1,14 +1,19 @@
<h2>DESCRIPTION</h2>
-<em>r.li.padsd</em> (patch area distribution standard deviation) calculates as:<br>
-<img src="rlipadsd_formula.png" alt="rlipadsd formula"> <br>
+<em>r.li.padsd</em> calculates the standard deviation of patch
+area sizes in hectares as:<br>
+<img src="rlipadsd_formula.png" alt="r.li.padsd formula"> <br>
with:<br>
<ul>
<li><b>MPS</b>: mean patch area size</li>
<li><b>a<small><small>i</small></small></b>: area of patch i</li>
- <li><b>N<small>patch</small></b>: number of patch</li>
+ <li><b>N<small>patch</small></b>: number of patches</li>
</ul>
+<p>
+This index is calculated using a 4 neighbour algorithm, diagonal cells
+are ignored when tracing a patch.
+
<h2>NOTES</h2>
Do not use absolute path names for the <b>output</b> map/file.
@@ -31,8 +36,11 @@
<em>r.li.setup</em>) and saving results in <em>my_out</em>, run:
<div class="code"><pre>
r.li.padsd map=my_map conf=my_conf output=my_out
+</pre></div>
+<p>
-# forest map example:
+Forest map (Spearfish sample dataset) example:
+<div class="code"><pre>
g.region rast=landcover.30m -p
r.mapcalc "forests = if(landcover.30m >= 41 && landcover.30m <= 43,1,null())"
r.li.padsd map=forests conf=movwindow7 out=forests_padsd_mov7
Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.padsd/padsd.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.padsd/padsd.c 2014-02-19 00:24:09 UTC (rev 59094)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.padsd/padsd.c 2014-02-19 00:26:04 UTC (rev 59095)
@@ -1,21 +1,27 @@
-/*
- * \brief calculates standard deviation of patch area
+/****************************************************************************
*
- * \AUTHOR: Serena Pallecchi student of Computer Science University of Pisa (Italy)
- * Commission from Faunalia Pontedera (PI) www.faunalia.it
+ * MODULE: r.li.padsd
+ * AUTHOR(S): Serena Pallecchi (original contributor)
+ * student of Computer Science University of Pisa (Italy)
+ * Commission from Faunalia Pontedera (PI) www.faunalia.it
+ * Fixes: Markus Neteler <neteler itc.it>
*
- * This program is free software under the GPL (>=v2)
- * Read the COPYING file that comes with GRASS for details.
- *
- */
+ * PURPOSE: calculates calculates standard deviation of patch areas
+ * COPYRIGHT: (C) 2007-2014 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.
+ *
+ *****************************************************************************/
-#include <grass/gis.h>
-#include <grass/glocale.h>
-
#include <stdlib.h>
#include <fcntl.h>
#include <math.h>
+#include <grass/gis.h>
+#include <grass/glocale.h>
+
#include "../r.li.daemon/defs.h"
#include "../r.li.daemon/avlDefs.h"
#include "../r.li.daemon/avlID.h"
@@ -24,6 +30,7 @@
int calculate(int fd, struct area_entry *ad, double *result);
int calculateD(int fd, struct area_entry *ad, double *result);
int calculateF(int fd, struct area_entry *ad, double *result);
+
int main(int argc, char *argv[])
{
struct Option *raster, *conf, *output;
@@ -37,13 +44,14 @@
/* define options */
raster = G_define_standard_option(G_OPT_R_MAP);
- conf = G_define_option();
+
+ conf = G_define_standard_option(G_OPT_F_INPUT);
conf->key = "conf";
conf->description = _("Configuration file");
- conf->gisprompt = "old_file,file,input";
- conf->type = TYPE_STRING;
conf->required = YES;
+
output = G_define_standard_option(G_OPT_R_OUTPUT);
+
if (G_parser(argc, argv))
exit(EXIT_FAILURE);
return calculateIndex(conf->answer, patchAreaDistributionSD, NULL,
@@ -62,25 +70,21 @@
return RLI_ERRORE;
switch (ad->data_type) {
case CELL_TYPE:
-
{
ris = calculate(fd, ad, &indice);
break;
}
case DCELL_TYPE:
-
{
ris = calculateD(fd, ad, &indice);
break;
}
case FCELL_TYPE:
-
{
ris = calculateF(fd, ad, &indice);
break;
}
default:
-
{
G_fatal_error("data type unknown");
return RLI_ERRORE;
@@ -90,10 +94,13 @@
*result = -1;
return RLI_ERRORE;
}
+
*result = indice;
+
return RLI_OK;
}
+
int calculate(int fd, struct area_entry *ad, double *result)
{
CELL *buf;
Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.patchdensity/description.html
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.patchdensity/description.html 2014-02-19 00:24:09 UTC (rev 59094)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.patchdensity/description.html 2014-02-19 00:26:04 UTC (rev 59095)
@@ -1,13 +1,21 @@
<h2>DESCRIPTION</h2>
-<em>r.li.patchdensity</em> calculates the "patch density index" as:
+<em>r.li.patchdensity</em> calculates the "patch density index",
+the number of patches per square kilometer, as:
<div class="code"><pre>
-f(sample_area) = (Patch_Number/Area) * 1000000
+PD = Npatch / A
</pre></div>
-that is 1000000 by number of patch for area unit.
-This index is calculated using a 4 neighbour algorithm.
+with:
+<ul>
+ <li><b>A</b>:sampling area size</li>
+ <li><b>Npatch</b>: number of patches</li>
+</ul>
+<p>
+This index is calculated using a 4 neighbour algorithm, diagonal cells
+are ignored when tracing a patch.
+
<h2>NOTES</h2>
Do not use absolute path names for the <b>output</b> map/file.
@@ -43,6 +51,7 @@
# patch density (7x7 moving window defined in r.li.setup):
r.li.patchdensity forests conf=movwindow7 out=forests_p_dens7
+r.univar forests_p_dens7
d.rast.leg forests_p_dens7
r.to.vect forests out=forests feature=area
Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.patchdensity/main.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.patchdensity/main.c 2014-02-19 00:24:09 UTC (rev 59094)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.patchdensity/main.c 2014-02-19 00:26:04 UTC (rev 59095)
@@ -7,7 +7,7 @@
* Commission from Faunalia Pontedera (PI) www.faunalia.it
* Fixes: Serena Pallecchi, Markus Neteler <neteler itc.it>
* PURPOSE: calculates patch density index
- * COPYRIGHT: (C) 2006-2007 by the GRASS Development Team
+ * COPYRIGHT: (C) 2006-2014 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
@@ -36,23 +36,18 @@
raster = G_define_standard_option(G_OPT_R_MAP);
- conf = G_define_option();
+ conf = G_define_standard_option(G_OPT_F_INPUT);
conf->key = "conf";
conf->description = _("Configuration file");
- conf->gisprompt = "old_file,file,input";
- conf->type = TYPE_STRING;
conf->required = YES;
output = G_define_standard_option(G_OPT_R_OUTPUT);
- /** add other options for index parameters here */
-
if (G_parser(argc, argv))
exit(EXIT_FAILURE);
return calculateIndex(conf->answer, patch_density, NULL, raster->answer,
output->answer);
-
}
Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.patchnum/description.html
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.patchnum/description.html 2014-02-19 00:24:09 UTC (rev 59094)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.patchnum/description.html 2014-02-19 00:26:04 UTC (rev 59095)
@@ -2,8 +2,11 @@
<em>r.li.patchnum</em> calculates the "patch number index" as:<br>
<I> f(sample_area)= Patch_Number </I><br>
-This index is calculated using a 4 neighbour algorithm<br>
+<p>
+This index is calculated using a 4 neighbour algorithm, diagonal cells
+are ignored when tracing a patch.
+
<h2>NOTES</h2>
Do not use absolute path names for the <b>output</b> map/file.
@@ -25,8 +28,11 @@
<em>r.li.setup</em>) and saving results in <em>my_out</em>, run:
<div class="code"><pre>
r.li.patchnum map=my_map conf=my_conf out=my_out
+</pre></div>
+<p>
-# forest map example:
+Forest map (Spearfish sample dataset) example:
+<div class="code"><pre>
g.region rast=landcover.30m -p
r.mapcalc "forests = if(landcover.30m >= 41 && landcover.30m <= 43,1,null())"
r.li.patchnum map=forests conf=movwindow7 out=forests_patchnum_mov7
Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.patchnum/main.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.patchnum/main.c 2014-02-19 00:24:09 UTC (rev 59094)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.patchnum/main.c 2014-02-19 00:26:04 UTC (rev 59095)
@@ -8,7 +8,7 @@
* Fixes: Markus Neteler <neteler itc.it>
*
* PURPOSE: calculates patch number index
- * COPYRIGHT: (C) 2007-2007 by the GRASS Development Team
+ * COPYRIGHT: (C) 2007-2014 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
@@ -38,22 +38,18 @@
raster = G_define_standard_option(G_OPT_R_MAP);
- conf = G_define_option();
+ conf = G_define_standard_option(G_OPT_F_INPUT);
conf->key = "conf";
conf->description = _("Configuration file");
- conf->gisprompt = "old_file,file,input";
- conf->type = TYPE_STRING;
conf->required = YES;
output = G_define_standard_option(G_OPT_R_OUTPUT);
-
if (G_parser(argc, argv))
exit(EXIT_FAILURE);
return calculateIndex(conf->answer, patch_number, NULL, raster->answer,
output->answer);
-
}
int patch_number(int fd, char **par, struct area_entry *ad, double *result)
Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.pielou/description.html
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.pielou/description.html 2014-02-19 00:24:09 UTC (rev 59094)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.pielou/description.html 2014-02-19 00:26:04 UTC (rev 59095)
@@ -1,7 +1,7 @@
<h2>DESCRIPTION</h2>
<em>r.li.pielou</em> calculates the "Pielou's diversity index" as: <br>
-<img src="r_li_pielou.png"><br>
+<img src="r_li_pielou.png" alt="r.li.pielou formula"> <br>
with:
<ul>
<li><b>J</b>: Pielou eveness index</li>
@@ -16,6 +16,7 @@
output will be a raster map, otherwise an ASCII file will be generated in
the <tt>$HOME/.r.li/output/</tt> folder.
<p>
+<!-- TODO: verify next: -->
If the input raster contains NULL value cells, <em>r.li.pielou</em>
returns -1 for these cells. <br>
If you want to change these -1 values to NULL, run subsequently on the resulting map:
@@ -30,8 +31,11 @@
<em>r.li.setup</em>) and saving results in <em>my_out</em>, run:
<div class="code"><pre>
r.li.pielou map=my_map conf=my_conf output=my_out
+</pre></div>
+<p>
-# forest map example:
+Forest map (Spearfish sample dataset) example:
+<div class="code"><pre>
g.region rast=landcover.30m -p
r.mapcalc "forests = if(landcover.30m >= 41 && landcover.30m <= 43,1,null())"
r.li.pielou map=forests conf=movwindow7 out=forests_pielou_mov7
Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.pielou/pielou.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.pielou/pielou.c 2014-02-19 00:24:09 UTC (rev 59094)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.pielou/pielou.c 2014-02-19 00:26:04 UTC (rev 59095)
@@ -26,6 +26,8 @@
#include "../r.li.daemon/avl.h"
#include "../r.li.daemon/daemon.h"
+/* template is shannon */
+
int calculate(int fd, struct area_entry *ad, double *result);
int calculateD(int fd, struct area_entry *ad, double *result);
@@ -62,11 +64,9 @@
raster = G_define_standard_option(G_OPT_R_MAP);
- conf = G_define_option();
+ conf = G_define_standard_option(G_OPT_F_INPUT);
conf->key = "conf";
conf->description = _("Configuration file");
- conf->type = TYPE_STRING;
- conf->gisprompt = "old_file,file,input";
conf->required = YES;
output = G_define_standard_option(G_OPT_R_OUTPUT);
@@ -76,18 +76,15 @@
return calculateIndex(conf->answer, pielou, NULL, raster->answer,
output->answer);
-
}
int pielou(int fd, char **par, struct area_entry *ad, double *result)
{
-
char *mapset;
int ris = RLI_OK;
double indice = 0;
struct Cell_head hd;
-
mapset = G_find_cell(ad->raster, "");
if (G_get_cellhd(ad->raster, mapset, &hd) == -1)
return RLI_ERRORE;
@@ -123,16 +120,15 @@
*result = indice;
return RLI_OK;
-
}
int calculate(int fd, struct area_entry *ad, double *result)
{
-
CELL *buf;
CELL corrCell;
CELL precCell;
+
int i, j;
int mask_fd = -1, *mask_buf;
int ris = 0;
@@ -159,7 +155,6 @@
generic_cell cc_passage; /*add to compute the number of class */
avl_tree albero = NULL;
-
AVL_table *array;
cc.t = CELL_TYPE;
@@ -176,15 +171,12 @@
masked = TRUE;
}
-
G_set_c_null_value(&precCell, 1);
-
/*for each row */
for (j = 0; j < ad->rl; j++) {
buf = RLI_get_cell_raster_row(fd, j + ad->y, ad);
-
if (masked) {
if (read(mask_fd, mask_buf, (ad->cl * sizeof(int))) < 0) {
G_fatal_error("mask read failed");
Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.renyi/description.html
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.renyi/description.html 2014-02-19 00:24:09 UTC (rev 59094)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.renyi/description.html 2014-02-19 00:26:04 UTC (rev 59095)
@@ -1,7 +1,7 @@
<h2>DESCRIPTION</h2>
<em>r.li.renyi</em> calculates the "Renyi's diversity index" as:<br>
-<img src="r_li_renyi.png"> <br>
+<img src="r_li_renyi.png" alt="r.li.renyi formula"> <br>
with:
<ul>
<li><b>H</b>: Renyi entropy</li>
@@ -33,8 +33,11 @@
<em>r.li.setup</em>) and saving results in <em>my_out</em>, run:
<div class="code"><pre>
r.li.renyi map=my_map conf=my_conf output=my_out alpha=0.6
+</pre></div>
+<p>
-# forest map example:
+Forest map (Spearfish sample dataset) example:
+<div class="code"><pre>
g.region rast=landcover.30m -p
r.mapcalc "forests = if(landcover.30m >= 41 && landcover.30m <= 43,1,null())"
r.li.renyi map=forests conf=movwindow7 out=forests_renyi_mov7_a06 alpha=0.6
Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.richness/description.html
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.richness/description.html 2014-02-19 00:24:09 UTC (rev 59094)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.richness/description.html 2014-02-19 00:26:04 UTC (rev 59095)
@@ -1,12 +1,15 @@
<h2>DESCRIPTION</h2>
-<em>r.li.richness</em> calculates the "richness diversity index" as:<br>
-<img src="rliRichness_formula.png alt="rliRichness formula"> <br>
+<em>r.li.richness</em> calculates the "richness diversity index" as:
+<br>
+<img src="rliRichness_formula.png" alt="r.li.richness formula">
+<br>
with:
<ul>
<li><b>m</b>: number of different patch types</li>
</ul>
+
<h2>NOTES</h2>
Do not use absolute path names for the <b>output</b> map/file.
@@ -24,31 +27,39 @@
after index calculation.
<h2>EXAMPLES</h2>
+
To calculate the richness diversity index on map <em>my_map</em>, using
<em>my_conf</em> configuration file (previously defined with
<em>r.li.setup</em>) and saving results in <em>my_out</em>, run:
<div class="code"><pre>
r.li.richness map=my_map conf=my_conf output=my_out
+</pre></div>
+<p>
-# forest map example:
+Forest map (Spearfish sample dataset) example:
+<div class="code"><pre>
g.region rast=landcover.30m -p
r.mapcalc "forests = if(landcover.30m >= 41 && landcover.30m <= 43,1,null())"
r.li.richness map=forests conf=movwindow7 out=forests_richness_mov7
r.univar forests_richness_mov7
</pre></div>
+
<h2>SEE ALSO</h2>
+
<em>
<a href="r.li.html">r.li</a> - package overview<br>
<a href="r.li.setup.html">r.li.setup</a>
</em>
<h2>REFERENCES</h2>
+
McGarigal, K., and B. J. Marks. 1995. FRAGSTATS: spatial pattern
analysis program for quantifying landscape structure. USDA For. Serv.
Gen. Tech. Rep. PNW-351. (<a href="http://treesearch.fs.fed.us/pubs/3064">PDF</a>)
<h2>AUTHORS</h2>
+
Serena Pallecchi student of Computer Science University of Pisa (Italy).<br>
Commission from Faunalia Pontedera (PI), Italy (www.faunalia.it)
Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.richness/richness.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.richness/richness.c 2014-02-19 00:24:09 UTC (rev 59094)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.richness/richness.c 2014-02-19 00:26:04 UTC (rev 59095)
@@ -1,6 +1,6 @@
/*
- * \brief calculates dominance's diversity index
+ * \brief calculates richness diversity index
*
* \AUTHOR: Serena Pallecchi student of Computer Science University of Pisa (Italy)
* Commission from Faunalia Pontedera (PI) www.faunalia.it
@@ -42,11 +42,9 @@
raster = G_define_standard_option(G_OPT_R_MAP);
- conf = G_define_option();
+ conf = G_define_standard_option(G_OPT_F_INPUT);
conf->key = "conf";
conf->description = _("Configuration file");
- conf->type = TYPE_STRING;
- conf->gisprompt = "old_file,file,input";
conf->required = YES;
output = G_define_standard_option(G_OPT_R_OUTPUT);
@@ -62,15 +60,10 @@
int dominance(int fd, char **par, struct area_entry *ad, double *result)
{
char *mapset;
-
int ris = RLI_OK;
-
double indice = 0;
-
struct Cell_head hd;
-
-
mapset = G_find_cell(ad->raster, "");
if (G_get_cellhd(ad->raster, mapset, &hd) == -1)
return RLI_ERRORE;
@@ -121,16 +114,11 @@
int ris = 0;
int masked = FALSE;
int a = 0; /* a=0 if all cells are null */
-
long m = 0;
-
double indice = 0;
-
avl_tree albero = NULL;
-
generic_cell uc;
-
uc.t = CELL_TYPE;
/* open mask if needed */
@@ -280,11 +268,8 @@
int ris = 0;
int masked = FALSE;
int a = 0; /* a=0 if all cells are null */
-
long m = 0;
-
double indice = 0;
-
avl_tree albero = NULL;
generic_cell uc;
Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.shannon/description.html
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.shannon/description.html 2014-02-19 00:24:09 UTC (rev 59094)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.shannon/description.html 2014-02-19 00:26:04 UTC (rev 59095)
@@ -1,7 +1,7 @@
<h2>DESCRIPTION</h2>
<em>r.li.shannon</em> calculates the "Shannon's diversity index" as:<br>
-<img src="rliShannon_formula.png" alt="rliShannon formula"> <br>
+<img src="rliShannon_formula.png" alt="r.li.shannon formula"> <br>
with:
<ul>
<li><b>i</b>: patch type</li>
@@ -33,8 +33,11 @@
<em>r.li.setup</em>) and saving results in <em>my_out</em>, run:
<div class="code"><pre>
r.li.shannon map=my_map conf=my_conf output=my_out
+</pre></div>
+<p>
-# forest map example:
+Forest map (Spearfish sample dataset) example:
+<div class="code"><pre>
g.region rast=landcover.30m -p
r.mapcalc "forests = if(landcover.30m >= 41 && landcover.30m <= 43,1,null())"
r.li.shannon map=forests conf=movwindow7 out=forests_shannon_mov7
Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.shannon/shannon.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.shannon/shannon.c 2014-02-19 00:24:09 UTC (rev 59094)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.shannon/shannon.c 2014-02-19 00:26:04 UTC (rev 59095)
@@ -1,13 +1,18 @@
-/*
- * \brief calculates shannon's diversity index
+/****************************************************************************
*
- * \AUTHOR: Serena Pallecchi student of Computer Science University of Pisa (Italy)
- * Commission from Faunalia Pontedera (PI) www.faunalia.it
+ * MODULE: r.li.shannon
+ * AUTHOR(S): Serena Pallecchi (original contributor)
+ * student of Computer Science University of Pisa (Italy)
+ * Commission from Faunalia Pontedera (PI) www.faunalia.it
*
- * This program is free software under the GPL (>=v2)
- * Read the COPYING file that comes with GRASS for details.
- *
- */
+ * PURPOSE: calculates Shannon's diversity index
+ * COPYRIGHT: (C) 2007-2014 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.
+ *
+ *****************************************************************************/
#include <grass/gis.h>
#include <grass/glocale.h>
@@ -21,6 +26,8 @@
#include "../r.li.daemon/avl.h"
#include "../r.li.daemon/daemon.h"
+/* template for dominance, renyi, pielou, simpson */
+
int calculate(int fd, struct area_entry *ad, double *result);
int calculateD(int fd, struct area_entry *ad, double *result);
int calculateF(int fd, struct area_entry *ad, double *result);
@@ -41,11 +48,9 @@
raster = G_define_standard_option(G_OPT_R_MAP);
- conf = G_define_option();
+ conf = G_define_standard_option(G_OPT_F_INPUT);
conf->key = "conf";
conf->description = _("Configuration file");
- conf->gisprompt = "old_file,file,input";
- conf->type = TYPE_STRING;
conf->required = YES;
output = G_define_standard_option(G_OPT_R_OUTPUT);
@@ -55,22 +60,16 @@
return calculateIndex(conf->answer, shannon, NULL, raster->answer,
output->answer);
-
}
int shannon(int fd, char **par, struct area_entry * ad, double *result)
{
-
char *mapset;
-
int ris = RLI_OK;
-
double indice = 0;
-
struct Cell_head hd;
-
mapset = G_find_cell(ad->raster, "");
if (G_get_cellhd(ad->raster, mapset, &hd) == -1)
return RLI_ERRORE;
@@ -106,13 +105,11 @@
*result = indice;
return RLI_OK;
-
}
int calculate(int fd, struct area_entry *ad, double *result)
{
-
CELL *buf;
CELL corrCell;
CELL precCell;
@@ -138,10 +135,8 @@
generic_cell cc;
avl_tree albero = NULL;
-
AVL_table *array;
-
cc.t = CELL_TYPE;
/* open mask if needed */
Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.shape/description.html
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.shape/description.html 2014-02-19 00:24:09 UTC (rev 59094)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.shape/description.html 2014-02-19 00:26:04 UTC (rev 59095)
@@ -26,8 +26,11 @@
<em>r.li.setup</em>) and saving results in <em>my_out</em>, run:
<div class="code"><pre>
r.li.shape map=my_map conf=my_conf output=my_out
+</pre></div>
+<p>
-# forest map example:
+Forest map (Spearfish sample dataset) example:
+<div class="code"><pre>
g.region rast=landcover.30m -p
r.mapcalc "forests = if(landcover.30m >= 41 && landcover.30m <= 43,1,null())"
r.li.shape map=forests conf=movwindow7 out=forests_shape_mov7
Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.shape/main.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.shape/main.c 2014-02-19 00:24:09 UTC (rev 59094)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.shape/main.c 2014-02-19 00:26:04 UTC (rev 59095)
@@ -36,11 +36,9 @@
raster = G_define_standard_option(G_OPT_R_MAP);
- conf = G_define_option();
+ conf = G_define_standard_option(G_OPT_F_INPUT);
conf->key = "conf";
conf->description = _("Configuration file");
- conf->gisprompt = "old_file,file,input";
- conf->type = TYPE_STRING;
conf->required = YES;
output = G_define_standard_option(G_OPT_R_OUTPUT);
@@ -52,13 +50,10 @@
return calculateIndex(conf->answer, shape_index, NULL, raster->answer,
output->answer);
-
}
int shape_index(int fd, char **par, struct area_entry *ad, double *result)
{
-
-
double area;
char *mapset;
struct Cell_head hd;
@@ -108,5 +103,6 @@
(ad->rl * ad->cl - null_count);
*result = area;
+
return 1;
}
Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.simpson/description.html
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.simpson/description.html 2014-02-19 00:24:09 UTC (rev 59094)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.simpson/description.html 2014-02-19 00:26:04 UTC (rev 59095)
@@ -1,7 +1,7 @@
<h2>DESCRIPTION</h2>
<em>r.li.simpson</em> calculates the "Simpson's diversity index" as:<br>
-<img src="rliSimpson_formula.png" alt="rliSimpson formula"> <br>
+<img src="rliSimpson_formula.png" alt="r.li.simpson formula"> <br>
with:
<ul>
<li><b>i</b>: patch type</li>
@@ -32,8 +32,11 @@
<em>r.li.setup</em>) and saving results in <em>my_out</em>, run:
<div class="code"><pre>
r.li.simpson map=my_map conf=my_conf output=my_out
+</pre></div>
+<p>
-# forest map example:
+Forest map (Spearfish sample dataset) example:
+<div class="code"><pre>
g.region rast=landcover.30m -p
r.mapcalc "forests = if(landcover.30m >= 41 && landcover.30m <= 43,1,null())"
r.li.simpson map=forests conf=movwindow7 out=forests_simpson_mov7
Modified: grass/branches/releasebranch_6_4/raster/r.li/r.li.simpson/simpson.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.li/r.li.simpson/simpson.c 2014-02-19 00:24:09 UTC (rev 59094)
+++ grass/branches/releasebranch_6_4/raster/r.li/r.li.simpson/simpson.c 2014-02-19 00:26:04 UTC (rev 59095)
@@ -1,27 +1,34 @@
-
-/*
- * \brief calculates Simpson's diversity index
+/****************************************************************************
*
- * \AUTHOR: Serena Pallecchi student of Computer Science University of Pisa (Italy)
- * Commission from Faunalia Pontedera (PI) www.faunalia.it
+ * MODULE: r.li.simpson
+ * AUTHOR(S): Serena Pallecchi (original contributor)
+ * student of Computer Science University of Pisa (Italy)
+ * Commission from Faunalia Pontedera (PI) www.faunalia.it
+ * Rewrite: Markus Metz
*
- * This program is free software under the GPL (>=v2)
- * Read the COPYING file that comes with GRASS for details.
- *
- */
+ * PURPOSE: calculates Simpson's diversity index
+ * COPYRIGHT: (C) 2007-2014 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.
+ *
+ *****************************************************************************/
-#include <grass/gis.h>
-#include <grass/glocale.h>
-
#include <stdlib.h>
#include <fcntl.h>
#include <math.h>
+#include <grass/gis.h>
+#include <grass/glocale.h>
+
#include "../r.li.daemon/defs.h"
#include "../r.li.daemon/avlDefs.h"
#include "../r.li.daemon/avl.h"
#include "../r.li.daemon/daemon.h"
+/* template is shannon */
+
double calculate(struct area_entry *ad, int fd, double *result);
double calculateD(struct area_entry *ad, int fd, double *result);
double calculateF(struct area_entry *ad, int fd, double *result);
@@ -45,8 +52,6 @@
conf = G_define_option();
conf->key = "conf";
conf->description = _("Configuration file");
- conf->type = TYPE_STRING;
- conf->gisprompt = "old_file,file,input";
conf->required = YES;
output = G_define_standard_option(G_OPT_R_OUTPUT);
@@ -56,7 +61,6 @@
return calculateIndex(conf->answer, simpson, NULL, raster->answer,
output->answer);
-
}
int simpson(int fd, char **par, struct area_entry *ad, double *result)
@@ -91,7 +95,6 @@
G_fatal_error("data type unknown");
return RLI_ERRORE;
}
-
}
if (ris != RLI_OK)
@@ -100,11 +103,9 @@
*result = indice;
return RLI_OK;
-
}
-
double calculate(struct area_entry *ad, int fd, double *result)
{
CELL *buf;
@@ -130,7 +131,6 @@
avl_tree albero = NULL;
AVL_table *array;
-
generic_cell uc;
uc.t = CELL_TYPE;
@@ -317,9 +317,7 @@
double t;
avl_tree albero = NULL;
-
AVL_table *array;
-
generic_cell uc;
uc.t = DCELL_TYPE;
@@ -526,7 +524,6 @@
G_set_f_null_value(&precCell, 1);
-
for (j = 0; j < ad->rl; j++) { /* for each row */
if (masked) {
if (read(mask_fd, mask_buf, (ad->cl * sizeof(int))) < 0) {
@@ -538,7 +535,6 @@
buf = RLI_get_fcell_raster_row(fd, j + ad->y, ad);
for (i = 0; i < ad->cl; i++) { /* for each fcell in the row */
-
area++;
corrCell = buf[i + ad->x];
@@ -663,10 +659,11 @@
G_free(array);
- if (masked)
+ if (masked) {
+ close(mask_fd);
G_free(mask_buf);
+ }
-
*result = indice;
return RLI_OK;
}
More information about the grass-commit
mailing list