[GRASS-SVN] r58963 - in grass/trunk/raster/r.li: . r.li.cwed r.li.daemon r.li.edgedensity r.li.patchdensity r.li.setup r.li.shannon
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Feb 8 21:57:12 PST 2014
Author: hamish
Date: 2014-02-08 21:57:12 -0800 (Sat, 08 Feb 2014)
New Revision: 58963
Modified:
grass/trunk/raster/r.li/r.li.cwed/r.li.cwed.html
grass/trunk/raster/r.li/r.li.daemon/daemon.c
grass/trunk/raster/r.li/r.li.daemon/daemon.h
grass/trunk/raster/r.li/r.li.daemon/r.li.daemon.html
grass/trunk/raster/r.li/r.li.edgedensity/edgedensity.c
grass/trunk/raster/r.li/r.li.html
grass/trunk/raster/r.li/r.li.patchdensity/r.li.patchdensity.html
grass/trunk/raster/r.li/r.li.setup/masked_area_selection.sh
grass/trunk/raster/r.li/r.li.setup/r.li.setup
grass/trunk/raster/r.li/r.li.setup/r.li.setup.html
grass/trunk/raster/r.li/r.li.setup/sample_area_vector.sh
grass/trunk/raster/r.li/r.li.setup/square_mouse_selection.sh
grass/trunk/raster/r.li/r.li.shannon/r.li.shannon.html
Log:
sync with devbr6 up to r58899
Modified: grass/trunk/raster/r.li/r.li.cwed/r.li.cwed.html
===================================================================
--- grass/trunk/raster/r.li/r.li.cwed/r.li.cwed.html 2014-02-09 05:00:58 UTC (rev 58962)
+++ grass/trunk/raster/r.li/r.li.cwed/r.li.cwed.html 2014-02-09 05:57:12 UTC (rev 58963)
@@ -38,6 +38,7 @@
<h2>EXAMPLES</h2>
+
To calculate mean pixel attribute index on map my_map, using
my_conf configuration file and saving results in
my_out file run:<br>
@@ -51,18 +52,23 @@
56,12,0.54<br>
23,66,0.99<br>
+
<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.
+
<h2>SEE ALSO</h2>
<em><a href="r.li.html">r.li</a></em> package overview <br>
<em><a href="r.li.daemon.html">r.li.daemon</a></em><br>
<em><a href="r.li.setup.html">r.li.setup</a></em>
+
<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/trunk/raster/r.li/r.li.daemon/daemon.c
===================================================================
--- grass/trunk/raster/r.li/r.li.daemon/daemon.c 2014-02-09 05:00:58 UTC (rev 58962)
+++ grass/trunk/raster/r.li/r.li.daemon/daemon.c 2014-02-09 05:57:12 UTC (rev 58963)
@@ -52,7 +52,7 @@
int res;
int i, doneDir, mv_fd, random_access;
- /*int mv_rows, mv_cols; */
+ /* int mv_rows, mv_cols; */
struct list *l;
msg m, doneJob;
@@ -152,7 +152,8 @@
error_Output(res, doneJob);
}
else {
- /*printf("todo ");fflush(stdout); *//* TODO scrivere su raster NULL ??? */
+ /* printf("todo "); fflush(stdout); */
+ /* TODO write to raster NULL ??? */
}
}
}
Modified: grass/trunk/raster/r.li/r.li.daemon/daemon.h
===================================================================
--- grass/trunk/raster/r.li/r.li.daemon/daemon.h 2014-02-09 05:00:58 UTC (rev 58962)
+++ grass/trunk/raster/r.li/r.li.daemon/daemon.h 2014-02-09 05:57:12 UTC (rev 58963)
@@ -23,9 +23,6 @@
#include "defs.h"
-/**
- * \brief number of r.li.workers to use
- */
#define NORMAL 1
#define MVWIN 2
#define GEN 3
Modified: grass/trunk/raster/r.li/r.li.daemon/r.li.daemon.html
===================================================================
--- grass/trunk/raster/r.li/r.li.daemon/r.li.daemon.html 2014-02-09 05:00:58 UTC (rev 58962)
+++ grass/trunk/raster/r.li/r.li.daemon/r.li.daemon.html 2014-02-09 05:57:12 UTC (rev 58963)
@@ -32,12 +32,13 @@
folder, which contains all index declarations. This function must be of this kind:
<br><div class="code"><pre>
int index(int fd, char ** par, area_des ad, double * result)
- </pre></div><br>
+ </pre></div>
+ <br>
where: <ul>
- <li><i>fd</i> is the raster map descriptor
- <li><i>par</i> is a matrix for special parameter (like argv in main)
- <li><i>ad</i> is the area descriptor
- <li><i>result</i> is where to put the index calculation result
+ <li><i>fd</i> is the raster map descriptor
+ <li><i>par</i> is a matrix for special parameter (like argv in main)
+ <li><i>ad</i> is the area descriptor
+ <li><i>result</i> is where to put the index calculation result
</ul>
This function has to return 1 on success and 0 otherwise. <br><br>
<li>
@@ -57,6 +58,7 @@
</ol>
Compile it using a changed Makefile based on the file for <em>r.li.patchdensity</em>.
+
<h2>NOTES</h2>
Using GRASS library function to access raster rows can slow down moving windows
@@ -69,6 +71,7 @@
to use an ad hoc build memory management developed to speed up the system.
The documentation is in doxygen files.
+
<h2>SEE ALSO</h2>
<em><a href="http://grass.osgeo.org/gdp/landscape/r_le_manual5.pdf">old r.le manual</a></em><br>
@@ -82,6 +85,7 @@
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>
Claudio Porta and Lucio Davide Spano, students of Computer Science
@@ -95,6 +99,11 @@
<i>Last changed: $Date$</i>
<hr>
-<p><a href="index.html">Main index</a> - <a href="raster.html">Raster index</a> - <a href="topics.html">Topics index</a> - <a href="keywords.html">Keywords Index</a> - <a href="full_index.html">Full index</a>
+<p><a href="index.html">Main index</a>
+ - <a href="raster.html">Raster index</a>
+ - <a href="topics.html">Topics index</a>
+ - <a href="keywords.html">Keywords Index</a>
+ - <a href="full_index.html">Full index</a>
+
</body>
</html>
Modified: grass/trunk/raster/r.li/r.li.edgedensity/edgedensity.c
===================================================================
--- grass/trunk/raster/r.li/r.li.edgedensity/edgedensity.c 2014-02-09 05:00:58 UTC (rev 58962)
+++ grass/trunk/raster/r.li/r.li.edgedensity/edgedensity.c 2014-02-09 05:57:12 UTC (rev 58963)
@@ -55,8 +55,9 @@
class->type = TYPE_STRING;
class->required = NO;
class->multiple = NO;
- class->description =
- "The value of the patch type, it can be integer, double or float; it will be changed in function of map type";
+ class->label = _("The value of the patch type");
+ class->description = _("It can be integer, double or float; "
+ "it will be changed in function of map type");
if (G_parser(argc, argv))
@@ -119,24 +120,18 @@
double e = 0;
double somma = 0;
double area = 0;
-
CELL *buf_corr, *buf_sup, *buf_inf;
CELL prevCell, corrCell, supCell, infCell, nextCell;
-
AVL_table *array;
-
long tot = 0;
long zero = 0;
long m = 0;
long bordoCorr = 0;
-
avl_tree albero = NULL;
-
int i, j;
int mask_fd = -1, *mask_corr, *mask_sup, *mask_inf;
int masked = FALSE;
int ris;
-
generic_cell c1;
buf_sup = NULL;
@@ -145,8 +140,8 @@
/* open mask if needed */
if (ad->mask == 1) {
if ((mask_fd = open(ad->mask_name, O_RDONLY, 0755)) < 0) {
- G_fatal_error("can't open mask %s", ad->mask_name);
- return RLI_ERRORE;
+ G_fatal_error("Cannot open mask file <%s>", ad->mask_name);
+ return RLI_ERRORE; /* FIXME: can not return from a fatal error */
}
mask_corr = G_malloc(ad->cl * sizeof(int));
@@ -173,9 +168,11 @@
/* the first time buf_sup is all null */
Rast_set_c_null_value(buf_sup + ad->x, ad->cl);
- for (j = 0; j < ad->rl; j++) { /* for each raster row */
+ /* for each raster row */
+ for (j = 0; j < ad->rl; j++) {
- 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);
@@ -398,8 +395,8 @@
/* open mask if needed */
if (ad->mask == 1) {
if ((mask_fd = open(ad->mask_name, O_RDONLY, 0755)) < 0) {
- G_fatal_error("can't open mask");
- return RLI_ERRORE;
+ G_fatal_error("Cannot open mask file");
+ return RLI_ERRORE; /* FIXME: can not return from a fatal error */
}
mask_corr = G_malloc(ad->cl * sizeof(int));
@@ -651,8 +648,8 @@
/* open mask if needed */
if (ad->mask == 1) {
if ((mask_fd = open(ad->mask_name, O_RDONLY, 0755)) < 0) {
- G_fatal_error("can't open mask");
- return RLI_ERRORE;
+ G_fatal_error("Cannot open mask file");
+ return RLI_ERRORE; /* FIXME: can not return from a fatal error */
}
mask_corr = G_malloc(ad->cl * sizeof(int));
Modified: grass/trunk/raster/r.li/r.li.html
===================================================================
--- grass/trunk/raster/r.li/r.li.html 2014-02-09 05:00:58 UTC (rev 58962)
+++ grass/trunk/raster/r.li/r.li.html 2014-02-09 05:57:12 UTC (rev 58963)
@@ -33,7 +33,7 @@
controlling the shape, size, number, and distribution of sampling
areas used to collect information about the landscape structure.
Sampling area shapes can be the entire map or a moving
-window of square, rectangular or with circular shape. The size of
+window of square, rectangular or circular shape. The size of
sampling areas can be changed, so that the landscape can be analyzed
at a variety of spatial scales simultaneously. Sampling areas may be
distributed across the landscape in a random, systematic, or
@@ -52,21 +52,26 @@
<li>run <em>r.li.setup</em>: create a configuration file selecting the parts of
raster to analyze.
-<li>run <em>r.li.'index'</em> (e.g., <em>r.li.patchdensity</em>) for calculate the selected
- index using on the areas selected on configuration file.
+<li>run one or more of the <em>r.li.<b>[index]</b></em> modules (e.g.,
+ <em>r.li.<b>patchdensity</b></em>) to calculate the selected index
+ using on the areas selected on configuration file.
</ol>
+
<h2>NOTE</h2>
-Also the <em>r.li.daemon</em> has a main function and it can be run, but it is only a
-template for development of new indices.
+The <em>r.li.daemon</em> module also has a "main" function front-end
+which can be run, but it is only a template for development of new
+indices so not built by default.
<!-- mhh ??: -->
-The function itself has no meaning, it can be used only for debug.
+The function itself has no meaning, it is only useful as an example and
+for debugging.
+
<h2>EXAMPLE</h2>
-To calculate a patch density index on a whole 'geology' raster map in the
-Spearfish region, using a 5x5 moving window, follow this procedure:
+Calculate a patch density index on the entire 'geology' raster map
+in the Spearfish sample dataset, using a 5x5 moving window:
<ol>
<li> CREATE A NEW CONFIGURATION FILE
@@ -76,14 +81,17 @@
r.li.setup
</pre></div>
<li> The main <em>r.li.setup</em> window is displayed, click on "New"
- <li> Now it is displayed the new configuration window,
+ <li> The new configuration window is now displayed, enter the
+ configuration file name (e.g., "my_conf", do not use absolute paths)
+
+ Now it is displayed the new configuration window,
enter the configuration file name (e.g., "my_conf", do not use absolute paths)
and the name of raster map (e.g., "geology").
The other fields are not needed for this configuration.
- <li> Click on "Setup sampling frame", select "Whole maplayer" and click "OK"
+ <li> Click on "Setup sampling frame", select "Whole map layer" and click "OK"
<li> Click on "Setup sampling areas", select "Moving window" and click "OK"
<li> Click on "Use keyboard to enter moving window dimension"
- <li> Select "Rectangle" and enter 5 on "heigth" and "width" fields
+ <li> Select "Rectangle" and enter 5 in the "height" and "width" fields
<li> Click on "Save settings"
<li> Close the <em>r.li.setup</em> window
</ol>
Modified: grass/trunk/raster/r.li/r.li.patchdensity/r.li.patchdensity.html
===================================================================
--- grass/trunk/raster/r.li/r.li.patchdensity/r.li.patchdensity.html 2014-02-09 05:00:58 UTC (rev 58962)
+++ grass/trunk/raster/r.li/r.li.patchdensity/r.li.patchdensity.html 2014-02-09 05:57:12 UTC (rev 58963)
@@ -44,7 +44,7 @@
g.region rast=landcover.30m -p
# extract forested areas:
r.category landcover.30m
-r.mapcalc "forests = if(landcover.30m >= 41 && landcover.30m <=43,1,null())"
+r.mapcalc "forests = if(landcover.30m >= 41 && landcover.30m <= 43, 1, null())"
# patch density (7x7 moving window defined in r.li.setup):
r.li.patchdensity forests conf=movwindow7 out=forests_p_dens7
Modified: grass/trunk/raster/r.li/r.li.setup/masked_area_selection.sh
===================================================================
--- grass/trunk/raster/r.li/r.li.setup/masked_area_selection.sh 2014-02-09 05:00:58 UTC (rev 58962)
+++ grass/trunk/raster/r.li/r.li.setup/masked_area_selection.sh 2014-02-09 05:57:12 UTC (rev 58963)
@@ -1,76 +1,88 @@
#!/bin/sh
-#%Module
+#
+# Masked area selection using r.digit
+#
+
+#%Module
#%description: Select a circular or polygonal area
#%End
#%option
#% key: raster
#% type: string
-#% description: raster map to to analyse
+#% description: Raster map to to analyse
#% required: yes
#%end
#%option
#% key: vector
#% type: string
-#% description: vector to overlay
+#% description: Vector map to overlay
#% required: no
#%end
#%option
#% key: site
#% type: string
-#% description: site to overlay
+#% description: Vector points map to overlay
#% required: no
#%end
#%option
#% key: config
#% type: string
-#% description: name of configuration file where insert areas
+#% description: Name of configuration file where insert areas
#% required: yes
#%end
#%option
#% key: north
#% type: string
-#% description: nothern edge (use only with f flag)
+#% description: Northern edge (use only with the 'f' flag)
#% required: no
#%end
#%option
#% key: south
#% type: string
-#% description:south edge (use only with f flag)
+#% description: Southern edge (use only with the 'f' flag)
#% required: no
#%end
#%option
#% key: east
#% type: string
-#% description: east edge(use only with f flag)
+#% description: Eastern edge (use only with the 'f' flag)
#% required: no
#%end
#%option
#% key: west
#% type: string
-#% description: west edge(use only with f flag)
+#% description: Western edge (use only with the 'f' flag)
#% required: no
#%end
#%flag
#% key: f
-#% description: sample frame yet selected
+#% description: Sample frame not yet selected, set from module options
#%end
#%flag
#% key: c
-#% description: take a circular area
+#% description: Take a circular area
#%end
# Where to find the others scripts
f_path="$GISBASE/etc/r.li.setup"
-# Check if we have grass
+# Check if we are in a GRASS session
if test "$GISBASE" = ""; then
- echo "You must be in GRASS GIS to run this program." >&2
- exit 1
+ echo "You must be in GRASS GIS to run this program." 1>&2
+ exit 1
fi
if [ "$1" != "@ARGS_PARSED@" ] ; then
- exec g.parser "$0" "$@"
+ exec g.parser "$0" "$@"
fi
+
+#### environment variables
+GISDBASE=`g.gisenv get=GISDBASE`
+LOCATION=`g.gisenv get=LOCATION_NAME`
+MAPSET=`g.gisenv get=MAPSET`
+: ${GISDBASE?} ${LOCATION?} ${MAPSET?}
+
+
#### set temporary files
TMP="`g.tempfile pid=$$`"
if [ $? -ne 0 ] || [ -z "$TMP" ] ; then
@@ -79,46 +91,46 @@
fi
-#### environment variables
-g.gisenv LOCATION_NAME > $TMP.var
-read LOCATION < $TMP.var
-g.gisenv GISDBASE > $TMP.var
-read GISDBASE < $TMP.var
-g.gisenv MAPSET > $TMP.var
-read MAPSET < $TMP.var
+# FIXME: use WIND_OVERRIDE
+
# show the sampling frame
-
-if [ $GIS_FLAG_f -eq 1 ] ; then
- g.region n=$GIS_OPT_north s=$GIS_OPT_south e=$GIS_OPT_east w=$GIS_OPT_west
+if [ "$GIS_FLAG_f" -eq 1 ] ; then
+ g.region n="$GIS_OPT_north" s="$GIS_OPT_south" e="$GIS_OPT_east" w="$GIS_OPT_west"
else
- g.region rast=$GIS_OPT_raster
+ g.region rast="$GIS_OPT_raster"
fi
-# open x1 monitor
+
+# open x1 Xmonitor
d.mon stop=x1
d.mon start=x1
-d.rast -o map=$GIS_OPT_raster
+d.rast -o map="$GIS_OPT_raster"
+
if [ -n "$GIS_OPT_vector" ] ; then
- d.vect map=$GIS_OPT_vector
+ d.vect map="$GIS_OPT_vector"
fi
if [ -n "$GIS_OPT_site" ] ; then
- d.vect map=$GIS_OPT_site
+ d.vect map="$GIS_OPT_site"
fi
-#let draw area
-if [ $GIS_FLAG_c -eq 1 ] ; then
- cp $f_path/circle.txt $$.txt
- echo "$$" >> $$.txt
+
+# setup for drawing area
+if [ "$GIS_FLAG_c" -eq 1 ] ; then
+ RDIG_INSTR="$f_path/circle.txt"
else
- cp $f_path/polygon.txt $$.txt
- echo "$$" >> $$.txt
+ RDIG_INSTR="$f_path/polygon.txt"
fi
-
-r.digit < $$.txt
-#show the selected area
-d.rast -o map=$$
-export name=$$.val
-$GRASS_WISH $f_path/area_query
+# feed options to r.digit
+r.digit output="tmp_rli_mask.$$" < "$RDIG_INSTR"
+
+
+# show the selected area
+d.rast -o map="tmp_rli_mask.$$"
+
+name=$$.val
+export name
+
+"$GRASS_WISH" "$f_path/area_query"
cat $name | cut -f1 -d ' ' > $name.var
read ok < $name.var
cat $name | cut -f2 -d' ' > $name.var
@@ -162,6 +174,9 @@
fi
d.mon stop=x1
-#clean tmp files
-rm -f $$*
-rm -f $TMP*
+
+# clean tmp files
+#FIXME: use g.tempfile
+rm -f "$$"*
+rm -f "$TMP"*
+
Modified: grass/trunk/raster/r.li/r.li.setup/r.li.setup
===================================================================
--- grass/trunk/raster/r.li/r.li.setup/r.li.setup 2014-02-09 05:00:58 UTC (rev 58962)
+++ grass/trunk/raster/r.li/r.li.setup/r.li.setup 2014-02-09 05:57:12 UTC (rev 58963)
@@ -5,7 +5,6 @@
# MODULE: r.li.setup
#
# AUTHOR(S): Spano Lucio Davide & Claudio Porta
-#
#
# PURPOSE: Configuration editor for r.li.<index>. It sets sampling frame and
# sample areas to analyze, the configuration is raster map indipendent.
@@ -14,22 +13,43 @@
# Read the COPYING file that comes with GRASS for details.
#
#############################################################################
+
#%Module
#% description: Configuration editor for r.li.'index'
#% keywords: raster, landscape structure analysis
#%End
if [ -z "$GISBASE" ] ; then
- echo "You must be in GRASS GIS to run this program."
+ echo "You must be in GRASS GIS to run this program." 1>&2
exit 1
fi
+
+cleanup()
+{
+ # remove temporary region
+ eval `g.findfile elem=windows file="tmp_rlisetup.$$" | grep '^name='`
+ if [ -n "$name" ] ; then
+ unset WIND_OVERRIDE
+ g.remove region="tmp_rlisetup.$$" --quiet
+ fi
+}
+trap "cleanup" 2 3 15
+
+
if [ $# -eq 0 ] ; then
- $GISBASE/etc/r.li.setup/r.li.setup.main
+ # setup internal region
+ g.region save="tmp_rlisetup.$$"
+ WIND_OVERRIDE="tmp_rlisetup.$$"
+ export WIND_OVERRIDE
+
+ "$GISBASE"/etc/r.li.setup/r.li.setup.main
+
+ cleanup
exit 0
fi
+
if [ "$1" != "@ARGS_PARSED@" ] ; then
- exec g.parser "$0" "$@"
+ exec g.parser "$0" "$@"
fi
-
Modified: grass/trunk/raster/r.li/r.li.setup/r.li.setup.html
===================================================================
--- grass/trunk/raster/r.li/r.li.setup/r.li.setup.html 2014-02-09 05:00:58 UTC (rev 58962)
+++ grass/trunk/raster/r.li/r.li.setup/r.li.setup.html 2014-02-09 05:57:12 UTC (rev 58963)
@@ -47,10 +47,11 @@
red for the sample
frame and blue for the sample areas), and other notes (disposition of
sample areas etc).
-The configuration file is saved in <tt>~/.grass7/r.li/my_conf</tt>.
+The configuration file is saved in <tt>~/.grass7/r.li/my_conf</tt>
+(the file name can be defined by the user).
<!-- NOT REALLY CLEAR: -->
Configuration output files are raster if moving window disposition was
-selected, otherwise they are in ~/.r.li/output folder.
+selected, otherwise they are in <tt>~/.r.li/output</tt> folder.
<br>
All dimension are percentage of raster rows or columns.
<li><em><b>Create a new file:</b></em> this create a new configuration
Modified: grass/trunk/raster/r.li/r.li.setup/sample_area_vector.sh
===================================================================
--- grass/trunk/raster/r.li/r.li.setup/sample_area_vector.sh 2014-02-09 05:00:58 UTC (rev 58962)
+++ grass/trunk/raster/r.li/r.li.setup/sample_area_vector.sh 2014-02-09 05:57:12 UTC (rev 58963)
@@ -2,131 +2,153 @@
#
# This program is free software under the GPL (>=v2)
# Read the COPYING file that comes with GRASS for details.
+#
-#%Module
-#% description: Create sample area from a vector map
+#%Module
+#% description: Create sample area from a vector map
#%End
#%option
#% key: raster
#% type: string
-#% description: raster map to to analyse
+#% gisprompt: old,cell,raster
+#% key_desc: name
+#% description: Raster map to to analyse
#% required: yes
#%end
#%option
#% key: vector
#% type: string
-#% description: vector map where areas are defined
+#% gisprompt: old,vector,vector
+#% key_desc: name
+#% description: Vector map where areas are defined
#% required: yes
#%end
#%option
#% key: config
#% type: string
-#% description: name of configuration file where insert areas
+#% key_desc: name
+#% gisprompt: new_file,file,output
+#% description: Name of configuration file where areas are to be saved
#% required: yes
#%end
-# Check if we have grass
-if test "$GISBASE" = ""; then
- echo "You must be in GRASS GIS to run this program." >&2
- exit 1
- fi
+# Check if we are in a GRASS session
+if [ -z "$GISBASE" ] ; then
+ echo "You must be in GRASS GIS to run this program." 1>&2
+ exit 1
+fi
+
if [ "$1" != "@ARGS_PARSED@" ] ; then
- exec g.parser "$0" "$@"
+ exec g.parser "$0" "$@"
fi
+
#### set temporary files
TMP="`g.tempfile pid=$$`"
if [ $? -ne 0 ] || [ -z "$TMP" ] ; then
- echo "ERROR: unable to create temporary files" 1>&2
- exit 1
+ echo "ERROR: unable to create temporary files" 1>&2
+ exit 1
fi
+
#### environment variables
-g.gisenv LOCATION_NAME > $TMP.var
-read LOCATION < $TMP.var
-g.gisenv GISDBASE > $TMP.var
-read GISDBASE < $TMP.var
-g.gisenv MAPSET > $TMP.var
-read MAPSET < $TMP.var
+GISDBASE=`g.gisenv get=GISDBASE`
+LOCATION=`g.gisenv get=LOCATION_NAME`
+MAPSET=`g.gisenv get=MAPSET`
+: ${GISDBASE?} ${LOCATION?} ${MAPSET?}
f_path="$GISBASE/etc/r.li.setup"
##############################################################
-#read categories from input vector, extract,
-#convert to raster and save the bounds to configuration file
+# read categories from input vector, extract,
+# convert to raster and save the bounds to configuration file
##############################################################
-#using v.category instead of v.build with cdump
-v.category input=$GIS_OPT_vector option=print > $TMP.cat
+# using v.category instead of v.build with cdump
+v.category input=$GIS_OPT_vector option=print | sort | uniq > "$TMP.cat"
-#get input vector name
+# get input vector name
GIS_OPT_input_vector=`echo $GIS_OPT_vector| cut -d'@' -f 1`
-#get input vector mapset
+# get input vector mapset
GIS_OPT_input_mapset=`echo $GIS_OPT_vector| cut -d'@' -f 2`
-#read input vector categories into CAT_LIST array
+# read input vector categories into CAT_LIST array
IFS=$'\r\n' CAT_LIST=($(cat $TMP.cat))
-TMP_REGION="reg`g.tempfile pid=$$`"
-#save the current region settings temporarily to avoid surpirses later.
-g.region save=$TMP_REGION
+# save the current region settings temporarily to avoid surpirses later.
+TMP_REGION="tmp_rlisetup.sampvect.$$"
+g.region save="$TMP_REGION"
-#process each feature in the vector having category values in the CAT_LIST array
-for CAT in "${CAT_LIST[@]}"
+# find a free Xmonitor
+XMON=x1
+for i in 1 2 3 4 5 6 7 ; do
+ result=`d.mon -L | grep -w "^x$i"`
+ if [ `echo "$result" | grep -c 'not'` -eq 1 ] ; then
+ XMON="x$i"
+ break
+ fi
+done
+
+
+# process each feature in the vector having category values in the CAT_LIST array
+for CAT in "${CAT_LIST[@]}"
do
- #vector to store a feature fro $GIS_OPT_vector with category value $CAT.
- #This temporary vector will be removed at the end.
+ # vector to store a feature fro $GIS_OPT_vector with category value $CAT.
+ # This temporary vector will be removed at the end.
EXTRACT=$GIS_OPT_input_vector"_"$CAT"_part@"$GIS_OPT_input_mapset
-
- #extract only a part of $GIS_OPT_vector where category = $CAT and store in $EXTRACT
- v.extract input=$GIS_OPT_vector output=$EXTRACT type=point,line,boundary,centroid,area,face new=-1 -d where='CAT='$CAT
-
- #TODO: anyway to check if x1 is in use?
- #opening monitor x1
- d.mon stop=x1
- d.mon start=x1
- #setting region with raster resolution
- g.region vect=$EXTRACT align=$GIS_OPT_raster
- d.rast -o $GIS_OPT_raster
- #render extracted vector map
- d.vect $EXTRACT
- #ask the user if he wants to analyse this vector and a name for raster
- #in graphical mode using wish
- export name=$TMP.val # where find the answer
- $GRASS_WISH $f_path/area_query
- cat $name | cut -f1 -d ' ' > $name.var
- read ok < $name.var
- cat $name | cut -f2 -d' ' > $name.var
- r_name=""
- read r_name < $name.var
- echo $r_name
- if [ $ok -eq 1 ] ; then
+ # extract only a part of $GIS_OPT_vector where category = $CAT and store in $EXTRACT
+ v.extract input=$GIS_OPT_vector output=$EXTRACT \
+ type=point,line,boundary,centroid,area,face \
+ new=-1 -d where='CAT='$CAT
+
+ # open Xmonitor
+ d.mon stop="$XMON"
+ d.mon start="$XMON"
+
+ # set region with raster resolution
+ g.region vect="$EXTRACT" align="$GIS_OPT_raster"
+ d.rast -o "$GIS_OPT_raster"
+
+ # render extracted vector map
+ d.vect "$EXTRACT"
+
+ # ask the user to analyse this vector and a name for raster in a Tcl GUI
+ name="$TMP.val" # where find the answer
+ export name
+
+ "$GRASS_WISH" "$f_path/area_query"
+
+ ok=`cat "$name" | cut -f1 -d ' '`
+ #cat "$name" | cut -f1 -d ' ' > "$name.var"
+ #read ok < "$name.var"
+ r_name=`cat "$name" | cut -f2 -d' '`
+ #cat "$name" | cut -f2 -d' ' > "$name.var"
+ #r_name=""
+ #read r_name < "$name.var"
+ echo "$r_name"
+
+ if [ "$ok" -eq 1 ] ; then
#area selected, create mask
- v.to.rast input=$EXTRACT output=$r_name use=cat value=1 rows=4096
- #read the region settings to save to configuration file
- g.region -g| grep "n=" | cut -f2 -d'='> $name.var
- read north < $name.var
- g.region -g| grep "s=" | cut -f2 -d'=' > $name.var
- read south < $name.var
- g.region -g| grep "e=" | cut -f2 -d'=' > $name.var
- read east < $name.var
- g.region -g| grep "w=" | cut -f2 -d'=' > $name.var
- read west < $name.var
- #write info in configuration file
- echo "MASKEDOVERLAYAREA $r_name|$north|$south|$east|$west" >> $GIS_OPT_conf
+ v.to.rast input="$EXTRACT" output="$r_name" use=cat value=1 rows=4096
+
+ # save the region settings into the configuration file
+ eval `g.region -g`
+ echo "MASKEDOVERLAYAREA $r_name|$n|$s|$e|$w" >> "$GIS_OPT_conf"
fi
+
#remove temporary vector map created from v.extract
- g.remove vect=$EXTRACT
+ g.remove vect="$EXTRACT"
#rm -fR "$GISDBASE"/"$LOCATION"/"$MAPSET"/vector/$GIS_OPT_vector"part"$I
- #echo DROP TABLE $GIS_OPT_vector"part"$I | db.execute
+ #echo DROP TABLE $GIS_OPT_vector"part"$I | db.execute
done
-d.mon stop=x1
-#restore user region
-g.region region=$TMP_REGION
-#remove temporary region, $TMP_REGION
-g.remove region=$TMP_REGION
-# clean tmp files
-rm -f $TMP*
+d.mon stop="$XMON"
+# restore the region (which itself is a WIND_OVERRIDE temporary region by
+# the r.li.setup main script)
+g.region region="$TMP_REGION"
+g.remove region="$TMP_REGION"
+
+# clean tmp files
+rm -f "$TMP"*
Modified: grass/trunk/raster/r.li/r.li.setup/square_mouse_selection.sh
===================================================================
--- grass/trunk/raster/r.li/r.li.setup/square_mouse_selection.sh 2014-02-09 05:00:58 UTC (rev 58962)
+++ grass/trunk/raster/r.li/r.li.setup/square_mouse_selection.sh 2014-02-09 05:57:12 UTC (rev 58963)
@@ -1,90 +1,94 @@
-#! /bin/sh
-
+#!/bin/sh
+#
+# This script selects a square area using the mouse
+#
# This program is free software under the GPL (>=v2)
# Read the COPYING file that comes with GRASS for details.
+#
-#this script select a square area using mouse
-
#%Module
#% description: Select a rectangular area
#%End
#%option
#% key: raster
#% type: string
-#% description: raster map to to analyse
+#% gisprompt: old,cell,raster
+#% description: Raster map to to analyse
#% required: yes
#%end
#%option
#% key: vector
#% type: string
-#% description: vector to overlay
+#% gisprompt: old,vector,vector
+#% description: Vector map to overlay
#% required: no
#%end
#%option
#% key: site
#% type: string
-#% description: site to overlay
+#% description: Vector points map to overlay
#% required: no
#%end
#%option
#% key: config
#% type: string
-#% description: name of configuration file where insert areas
+#% gisprompt: new,file,file
+#% description: Name of configuration file where inserted areas will be stored
#% required: yes
#%end
#%option
#% key: north
#% type: string
-#% description: nothern edge (use only with f flag)
+#% description: Northern edge (use only with the 'f' flag)
#% required: no
#%end
#%option
#% key: south
#% type: string
-#% description:south edge (use only with f flag)
+#% description: Southern edge (use only with the 'f' flag)
#% required: no
#%end
#%option
#% key: east
#% type: string
-#% description: east edge(use only with f flag)
+#% description: Eastern edge (use only with the 'f' flag)
#% required: no
#%end
#%option
#% key: west
#% type: string
-#% description: west edge(use only with f flag)
+#% description: Western edge (use only with the 'f' flag)
#% required: no
#%end
#%flag
#% key: f
-#% description: sample frame yet selected
+#% description: Sample frame selected by module options
#%end
f_path="$GISBASE/etc/r.li.setup"
-# Check if we have grass
+# Check if we are in a GRASS session
if test "$GISBASE" = ""; then
- echo "You must be in GRASS GIS to run this program." >&2
- exit 1
+ echo "You must be in GRASS GIS to run this program." >&2
+ exit 1
fi
+
if [ "$1" != "@ARGS_PARSED@" ] ; then
- exec g.parser "$0" "$@"
+ exec g.parser "$0" "$@"
fi
-
-# open x1 monitor
+# open x1 Xmonitor
d.mon stop=x1
d.mon start=x1
g.region rast=$GIS_OPT_raster
-#### set temporary files
+#### create temporary file
TMP="`g.tempfile pid=$$`"
if [ $? -ne 0 ] || [ -z "$TMP" ] ; then
- echo "ERROR: unable to create temporary files" 1>&2
+ echo "ERROR: unable to create temporary file" 1>&2
exit 1
fi
@@ -104,27 +108,33 @@
echo "START $s_n|$s_s|$s_e|$s_w|$s_nsres|$s_ewres" >> $GIS_OPT_conf
# show the sampling frame
-if [ $GIS_FLAG_f -eq 1 ] ; then
- g.region n=$GIS_OPT_north s=$GIS_OPT_south e=$GIS_OPT_east w=$GIS_OPT_west
+if [ "$GIS_FLAG_f" -eq 1 ] ; then
+ g.region n="$GIS_OPT_north" s="$GIS_OPT_south" \
+ e="$GIS_OPT_east" w="$GIS_OPT_west"
fi
-d.rast -o map=$GIS_OPT_raster
+d.rast -o map="$GIS_OPT_raster"
+
if [ -n "$GIS_OPT_vector" ] ; then
- d.vect map=$GIS_OPT_vector
+ d.vect map="$GIS_OPT_vector"
fi
if [ -n "$GIS_OPT_site" ] ; then
- d.vect map=$GIS_OPT_site
+ d.vect map="$GIS_OPT_site" color=red fcolor=red size=5 icon=basic/circle
fi
-#let draw area
+# let draw area
d.zoom
-#ask if the selected area is right
-export name=$TMP #where write the answer
-$GRASS_WISH $f_path/square_query
-read ok < $TMP.var
-if [ $ok -eq 0 ] ; then
- echo "NO" >> $GIS_OPT_conf
+# ask if the selected area is right
+name="$TMP" # file where write the answer
+export name
+
+"$GRASS_WISH" "$f_path/square_query"
+
+read ok < "$TMP.var"
+
+if [ "$ok" -eq 0 ] ; then
+ echo "NO" >> "$GIS_OPT_conf"
fi
if [ $ok -eq 1 ] ; then
@@ -144,11 +154,9 @@
echo "SQUAREAREA $n|$s|$e|$w|$nsres|$ewres" >> $GIS_OPT_conf
fi
-#close monitor
+# close the Xmonitor
d.mon stop=x1
+
# clean tmp files
rm -f $TMP*
-
-
-
Modified: grass/trunk/raster/r.li/r.li.shannon/r.li.shannon.html
===================================================================
--- grass/trunk/raster/r.li/r.li.shannon/r.li.shannon.html 2014-02-09 05:00:58 UTC (rev 58962)
+++ grass/trunk/raster/r.li/r.li.shannon/r.li.shannon.html 2014-02-09 05:57:12 UTC (rev 58963)
@@ -16,6 +16,7 @@
If the "moving window" method was selected in <b>r.li.setup</b>, then the
output will be a raster map, otherwise an ASCII file will be generated in
the <tt>~/.r.li/output/</tt> folder.
+
<p>
If input raster is full of null values r.li.shannon returns -1. <br>
<!-- does that mean the program exit code or raster values?? -->
More information about the grass-commit
mailing list