PostGIS  2.5.0beta1dev-r@@SVN_REVISION@@

◆ lwcollection_split()

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

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

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