-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
committed
Jul 9, 2009
1 parent
91e4a28
commit d6ebb46
Showing
6 changed files
with
104 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
|