PostGIS  3.0.0dev-r@@SVN_REVISION@@

◆ lwcollection_homogenize()

static LWGEOM* lwcollection_homogenize ( const LWCOLLECTION col)
static

Definition at line 116 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().

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 */
126  init_homogenizebuffer(&buffer);
127  lwcollection_build_buffer(col, &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 }
int cnt[NUMTYPES]
Definition: lwhomogenize.c:32
uint32_t ngeoms
Definition: liblwgeom.h:509
int32_t srid
Definition: liblwgeom.h:401
uint8_t flags
Definition: liblwgeom.h:506
static void init_homogenizebuffer(HomogenizeBuffer *buffer)
Definition: lwhomogenize.c:37
Datum buffer(PG_FUNCTION_ARGS)
LWGEOM ** geoms
Definition: liblwgeom.h:511
LWCOLLECTION * buf[NUMTYPES]
Definition: lwhomogenize.c:33
#define NUMTYPES
Definition: liblwgeom.h:100
int32_t srid
Definition: liblwgeom.h:508
#define FLAGS_GET_Z(flags)
Macros for manipulating the &#39;flags&#39; byte.
Definition: liblwgeom.h:139
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:140
type
Definition: ovdump.py:41
void lwcollection_free(LWCOLLECTION *col)
Definition: lwcollection.c:356
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:90
LWGEOM * lwcollection_as_lwgeom(const LWCOLLECTION *obj)
Definition: lwgeom.c:291
Here is the call graph for this function:
Here is the caller graph for this function: