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

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

105 {
106  int i;
107  int ntypes = 0;
108  int type = 0;
109  LWGEOM *outgeom = NULL;
110 
112 
113  /* Sort all the parts into a buffer */
114  init_homogenizebuffer(&buffer);
115  lwcollection_build_buffer(col, &buffer);
116 
117  /* Check for homogeneity */
118  for ( i = 0; i < NUMTYPES; i++ )
119  {
120  if ( buffer.cnt[i] > 0 )
121  {
122  ntypes++;
123  type = i;
124  }
125  }
126 
127  /* No types? Huh. Return empty. */
128  if ( ntypes == 0 )
129  {
130  LWCOLLECTION *outcol;
132  outgeom = lwcollection_as_lwgeom(outcol);
133  }
134  /* One type, return homogeneous collection */
135  else if ( ntypes == 1 )
136  {
137  LWCOLLECTION *outcol;
138  outcol = buffer.buf[type];
139  if ( outcol->ngeoms == 1 )
140  {
141  outgeom = outcol->geoms[0];
142  outcol->ngeoms=0; lwcollection_free(outcol);
143  }
144  else
145  {
146  outgeom = lwcollection_as_lwgeom(outcol);
147  }
148  outgeom->srid = col->srid;
149  }
150  /* Bah, more than out type, return anonymous collection */
151  else if ( ntypes > 1 )
152  {
153  int j;
154  LWCOLLECTION *outcol;
156  for ( j = 0; j < NUMTYPES; j++ )
157  {
158  if ( buffer.buf[j] )
159  {
160  LWCOLLECTION *bcol = buffer.buf[j];
161  if ( bcol->ngeoms == 1 )
162  {
163  lwcollection_add_lwgeom(outcol, bcol->geoms[0]);
164  bcol->ngeoms=0; lwcollection_free(bcol);
165  }
166  else
167  {
169  }
170  }
171  }
172  outgeom = lwcollection_as_lwgeom(outcol);
173  }
174 
175  return outgeom;
176 }
int cnt[NUMTYPES]
Definition: lwhomogenize.c:19
int32_t srid
Definition: liblwgeom.h:355
uint8_t flags
Definition: liblwgeom.h:460
static void init_homogenizebuffer(HomogenizeBuffer *buffer)
Definition: lwhomogenize.c:24
Datum buffer(PG_FUNCTION_ARGS)
LWGEOM ** geoms
Definition: liblwgeom.h:465
LWCOLLECTION * buf[NUMTYPES]
Definition: lwhomogenize.c:20
#define NUMTYPES
Definition: liblwgeom.h:76
int32_t srid
Definition: liblwgeom.h:462
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:106
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:107
void lwcollection_free(LWCOLLECTION *col)
Definition: lwcollection.c:316
static void lwcollection_build_buffer(const LWCOLLECTION *col, HomogenizeBuffer *buffer)
Definition: lwhomogenize.c:63
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:66
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: