setup_trans.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. ****************************************************************************
  3. *
  4. * MODULE: v.transform
  5. * AUTHOR(S): See other files as well...
  6. * Eric G. Miller <egm2@jps.net>
  7. * PURPOSE: To transform a vector layer's coordinates via a set of tie
  8. * points.
  9. * COPYRIGHT: (C) 2002 by the GRASS Development Team
  10. *
  11. * This program is free software under the GNU General Public
  12. * License (>=v2). Read the file COPYING that comes with GRASS
  13. * for details.
  14. *
  15. *****************************************************************************/
  16. /*
  17. * Functions in this file:
  18. * setup_transform ( n_points)
  19. * returns: ALL_OK, POINTS_NOT_SPREAD, NEED_MORE_POINTS
  20. * init_transform_arrays()
  21. * print_transform_error(stat)
  22. *
  23. * Written by the GRASS Team, 02/16/90, -mh .
  24. */
  25. #include <stdlib.h>
  26. #include <stdio.h>
  27. #include <grass/glocale.h>
  28. #include <grass/gis.h>
  29. #include "trans.h"
  30. int setup_transform(int n_points)
  31. {
  32. int status;
  33. /* compute_transformation_coef() returns:
  34. * -2, Not enough points
  35. * 1, everything is okay
  36. * -1, points weren't spread out enough
  37. */
  38. /* if there are enough points registered compute residuals */
  39. if (n_points >= MIN_COOR)
  40. status = compute_transformation_coef(ax, ay, bx, by, use, MAX_COOR);
  41. else
  42. return (NEED_MORE_POINTS);
  43. if (status != ALL_OK)
  44. return (POINTS_NOT_SPREAD);
  45. residuals_a_predicts_b(ax, ay, bx, by, use, MAX_COOR, residuals, &rms);
  46. return (ALL_OK);
  47. } /* setup_transform() */
  48. int init_transform_arrays(void)
  49. {
  50. int i;
  51. /* initiliaze use[], no points valid */
  52. for (i = 0; i < MAX_COOR; ++i) {
  53. *(use + i) = 0;
  54. *(bx + i) = 0;
  55. *(by + i) = 0;
  56. *(residuals + i) = 0;
  57. }
  58. reg_cnt = 0;
  59. return 0;
  60. }
  61. int print_transform_error(int stat)
  62. {
  63. switch (stat) {
  64. case POINTS_NOT_SPREAD:
  65. G_fatal_error(_("The points weren't spread out enough."));
  66. break;
  67. case NEED_MORE_POINTS:
  68. G_fatal_error(_("You need to enter at least %d points."), MIN_COOR);
  69. break;
  70. default:
  71. G_fatal_error("Your calling print_transform_error() with no error.");
  72. break;
  73. }
  74. return 0;
  75. }