PostGIS  2.2.7dev-r@@SVN_REVISION@@
static LWGEOM* lwcollection_homogenize ( const LWCOLLECTION col)
static

Definition at line 103 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, and LWCOLLECTION::srid.

Referenced by lwgeom_homogenize().

104 {
105  int i;
106  int ntypes = 0;
107  int type = 0;
108  LWGEOM *outgeom = NULL;
109 
111 
112  /* Sort all the parts into a buffer */
113  init_homogenizebuffer(&buffer);
114  lwcollection_build_buffer(col, &buffer);
115 
116  /* Check for homogeneity */
117  for ( i = 0; i < NUMTYPES; i++ )
118  {
119  if ( buffer.cnt[i] > 0 )
120  {
121  ntypes++;
122  type = i;
123  }
124  }
125 
126  /* No types? Huh. Return empty. */
127  if ( ntypes == 0 )
128  {
129  LWCOLLECTION *outcol;
131  outgeom = lwcollection_as_lwgeom(outcol);
132  }
133  /* One type, return homogeneous collection */
134  else if ( ntypes == 1 )
135  {
136  LWCOLLECTION *outcol;
137  outcol = buffer.buf[type];
138  if ( outcol->ngeoms == 1 )
139  {
140  outgeom = outcol->geoms[0];
141  outcol->ngeoms=0; lwcollection_free(outcol);
142  }
143  else
144  {
145  outgeom = lwcollection_as_lwgeom(outcol);
146  }
147  outgeom->srid = col->srid;
148  }
149  /* Bah, more than out type, return anonymous collection */
150  else if ( ntypes > 1 )
151  {
152  int j;
153  LWCOLLECTION *outcol;
155  for ( j = 0; j < NUMTYPES; j++ )
156  {
157  if ( buffer.buf[j] )
158  {
159  LWCOLLECTION *bcol = buffer.buf[j];
160  if ( bcol->ngeoms == 1 )
161  {
162  lwcollection_add_lwgeom(outcol, bcol->geoms[0]);
163  bcol->ngeoms=0; lwcollection_free(bcol);
164  }
165  else
166  {
168  }
169  }
170  }
171  outgeom = lwcollection_as_lwgeom(outcol);
172  }
173 
174  return outgeom;
175 }
int cnt[NUMTYPES]
Definition: lwhomogenize.c:18
int32_t srid
Definition: liblwgeom.h:383
uint8_t flags
Definition: liblwgeom.h:488
static void init_homogenizebuffer(HomogenizeBuffer *buffer)
Definition: lwhomogenize.c:23
Datum buffer(PG_FUNCTION_ARGS)
LWGEOM ** geoms
Definition: liblwgeom.h:493
LWCOLLECTION * buf[NUMTYPES]
Definition: lwhomogenize.c:19
#define NUMTYPES
Definition: liblwgeom.h:86
int32_t srid
Definition: liblwgeom.h:490
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:124
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:125
void lwcollection_free(LWCOLLECTION *col)
Definition: lwcollection.c:326
static void lwcollection_build_buffer(const LWCOLLECTION *col, HomogenizeBuffer *buffer)
Definition: lwhomogenize.c:62
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int srid, char hasz, char hasm)
Definition: lwcollection.c:81
LWCOLLECTION * lwcollection_add_lwgeom(LWCOLLECTION *col, const LWGEOM *geom)
Appends geom to the collection managed by col.
Definition: lwcollection.c:174
#define COLLECTIONTYPE
Definition: liblwgeom.h:76
LWGEOM * lwcollection_as_lwgeom(const LWCOLLECTION *obj)
Definition: lwgeom.c:219

Here is the call graph for this function:

Here is the caller graph for this function: