PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ lwcollection_homogenize()

static LWGEOM* lwcollection_homogenize ( const LWCOLLECTION col)
static

Definition at line 116 of file lwhomogenize.c.

117 {
118  int i;
119  int ntypes = 0;
120  int type = 0;
121  LWGEOM *outgeom = NULL;
122 
124 
125  /* Sort all the parts into a buffer */
128 
129  /* Check for homogeneity */
130  for ( i = 0; i < NUMTYPES; i++ )
131  {
132  if ( buffer.cnt[i] > 0 )
133  {
134  ntypes++;
135  type = i;
136  }
137  }
138 
139  /* No types? Huh. Return empty. */
140  if ( ntypes == 0 )
141  {
142  LWCOLLECTION *outcol;
144  outgeom = lwcollection_as_lwgeom(outcol);
145  }
146  /* One type, return homogeneous collection */
147  else if ( ntypes == 1 )
148  {
149  LWCOLLECTION *outcol;
150  outcol = buffer.buf[type];
151  if ( outcol->ngeoms == 1 )
152  {
153  outgeom = outcol->geoms[0];
154  outcol->ngeoms=0; lwcollection_free(outcol);
155  }
156  else
157  {
158  outgeom = lwcollection_as_lwgeom(outcol);
159  }
160  outgeom->srid = col->srid;
161  }
162  /* Bah, more than out type, return anonymous collection */
163  else if ( ntypes > 1 )
164  {
165  int j;
166  LWCOLLECTION *outcol;
168  for ( j = 0; j < NUMTYPES; j++ )
169  {
170  if ( buffer.buf[j] )
171  {
172  LWCOLLECTION *bcol = buffer.buf[j];
173  if ( bcol->ngeoms == 1 )
174  {
175  lwcollection_add_lwgeom(outcol, bcol->geoms[0]);
176  bcol->ngeoms=0; lwcollection_free(bcol);
177  }
178  else
179  {
181  }
182  }
183  }
184  outgeom = lwcollection_as_lwgeom(outcol);
185  }
186 
187  return outgeom;
188 }
LWGEOM * lwcollection_as_lwgeom(const LWCOLLECTION *obj)
Definition: lwgeom.c:291
#define COLLECTIONTYPE
Definition: liblwgeom.h:122
#define FLAGS_GET_Z(flags)
Definition: liblwgeom.h:179
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int32_t srid, char hasz, char hasm)
Definition: lwcollection.c:92
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:180
void lwcollection_free(LWCOLLECTION *col)
Definition: lwcollection.c:357
LWCOLLECTION * lwcollection_add_lwgeom(LWCOLLECTION *col, const LWGEOM *geom)
Appends geom to the collection managed by col.
Definition: lwcollection.c:188
#define NUMTYPES
Definition: liblwgeom.h:132
static void lwcollection_build_buffer(const LWCOLLECTION *col, HomogenizeBuffer *buffer)
Definition: lwhomogenize.c:76
static void init_homogenizebuffer(HomogenizeBuffer *buffer)
Definition: lwhomogenize.c:37
type
Definition: ovdump.py:42
Datum buffer(PG_FUNCTION_ARGS)
lwflags_t flags
Definition: liblwgeom.h:563
uint32_t ngeoms
Definition: liblwgeom.h:566
LWGEOM ** geoms
Definition: liblwgeom.h:561
int32_t srid
Definition: liblwgeom.h:562
int32_t srid
Definition: liblwgeom.h:446

References buffer(), 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().

Here is the call graph for this function:
Here is the caller graph for this function: