r.plane.py 3.3 KB

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