PostGIS  2.5.2dev-r@@SVN_REVISION@@

◆ lwcollection_homogenize()

static LWGEOM* lwcollection_homogenize ( const LWCOLLECTION col)
static

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

120 {
121  int i;
122  int ntypes = 0;
123  int type = 0;
124  LWGEOM *outgeom = NULL;
125 
127 
128  /* Sort all the parts into a buffer */
129  init_homogenizebuffer(&buffer);
130  lwcollection_build_buffer(col, &buffer);
131 
132  /* Check for homogeneity */
133  for ( i = 0; i < NUMTYPES; i++ )
134  {
135  if ( buffer.cnt[i] > 0 )
136  {
137  ntypes++;
138  type = i;
139  }
140  }
141 
142  /* No types? Huh. Return empty. */
143  if ( ntypes == 0 )
144  {
145  LWCOLLECTION *outcol;
147  outgeom = lwcollection_as_lwgeom(outcol);
148  }
149  /* One type, return homogeneous collection */
150  else if ( ntypes == 1 )
151  {
152  LWCOLLECTION *outcol;
153  outcol = buffer.buf[type];
154  if ( outcol->ngeoms == 1 )
155  {
156  outgeom = outcol->geoms[0];
157  outcol->ngeoms=0; lwcollection_free(outcol);
158  }
159  else
160  {
161  outgeom = lwcollection_as_lwgeom(outcol);
162  }
163  outgeom->srid = col->srid;
164  }
165  /* Bah, more than out type, return anonymous collection */
166  else if ( ntypes > 1 )
167  {
168  int j;
169  LWCOLLECTION *outcol;
171  for ( j = 0; j < NUMTYPES; j++ )
172  {
173  if ( buffer.buf[j] )
174  {
175  LWCOLLECTION *bcol = buffer.buf[j];
176  if ( bcol->ngeoms == 1 )
177  {
178  lwcollection_add_lwgeom(outcol, bcol->geoms[0]);
179  bcol->ngeoms=0; lwcollection_free(bcol);
180  }
181  else
182  {
184  }
185  }
186  }
187  outgeom = lwcollection_as_lwgeom(outcol);
188  }
189 
190  return outgeom;
191 }
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:300
Here is the call graph for this function:
Here is the caller graph for this function: