PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ lwcollection_split()

static LWGEOM * lwcollection_split ( const LWCOLLECTION lwcoll_in,
const LWGEOM blade_in 
)
static

Definition at line 489 of file lwgeom_geos_split.c.

490 {
491  LWGEOM** split_vector=NULL;
492  LWCOLLECTION* out;
493  size_t split_vector_capacity;
494  size_t split_vector_size=0;
495  size_t i,j;
496 
497  split_vector_capacity=8;
498  split_vector = lwalloc(split_vector_capacity * sizeof(LWGEOM*));
499  if ( ! split_vector )
500  {
501  lwerror("Out of virtual memory");
502  return NULL;
503  }
504 
505  for (i=0; i<lwcoll_in->ngeoms; ++i)
506  {
507  LWCOLLECTION* col;
508  LWGEOM* split = lwgeom_split(lwcoll_in->geoms[i], blade_in);
509  /* an exception should prevent this from ever returning NULL */
510  if ( ! split ) return NULL;
511 
512  col = lwgeom_as_lwcollection(split);
513  /* Output, if any, will always be a collection */
514  assert(col);
515 
516  /* Reallocate split_vector if needed */
517  if ( split_vector_size + col->ngeoms > split_vector_capacity )
518  {
519  /* NOTE: we could be smarter on reallocations here */
520  split_vector_capacity += col->ngeoms;
521  split_vector = lwrealloc(split_vector,
522  split_vector_capacity * sizeof(LWGEOM*));
523  if ( ! split_vector )
524  {
525  lwerror("Out of virtual memory");
526  return NULL;
527  }
528  }
529 
530  for (j=0; j<col->ngeoms; ++j)
531  {
532  col->geoms[j]->srid = SRID_UNKNOWN; /* strip srid */
533  split_vector[split_vector_size++] = col->geoms[j];
534  }
535  lwfree(col->geoms);
536  lwfree(col);
537  }
538 
539  /* Now split_vector has split_vector_size geometries */
540  out = lwcollection_construct(COLLECTIONTYPE, lwcoll_in->srid,
541  NULL, split_vector_size, split_vector);
542 
543  return (LWGEOM*)out;
544 }
#define COLLECTIONTYPE
Definition: liblwgeom.h:91
void * lwrealloc(void *mem, size_t size)
Definition: lwutil.c:237
void lwfree(void *mem)
Definition: lwutil.c:244
LWCOLLECTION * lwcollection_construct(uint8_t type, int srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms)
Definition: lwcollection.c:43
void * lwalloc(size_t size)
Definition: lwutil.c:229
LWCOLLECTION * lwgeom_as_lwcollection(const LWGEOM *lwgeom)
Definition: lwgeom.c:224
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:188
LWGEOM * lwgeom_split(const LWGEOM *lwgeom_in, const LWGEOM *blade_in)
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
uint32_t ngeoms
Definition: liblwgeom.h:510
LWGEOM ** geoms
Definition: liblwgeom.h:512
int32_t srid
Definition: liblwgeom.h:509
int32_t srid
Definition: liblwgeom.h:402

References COLLECTIONTYPE, LWCOLLECTION::geoms, lwalloc(), lwcollection_construct(), lwerror(), lwfree(), lwgeom_as_lwcollection(), lwgeom_split(), lwrealloc(), LWCOLLECTION::ngeoms, LWGEOM::srid, LWCOLLECTION::srid, and SRID_UNKNOWN.

Referenced by lwgeom_split().

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