PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ lwcollection_split()

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

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

512 {
513  LWGEOM** split_vector=NULL;
514  LWCOLLECTION* out;
515  size_t split_vector_capacity;
516  size_t split_vector_size=0;
517  size_t i,j;
518 
519  split_vector_capacity=8;
520  split_vector = lwalloc(split_vector_capacity * sizeof(LWGEOM*));
521  if ( ! split_vector )
522  {
523  lwerror("Out of virtual memory");
524  return NULL;
525  }
526 
527  for (i=0; i<lwcoll_in->ngeoms; ++i)
528  {
529  LWCOLLECTION* col;
530  LWGEOM* split = lwgeom_split(lwcoll_in->geoms[i], blade_in);
531  /* an exception should prevent this from ever returning NULL */
532  if ( ! split ) return NULL;
533 
534  col = lwgeom_as_lwcollection(split);
535  /* Output, if any, will always be a collection */
536  assert(col);
537 
538  /* Reallocate split_vector if needed */
539  if ( split_vector_size + col->ngeoms > split_vector_capacity )
540  {
541  /* NOTE: we could be smarter on reallocations here */
542  split_vector_capacity += col->ngeoms;
543  split_vector = lwrealloc(split_vector,
544  split_vector_capacity * sizeof(LWGEOM*));
545  if ( ! split_vector )
546  {
547  lwerror("Out of virtual memory");
548  return NULL;
549  }
550  }
551 
552  for (j=0; j<col->ngeoms; ++j)
553  {
554  col->geoms[j]->srid = SRID_UNKNOWN; /* strip srid */
555  split_vector[split_vector_size++] = col->geoms[j];
556  }
557  lwfree(col->geoms);
558  lwfree(col);
559  }
560 
561  /* Now split_vector has split_vector_size geometries */
562  out = lwcollection_construct(COLLECTIONTYPE, lwcoll_in->srid,
563  NULL, split_vector_size, split_vector);
564 
565  return (LWGEOM*)out;
566 }
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:30
void lwfree(void *mem)
Definition: lwutil.c:214
int32_t srid
Definition: liblwgeom.h:383
LWGEOM ** geoms
Definition: liblwgeom.h:493
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:172
int32_t srid
Definition: liblwgeom.h:490
LWCOLLECTION * lwgeom_as_lwcollection(const LWGEOM *lwgeom)
Definition: lwgeom.c:143
void * lwrealloc(void *mem, size_t size)
Definition: lwutil.c:207
void * lwalloc(size_t size)
Definition: lwutil.c:199
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:74
#define COLLECTIONTYPE
Definition: liblwgeom.h:76
Here is the call graph for this function:
Here is the caller graph for this function: