xcoor.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #include <grass/gis.h>
  2. #include <grass/raster.h>
  3. #include "globals.h"
  4. #include "globals2.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. DCELL *res = args[0];
  15. DCELL x;
  16. int i;
  17. if (argc > 0)
  18. return E_ARG_HI;
  19. if (argt[0] != DCELL_TYPE)
  20. return E_RES_TYPE;
  21. x = Rast_col_to_easting(0.5, &current_region2);
  22. for (i = 0; i < columns; i++) {
  23. res[i] = x;
  24. x += current_region2.ew_res;
  25. }
  26. return 0;
  27. }
  28. int f_y(int argc, const int *argt, void **args)
  29. {
  30. DCELL *res = args[0];
  31. DCELL y;
  32. int i;
  33. if (argc > 0)
  34. return E_ARG_HI;
  35. if (argt[0] != DCELL_TYPE)
  36. return E_RES_TYPE;
  37. y = Rast_row_to_northing(current_row + 0.5, &current_region2);
  38. for (i = 0; i < columns; i++)
  39. res[i] = y;
  40. return 0;
  41. }
  42. int f_z(int argc, const int *argt, void **args)
  43. {
  44. DCELL *res = args[0];
  45. int i;
  46. if (argc > 0)
  47. return E_ARG_HI;
  48. if (argt[0] != DCELL_TYPE)
  49. return E_RES_TYPE;
  50. for (i = 0; i < columns; i++)
  51. SET_NULL_D(&res[i]);
  52. return 0;
  53. }