r.plane.py 3.3 KB

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