-
-
Notifications
You must be signed in to change notification settings - Fork 288
/
r.out.xyz.py
executable file
·69 lines (62 loc) · 1.93 KB
/
r.out.xyz.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python
############################################################################
#
# MODULE: r.out.xyz
# AUTHOR: M. Hamish Bowman, Dept. Marine Science, Otago University,
# New Zealand
# Converted to Python by Glynn Clements
# PURPOSE: Export a raster map as x,y,z values based on cell centers
# This is a simple wrapper script for "r.stats -1ng"
#
# COPYRIGHT: (c) 2006 Hamish Bowman, and the GRASS Development Team
# (c) 2008 Glynn Clements, and the GRASS Development Team
# This program is free software under the GNU General Public
# License (>=v2). Read the file COPYING that comes with GRASS
# for details.
#
#############################################################################
#%module
#% description: Exports a raster map to a text file as x,y,z values based on cell centers.
#% keyword: raster
#% keyword: export
#% keyword: ASCII
#% keyword: conversion
#%end
#%option G_OPT_R_INPUTS
#% multiple: yes
#%end
#%option G_OPT_F_OUTPUT
#% description: Name for output file (if omitted or "-" output to stdout)
#% required: no
#%end
#%option G_OPT_F_SEP
#%end
#%flag
#% key: i
#% description: Include no data values
#%end
import sys
from grass.script import core as grass
from grass.exceptions import CalledModuleError
def main():
# if no output filename, output to stdout
output = options['output']
donodata = flags['i']
if donodata:
statsflags="1g"
else:
statsflags="1gn"
parameters = dict(flags=statsflags,
input=options['input'],
separator=options['separator'])
if output:
parameters.update(output=output)
ret = 0
try:
grass.run_command("r.stats", **parameters)
except CalledModuleError:
ret = 1
sys.exit(ret)
if __name__ == "__main__":
options, flags = grass.parser()
main()