r.plane.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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,2008 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. #%module
  19. #% description: Creates raster plane map given dip (inclination), aspect (azimuth) and one point.
  20. #% keywords: raster
  21. #% keywords: elevation
  22. #%end
  23. #%option G_OPT_R_OUTPUT
  24. #%end
  25. #%option
  26. #% key: dip
  27. #% type: double
  28. #% gisprompt: -90-90
  29. #% answer: 0.0
  30. #% description: Dip of plane in degrees
  31. #% required : yes
  32. #%end
  33. #%option
  34. #% key: azimuth
  35. #% type: double
  36. #% gisprompt: 0-360
  37. #% answer: 0.0
  38. #% description: Azimuth of the plane in degrees
  39. #% required : yes
  40. #%end
  41. #%option
  42. #% key: easting
  43. #% type: double
  44. #% description: Easting coordinate of a point on the plane
  45. #% required : yes
  46. #%end
  47. #%option
  48. #% key: northing
  49. #% type: double
  50. #% description: Northing coordinate of a point on the plane
  51. #% required : yes
  52. #%end
  53. #%option
  54. #% key: elevation
  55. #% type: double
  56. #% description: Elevation coordinate of a point on the plane
  57. #% required : yes
  58. #%end
  59. #%option
  60. #% key: type
  61. #% type: string
  62. #% options: int,float,double
  63. #% description: Type of the raster map to be created
  64. #% required : yes
  65. #%end
  66. import sys
  67. import os
  68. import math
  69. import string
  70. import grass.script as grass
  71. def main():
  72. name = options['name']
  73. type = options['type']
  74. dip = float(options['dip'])
  75. az = float(options['azimuth'])
  76. ea = float(options['easting'])
  77. no = float(options['northing'])
  78. el = float(options['elevation'])
  79. reg = grass.region()
  80. ### test input values ###
  81. if abs(dip) >= 90:
  82. grass.fatal(_("dip must be between -90 and 90."))
  83. if az < 0 or az >= 360:
  84. grass.fatal(_("azimuth must be between 0 and 360"))
  85. ### now the actual algorithm
  86. az_r = math.radians(-az)
  87. sinaz = math.sin(az_r)
  88. cosaz = math.cos(az_r)
  89. dip_r = math.radians(-dip)
  90. tandip = math.tan(dip_r)
  91. kx = sinaz * tandip
  92. ky = cosaz * tandip
  93. kz = el - ea * sinaz * tandip - no * cosaz * tandip
  94. if type == "int":
  95. round = "round"
  96. else:
  97. round = ""
  98. grass.mapcalc("$name = $type($round(x() * $kx + y() * $ky + $kz))",
  99. name = name, type = type, round = round, kx = kx, ky = ky, kz = kz)
  100. grass.raster_history(name)
  101. grass.message(_("Done."))
  102. t = string.Template("Raster map <$name> generated by r.plane " +
  103. "at point $ea E, $no N, elevation $el with dip = $dip degrees and " +
  104. "aspect = $az degrees ccw from north.")
  105. grass.message(t.substitute(name = name, ea = ea, no = no, el = el, dip = dip, az = az))
  106. if __name__ == "__main__":
  107. options, flags = grass.parser()
  108. main()