r.plane.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. ############################################################################
  4. #
  5. # MODULE: r.plane for GRASS 5.7; based on r.plane for GRASS 5
  6. # AUTHOR(S): 1994, Stefan Jäger, University of Heidelberg/USGS
  7. # updated to GRASS 5.7 by Michael Barton
  8. # Dec 2004: Alessandro Frigeri & Ivan Marchesini
  9. # Modified to produce floating and double values maps
  10. # Converted to Python by Glynn Clements
  11. # PURPOSE: Creates a raster plane map from user specified inclination and azimuth
  12. # COPYRIGHT: (C) 2004-2012 by the GRASS Development Team
  13. #
  14. # This program is free software under the GNU General Public
  15. # License (>=v2). Read the file COPYING that comes with GRASS
  16. # for details.
  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. import sys
  68. import os
  69. import math
  70. import string
  71. import grass.script as grass
  72. def main():
  73. name = options['output']
  74. type = options['type']
  75. dip = float(options['dip'])
  76. az = float(options['azimuth'])
  77. ea = float(options['easting'])
  78. no = float(options['northing'])
  79. el = float(options['elevation'])
  80. reg = grass.region()
  81. ### test input values ###
  82. if abs(dip) >= 90:
  83. grass.fatal(_("dip must be between -90 and 90."))
  84. if az < 0 or az >= 360:
  85. grass.fatal(_("azimuth must be between 0 and 360"))
  86. ### now the actual algorithm
  87. az_r = math.radians(-az)
  88. sinaz = math.sin(az_r)
  89. cosaz = math.cos(az_r)
  90. dip_r = math.radians(-dip)
  91. tandip = math.tan(dip_r)
  92. kx = sinaz * tandip
  93. ky = cosaz * tandip
  94. kz = el - ea * sinaz * tandip - no * cosaz * tandip
  95. if type == "CELL":
  96. round = "round"
  97. dtype = "int"
  98. elif type == "FCELL":
  99. round = ""
  100. dtype = "float"
  101. else:
  102. round = ""
  103. dtype = "double"
  104. grass.mapcalc("$name = $type($round(x() * $kx + y() * $ky + $kz))",
  105. name = name, type = dtype, round = round, kx = kx, ky = ky, kz = kz)
  106. grass.run_command('r.support', map = name, history = '')
  107. grass.raster_history(name)
  108. grass.message(_("Done."))
  109. t = string.Template("Raster map <$name> generated by r.plane " +
  110. "at point $ea E, $no N, elevation $el with dip = $dip degrees and " +
  111. "aspect = $az degrees ccw from north.")
  112. grass.message(t.substitute(name = name, ea = ea, no = no, el = el, dip = dip, az = az))
  113. if __name__ == "__main__":
  114. options, flags = grass.parser()
  115. main()