PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ lwcollection_homogenize()

static LWGEOM* lwcollection_homogenize ( const LWCOLLECTION col)
static

Definition at line 117 of file lwhomogenize.c.

References HomogenizeBuffer::buf, buffer(), HomogenizeBuffer::cnt, COLLECTIONTYPE, LWCOLLECTION::flags, FLAGS_GET_M, FLAGS_GET_Z, LWCOLLECTION::geoms, init_homogenizebuffer(), lwcollection_add_lwgeom(), lwcollection_as_lwgeom(), lwcollection_build_buffer(), lwcollection_construct_empty(), lwcollection_free(), LWCOLLECTION::ngeoms, NUMTYPES, LWGEOM::srid, LWCOLLECTION::srid, and ovdump::type.

Referenced by lwgeom_homogenize().

118 {
119  int i;
120  int ntypes = 0;
121  int type = 0;
122  LWGEOM *outgeom = NULL;
123 
125 
126  /* Sort all the parts into a buffer */
127  init_homogenizebuffer(&buffer);
128  lwcollection_build_buffer(col, &buffer);
129 
130  /* Check for homogeneity */
131  for ( i = 0; i < NUMTYPES; i++ )
132  {
133  if ( buffer.cnt[i] > 0 )
134  {
135  ntypes++;
136  type = i;
137  }
138  }
139 
140  /* No types? Huh. Return empty. */
141  if ( ntypes == 0 )
142  {
143  LWCOLLECTION *outcol;
145  outgeom = lwcollection_as_lwgeom(outcol);
146  }
147  /* One type, return homogeneous collection */
148  else if ( ntypes == 1 )
149  {
150  LWCOLLECTION *outcol;
151  outcol = buffer.buf[type];
152  if ( outcol->ngeoms == 1 )
153  {
154  outgeom = outcol->geoms[0];
155  outcol->ngeoms=0; lwcollection_free(outcol);
156  }
157  else
158  {
159  outgeom = lwcollection_as_lwgeom(outcol);
160  }
161  outgeom->srid = col->srid;
162  }
163  /* Bah, more than out type, return anonymous collection */
164  else if ( ntypes > 1 )
165  {
166  int j;
167  LWCOLLECTION *outcol;
169  for ( j = 0; j < NUMTYPES; j++ )
170  {
171  if ( buffer.buf[j] )
172  {
173  LWCOLLECTION *bcol = buffer.buf[j];
174  if ( bcol->ngeoms == 1 )
175  {
176  lwcollection_add_lwgeom(outcol, bcol->geoms[0]);
177  bcol->ngeoms=0; lwcollection_free(bcol);
178  }
179  else
180  {
182  }
183  }
184  }
185  outgeom = lwcollection_as_lwgeom(outcol);
186  }
187 
188  return outgeom;
189 }
int cnt[NUMTYPES]
Definition: lwhomogenize.c:32
int32_t srid
Definition: liblwgeom.h:399
uint8_t flags
Definition: liblwgeom.h:504
static void init_homogenizebuffer(HomogenizeBuffer *buffer)
Definition: lwhomogenize.c:37
Datum buffer(PG_FUNCTION_ARGS)
LWGEOM ** geoms
Definition: liblwgeom.h:509
LWCOLLECTION * buf[NUMTYPES]
Definition: lwhomogenize.c:33
#define NUMTYPES
Definition: liblwgeom.h:101
int32_t srid
Definition: liblwgeom.h:506
#define FLAGS_GET_Z(flags)
Macros for manipulating the &#39;flags&#39; byte.
Definition: liblwgeom.h:140
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:141
type
Definition: ovdump.py:41
void lwcollection_free(LWCOLLECTION *col)
Definition: lwcollection.c:340
static void lwcollection_build_buffer(const LWCOLLECTION *col, HomogenizeBuffer *buffer)
Definition: lwhomogenize.c:76
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int srid, char hasz, char hasm)
Definition: lwcollection.c:94
LWCOLLECTION * lwcollection_add_lwgeom(LWCOLLECTION *col, const LWGEOM *geom)
Appends geom to the collection managed by col.
Definition: lwcollection.c:187
#define COLLECTIONTYPE
Definition: liblwgeom.h:91
LWGEOM * lwcollection_as_lwgeom(const LWCOLLECTION *obj)
Definition: lwgeom.c:268
Here is the call graph for this function:
Here is the caller graph for this function: