feature.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /* changes line 37 for Linux - Markus Neteler (Jan. 1998) */
  2. /*****************************************************************************/
  3. /*** ***/
  4. /*** feature() ***/
  5. /*** Returns a terrain feature based on the 6 quadratic coefficients ***/
  6. /*** that define a local trend surface. ***/
  7. /*** Jo Wood, Department of Geography, V2.1 30th March, 1995 ***/
  8. /*** ***/
  9. /*****************************************************************************/
  10. #include "param.h"
  11. #include <math.h>
  12. DCELL feature(double *coeff)
  13. { /* Set of six quadratic coefficients. */
  14. /* Quadratic function in the form of
  15. z = ax^2 + by^2 + cxy + dx + ey +f */
  16. double a = C_A * zscale, /* Scale parameters if necessary. */
  17. b = C_B * zscale,
  18. c = C_C * zscale, d = C_D * zscale, e = C_E * zscale;
  19. double maxic, minic, /* Minimium and maximum curvature. */
  20. slope, /* Slope. */
  21. crosc; /* Cross-sectional curvature. */
  22. minic = (-a - b - sqrt((a - b) * (a - b) + c * c));
  23. maxic = (-a - b + sqrt((a - b) * (a - b) + c * c));
  24. slope = RAD2DEG * atan(sqrt((d * d) + (e * e)));
  25. crosc = -2.0 * (b * d * d + a * e * e - c * d * e) / (d * d + e * e);
  26. /*
  27. Feature slope crosc maxic minic
  28. Peak 0 # +ve +ve
  29. Ridge 0 # +ve 0
  30. +ve +ve # #
  31. Pass 0 # +ve -ve
  32. Plane 0 # 0 0
  33. +ve 0 # #
  34. Channel 0 # 0 -ve
  35. +ve -ve # #
  36. Pit 0 # -ve -ve
  37. Table 5.3 Simplified feature classification criteria.
  38. # indicates undefined, or not part of selection criteria.
  39. http://www.geog.le.ac.uk/jwo/research/dem_char/thesis/05feat.htm
  40. */
  41. /* Case 1: Surface is sloping. Cannot be a peak,pass or pit. Therefore
  42. calculate the cross-sectional curvature to characterise as
  43. channel, ridge or planar. */
  44. if (slope > slope_tol) {
  45. if (crosc > curve_tol) {
  46. return (RIDGE);
  47. }
  48. else if (crosc < -curve_tol) {
  49. return (CHANNEL);
  50. }
  51. else {
  52. return (FLAT);
  53. }
  54. }
  55. else {
  56. /* Case 2: Surface has (approximately) vertical slope normal. Feature
  57. can be of any type. */
  58. if (maxic > curve_tol) {
  59. if (minic > curve_tol) {
  60. return (PEAK);
  61. }
  62. else if (minic < -curve_tol) {
  63. return (PASS);
  64. }
  65. else {
  66. return (RIDGE);
  67. }
  68. }
  69. else if (maxic < -curve_tol) {
  70. if (minic < -curve_tol) {
  71. return (PIT);
  72. }
  73. }
  74. else {
  75. if (minic < -curve_tol) {
  76. return (CHANNEL);
  77. }
  78. else if (minic > curve_tol && minic < -curve_tol) {
  79. return (FLAT);
  80. }
  81. }
  82. }
  83. return (FLAT);
  84. }