Skip to content

Commit 4863504

Browse files
author
Médéric RIBREUX
committed
Add r.tile algorithm
1 parent 3db6035 commit 4863504

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
r.tile
2+
Splits a raster map into tiles
3+
Raster (r.*)
4+
ParameterRaster|input|Name of input raster map|False
5+
ParameterString|output|Output base name of rasters|None|False|False
6+
ParameterNumber|width|Width of tiles (columns)|1|None|1024|True
7+
ParameterNumber|height|Height of tiles (rows)|1|None|1024|True
8+
OutputDirectory|output_dir|Tiles Directory
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
***************************************************************************
5+
r_tile.py
6+
---------
7+
Date : February 2016
8+
Copyright : (C) 2016 by Médéric Ribreux
9+
Email : medspx at medspx dot fr
10+
***************************************************************************
11+
* *
12+
* This program is free software; you can redistribute it and/or modify *
13+
* it under the terms of the GNU General Public License as published by *
14+
* the Free Software Foundation; either version 2 of the License, or *
15+
* (at your option) any later version. *
16+
* *
17+
***************************************************************************
18+
"""
19+
20+
__author__ = 'Médéric Ribreux'
21+
__date__ = 'February 2016'
22+
__copyright__ = '(C) 2016, Médéric Ribreux'
23+
24+
# This will get replaced with a git SHA1 when you do a git archive
25+
26+
__revision__ = '$Format:%H$'
27+
28+
29+
def processCommand(alg):
30+
# Remove output for command
31+
output_dir = alg.getOutputFromName('output_dir')
32+
alg.removeOutputFromName('output_dir')
33+
alg.processCommand()
34+
alg.addOutput(output_dir)
35+
36+
37+
def processOutputs(alg):
38+
# All the named rasters should be extracted to output_dir
39+
basename = alg.getParameterValue('output')
40+
output_dir = alg.getOutputValue('output_dir')
41+
42+
# Get the list of rasters matching the basename
43+
commands = ["for r in $(g.list type=rast pattern='{}*'); do".format(basename)]
44+
commands.append(" r.out.gdal -t input=${{r}} output={}/${{r}}.tif createopt=\"TFW=YES,COMPRESS=LZW\"".format(output_dir))
45+
commands.append("done")
46+
alg.commands.extend(commands)

0 commit comments

Comments
 (0)