PostGIS  2.5.0dev-r@@SVN_REVISION@@
static LWCOLLECTION * lwcollection_wrapx ( const LWCOLLECTION lwcoll_in,
double  cutx,
double  amount 
)
static

Definition at line 121 of file lwgeom_wrapx.c.

References COLLECTIONTYPE, LWCOLLECTION::geoms, lwalloc(), lwcollection_construct(), LWDEBUGF, lwerror(), lwfree(), lwgeom_free(), lwgeom_wrapx(), lwnotice(), MULTITYPE, LWCOLLECTION::ngeoms, LWCOLLECTION::srid, and LWCOLLECTION::type.

Referenced by lwgeom_split_wrapx(), and lwgeom_wrapx().

122 {
123  LWGEOM** wrap_geoms;
124  LWCOLLECTION* out;
125  uint32_t i;
126  int outtype = lwcoll_in->type;
127 
128  wrap_geoms = lwalloc(lwcoll_in->ngeoms * sizeof(LWGEOM*));
129  if ( ! wrap_geoms )
130  {
131  lwerror("Out of virtual memory");
132  return NULL;
133  }
134 
135  for (i=0; i<lwcoll_in->ngeoms; ++i)
136  {
137  LWDEBUGF(3, "Wrapping collection element %d", i);
138  wrap_geoms[i] = lwgeom_wrapx(lwcoll_in->geoms[i], cutx, amount);
139  /* an exception should prevent this from ever returning NULL */
140  if ( ! wrap_geoms[i] ) {
141  uint32_t j;
142  lwnotice("Error wrapping geometry, cleaning up");
143  for (j = 0; j < i; j++)
144  {
145  lwnotice("cleaning geometry %d (%p)", j, wrap_geoms[j]);
146  lwgeom_free(wrap_geoms[j]);
147  }
148  lwfree(wrap_geoms);
149  lwnotice("cleanup complete");
150  return NULL;
151  }
152  if ( outtype != COLLECTIONTYPE ) {
153  if ( MULTITYPE[wrap_geoms[i]->type] != outtype )
154  {
155  outtype = COLLECTIONTYPE;
156  }
157  }
158  }
159 
160  /* Now wrap_geoms has wrap_geoms_size geometries */
161  out = lwcollection_construct(outtype, lwcoll_in->srid, NULL,
162  lwcoll_in->ngeoms, wrap_geoms);
163 
164  return out;
165 }
LWCOLLECTION * lwcollection_construct(uint8_t type, int srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms)
Definition: lwcollection.c:43
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
Definition: lwutil.c:177
void lwfree(void *mem)
Definition: lwutil.c:244
uint8_t type
Definition: liblwgeom.h:502
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1137
uint32_t ngeoms
Definition: liblwgeom.h:506
unsigned int uint32_t
Definition: uthash.h:78
LWGEOM ** geoms
Definition: liblwgeom.h:508
LWGEOM * lwgeom_wrapx(const LWGEOM *lwgeom_in, double cutx, double amount)
wrap geometry on given cut x value
Definition: lwgeom_wrapx.c:169
int32_t srid
Definition: liblwgeom.h:505
uint8_t MULTITYPE[NUMTYPES]
Look-up for the correct MULTI* type promotion for singleton types.
Definition: lwgeom.c:344
void * lwalloc(size_t size)
Definition: lwutil.c:229
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
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: