[GRASS-SVN] r72434 - in grass-addons/grass7/imagery: . i.signature.list

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Mar 20 12:00:45 PDT 2018


Author: lucadelu
Date: 2018-03-20 12:00:45 -0700 (Tue, 20 Mar 2018)
New Revision: 72434

Added:
   grass-addons/grass7/imagery/i.signature.list/
   grass-addons/grass7/imagery/i.signature.list/Makefile
   grass-addons/grass7/imagery/i.signature.list/i.signature.list.html
   grass-addons/grass7/imagery/i.signature.list/i.signature.list.py
Log:
i.signature.list: added module, see #3526

Added: grass-addons/grass7/imagery/i.signature.list/Makefile
===================================================================
--- grass-addons/grass7/imagery/i.signature.list/Makefile	                        (rev 0)
+++ grass-addons/grass7/imagery/i.signature.list/Makefile	2018-03-20 19:00:45 UTC (rev 72434)
@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../..
+
+PGM = i.signature.list
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script

Added: grass-addons/grass7/imagery/i.signature.list/i.signature.list.html
===================================================================
--- grass-addons/grass7/imagery/i.signature.list/i.signature.list.html	                        (rev 0)
+++ grass-addons/grass7/imagery/i.signature.list/i.signature.list.html	2018-03-20 19:00:45 UTC (rev 72434)
@@ -0,0 +1,12 @@
+<H2>DESCRIPTION</H2>
+<em>i.signature.list</em> list name of signature file for group and subgroup. If group and subgroup options are not set it will iterate over all groups and subgroups available
+
+<H2>EXAMPLE</H2>
+<div div="code"><pre>
+i.signature.list group=name subgroup=subname
+</pre></div>
+
+
+<H2>AUTHOR</H2>
+
+Luca Delucchi

Added: grass-addons/grass7/imagery/i.signature.list/i.signature.list.py
===================================================================
--- grass-addons/grass7/imagery/i.signature.list/i.signature.list.py	                        (rev 0)
+++ grass-addons/grass7/imagery/i.signature.list/i.signature.list.py	2018-03-20 19:00:45 UTC (rev 72434)
@@ -0,0 +1,91 @@
+#!/usr/bin/env python
+#
+############################################################################
+#
+# MODULE:	i.signature.list
+# AUTHOR(S):	Luca Delucchi
+#
+# PURPOSE:	List signature file for a group/subgroup
+# COPYRIGHT:	(C) 1997-2016 by the GRASS Development Team
+#
+#		This program is free software under the GNU General Public
+#		License (>=v2). Read the file COPYING that comes with GRASS
+#		for details.
+#
+#############################################################################
+
+
+#%flag
+#% key: g
+#% description: Return in shell script style, it require group and subgroup options
+#%end
+
+#%option G_OPT_I_GROUP
+#% description: Group to use for segmentation
+#% required : no
+#%end
+
+#%option G_OPT_I_SUBGROUP 
+#% description: Group to use for segmentation
+#% required : no
+#%end
+
+import os
+import sys
+import grass.script as grass
+
+def main():
+    group = options['group']
+    sub = options['subgroup']
+    flagg = flags['g']
+    
+    if flagg and not (group and sub):
+        grass.fatal(_("'g' flag requires group and subgroup options"))
+   
+    gisenv = grass.gisenv()
+    
+    path = os.path.join(
+            gisenv['GISDBASE'],
+            gisenv['LOCATION_NAME'])
+    
+    if group:
+        try:
+            name, mapset = group.split('@', 1)
+        except ValueError:
+            name = group
+            mapset = gisenv['MAPSET']
+        if not flagg:
+            print("Group: {}".format(name))
+        path = os.path.join(path, mapset, 'group', name)
+        if sub:
+            path = os.path.join(path, 'subgroup', sub)
+            if not flagg:
+                print("    Subgroup: {}".format(sub))
+            for sig in os.listdir(path):
+                if sig != 'REF':
+                    if flagg:
+                        print(sig)
+                    else:
+                        print("        {}".format(sig))
+        else:
+            path = os.path.join(path, 'subgroup')
+            for di in os.listdir(path):
+                for sig in os.listdir(os.path.join(path, di)):
+                    if sig != 'REF':
+                        print("        {}".format(sig))
+    else:
+        path = os.path.join(path, gisenv['MAPSET'], 'group')
+        for gr in os.listdir(path):
+            print("Group: {}".format(gr))
+            for di in os.listdir(os.path.join(path, gr, 'subgroup')):
+                print("    Subgroup: {}".format(di))
+                for sig in os.listdir(os.path.join(path, gr, 'subgroup', di)):
+                    if sig != 'REF':
+                        print("        {}".format(sig))
+                
+    return
+
+
+if __name__ == "__main__":
+    options, flags = grass.parser()
+    sys.exit(main())



More information about the grass-commit mailing list