[GRASS-SVN] r53247 - in grass-addons/grass6/raster: r.connectivity.corridors r.connectivity.distance r.connectivity.network
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Sep 20 11:38:12 PDT 2012
Author: sbl
Date: 2012-09-20 11:38:11 -0700 (Thu, 20 Sep 2012)
New Revision: 53247
Modified:
grass-addons/grass6/raster/r.connectivity.corridors/description.html
grass-addons/grass6/raster/r.connectivity.corridors/r.connectivity.corridors
grass-addons/grass6/raster/r.connectivity.distance/description.html
grass-addons/grass6/raster/r.connectivity.distance/r.connectivity.distance
grass-addons/grass6/raster/r.connectivity.network/description.html
grass-addons/grass6/raster/r.connectivity.network/r.connectivity.network
Log:
Bugfixes for r.connectivity
Modified: grass-addons/grass6/raster/r.connectivity.corridors/description.html
===================================================================
--- grass-addons/grass6/raster/r.connectivity.corridors/description.html 2012-09-20 15:29:13 UTC (rev 53246)
+++ grass-addons/grass6/raster/r.connectivity.corridors/description.html 2012-09-20 18:38:11 UTC (rev 53247)
@@ -28,6 +28,8 @@
<br>
<b>Create input patch vector map</b><br>
+<b>Create input patch vector map</b><br>
+
<div class="code"><pre>
###Set region
g.region -p rast=landuse96_28m at PERMANENT align=landuse96_28m at PERMANENT
@@ -36,19 +38,10 @@
##Extract habitat patches
#Condition 1: Category 11 = Bottomland Hardwoods/Hardwood Swamps
#Condition 2: no border-cells are suitable
-r.mapcalc "patches=if(\
-landuse96_28m[0,1]==11&&\
-landuse96_28m[0,-1]==11&&\
-landuse96_28m[1,1]==11&&\
-landuse96_28m[1,0]==11&&\
-landuse96_28m[1,-1]==11&&\
-landuse96_28m[-1,1]==11&&\
-landuse96_28m[-1,0]==11&&\
-landuse96_28m[-1,-1]==11&&\
-landuse96_28m==11,1,null())"
+r.mapcalc "patches=if(landuse96_28m[0,1]==11&&landuse96_28m[0,-1]==11&&landuse96_28m[1,1]==11&&landuse96_28m[1,0]==11&&landuse96_28m[1,-1]==11&&landuse96_28m[-1,1]==11&&landuse96_28m[-1,0]==11&&landuse96_28m[-1,-1]==11&&landuse96_28m==11,1,null())"
#Vectorize patches
-r.to.vect input=patches output=patches feature=area --overwrite
+r.to.vect input=patches output=patches feature=area
#Add a column for the population proxy (in this case area in hectares)
v.db.addcol map=patches layer=1 'columns=area_ha double precision'
@@ -57,7 +50,7 @@
v.to.db map=patches type=point,line,boundary,centroid layer=1 qlayer=1 option=area units=hectares columns=area_ha
#Extract core habitat areas with more than 1 ha
-v.extract input=patches at user1 output=patches_1ha type=point,line,boundary,centroid,area,face layer=1 where=area_ha>1 new=-1 --overwrite
+v.extract input=patches output=patches_1ha type=area layer=1 where="area_ha>1"
</pre></div>
<b>Create a cost raster (se also: <em>r.cost</em>)</b><br>
@@ -68,6 +61,7 @@
<div class="code"><pre>
#Reclassify land use map
+#Windows users may have to use the GUI version of r.reclass and paste the rules there...
echo '0 = 56 #not classified (2*resolution (28m))
1 = NULL #High Intensity Developed (absolut barrier)
2 = 140 #Low Intensity Developed (5*resolution (28m))
Modified: grass-addons/grass6/raster/r.connectivity.corridors/r.connectivity.corridors
===================================================================
--- grass-addons/grass6/raster/r.connectivity.corridors/r.connectivity.corridors 2012-09-20 15:29:13 UTC (rev 53246)
+++ grass-addons/grass6/raster/r.connectivity.corridors/r.connectivity.corridors 2012-09-20 18:38:11 UTC (rev 53247)
@@ -361,7 +361,6 @@
for w in $weights
do
integer_column=$(echo $column_check | tr ' ' '\n' | grep -w "INTEGER|${w}")
- echo $integer_column
if [ "$integer_column" ] ; then
#For integer columns
if [ $CORES -gt 1 -a "$OS_type" != "Win" ] ; then
@@ -369,7 +368,7 @@
r_reclass=
for fid in $selected_edges_ud
do
- r_reclass=${r_reclass}\#$(echo $table_extract | tr ' ' '\n' | cut -f1,$weight_position -d',' | awk -v FID=$fid -v WEIGHT=$w -v PREFIX=$PREFIX -v FS=',' '{if($1==FID) print "echo " $1 "=" $2 " | r.reclass input=" PREFIX "_corridor_" $1 " output=" PREFIX "_corridor_" $1 "_" WEIGHT " --overwrite --verbose"}' | head -n 1)
+ r_reclass=${r_reclass}\#$(echo $table_extract | tr ' ' '\n' | cut -f1,$weight_position -d',' --output-delimiter=' ' | awk -v FID=$fid -v WEIGHT=$w -v PREFIX=$PREFIX '{if($1==FID) print "echo " $1 "=" $2 " | r.reclass input=" PREFIX "_corridor_" $1 " output=" PREFIX "_corridor_" $1 "_" WEIGHT " --overwrite --verbose"}' | head -n 1)
done
#Reclass maps using xargs
echo $r_reclass | sed 's/^.//' | tr '#' '\n' | xargs -P $CORES -n 1 -i echo {} | sh
@@ -377,7 +376,7 @@
#Reclass maps using for-loop
for fid in $selected_edges_ud
do
- echo $table_extract | tr ' ' '\n' | cut -f1,$counter -d',' | awk -v FID=$fid -v WEIGHT=$w '{if($1==FID) print $1 " = " $2}' | head -n 1 | r.reclass input=${PREFIX}_corridor_${fid} output=${PREFIX}_corridor_${fid}_${w} --overwrite --verbose
+ echo $table_extract | tr ' ' '\n' | cut -f1,$weight_position -d',' --output-delimiter=' ' | awk -v FID=$fid '{if($1==FID) print $1 " = " $2}' | head -n 1 | r.reclass input=${PREFIX}_corridor_${fid} output=${PREFIX}_corridor_${fid}_${w} --overwrite --verbose
done
fi
else
@@ -387,18 +386,18 @@
r_recode=
for fid in $selected_edges_ud
do
- r_recode=${r_recode}\#$(echo $table_extract | tr ' ' '\n' | cut -f1,$weight_position -d',' | awk -v FID=$fid -v WEIGHT=$w -v PREFIX=$PREFIX -v FS=',' '{if($1==FID) print "echo " $1 ":" $1 ":" $2 ":" $2 " | r.recode input=" PREFIX "_corridor_" $1 " output=" PREFIX "_corridor_" $1 "_" WEIGHT " rules=- --overwrite --verbose"}' | head -n 1)
+ r_recode=${r_recode}\#$(echo $table_extract | tr ' ' '\n' | cut -f1,$weight_position -d',' --output-delimiter=' ' | awk -v FID=$fid -v WEIGHT=$w -v PREFIX=$PREFIX '{if($1==FID) print "echo " $1 ":" $1 ":" $2 ":" $2 " | r.recode input=" PREFIX "_corridor_" $1 " output=" PREFIX "_corridor_" $1 "_" WEIGHT " rules=- --overwrite --verbose"}' | head -n 1)
done
#Recode maps using xargs
echo $r_recode | sed 's/^.//' | tr '#' '\n' | xargs -P $CORES -n 1 -i echo {} | sh
else
- #Reclass maps using for-loop
+ #Recode maps using for-loop
for fid in $selected_edges_ud
do
- echo $table_extract | tr ' ' '\n' | cut -f1,$counter -d',' | awk -v FID=$fid -v WEIGHT=$w '{if($1==FID) print $1 " = " $2}' | head -n 1 | r.recode input=${PREFIX}_corridor_${fid} output=${PREFIX}_corridor_${fid}_${w} --overwrite --verbose
+ echo $table_extract | tr ' ' '\n' | cut -f1,$weight_position -d',' --output-delimiter=' ' | awk -v FID=$fid '{if($1==FID) print $1 ":" $1 ":" $2 ":" $2}' | head -n 1 | r.recode input=${PREFIX}_corridor_${fid} output=${PREFIX}_corridor_${fid}_${w} --overwrite --verbose
done
fi
- counter=$`expr $weight_position + 1`
+ weight_position=$`expr $weight_position + 1`
fi
#Collect list of corridors
corridor_list=$(echo $selected_edges_ud | tr ' ' '\n' | awk -v PREFIX=$PREFIX -v WEIGHT=$w '{print PREFIX "_corridor_" $1 "_" WEIGHT}' | tr '\n' ',' | sed 's/.$//')
Modified: grass-addons/grass6/raster/r.connectivity.distance/description.html
===================================================================
--- grass-addons/grass6/raster/r.connectivity.distance/description.html 2012-09-20 15:29:13 UTC (rev 53246)
+++ grass-addons/grass6/raster/r.connectivity.distance/description.html 2012-09-20 18:38:11 UTC (rev 53247)
@@ -60,19 +60,10 @@
##Extract habitat patches
#Condition 1: Category 11 = Bottomland Hardwoods/Hardwood Swamps
#Condition 2: no border-cells are suitable
-r.mapcalc "patches=if(\
-landuse96_28m[0,1]==11&&\
-landuse96_28m[0,-1]==11&&\
-landuse96_28m[1,1]==11&&\
-landuse96_28m[1,0]==11&&\
-landuse96_28m[1,-1]==11&&\
-landuse96_28m[-1,1]==11&&\
-landuse96_28m[-1,0]==11&&\
-landuse96_28m[-1,-1]==11&&\
-landuse96_28m==11,1,null())"
+r.mapcalc "patches=if(landuse96_28m[0,1]==11&&landuse96_28m[0,-1]==11&&landuse96_28m[1,1]==11&&landuse96_28m[1,0]==11&&landuse96_28m[1,-1]==11&&landuse96_28m[-1,1]==11&&landuse96_28m[-1,0]==11&&landuse96_28m[-1,-1]==11&&landuse96_28m==11,1,null())"
#Vectorize patches
-r.to.vect input=patches output=patches feature=area --overwrite
+r.to.vect input=patches output=patches feature=area
#Add a column for the population proxy (in this case area in hectares)
v.db.addcol map=patches layer=1 'columns=area_ha double precision'
@@ -81,7 +72,7 @@
v.to.db map=patches type=point,line,boundary,centroid layer=1 qlayer=1 option=area units=hectares columns=area_ha
#Extract core habitat areas with more than 1 ha
-v.extract input=patches at user1 output=patches_1ha type=point,line,boundary,centroid,area,face layer=1 where=area_ha>1 new=-1 --overwrite
+v.extract input=patches output=patches_1ha type=area layer=1 where="area_ha>1"
</pre></div>
<b>Create a cost raster (se also: <em>r.cost</em>)</b><br>
@@ -92,6 +83,7 @@
<div class="code"><pre>
#Reclassify land use map
+#Windows users may have to use the GUI version of r.reclass and paste the rules there...
echo '0 = 56 #not classified (2*resolution (28m))
1 = NULL #High Intensity Developed (absolut barrier)
2 = 140 #Low Intensity Developed (5*resolution (28m))
@@ -151,7 +143,7 @@
When all analysis is finnished some cleanup may be appropriate, in order to save disk space:<br>
<div class="code"><pre>
-#Add the f-lag (-f) to the following two commands if you are sure you want to delete all intermediate map from r.connectivity.*.
+#Add the f-lag (-f) to the following two commands if you are sure you want to delete all intermediate maps from r.connectivity.*.
g.mremove rast=hws_connectivity_corridor_*
g.mremove rast=hws_connectivity_patch_*
</pre></div>
Modified: grass-addons/grass6/raster/r.connectivity.distance/r.connectivity.distance
===================================================================
--- grass-addons/grass6/raster/r.connectivity.distance/r.connectivity.distance 2012-09-20 15:29:13 UTC (rev 53246)
+++ grass-addons/grass6/raster/r.connectivity.distance/r.connectivity.distance 2012-09-20 18:38:11 UTC (rev 53247)
@@ -374,16 +374,17 @@
do
g.message -v "Calculating connectivity-distances for patch number $p"
#Extract patch polygons
- centroid_number=$(v.extract --overwrite --verbose input=$PATCHES output=${PREFIX}_patch_${p} where="cat=${p}" 2>&1 | grep "Number of centroids:" | cut -f4 -d' ')
+ v.extract --overwrite --quiet input=$PATCHES output=${PREFIX}_patch_${p} list=$p 2>&1
+ eval `v.info -t map=${PREFIX}_patch_${p}`
#Extract centroids of convex hull for multipolygons and export data as network vertices
- if [ $centroid_number -gt 1 ] ; then
+ if [ $centroids -gt 1 ] ; then
v.hull -a -f --overwrite --quiet input=${PREFIX}_patch_${p} output=${PREFIX}_patch_${p}_ch 2>&1 > /dev/null
xy=$(v.to.db -p --quiet map=${PREFIX}_patch_${p}_ch option=coor | cut -f2,3 -d'|' --output-delimiter=';')
echo "${p};$xy" >> ${FOLDER}/vertices_part_1.csv
g.remove -f vect=${PREFIX}_patch_${p}_ch --quiet 2>&1 > /dev/null
- g.message -v "Patch ${p} has $centroid_number centroids. Using centroid of the convex hull of all polygon parts."
+ g.message -v "Patch ${p} has $centroids centroids. Using centroid of the convex hull of all polygon parts."
#Remove node data for patches without centroid
- elif [ $centroid_number -eq 0 ] ; then
+ elif [ $centroids -eq 0 ] ; then
g.remove -f vect=${PREFIX}_patch_${p} --quiet 2>&1 > /dev/null
echo "${p};no centroid" >> ${FOLDER}/unconsidered_patches.csv
cat ${FOLDER}/vertices_part_1.csv | sed "/^${p};/d" > ${FOLDER}/vertices_part_1.csv
Modified: grass-addons/grass6/raster/r.connectivity.network/description.html
===================================================================
--- grass-addons/grass6/raster/r.connectivity.network/description.html 2012-09-20 15:29:13 UTC (rev 53246)
+++ grass-addons/grass6/raster/r.connectivity.network/description.html 2012-09-20 18:38:11 UTC (rev 53247)
@@ -1,8 +1,8 @@
<h2>DESCRIPTION</h2>
<dl>
-Recently, graph-theory has been characterised as an efficient and useful tool for conservation planning (e.g. Bunn et al. 2000, Calabrese & Fagan 2004, Minor & Urban 2008, Zetterberg et. al. 2010). As a part of the r.connectivity.* tool-chain, r.connectivity.network is intended to make graph-theory more easily available to conservation planning.
+Recently, graph-theory has been characterised as an efficient and useful tool for conservation planning (e.g. Bunn et al. 2000, Calabrese & Fagan 2004, Minor & Urban 2008, Zetterberg et. al. 2010). As a part of the r.connectivity.* tool-chain, r.connectivity.network is intended to make graph-theory more easily available to conservation planning.
<br><br>
-r.connectivity.network is the 2nd tool of the r.connectivity.* toolchain and performs the (core) network analysis (usig the igraph-package in R)on the network data prepared with r.connectivity.distance. This network data is analysed on graph, edge and vertex level.
+r.connectivity.network is the 2nd tool of the r.connectivity.* toolchain and performs the (core) network analysis (usig the igraph-package in R) on the network data prepared with r.connectivity.distance. This network data is analysed on graph, edge and vertex level.
<br><br>
Connectivity measures for the graph level are: number of vertices, number of edges, number of clusters, size of the largest cluster, average cluster size, diameter, density, modularity, number of communities, community size (in number of vertices) Network characteristics are visualised in a plot showing an overview over number of connections, number of components and and the size of the largest network component within the network with regards to cost-distance between patches.
<br><br>
@@ -19,6 +19,9 @@
!!!This script is designed to work based on the output of r.connectivity.distance!!!
</dl>
+<h2>REQUIREMENTS</h2>
+For running this tool R language and environment for statistical computing and graphics has to be installed (see: <a href=http://www.r-project.org>http://www.r-project.org</a>). Furthermore the <a href=http://cran.r-project.org/web/packages/igraph/index.html>igraph</a> package in R is required with version 0.6-2 or newer. For parallel processing (at the moment only supported for Linux) the R packages <a href=http://cran.r-project.org/web/packages/doMC/index.html>doMC</a>, <a href=http://cran.r-project.org/web/packages/multicore/index.html>multicore</a>, <a href=http://cran.r-project.org/web/packages/iterators/index.html>iterators</a>, <a href=http://cran.r-project.org/web/packages/codetools/index.html>codetools</a> and <a href=http://cran.r-project.org/web/packages/foreach/index.html>foreach</a> are required as well. All R packages can be installed by running the AddOn using the <em><b>i-flag (-i)</b></em>. Installation requires internet access. For postscript output (overvi
ew and kernel plot) also <a href=http://www.ghostscript.com/>ghostscript</a> is required.
+
<h2>OUTPUT NOTES</h2>
<h3>Field naming</h3>
<dl>
@@ -185,6 +188,8 @@
<br>
<b>Create input patch vector map</b><br>
+<b>Create input patch vector map</b><br>
+
<div class="code"><pre>
###Set region
g.region -p rast=landuse96_28m at PERMANENT align=landuse96_28m at PERMANENT
@@ -193,19 +198,10 @@
##Extract habitat patches
#Condition 1: Category 11 = Bottomland Hardwoods/Hardwood Swamps
#Condition 2: no border-cells are suitable
-r.mapcalc "patches=if(\
-landuse96_28m[0,1]==11&&\
-landuse96_28m[0,-1]==11&&\
-landuse96_28m[1,1]==11&&\
-landuse96_28m[1,0]==11&&\
-landuse96_28m[1,-1]==11&&\
-landuse96_28m[-1,1]==11&&\
-landuse96_28m[-1,0]==11&&\
-landuse96_28m[-1,-1]==11&&\
-landuse96_28m==11,1,null())"
+r.mapcalc "patches=if(landuse96_28m[0,1]==11&&landuse96_28m[0,-1]==11&&landuse96_28m[1,1]==11&&landuse96_28m[1,0]==11&&landuse96_28m[1,-1]==11&&landuse96_28m[-1,1]==11&&landuse96_28m[-1,0]==11&&landuse96_28m[-1,-1]==11&&landuse96_28m==11,1,null())"
#Vectorize patches
-r.to.vect input=patches output=patches feature=area --overwrite
+r.to.vect input=patches output=patches feature=area
#Add a column for the population proxy (in this case area in hectares)
v.db.addcol map=patches layer=1 'columns=area_ha double precision'
@@ -214,7 +210,7 @@
v.to.db map=patches type=point,line,boundary,centroid layer=1 qlayer=1 option=area units=hectares columns=area_ha
#Extract core habitat areas with more than 1 ha
-v.extract input=patches at user1 output=patches_1ha type=point,line,boundary,centroid,area,face layer=1 where=area_ha>1 new=-1 --overwrite
+v.extract input=patches output=patches_1ha type=area layer=1 where="area_ha>1"
</pre></div>
<b>Create a cost raster (se also: <em>r.cost</em>)</b><br>
@@ -225,6 +221,7 @@
<div class="code"><pre>
#Reclassify land use map
+#Windows users may have to use the GUI version of r.reclass and paste the rules there...
echo '0 = 56 #not classified (2*resolution (28m))
1 = NULL #High Intensity Developed (absolut barrier)
2 = 140 #Low Intensity Developed (5*resolution (28m))
@@ -284,7 +281,7 @@
When all analysis is finnished some cleanup may be appropriate, in order to save disk space:<br>
<div class="code"><pre>
-#Add the f-lag (-f) to the following two commands if you are sure you want to delete all intermediate map from r.connectivity.*.
+#Add the f-lag (-f) to the following two commands if you are sure you want to delete all intermediate maps from r.connectivity.*.
g.mremove rast=hws_connectivity_corridor_*
g.mremove rast=hws_connectivity_patch_*
</pre></div>
Modified: grass-addons/grass6/raster/r.connectivity.network/r.connectivity.network
===================================================================
--- grass-addons/grass6/raster/r.connectivity.network/r.connectivity.network 2012-09-20 15:29:13 UTC (rev 53246)
+++ grass-addons/grass6/raster/r.connectivity.network/r.connectivity.network 2012-09-20 18:38:11 UTC (rev 53247)
@@ -264,10 +264,17 @@
#Check if R is installed
- if [ ! -x "`which R`" ] ; then
+
+if [ ! -x "`which R`" ] ; then
+ if [ "$OS_type" = "Win" ] ; then
+ g.message -e "R is required, but can not be found on the system."
+ g.message -e "Please install R, or - if it is allready installed - please add the path to R to your environment variables (see: http://grass.osgeo.org/wiki/R_statistics#MS_Windows)."
+ exit 1
+ else
g.message -e "R is required, please install R first"
exit 1
fi
+fi
#Visualise the negative exponential decay kernel and exit (if requested)
if [ $X_FLAG -eq 1 ] ; then
@@ -285,7 +292,7 @@
#Check if ghostscript is installed
if [ $OVERVIEW_PLOT ] ; then
if [ "$OS_type" = "Win" ] ; then
- g.message -v "Assuming ghostscript is installed on MS Windows"
+ g.message -w "Ghostscript is required. Assuming ghostscript is installed on MS Windows"
#Check for ghostscript deactivated on Windows because the path to gswin32 is not defined in the environment settings by ghostscript installation automatically
# if [ ! -x "`which gswin32`" ] ; then
# g.message -e "ghostscript is required for postscript output, can not find ghostscript (gswin32.exe), please install ghostscript first (or check environment path settings)"
@@ -301,7 +308,7 @@
fi
if [ $KERNEL_PLOT ]; then
if [ "$OS_type" = "Win" ] ; then
- g.message -v "Assuming ghostscript is installed on MS Windows"
+ g.message -w "Ghostscript is required. Assuming ghostscript is installed on MS Windows"
#Check for ghostscript deactivated on Windows because the path to gswin32 is not defined in the environment settings by ghostscript installation automatically
# if [ ! -x "`which gswin32`" ] ; then
# g.message -e "ghostscript is required for postscript output, can not find ghostscript (gswin32.exe), please install ghostscript first (or check environment path settings)"
More information about the grass-commit
mailing list