~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to scripts/r.plane/r.plane.py

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
#
 
3
############################################################################
 
4
#
 
5
# MODULE:       r.plane for GRASS 5.7; based on r.plane for GRASS 5
 
6
# AUTHOR(S):    CERL?; updated to GRASS 5.7 by Michael Barton
 
7
#               Dec 2004: Alessandro Frigeri & Ivan Marchesini
 
8
#               Modified to produce floating and double values maps
 
9
#               Converted to Python by Glynn Clements
 
10
# PURPOSE:      Creates a raster plane map from user specified inclination and azimuth
 
11
# COPYRIGHT:    (C) 2004-2012 by the GRASS Development Team
 
12
#
 
13
#               This program is free software under the GNU General Public
 
14
#               License (>=v2). Read the file COPYING that comes with GRASS
 
15
#               for details.
 
16
#
 
17
#############################################################################
 
18
 
 
19
#%module
 
20
#% description: Creates raster plane map given dip (inclination), aspect (azimuth) and one point.
 
21
#% keyword: raster
 
22
#% keyword: elevation
 
23
#%end
 
24
#%option G_OPT_R_OUTPUT
 
25
#%end
 
26
#%option
 
27
#% key: dip
 
28
#% type: double
 
29
#% gisprompt: -90-90
 
30
#% answer: 0.0
 
31
#% description: Dip of plane in degrees
 
32
#% required : yes
 
33
#%end
 
34
#%option
 
35
#% key: azimuth
 
36
#% type: double
 
37
#% gisprompt: 0-360
 
38
#% answer: 0.0
 
39
#% description: Azimuth of the plane in degrees
 
40
#% required : yes
 
41
#%end
 
42
#%option
 
43
#% key: easting
 
44
#% type: double
 
45
#% description: Easting coordinate of a point on the plane
 
46
#% required : yes
 
47
#%end
 
48
#%option
 
49
#% key: northing
 
50
#% type: double
 
51
#% description: Northing coordinate of a point on the plane
 
52
#% required : yes
 
53
#%end
 
54
#%option
 
55
#% key: elevation
 
56
#% type: double
 
57
#% description: Elevation coordinate of a point on the plane
 
58
#% required : yes
 
59
#%end
 
60
#%option
 
61
#% key: type
 
62
#% type: string 
 
63
#% options: CELL,FCELL,DCELL
 
64
#% description: Type of raster map to be created
 
65
#% answer: FCELL
 
66
#%end
 
67
 
 
68
import sys
 
69
import os
 
70
import math
 
71
import string
 
72
import grass.script as grass
 
73
 
 
74
def main():
 
75
    name = options['output']
 
76
    type = options['type']
 
77
    dip = float(options['dip'])
 
78
    az  = float(options['azimuth'])
 
79
    ea  = float(options['easting'])
 
80
    no  = float(options['northing'])
 
81
    el  = float(options['elevation'])
 
82
 
 
83
    reg = grass.region()
 
84
 
 
85
    ### test input values ###
 
86
    if abs(dip) >= 90:
 
87
        grass.fatal(_("dip must be between -90 and 90."))
 
88
 
 
89
    if az < 0 or az >= 360:
 
90
        grass.fatal(_("azimuth must be between 0 and 360"))
 
91
 
 
92
    ### now the actual algorithm
 
93
    az_r  = math.radians(-az)
 
94
    sinaz = math.sin(az_r)
 
95
    cosaz = math.cos(az_r)
 
96
 
 
97
    dip_r = math.radians(-dip)
 
98
    tandip = math.tan(dip_r)
 
99
 
 
100
    kx = sinaz * tandip
 
101
    ky = cosaz * tandip
 
102
    kz = el - ea * sinaz * tandip - no * cosaz * tandip
 
103
 
 
104
    if type == "CELL":
 
105
        round = "round"
 
106
        dtype = "int"
 
107
    elif type == "FCELL":
 
108
        round = ""
 
109
        dtype = "float"
 
110
    else:
 
111
        round = ""
 
112
        dtype = "double"
 
113
 
 
114
    grass.mapcalc("$name = $type($round(x() * $kx + y() * $ky + $kz))",
 
115
                  name = name, type = dtype, round = round, kx = kx, ky = ky, kz = kz)
 
116
 
 
117
    grass.run_command('r.support', map = name, history = '')
 
118
    grass.raster_history(name)
 
119
 
 
120
    grass.message(_("Done."))
 
121
    t = string.Template("Raster map <$name> generated by r.plane " +
 
122
                        "at point $ea E, $no N, elevation $el with dip = $dip degrees and " +
 
123
                        "aspect = $az degrees ccw from north.")
 
124
    grass.message(t.substitute(name = name, ea = ea, no = no, el = el, dip = dip, az = az))
 
125
 
 
126
if __name__ == "__main__":
 
127
    options, flags = grass.parser()
 
128
    main()