[GRASS-SVN] r52997 - in grass-addons/grass6/raster: . r.connectivity.corridors

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Aug 30 11:39:16 PDT 2012


Author: sbl
Date: 2012-08-30 11:39:15 -0700 (Thu, 30 Aug 2012)
New Revision: 52997

Added:
   grass-addons/grass6/raster/r.connectivity.corridors/
   grass-addons/grass6/raster/r.connectivity.corridors/Makefile
   grass-addons/grass6/raster/r.connectivity.corridors/description.html
   grass-addons/grass6/raster/r.connectivity.corridors/r.connectivity.corridors
Log:
A new addon for connectivity analysis based on graph theory


Property changes on: grass-addons/grass6/raster/r.connectivity.corridors
___________________________________________________________________
Added: svn:ignore
   + :


Added: grass-addons/grass6/raster/r.connectivity.corridors/Makefile
===================================================================
--- grass-addons/grass6/raster/r.connectivity.corridors/Makefile	                        (rev 0)
+++ grass-addons/grass6/raster/r.connectivity.corridors/Makefile	2012-08-30 18:39:15 UTC (rev 52997)
@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../..
+
+PGM = r.connectivity.corridors
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script

Added: grass-addons/grass6/raster/r.connectivity.corridors/description.html
===================================================================
--- grass-addons/grass6/raster/r.connectivity.corridors/description.html	                        (rev 0)
+++ grass-addons/grass6/raster/r.connectivity.corridors/description.html	2012-08-30 18:39:15 UTC (rev 52997)
@@ -0,0 +1,89 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+<title>GRASS GIS manual: r.connectivity.corridors</title>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+<link rel="stylesheet" href="grassdocs.css" type="text/css">
+</head>
+<body bgcolor="white">
+
+<img src="grass_logo.png" alt="GRASS logo"><hr align=center size=6 noshade>
+
+<h2>NAME</h2>
+<em><b>r.connectivity.corridors</b></em>  - Compute corridors between habitat patches for edges from r.connectivity.network based on (cost) distance raster maps from r.connectivity.distance
+<h2>KEYWORDS</h2>
+<dl>
+raster, vector, connectivity, network, corridor
+</dl>
+
+<h2>SYNOPSIS</h2>
+<b>r.connectivity.corridors</b><br>
+<b>r.connectivity.corridors help</b><br>
+<b>r.connectivity.corridors</b> [-<b>sdr</b>] <b>folder</b>=<em>string</em> <b>suffix</b>=<em>string</em>  [<b>corridor_tolerance</b>=<em>float</em>]   [<b>where</b>=<em>where (SQL statement)</em>]   [<b>weights</b>=<em>Column names</em>[,<i>Column names</i>,...]]   [<b>cores</b>=<em>integer</em>]   [--<b>verbose</b>]  [--<b>quiet</b>] 
+
+<h3>Flags:</h3>
+<dl>
+<dt><b>-s</b></dt>
+<dd>Show edges selected by WHERE-clause and exit</dd>
+
+<dt><b>-d</b></dt>
+<dd>Assign distance values to corridors instead of connection IDs and weights</dd>
+
+<dt><b>-r</b></dt>
+<dd>Recalculate already computed corridors (default is only weight and summarize already existing corridor maps)</dd>
+
+<dt><b>--verbose</b></dt>
+<dd>Verbose module output</dd>
+<dt><b>--quiet</b></dt>
+<dd>Quiet module output</dd>
+</dl>
+
+<h3>Parameters:</h3>
+<dl>
+<dt><b>folder</b>=<em>string</em></dt>
+<dd>Folder where all (non map) output data from r.connectivity.* is stored (input)</dd>
+
+<dt><b>suffix</b>=<em>string</em></dt>
+<dd>Suffix for specifying corridor summary result</dd>
+
+<dt><b>corridor_tolerance</b>=<em>float</em></dt>
+<dd>Tolerance for deviation of corridors from (cost) distance between a pair of vertices (in % of the undirected (cost) distance of the edge)</dd>
+<dd>Default: <em>0.0</em></dd>
+
+<dt><b>where</b>=<em>string (SQL where statement)</em></dt>
+<dd>WHERE conditions of SQL statement without 'where' keyword. (example: cf_mst_ud = 1 or cf_eb_ud > 100)</dd>
+
+<dt><b>weights</b>=<em>string (Column name[,<i>Column name</i>,...])</em></dt>
+<dd>Column names for weights which should be assigned to the corridors separated by comma (multiple)</dd>
+
+<dt><b>cores</b>=<em>integer</em></dt>
+<dd>Number of cores to be used for multithreading (1 means no multithreading)</dd>
+<dd>Default: <em>1</em></dd>
+</dl>
+
+<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.corridors is intended to make graph-theory more easily available to conservation planning.
+<br><br>
+r.connectivity.corridors is th 3rd tool of the r.connectivity.* toolchain.
+<br><br>
+r.connectivity.corridors loops through the attribute-table of the edge- output vector map from r.connectivity.network and computes the corridor for each edge of a user-defined set of edges. r.connectivity.corridors can account for the importance of the corridors for the entire networkby reclassifying them with regards to network measures from r.connectivity.network.
+<br><br>
+Finally, all individual corridors are being put together using r.series. In this step the values of the cells in all corridor maps are summed up, which indicates the importance of an area (raster cell) for the network of the given patches (either the number of corridors a cell is part of, or other graph-theoretical measures for corridor importance).
+<br><br>
+!!!Corridors are only computed for an undirected graph.!!!
+<br><br>
+Output raster maps are named according to a user defined prefix and suffix.
+
+</dl>
+
+<h2>SEE ALSO</h2>
+<a href="r.connectivity.distance">r.connectivity.distance</a>, <a href="r.connectivity.network">r.connectivity.network</a><br>
+
+<h2>AUTHOR</h2>
+Stefan Blumentrath, Norwegian Institute for Nature Research (NINA)
+<br><br>
+<i>Last changed: $Date$</i>
+
+</body>
+</html>

