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