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

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

397 {
398  LWGEOM** split_vector=NULL;
399  LWCOLLECTION* out;
400  size_t split_vector_capacity;
401  size_t split_vector_size=0;
402  size_t i,j;
403 
404  split_vector_capacity=8;
405  split_vector = lwalloc(split_vector_capacity * sizeof(LWGEOM*));
406  if ( ! split_vector )
407  {
408  lwerror("Out of virtual memory");
409  return NULL;
410  }
411 
412  for (i=0; i<lwcoll_in->ngeoms; ++i)
413  {
414  LWCOLLECTION* col;
415  LWGEOM* split = lwgeom_split(lwcoll_in->geoms[i], blade_in);
416  /* an exception should prevent this from ever returning NULL */
417  if ( ! split ) return NULL;
418 
419  col = lwgeom_as_lwcollection(split);
420  /* Output, if any, will always be a collection */
421  assert(col);
422 
423  /* Reallocate split_vector if needed */
424  if ( split_vector_size + col->ngeoms > split_vector_capacity )
425  {
426  /* NOTE: we could be smarter on reallocations here */
427  split_vector_capacity += col->ngeoms;
428  split_vector = lwrealloc(split_vector,
429  split_vector_capacity * sizeof(LWGEOM*));
430  if ( ! split_vector )
431  {
432  lwerror("Out of virtual memory");
433  return NULL;
434  }
435  }
436 
437  for (j=0; j<col->ngeoms; ++j)
438  {
439  col->geoms[j]->srid = SRID_UNKNOWN; /* strip srid */
440  split_vector[split_vector_size++] = col->geoms[j];
441  }
442  lwfree(col->geoms);
443  lwfree(col);
444  }
445 
446  /* Now split_vector has split_vector_size geometries */
447  out = lwcollection_construct(COLLECTIONTYPE, lwcoll_in->srid,
448  NULL, split_vector_size, split_vector);
449 
450  return (LWGEOM*)out;
451 }
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:190
int32_t srid
Definition: liblwgeom.h:355
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:67
LWGEOM ** geoms
Definition: liblwgeom.h:465
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:154
int32_t srid
Definition: liblwgeom.h:462
LWCOLLECTION * lwgeom_as_lwcollection(const LWGEOM *lwgeom)
Definition: lwgeom.c:143
void * lwrealloc(void *mem, size_t size)
Definition: lwutil.c:183
void * lwalloc(size_t size)
Definition: lwutil.c:175
#define COLLECTIONTYPE
Definition: liblwgeom.h:66

Here is the call graph for this function:

Here is the caller graph for this function: