Skip to content
Permalink
Browse files

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@11033 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
rugginoso
rugginoso committed Jul 9, 2009
1 parent 91e4a28 commit d6ebb464a1fcf3b9524e66389b8411234e8f51a5
@@ -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"/>
Binary file not shown.
@@ -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>
@@ -3022,6 +3022,11 @@ QgsGrassModuleFile::QgsGrassModuleFile(
{
mType = Multiple;
}

if ( qdesc.attribute( "type" ).toLower() == "directory")
{
mType = Directory;
}

if ( !qdesc.attribute( "filters" ).isNull() )
{
@@ -3092,6 +3097,10 @@ void QgsGrassModuleFile::browse()
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 );
@@ -816,7 +816,7 @@ class QgsGrassModuleFile: public QgsGrassModuleGroupBoxItem
~QgsGrassModuleFile();

//! File type
enum Type { Old, New, Multiple };
enum Type { Old, New, Multiple, Directory };

// Reimplemented methods from QgsGrassModuleOptions
QStringList options();
@@ -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()

0 comments on commit d6ebb46

Please sign in to comment.
You can’t perform that action at this time.