xcoor3.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #include <grass/gis.h>
  2. #include <grass/raster3d.h>
  3. #include "globals.h"
  4. #include "globals3.h"
  5. #include "expression.h"
  6. #include "func_proto.h"
  7. /**********************************************************************
  8. x() easting at center of column
  9. y() northing at center of row
  10. z() height at center of depth
  11. **********************************************************************/
  12. int f_x(int argc, const int *argt, void **args)
  13. {
  14. RASTER3D_Region *window = &current_region3;
  15. DCELL *res = args[0];
  16. DCELL x;
  17. int i;
  18. if (argc > 0)
  19. return E_ARG_HI;
  20. if (argt[0] != DCELL_TYPE)
  21. return E_RES_TYPE;
  22. x = window->west + 0.5 * window->ew_res;
  23. for (i = 0; i < columns; i++) {
  24. res[i] = x;
  25. x += window->ew_res;
  26. }
  27. return 0;
  28. }
  29. int f_y(int argc, const int *argt, void **args)
  30. {
  31. RASTER3D_Region *window = &current_region3;
  32. DCELL *res = args[0];
  33. DCELL y;
  34. int i;
  35. if (argc > 0)
  36. return E_ARG_HI;
  37. if (argt[0] != DCELL_TYPE)
  38. return E_RES_TYPE;
  39. y = window->north - (current_row + 0.5) * window->ns_res;
  40. for (i = 0; i < columns; i++)
  41. res[i] = y;
  42. return 0;
  43. }
  44. int f_z(int argc, const int *argt, void **args)
  45. {
  46. RASTER3D_Region *window = &current_region3;
  47. DCELL *res = args[0];
  48. DCELL z;
  49. int i;
  50. if (argc > 0)
  51. return E_ARG_HI;
  52. if (argt[0] != DCELL_TYPE)
  53. return E_RES_TYPE;
  54. z = window->bottom + ((current_depth) + 0.5) * window->tb_res;
  55. for (i = 0; i < columns; i++)
  56. res[i] = z;
  57. return 0;
  58. }