PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ lwcollection_homogenize()

static LWGEOM * lwcollection_homogenize ( const LWCOLLECTION col)
static

Definition at line 116 of file lwhomogenize.c.

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 */
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}
#define COLLECTIONTYPE
Definition liblwgeom.h:108
#define FLAGS_GET_Z(flags)
Definition liblwgeom.h:165
#define FLAGS_GET_M(flags)
Definition liblwgeom.h:166
void lwcollection_free(LWCOLLECTION *col)
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int32_t srid, char hasz, char hasm)
LWCOLLECTION * lwcollection_add_lwgeom(LWCOLLECTION *col, const LWGEOM *geom)
Appends geom to the collection managed by col.
#define NUMTYPES
Definition liblwgeom.h:118
LWGEOM * lwcollection_as_lwgeom(const LWCOLLECTION *obj)
Definition lwgeom.c:337
static void lwcollection_build_buffer(const LWCOLLECTION *col, HomogenizeBuffer *buffer)
static void init_homogenizebuffer(HomogenizeBuffer *buffer)
Datum buffer(PG_FUNCTION_ARGS)
#define ntypes
lwflags_t flags
Definition liblwgeom.h:577
uint32_t ngeoms
Definition liblwgeom.h:580
LWGEOM ** geoms
Definition liblwgeom.h:575
int32_t srid
Definition liblwgeom.h:576
int32_t srid
Definition liblwgeom.h:460

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, ntypes, NUMTYPES, LWGEOM::srid, and LWCOLLECTION::srid.

Referenced by lwgeom_homogenize().

Here is the call graph for this function:
Here is the caller graph for this function: