[GRASS-SVN] r54819 - grass-addons/grass6/raster/r.mess
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Jan 30 07:43:36 PST 2013
Author: pvanbosgeo
Date: 2013-01-30 07:43:36 -0800 (Wed, 30 Jan 2013)
New Revision: 54819
Modified:
grass-addons/grass6/raster/r.mess/r.mess
Log:
Changed so script so if a raster reference layer is used as input, an existing MASK is respected (this was already the case if a vector reference layer was used).
Modified: grass-addons/grass6/raster/r.mess/r.mess
===================================================================
--- grass-addons/grass6/raster/r.mess/r.mess 2013-01-30 14:50:10 UTC (rev 54818)
+++ grass-addons/grass6/raster/r.mess/r.mess 2013-01-30 15:43:36 UTC (rev 54819)
@@ -1,5 +1,7 @@
#!/bin/sh
#
+set-x
+
########################################################################
#
# MODULE: r.mess
@@ -70,7 +72,7 @@
#%option
#% key: output
#% type: string
-#% gisprompt: new
+#% gisprompt: new,cell,raster
#% description: Root name of the output MESS data layers
#% key_desc: name
#% required: yes
@@ -278,9 +280,14 @@
# One option is to convert the floating layers to integer layers after
# multiplying first with a number equal to the reciprocal of the value
# given under the digits option
-
- system("g.remove -f rast=MASK") # should I backup possible existing MASK?
+ fft <- system("g.findfile --quiet element=cell file=MASK", ignore.stdout = TRUE)
+ if(fft==0){
+ rname <- paste("MASK",paste(sample(c(0:9, letters, LETTERS), 12, replace=TRUE), collapse=""), sep="_")
+ execGRASS("g.copy", rast=paste("MASK", rname, sep=","))
+ system("g.remove -f rast=MASK")
+ }
+
# make compatible for both v6.4 and 7
if(grassversion==7){
system(paste("r.mask raster=", vtl, sep=""))
@@ -312,6 +319,11 @@
tmp.rule <- tempfile(pattern = "file", tmpdir = tempdir(), fileext = ".rules")
write.table(xy2, file=tmp.rule, quote=F, row.names=F, col.names=F)
+ # Restore mask
+ if(fft==0){
+ execGRASS("g.rename", rast=paste(rname,"MASK", sep=","), intern=TRUE)
+ }
+
# Create the recode layer and calculate the IES
system(paste("r.recode input=", ipl[i], " output=", tml[i], " rules=", tmp.rule, sep=""))
system(paste("r.mapcalc '", opi[i], " = if(", tml[i], "==0, (float(", ipl[i], ")-", envmin, ")/(", envmax, "-", envmin, ") *100.0, if(", tml[i], "<=50, 2 * ", tml[i], ", if(", tml[i], "<100.0, 2 * (100.0- ", tml[i], "), (", envmax, "- float(", ipl[i], "))/(", envmax, "-", envmin, ") * 100.0)))'", sep=""))
More information about the grass-commit
mailing list