Added: grass-addons/grass6/raster/r.connectivity.corridors/r.connectivity.corridors
===================================================================
--- grass-addons/grass6/raster/r.connectivity.corridors/r.connectivity.corridors	                        (rev 0)
+++ grass-addons/grass6/raster/r.connectivity.corridors/r.connectivity.corridors	2012-08-30 18:39:15 UTC (rev 52997)
@@ -0,0 +1,402 @@
+#!/bin/sh 
+# 
+############################################################################ 
+# 
+# MODULE:       r.connectivity.corridor 
+# AUTHOR(S):    Stefan Blumentrath <stefan dot blumentrath at nina dot no > 
+# PURPOSE:      Compute corridors between habitat patches of an input-layer 
+#               based on distance raster maps produced by r.connecivity.distance. 
+#               Corridor-importance can be evaluated based on results from 
+#               r.connectivity.network.
+#               
+#               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.distance 
+#               is intended to make graph-theory more easily available to conservation 
+#               planning.
+#
+#               r.connectivity.corridors is th 3rd tool of the r.connectivity.* toolchain.
+#
+#               r.connectivity.corridors loops through the attribute-table of 
+#               the edge- output vector map from r.connectivity.network and 
+#               computes the corridor for each edge of a user-defined set of 
+#               edges. r.connectivity.corridors can account for the importance 
+#               of the corridors for the entire networkby reclassifying them 
+#               with regards to network measures from r.connectivity.network.
+#
+#               Finally, all individual corridors are being put together 
+#               using r.series. In this step the values of the cells in all 
+#               corridor maps are summed up, which indicates the importance 
+#               of an area (raster cell) for the network of the given patches 
+#               (either the number of corridors a cell is part of, or other 
+#               graph-theoretical measures for corridor importance).
+#
+#               !!!Corridors are only computed for an undirected graph.!!!
+#
+#               Output raster maps are named according to a user defined 
+#               prefix and suffix.
+# 
+# COPYRIGHT:    (C) 2011 by the Norwegian Institute for Nature Research (NINA)
+# 
+#               This program is free software under the GNU General Public 
+#               License (>=v2). Read the file COPYING that comes with GRASS 
+#               for details. 
+# 
+############################################################################# 
+#
+# REQUIREMENTS:
+#
+#
+#%Module 
+#% description: Compute corridors between habitat patches of an input-layer based on (cost) distance raster maps
+#%End 
+#
+#%option 
+#% key: folder
+#% type: string 
+#% description: Folder where all (non map) output data from r.connectivity.* is stored 
+#% required : yes
+#%end 
+#
+#%option 
+#% key: suffix
+#% type: string 
+#% description: Output suffix for corridor summary result 
+#% required : yes
+#%end 
+#
+#%option 
+#% key: corridor_tolerance
+#% type: double
+#% description: Tolerance for deviation from (cost) distance within corridors (in %)
+#% required : no
+#% answer : 0.0
+#%end
+#
+#%Option
+#% key: where
+#% type: string
+#% required: no
+#% multiple: no
+#% key_desc: where (SQL statement)
+#% description: WHERE conditions of SQL statement without 'where' keyword. (example: cf_mst_ud = 1 or cf_eb_ud > 100)
+#%End
+#
+#%Option
+#% key: weights
+#% type: string
+#% required: no
+#% multiple: yes
+#% key_desc: Column names
+#% description: Column names separated by comma
+#%End
+#
+#%flag
+#% key: s
+#% description: Show edges selected by WHERE-clause and exit
+#%end
+#
+#%flag
+#% key: d
+#% description: Assign distance values to corridors instead of connection ids and weights
+#%end
+#
+#%flag
+#% key: r
+#% description: Recalculate already computed corridors (default is only weight and summarize already existing corridor maps) 
+#%end
+#
+#%option 
+#% key: cores
+#% type: integer
+#% description: Cores used for multithreading (1 means no multithreading)
+#% required : no
+#% answer : 1
+#%end
+#
+
+
+FOLDER="${GIS_OPT_FOLDER}"
+
+#
+#Check if script is started from within GRASS
+if [ -z "$GISBASE" ] ; then
+    echo "You must be in GRASS GIS to run this program." 1>&2
+    exit 1
+fi
+#
+# Pass evtl. command line arguments to gui and start it 
+if [ "$1" != "@ARGS_PARSED@" ] ; then
+    exec g.parser "$0" "$@"
+fi
+#Check if awk is installed
+if [ ! -x "`which awk`" ] ; then
+    g.message -e "awk is required, please install awk first" 
+    exit 1
+fi
+
+#set environment so that awk works properly in all languages
+unset LC_ALL 
+LC_NUMERIC=C 
+export LC_NUMERIC 
+
+#Check if input files and folder exist
+#Check if FOLDER (containing the necessary data of the r.connectivity.* tool-chain) exists
+if [ ! -d "$FOLDER" ] ; then
+    g.message -e "Cannot find folder ${FOLDER}."
+	exit 1
+fi
+
+#Check for log-file of the r.connectivity.* tool-chain
+if [ ! -r "${FOLDER}/r_connectivity.log" ] ; then 
+	g.message -e "r.connectivity.\* log-file could not be found or is not readable."
+	exit 1
+fi
+
+#Read variables from log-file
+. ${FOLDER}/r_connectivity.log
+
+#Parse remaining variables
+SUFFIX=${GIS_OPT_SUFFIX}
+CORRIDOR_TOLERANCE="${GIS_OPT_CORRIDOR_TOLERANCE}"
+CORES="${GIS_OPT_CORES}"
+WHERE="${GIS_OPT_WHERE}"
+WEIGHTS="${GIS_OPT_WEIGHTS}"
+S_FLAG=${GIS_FLAG_S}
+D_FLAG=${GIS_FLAG_D}
+R_FLAG=${GIS_FLAG_R}
+
+#Check if edge vector map exists
+eval `g.findfile element=vector file=${PREFIX}_edges`
+edges=$name
+if [ ! "$name" ] ; then
+    g.message -e "Cannot find vector map ${PREFIX}_edges." 
+    exit 1
+fi
+
+#
+#Check if db-connection for edge map exists
+con=$(v.db.connect -g -l map=$edges  2>/dev/null)
+if [ $(echo $con | wc -w) -eq 0 ] ; then
+	g.message -e "Database connection for map ${edges} is not defined."
+	exit 1
+fi
+
+#Check if required columns exist and are of required type
+if [ "$WEIGHTS" ] ; then
+	required_columns="con_id_u,from_p,to_p,cd_u,${WEIGHTS}"
+else
+	required_columns="con_id_u,from_p,to_p,cd_u"
+fi
+
+column_check=$(v.db.connect -c map="$edges")
+
+for rc in $(echo $required_columns | tr ',' ' ')
+do
+	column_name=$(echo $column_check | grep "$rc" | cut -f2 -d'|')
+	if [ ! "$column_name" ] ; then
+		g.message -e "Cannot find the reqired/requested column ${rc} in vector map ${edges}." 
+    exit 1
+	else
+		#######################################CHECK!!!
+		column_type=$(echo $column_check | grep "$rc" | cut -f1 -d'|')
+		if [ "$column_type" != "INTEGER" -a "$column_type" != "DOUBLE PRECISION" ] ; then
+			g.message -e "Column ${column_name} is of type ${column_type}. Only numeric types (integer or double precision) allowed!" 
+			exit 1
+		fi
+		#######################################
+	fi
+done
+
+
+#Extract necessary informartion on edges from attribute table of edge map
+if [ ! "$WHERE" ] ; then
+	table_extract=$(v.db.select -c map="$edges" columns="$required_columns" fs=',')
+else
+	select="v.db.select -c map=$edges columns=$required_columns where=\"$WHERE\" fs=',' 2>/dev/null"
+	table_extract=$(eval $select)
+	if [ $(echo "$table_extract" | wc -w) -le 0 ] ; then
+		g.message -e "No edges selected. Please check where-clause ${WHERE}!"
+		exit 1
+	fi
+fi
+
+#Get unique identifiers for the selected undirected edges
+selected_edges_ud=$(echo $table_extract | tr ' ' '\n' | cut -f1 -d',' | uniq)
+#echo $table_extract | tr ' ' '\n' | cut -f1 -d','
+
+#Output result of WHERE-clause and exit (if requested)
+if [ $S_FLAG -eq 1 ] ; then 
+	g.message -i "con_id_u|from_p|to_p"
+	for fid in $selected_edges_ud
+	do
+		message_text=$(echo $table_extract | tr ' ' '\n' | tr ',' ' ' | awk -v FID=$fid '{if($1==FID) print $1 "|" $2 "|" $3}' | head -n 1)
+		g.message -i "$message_text"
+	done
+	exit 0
+fi
+
+#Check if cost distance raster maps exist
+cd_map_patches=$(echo $table_extract | tr ' ' '\n' | cut -f2 -d',')
+cd_map_patches="${cd_map_patches} $(echo $table_extract | tr ' ' '\n' | cut -f3 -d',')"
+req_patches=$(echo $cd_map_patches | tr ' ' '\n' | sort -n | uniq)
+
+for p in $req_patches
+do
+	if [ $EUCL_DIST -eq 1 ] ; then
+		#Check if euclidean distance raster maps exist
+		eval `g.findfile element=cell file="${PREFIX}_patch_${p}_eucl_dist"`
+		if [ ! -r "$file" ] ; then
+			g.message -e "Cannot find raster map ${PREFIX}_patch_${p}_eucl_dist."
+			exit 1
+		fi
+	else
+		#Check if cost distance raster maps exist
+		eval `g.findfile element=cell file="${PREFIX}_patch_${p}_cost_dist"`
+		if [ ! -r "$file" ] ; then
+			g.message -e "Cannot find raster map ${PREFIX}_patch_${p}_cost_dist."
+			exit 1
+		fi
+	fi
+done
+
+if [ $EUCL_DIST -eq 1 ] ; then
+	if [ $D_FLAG -eq 1 ] ; then 
+		#Create mapcalculator expressions for euclidean distance corridors, assigning distance values
+		mc_expressions=
+		for fid in $selected_edges_ud
+		do
+			if [ $R_FLAG -ne 1 ] ; then
+				eval `g.findfile element=cell file="${PREFIX}_corridor_${fid}_eucl_dist"`
+				if [ -r "$file" ] ; then
+					continue
+				fi
+			fi
+			mc_expressions=${mc_expressions}\#$(echo $table_extract | tr ' ' '\n' | tr ',' ' ' | awk -v FID=$fid -v PREFIX=$PREFIX -v CORRIDOR_TOLERANCE=$CORRIDOR_TOLERANCE '{if($1==FID) print PREFIX "_corridor_" $1 "eucl_dist=if((" PREFIX "_patch_" $1 "_eucl_dist+" PREFIX "_patch_" $2 "_eucl_dist)-("(" PREFIX "_patch_" $1 "_eucl_dist+" PREFIX "_patch_" $2 "_eucl_dist)*" CORRIDOR_TOLERANCE "/100.0)<=(" PREFIX "_patch_" $1 "_eucl_dist+" PREFIX "_patch_" $2 "_eucl_dist)," $1 ",null())"}' | head -n 1)
+		done
+	else
+		#Create mapcalculator expressions for euclidean distance corridors, assigning connection IDs for reclassification
+		mc_expressions=
+		for fid in $selected_edges_ud
+		do
+			if [ $R_FLAG -ne 1 ] ; then
+				eval `g.findfile element=cell file="${PREFIX}_corridor_${fid}"`
+				if [ -r "$file" ] ; then
+					continue
+				fi
+			fi
+			mc_expressions=${mc_expressions}\#$(echo $table_extract | tr ' ' '\n' | tr ',' ' ' | awk -v FID=$fid -v PREFIX=$PREFIX -v CORRIDOR_TOLERANCE=$CORRIDOR_TOLERANCE '{if($1==FID) print PREFIX "_corridor_" $1 "=if((" PREFIX "_patch_" $1 "_eucl_dist+" PREFIX "_patch_" $2 "_eucl_dist)-("(" PREFIX "_patch_" $1 "_eucl_dist+" PREFIX "_patch_" $2 "_eucl_dist)*" CORRIDOR_TOLERANCE "/100.0)<=" $4 "," $1 ",null())"}' | head -n 1)
+		done
+	fi
+else
+	if [ $D_FLAG -eq 1 ] ; then 
+		#Create mapcalculator expressions for cost distance corridors, assigning distance values
+		mc_expressions=
+		for fid in $selected_edges_ud
+		do
+			if [ $R_FLAG -ne 1 ] ; then
+				eval `g.findfile element=cell file="${PREFIX}_corridor_${fid}_cost_dist"`
+				if [ -r "$file" ] ; then
+					continue
+				fi
+			fi
+			mc_expressions=${mc_expressions}\#$(echo $table_extract | tr ' ' '\n' | tr ',' ' ' | awk -v FID=$fid -v PREFIX=$PREFIX -v CORRIDOR_TOLERANCE=$CORRIDOR_TOLERANCE '{if($1==FID) print PREFIX "_corridor_" $1 "_cost_dist=if((" PREFIX "_patch_" $1 "_cost_dist+" PREFIX "_patch_" $2 "_cost_dist)-((" PREFIX "_patch_" $1 "_cost_dist+" PREFIX "_patch_" $2 "_cost_dist)*" CORRIDOR_TOLERANCE "/100.0)<=(" PREFIX "_patch_" $1 "_cost_dist+" PREFIX "_patch_" $2 "_cost_dist),(" PREFIX "_patch_" $1 "_cost_dist+" PREFIX "_patch_" $2 "_cost_dist),null())"}' | head -n 1)
+		done
+	else
+		#Create mapcalculator expressions for cost distance corridors, assigning connection IDs for reclassification
+		mc_expressions=
+		for fid in $selected_edges_ud
+		do
+			if [ $R_FLAG -ne 1 ] ; then
+				eval `g.findfile element=cell file="${PREFIX}_corridor_${fid}"`
+				if [ -r "$file" ] ; then
+					continue
+				fi
+			fi
+			mc_expressions=${mc_expressions}\#$(echo $table_extract | tr ' ' '\n' | tr ',' ' ' | awk -v FID=$fid -v PREFIX=$PREFIX -v CORRIDOR_TOLERANCE=$CORRIDOR_TOLERANCE '{if($1==FID) print PREFIX "_corridor_" $1 "=if((" PREFIX "_patch_" $2 "_cost_dist+" PREFIX "_patch_" $3 "_cost_dist)-((" PREFIX "_patch_" $2 "_cost_dist+" PREFIX "_patch_" $3 "_cost_dist)*" CORRIDOR_TOLERANCE "/100.0)<=" $4 "," $1 ",null())"}' | head -n 1)
+		done
+	fi
+fi
+
+###Calculate corridors
+if [ "$(echo $mc_expressions | sed 's/^.//')" ] ; then
+	if [ $(echo $mc_expressions | sed 's/^.//' | tr '#' '\n' | wc -w) -ge 1 ] ; then
+		if [ $CORES -gt 1 ] ; then
+			echo $mc_expressions | sed 's/^.//' | tr '#' '\n' | xargs -P $CORES -n 1 -i r.mapcalc {}
+		else
+			for mce in $(echo $mc_expressions | sed 's/^.//' | tr '#' '\n')
+			do
+				r.mapcalc "$mce"
+			done
+		fi
+	fi
+fi
+
+if [ $D_FLAG -eq 1 ] ; then
+	#Summarize corridors if distance values are assigned
+	if [ $EUCL_DIST -eq 1 ] ; then
+		corridor_list=$(echo $selected_edges_ud | tr ' ' '\n' | awk -v PREFIX=$PREFIX '{print PREFIX "_corridor_" $1 "eucl_dist"}' | tr '\n' ',' | sed 's/.$//')
+		r.series input=$corridor_list output=${PREFIX}_corridors_min_eucl_dist_${SUFFIX} method=minimum --overwrite
+	else
+		corridor_list=$(echo $selected_edges_ud | tr ' ' '\n' | awk -v PREFIX=$PREFIX '{print PREFIX "_corridor_" $1 "_cost_dist"}' | tr '\n' ',' | sed 's/.$//')
+		r.series input=$corridor_list output=${PREFIX}_corridors_min_cost_dist method=minimum --overwrite
+	fi
+else
+	#Summarize corridors
+	if [ ! "$WEIGHTS" ] ; then
+		corridor_list=$(echo $selected_edges_ud | tr ' ' '\n' | awk -v PREFIX=$PREFIX '{print PREFIX "_corridor_" $1}' | tr '\n' ',' | sed 's/.$//')
+		r.series input=$corridor_list output=${PREFIX}_corridors_count_${SUFFIX} method=count
+	else
+		#Weight corridors according to user requested weights
+		weights=$(echo $WEIGHTS | tr ',' ' ')
+		weight_position=5
+		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 ] ; then
+					#Create r.reclass-commands for xargs
+					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)
+					done
+					#Reclass maps using xargs
+					echo $r_reclass | sed 's/^.//' | tr '#' '\n' | xargs -P $CORES -n 1 -i echo {} | sh
+				else
+					#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
+					done
+				fi
+			else
+				 #For double or floating point columns
+				if [ $CORES -gt 1 ] ; then
+					#Create r.recode-commands for xargs
+					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)
+					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
+					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
+					done
+				fi
+			counter=$`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/.$//')
+			#Summarize corridors using r.series
+			r.series input=$corridor_list output=${PREFIX}_corridors_${w}_sum_${SUFFIX} method=sum
+		done
+	fi
+fi


Property changes on: grass-addons/grass6/raster/r.connectivity.corridors/r.connectivity.corridors
___________________________________________________________________
Added: svn:executable
   + *



More information about the grass-commit mailing list