PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ lwcollection_homogenize()

static LWGEOM* lwcollection_homogenize ( const LWCOLLECTION col)
static

Definition at line 119 of file lwhomogenize.c.

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 */
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 }
LWGEOM * lwcollection_as_lwgeom(const LWCOLLECTION *obj)
Definition: lwgeom.c:300
#define COLLECTIONTYPE
Definition: liblwgeom.h:91
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int srid, char hasz, char hasm)
Definition: lwcollection.c:94
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:140
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:141
void lwcollection_free(LWCOLLECTION *col)
Definition: lwcollection.c:356
LWCOLLECTION * lwcollection_add_lwgeom(LWCOLLECTION *col, const LWGEOM *geom)
Appends geom to the collection managed by col.
Definition: lwcollection.c:187
#define NUMTYPES
Definition: liblwgeom.h:101
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:41
Datum buffer(PG_FUNCTION_ARGS)
uint32_t ngeoms
Definition: liblwgeom.h:510
uint8_t flags
Definition: liblwgeom.h:507
LWGEOM ** geoms
Definition: liblwgeom.h:512
int32_t srid
Definition: liblwgeom.h:509
int32_t srid
Definition: liblwgeom.h:402

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: