PostGIS  2.3.7dev-r@@SVN_REVISION@@
static LWGEOM * lwcollection_split ( const LWCOLLECTION lwcoll_in,
const LWGEOM blade_in 
)
static

Definition at line 498 of file lwgeom_geos_split.c.

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().

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

Here is the call graph for this function:

Here is the caller graph for this function: