r.plane.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. #%module
  19. #% description: Creates raster plane map given dip (inclination), aspect (azimuth) and one point.
  20. #% keyword: raster
  21. #% keyword: 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 G_OPT_R_TYPE
  60. #% answer: FCELL
  61. #% required: no
  62. #%end
  63. import math
  64. import string
  65. import grass.script as gscript
  66. def main():
  67. name = options['output']
  68. type = options['type']
  69. dip = float(options['dip'])
  70. az = float(options['azimuth'])
  71. ea = float(options['easting'])
  72. no = float(options['northing'])
  73. el = float(options['elevation'])
  74. # reg = gscript.region()
  75. ### test input values ###
  76. if abs(dip) >= 90:
  77. gscript.fatal(_("dip must be between -90 and 90."))
  78. if az < 0 or az >= 360:
  79. gscript.fatal(_("azimuth must be between 0 and 360"))
  80. # now the actual algorithm
  81. az_r = math.radians(-az)
  82. sinaz = math.sin(az_r)
  83. cosaz = math.cos(az_r)
  84. dip_r = math.radians(-dip)
  85. tandip = math.tan(dip_r)
  86. kx = sinaz * tandip
  87. ky = cosaz * tandip
  88. kz = el - ea * sinaz * tandip - no * cosaz * tandip
  89. if type == "CELL":
  90. round = "round"
  91. dtype = "int"
  92. elif type == "FCELL":
  93. round = ""
  94. dtype = "float"
  95. else:
  96. round = ""
  97. dtype = "double"
  98. gscript.mapcalc("$name = $type($round(x() * $kx + y() * $ky + $kz))",
  99. name=name, type=dtype, round=round, kx=kx, ky=ky, kz=kz)
  100. gscript.run_command('r.support', map=name, history='')
  101. gscript.raster_history(name)
  102. gscript.message(_("Done."))
  103. t = string.Template("Raster map <$name> generated by r.plane "
  104. "at point $ea E, $no N, elevation $el with dip = $dip"
  105. " degrees and aspect = $az degrees ccw from north.")
  106. gscript.message(t.substitute(name=name, ea=ea, no=no, el=el, dip=dip,
  107. az=az))
  108. if __name__ == "__main__":
  109. options, flags = gscript.parser()
  110. main()