[QGIS Commit] r11033 - in trunk/qgis/src/plugins/grass: . modules-6.4 scripts

svn_qgis at osgeo.org svn_qgis at osgeo.org
Wed Jul 8 21:54:00 EDT 2009


Author: rugginoso
Date: 2009-07-08 21:53:59 -0400 (Wed, 08 Jul 2009)
New Revision: 11033

Added:
   trunk/qgis/src/plugins/grass/modules-6.4/qgis.r.external.all.1.png
   trunk/qgis/src/plugins/grass/modules-6.4/qgis.r.external.all.qgm
   trunk/qgis/src/plugins/grass/scripts/qgis.r.external.all.py
Modified:
   trunk/qgis/src/plugins/grass/modules-6.4/default.qgc
   trunk/qgis/src/plugins/grass/qgsgrassmodule.cpp
   trunk/qgis/src/plugins/grass/qgsgrassmodule.h
Log:
Fixed #1763:
* Added python script qgis.r.external.all.py
* Added module and icon file for qgis.r.external.all
* Changed the module parser to accept the 'directory' attribute to allow the directory selection


Modified: trunk/qgis/src/plugins/grass/modules-6.4/default.qgc
===================================================================
--- trunk/qgis/src/plugins/grass/modules-6.4/default.qgc	2009-07-08 11:30:44 UTC (rev 11032)
+++ trunk/qgis/src/plugins/grass/modules-6.4/default.qgc	2009-07-09 01:53:59 UTC (rev 11033)
@@ -22,6 +22,7 @@
 				<grass name="r.in.aster"/>
 				<grass name="r.external"/>
 				<grass name="r.external.qgis"/>
+				<grass name="qgis.r.external.all"/>
 			</section>
 			 <section label="Import vector">
                                 <grass name="v.in.ogr.qgis"/>

Added: trunk/qgis/src/plugins/grass/modules-6.4/qgis.r.external.all.1.png
===================================================================
(Binary files differ)


Property changes on: trunk/qgis/src/plugins/grass/modules-6.4/qgis.r.external.all.1.png
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Added: trunk/qgis/src/plugins/grass/modules-6.4/qgis.r.external.all.qgm
===================================================================
--- trunk/qgis/src/plugins/grass/modules-6.4/qgis.r.external.all.qgm	                        (rev 0)
+++ trunk/qgis/src/plugins/grass/modules-6.4/qgis.r.external.all.qgm	2009-07-09 01:53:59 UTC (rev 11033)
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE qgisgrassmodule SYSTEM "http://mrcc.com/qgisgrassdatamodule.dtd">
+<qgisgrassmodule label="Link all GDAL supported raster files into a directory to binary raster map layers." module="qgis.r.external.all.py">
+	<flag key="o"/>
+	<flag key="e"/>
+	<flag key="r"/>
+	<file key="input" type="directory" />
+	<option key="band"/>
+</qgisgrassmodule>

Modified: trunk/qgis/src/plugins/grass/qgsgrassmodule.cpp
===================================================================
--- trunk/qgis/src/plugins/grass/qgsgrassmodule.cpp	2009-07-08 11:30:44 UTC (rev 11032)
+++ trunk/qgis/src/plugins/grass/qgsgrassmodule.cpp	2009-07-09 01:53:59 UTC (rev 11033)
@@ -3022,6 +3022,11 @@
   {
     mType = Multiple;
   }
+  
+  if ( qdesc.attribute( "type" ).toLower() == "directory")
+  {
+    mType = Directory; 
+  }
 
   if ( !qdesc.attribute( "filters" ).isNull() )
   {
@@ -3092,6 +3097,10 @@
       fd->setFileMode( QFileDialog::ExistingFiles );
       fd->setAcceptMode( QFileDialog::AcceptOpen );
       break;
+    case Directory:
+      fd->setFileMode( QFileDialog::Directory );
+      fd->setAcceptMode( QFileDialog::AcceptOpen );
+      break;
     default:
       fd->setFileMode( QFileDialog::ExistingFile );
       fd->setAcceptMode( QFileDialog::AcceptOpen );

Modified: trunk/qgis/src/plugins/grass/qgsgrassmodule.h
===================================================================
--- trunk/qgis/src/plugins/grass/qgsgrassmodule.h	2009-07-08 11:30:44 UTC (rev 11032)
+++ trunk/qgis/src/plugins/grass/qgsgrassmodule.h	2009-07-09 01:53:59 UTC (rev 11033)
@@ -816,7 +816,7 @@
     ~QgsGrassModuleFile();
 
     //! File type
-    enum Type { Old, New, Multiple };
+    enum Type { Old, New, Multiple, Directory };
 
     // Reimplemented methods from QgsGrassModuleOptions
     QStringList options();

Added: trunk/qgis/src/plugins/grass/scripts/qgis.r.external.all.py
===================================================================
--- trunk/qgis/src/plugins/grass/scripts/qgis.r.external.all.py	                        (rev 0)
+++ trunk/qgis/src/plugins/grass/scripts/qgis.r.external.all.py	2009-07-09 01:53:59 UTC (rev 11033)
@@ -0,0 +1,84 @@
+#!/usr/bin/env python
+
+############################################################################
+#
+# MODULE:       qgis.r.external.all.py
+# AUTHOR(S):    Lorenzo Masini
+#
+# PURPOSE:      Link all GDAL supported raster files into a directory 
+#		to binary raster map layers.
+# COPYRIGHT:    (C) 2009 by Lorenzo Masini
+#
+#               This program is free software under the GNU General Public
+#               License (>=v2). Read the file COPYING that comes with GRASS
+#               for details.
+#
+#############################################################################
+
+#%Module
+#% description: Link all GDAL supported raster files into a directory to binary raster map layers.
+#% keywords: raster, import
+#%End
+
+#%option
+#% key: input
+#% type: string
+#% gisprompt: input
+#% key_desc : name
+#% description: Directory containing raster files
+#% required : yes
+#%end
+
+#%option
+#% key: band
+#% type: integer
+#% description: Band to select
+#% answer: 1
+#% required : no
+#%end
+
+#%flag
+#% key: o
+#% description: Override projection (use location's projection)
+#%end
+
+#%flag
+#% key: e
+#% description: Extend location extents based on new dataset
+#%end
+
+#%flag
+#% key: r
+#% description: Recursively scan subdirectories
+
+import sys
+import os
+try:
+    from grass.script import core as grass
+except ImportError:
+    import grass
+except:
+    raise Exception ("Cannot find 'grass' Python module. Python is supported by GRASS from version >= 6.4" )
+
+
+def import_directory_of_rasters(directory, recursive):
+    for dir, dirnames, filenames in os.walk(directory):
+	for filename in filenames:
+		if grass.run_command('r.external', flags=flags_string, input=os.path.join(dir, filename), band=options['band'], output=filename[:-4], title=filename[:-4]) != 0:
+			grass.warning('Cannot import file' + filename)
+	if not recursive:
+		break
+	for dirname in dirnames:
+		import_directory_of_rasters(dirname, recursive)
+
+def main():
+    input = options['input']
+    recursive = flags['r']
+	
+    import_directory_of_rasters(input, recursive)
+	 	
+if __name__ == "__main__":
+    options, flags = grass.parser()
+    flags_string = "".join([k for k in flags.keys() if flags[k] and k != 'r'])
+    main()
+


Property changes on: trunk/qgis/src/plugins/grass/scripts/qgis.r.external.all.py
___________________________________________________________________
Added: svn:executable
   + *



More information about the QGIS-commit mailing list