c_reclass.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*!
  2. \file cluster/c_reclass.c
  3. \brief Cluster library - Reclass data
  4. (C) 2001-2009 by the GRASS Development Team
  5. This program is free software under the GNU General Public License
  6. (>=v2). Read the file COPYING that comes with GRASS for details.
  7. \author Original author CERL
  8. */
  9. #include <grass/cluster.h>
  10. /*!
  11. \brief Reclass data
  12. \param C pointer to Cluster structure
  13. \param minsize minimum class size
  14. \return 0 on success
  15. \return 1 no change
  16. */
  17. int I_cluster_reclass(struct Cluster *C, int minsize)
  18. {
  19. int band, c, hole, move, p;
  20. for (c = 0; c < C->nclasses; c++)
  21. C->reclass[c] = c;
  22. /* find first `empty' class */
  23. for (hole = 0; hole < C->nclasses; hole++)
  24. if (C->count[hole] < minsize)
  25. break;
  26. /* if none, just return */
  27. if (hole >= C->nclasses)
  28. return 1;
  29. for (move = hole; move < C->nclasses; move++)
  30. if (C->count[move] >= minsize) {
  31. C->reclass[move] = hole;
  32. C->count[hole] = C->count[move];
  33. for (band = 0; band < C->nbands; band++)
  34. C->sum[band][hole] = C->sum[band][move];
  35. hole++;
  36. }
  37. else
  38. C->reclass[move] = -1; /* eliminate this class */
  39. for (p = 0; p < C->npoints; p++)
  40. C->class[p] = C->reclass[C->class[p]];
  41. C->nclasses = hole;
  42. return 0;
  43. }