[GRASS-SVN] r53912 - in grass-addons/grass6/raster: . r.to.drsa
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Nov 19 05:37:56 PST 2012
Author: gianluca
Date: 2012-11-19 05:37:56 -0800 (Mon, 19 Nov 2012)
New Revision: 53912
Added:
grass-addons/grass6/raster/r.to.drsa/
grass-addons/grass6/raster/r.to.drsa/Makefile
grass-addons/grass6/raster/r.to.drsa/description.html
grass-addons/grass6/raster/r.to.drsa/r.to.drsa.py
Log:
Added: grass-addons/grass6/raster/r.to.drsa/Makefile
===================================================================
--- grass-addons/grass6/raster/r.to.drsa/Makefile (rev 0)
+++ grass-addons/grass6/raster/r.to.drsa/Makefile 2012-11-19 13:37:56 UTC (rev 53912)
@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../..
+
+PGM = r.to.drsa
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script
Added: grass-addons/grass6/raster/r.to.drsa/description.html
===================================================================
--- grass-addons/grass6/raster/r.to.drsa/description.html (rev 0)
+++ grass-addons/grass6/raster/r.to.drsa/description.html 2012-11-19 13:37:56 UTC (rev 53912)
@@ -0,0 +1,35 @@
+<h2>DESCRIPTION</h2>
+
+The <em>r.ro.drsa</em> module will export raster maps as a *isf file
+readable in jMAF, JAMM or 4eMka2 sofware <a href="http://idss.cs.put.poznan.pl/">Laboratory of Intelligent Decision Support Systems - Poznan University.</a>
+<p>
+<em>(GRASS python Script)</em>
+
+<h2>NOTES</h2>
+
+
+<p>
+This module, as all GRASS raster modules, will export cells based on the
+current region settings. See the <em>g.region</em> module for details.
+
+
+<h2>TODO</h2>
+
+
+
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="r.roughset.html">r.roughset</a>,
+<a href="r.mcda.regime.html">r.mcda.regime</a>,
+<a href="r.mcda.fuzzy.html">r.mcda.fuzzy</a>
+<a href="r.mcda.electre.html">r.mcda.electre</a>,
+<a href="r.in.drsa.html">r.in.drsa</a>
+</em>
+
+<h2>AUTHORS</h2>
+Antonio Boggia - Gianluca Massei<br>
+Department of Economics and Appraisal - University of Perugia - Italy
+<p>
+<i>Last changed: $Date: 2012-09-12 22:32:08 +0200 (mer, 12 set 2012) $</i>
Added: grass-addons/grass6/raster/r.to.drsa/r.to.drsa.py
===================================================================
--- grass-addons/grass6/raster/r.to.drsa/r.to.drsa.py (rev 0)
+++ grass-addons/grass6/raster/r.to.drsa/r.to.drsa.py 2012-11-19 13:37:56 UTC (rev 53912)
@@ -0,0 +1,127 @@
+#!/usr/bin/env python
+############################################################################
+#
+# MODULE: r.to.drsa
+# AUTHOR: Gianluca Massei - Antonio Boggia
+# PURPOSE: Export criteria raster maps and decision raster map in a *.isf
+# file for dominance rough set approach analysis (DRSA)
+# Dominance Rough Set Analysis (e.g. 4eMka2,JAMM, jMAF).
+# COPYRIGHT: c) 2010 Gianluca Massei, Antonio Boggia and the GRASS
+# Development Team. This program is free software under the
+# GNU General PublicLicense (>=v2). Read the file COPYING
+# that comes with GRASS for details.
+#
+#############################################################################
+
+#%Module
+#% description: Export criteria raster maps and decision raster map in a *.isf file (e.g. 4eMka2, jMAF) for dominance rough set approach analysis
+#% keywords: raster, Dominance Rough Set Approach
+#% keywords: Multi Criteria Decision Analysis (MCDA)
+#%End
+#%option
+#% key: attributes
+#% type: string
+#% multiple: yes
+#% gisprompt: old,cell,raster
+#% key_desc: name
+#% description: Name of criteria raster maps
+#% required: yes
+#%end
+#%option
+#% key: preferences
+#% type: string
+#% key_desc: character
+#% description: gain,cost,none
+#% required: yes
+#%end
+#%option
+#% key: decision
+#% type: string
+#% gisprompt: old,cell,raster
+#% key_desc: name
+#% description: Name of decision raster map
+#% required: yes
+#%end
+#%option
+#% key: output
+#% type: string
+#% gisprompt: new_file,file,output
+#% key_desc: name
+#% description: Name for output file (*.isf file, Information System)
+#% answer:infosys.isf
+#% required: yes
+#%end
+
+
+import sys
+##from grass.script import core as grass
+import grass.script as grass
+
+def main():
+ attributes = options['attributes'].split(',')
+ preferences=options['preferences'].split(',')
+ decision=options['decision']
+ output = options['output']
+
+ gregion = grass.region()
+ nrows = gregion['rows']
+ ncols = gregion['cols']
+ ewres=int(gregion['ewres'])
+ nsres=int(gregion['nsres'])
+ print nrows, ncols, ewres,nsres
+
+ outf = file(output,"w")
+ outf.write("**ATTRIBUTES\n")
+ for i in range(len(attributes)):
+ outf.write("+ %s: (continuous)\n" % attributes[i])
+ outf.write("+ %s: [" % decision)
+ value=[]
+ value=grass.read_command("r.describe", flags = "1n", map = decision)
+ v=value.split()
+
+ for i in range(len(v)-1):
+ outf.write("%s, " % str(v[i]))
+ outf.write("%s]\n" % str(v[len(v)-1]))
+ outf.write("decision: %s\n" % decision)
+
+ outf.write("\n**PREFERENCES\n")
+ for i in range(len(attributes)):
+ if(preferences[i]==""):
+ preferences[i]="none"
+ outf.write("%s: %s\n" % (attributes[i], preferences[i]))
+ outf.write("%s: gain\n" % decision)
+
+
+ outf.write("\n**EXAMPLES\n")
+ examples=[]
+ MATRIX=[]
+ for i in range(len(attributes)):
+ grass.mapcalc("rast=if(isnull(${decision})==0,${attribute},null())",
+ rast="rast",
+ decision=decision,
+ attribute=attributes[i])
+ tmp=grass.read_command("r.stats", flags = "1n", nv="?", input = "rast")
+ example=tmp.split()
+ examples.append(example)
+ tmp=grass.read_command("r.stats", flags = "1n", nv="?", input = decision)
+ example=tmp.split()
+
+ examples.append(example)
+ MATRIX=map(list,zip(*examples))
+
+ MATRIX=[r for r in MATRIX if not '?' in r] #remove all rows with almost one "?"
+ MATRIX=[list(i) for i in set(tuple(j) for j in MATRIX)] #remove duplicate example
+
+ print "rows:%d - col:%d" %(len(MATRIX),len(MATRIX[0]))
+ for r in range(len(MATRIX)):
+ for c in range(len(MATRIX[0])):
+ outf.write("%s " % str(MATRIX[r][c]))
+ outf.write("\n")
+
+ outf.write("**END")
+ outf.close()
+
+
+if __name__ == "__main__":
+ options, flags = grass.parser()
+ sys.exit(main())
More information about the grass-commit
mailing list