PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ gserialized_list_union()

LWGEOM * gserialized_list_union ( List *  list,
float8  gridSize 
)
static

Definition at line 268 of file lwgeom_union.c.

269 {
270  int ngeoms = 0;
271  LWGEOM **geoms;
272  int32_t srid = SRID_UNKNOWN;
273  bool first = true;
274  int empty_type = 0;
275  int has_z = LW_FALSE;
276  ListCell *cell;
277 
278  if (list_length(list) == 0)
279  return NULL;
280 
281  geoms = lwalloc(list_length(list) * sizeof(LWGEOM*));
282  foreach (cell, list)
283  {
284  GSERIALIZED *gser;
285  LWGEOM *geom;
286 
287  gser = (GSERIALIZED*)lfirst(cell);
288  assert(gser);
289  geom = lwgeom_from_gserialized(gser);
290 
291  if (!lwgeom_is_empty(geom))
292  {
293  geoms[ngeoms++] = geom; /* no cloning */
294  if (first)
295  {
296  srid = lwgeom_get_srid(geom);
297  has_z = lwgeom_has_z(geom);
298  first = false;
299  }
300  }
301  else
302  {
303  int type = lwgeom_get_type(geom);
304  if (type > empty_type)
305  empty_type = type;
306  if (srid == SRID_UNKNOWN)
307  srid = lwgeom_get_srid(geom);
308  }
309  }
310 
311  if (ngeoms > 0)
312  {
313  /*
314  * Create a collection and pass it into cascaded union
315  */
316  LWCOLLECTION *col = lwcollection_construct(COLLECTIONTYPE, srid, NULL, ngeoms, geoms);
318  if (!result)
319  lwcollection_free(col);
320  return result;
321  }
322 
323  /*
324  * Only empty geometries in the list,
325  * create geometry with largest type number or return NULL
326  */
327  return (empty_type > 0)
328  ? lwgeom_construct_empty(empty_type, srid, has_z, 0)
329  : NULL;
330 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:262
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
Definition: gserialized.c:239
#define LW_FALSE
Definition: liblwgeom.h:94
LWGEOM * lwcollection_as_lwgeom(const LWCOLLECTION *obj)
Definition: lwgeom.c:309
#define COLLECTIONTYPE
Definition: liblwgeom.h:108
int32_t lwgeom_get_srid(const LWGEOM *geom)
Return SRID number.
Definition: lwgeom.c:927
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
Definition: lwgeom.c:934
LWGEOM * lwgeom_unaryunion_prec(const LWGEOM *geom1, double gridSize)
void lwcollection_free(LWCOLLECTION *col)
Definition: lwcollection.c:357
void * lwalloc(size_t size)
Definition: lwutil.c:227
LWCOLLECTION * lwcollection_construct(uint8_t type, int32_t srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms)
Definition: lwcollection.c:42
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:215
LWGEOM * lwgeom_construct_empty(uint8_t type, int32_t srid, char hasz, char hasm)
Definition: lwgeom.c:2105
static uint32_t lwgeom_get_type(const LWGEOM *geom)
Return LWTYPE number.
Definition: lwinline.h:145
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
Definition: lwinline.h:203
type
Definition: ovdump.py:42

References COLLECTIONTYPE, LW_FALSE, lwalloc(), lwcollection_as_lwgeom(), lwcollection_construct(), lwcollection_free(), lwgeom_construct_empty(), lwgeom_from_gserialized(), lwgeom_get_srid(), lwgeom_get_type(), lwgeom_has_z(), lwgeom_is_empty(), lwgeom_unaryunion_prec(), result, SRID_UNKNOWN, and ovdump::type.

Referenced by pgis_geometry_union_parallel_finalfn().

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