Skip to content

Commit f7791e7

Browse files
author
rugginoso
committedJul 9, 2009
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 git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@11033 c8812cc2-4d05-0410-92ff-de0c093fc19c

File tree

6 files changed

+104
-1
lines changed

6 files changed

+104
-1
lines changed
 

‎src/plugins/grass/modules-6.4/default.qgc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<grass name="r.in.aster"/>
2323
<grass name="r.external"/>
2424
<grass name="r.external.qgis"/>
25+
<grass name="qgis.r.external.all"/>
2526
</section>
2627
<section label="Import vector">
2728
<grass name="v.in.ogr.qgis"/>
Loading
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE qgisgrassmodule SYSTEM "http://mrcc.com/qgisgrassdatamodule.dtd">
3+
<qgisgrassmodule label="Link all GDAL supported raster files into a directory to binary raster map layers." module="qgis.r.external.all.py">
4+
<flag key="o"/>
5+
<flag key="e"/>
6+
<flag key="r"/>
7+
<file key="input" type="directory" />
8+
<option key="band"/>
9+
</qgisgrassmodule>

‎src/plugins/grass/qgsgrassmodule.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3022,6 +3022,11 @@ QgsGrassModuleFile::QgsGrassModuleFile(
30223022
{
30233023
mType = Multiple;
30243024
}
3025+
3026+
if ( qdesc.attribute( "type" ).toLower() == "directory")
3027+
{
3028+
mType = Directory;
3029+
}
30253030

30263031
if ( !qdesc.attribute( "filters" ).isNull() )
30273032
{
@@ -3092,6 +3097,10 @@ void QgsGrassModuleFile::browse()
30923097
fd->setFileMode( QFileDialog::ExistingFiles );
30933098
fd->setAcceptMode( QFileDialog::AcceptOpen );
30943099
break;
3100+
case Directory:
3101+
fd->setFileMode( QFileDialog::Directory );
3102+
fd->setAcceptMode( QFileDialog::AcceptOpen );
3103+
break;
30953104
default:
30963105
fd->setFileMode( QFileDialog::ExistingFile );
30973106
fd->setAcceptMode( QFileDialog::AcceptOpen );

‎src/plugins/grass/qgsgrassmodule.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ class QgsGrassModuleFile: public QgsGrassModuleGroupBoxItem
816816
~QgsGrassModuleFile();
817817

818818
//! File type
819-
enum Type { Old, New, Multiple };
819+
enum Type { Old, New, Multiple, Directory };
820820

821821
// Reimplemented methods from QgsGrassModuleOptions
822822
QStringList options();
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/usr/bin/env python
2+
3+
############################################################################
4+
#
5+
# MODULE: qgis.r.external.all.py
6+
# AUTHOR(S): Lorenzo Masini
7+
#
8+
# PURPOSE: Link all GDAL supported raster files into a directory
9+
# to binary raster map layers.
10+
# COPYRIGHT: (C) 2009 by Lorenzo Masini
11+
#
12+
# This program is free software under the GNU General Public
13+
# License (>=v2). Read the file COPYING that comes with GRASS
14+
# for details.
15+
#
16+
#############################################################################
17+
18+
#%Module
19+
#% description: Link all GDAL supported raster files into a directory to binary raster map layers.
20+
#% keywords: raster, import
21+
#%End
22+
23+
#%option
24+
#% key: input
25+
#% type: string
26+
#% gisprompt: input
27+
#% key_desc : name
28+
#% description: Directory containing raster files
29+
#% required : yes
30+
#%end
31+
32+
#%option
33+
#% key: band
34+
#% type: integer
35+
#% description: Band to select
36+
#% answer: 1
37+
#% required : no
38+
#%end
39+
40+
#%flag
41+
#% key: o
42+
#% description: Override projection (use location's projection)
43+
#%end
44+
45+
#%flag
46+
#% key: e
47+
#% description: Extend location extents based on new dataset
48+
#%end
49+
50+
#%flag
51+
#% key: r
52+
#% description: Recursively scan subdirectories
53+
54+
import sys
55+
import os
56+
try:
57+
from grass.script import core as grass
58+
except ImportError:
59+
import grass
60+
except:
61+
raise Exception ("Cannot find 'grass' Python module. Python is supported by GRASS from version >= 6.4" )
62+
63+
64+
def import_directory_of_rasters(directory, recursive):
65+
for dir, dirnames, filenames in os.walk(directory):
66+
for filename in filenames:
67+
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:
68+
grass.warning('Cannot import file' + filename)
69+
if not recursive:
70+
break
71+
for dirname in dirnames:
72+
import_directory_of_rasters(dirname, recursive)
73+
74+
def main():
75+
input = options['input']
76+
recursive = flags['r']
77+
78+
import_directory_of_rasters(input, recursive)
79+
80+
if __name__ == "__main__":
81+
options, flags = grass.parser()
82+
flags_string = "".join([k for k in flags.keys() if flags[k] and k != 'r'])
83+
main()
84+

0 commit comments

Comments
 (0)
Please sign in to comment.