PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ lwpoly_make_geos_friendly()

LWGEOM * lwpoly_make_geos_friendly ( LWPOLY poly)

Definition at line 239 of file liblwgeom/lwgeom_geos_clean.c.

References lwalloc(), LWDEBUGF, lwfree(), POINTARRAY::npoints, LWPOLY::nrings, ptarray_free(), ring_make_geos_friendly(), and LWPOLY::rings.

Referenced by LWGEOM_GEOS_getPointN(), and lwgeom_make_geos_friendly().

240 {
241  LWGEOM* ret;
242  POINTARRAY **new_rings;
243  int i;
244 
245  /* If the polygon has no rings there's nothing to do */
246  if ( ! poly->nrings ) return (LWGEOM*)poly;
247 
248  /* Allocate enough pointers for all rings */
249  new_rings = lwalloc(sizeof(POINTARRAY*)*poly->nrings);
250 
251  /* All rings must be closed and have > 3 points */
252  for (i=0; i<poly->nrings; i++)
253  {
254  POINTARRAY* ring_in = poly->rings[i];
255  POINTARRAY* ring_out = ring_make_geos_friendly(ring_in);
256 
257  if ( ring_in != ring_out )
258  {
259  LWDEBUGF(3, "lwpoly_make_geos_friendly: ring %d cleaned, now has %d points", i, ring_out->npoints);
260  ptarray_free(ring_in);
261  }
262  else
263  {
264  LWDEBUGF(3, "lwpoly_make_geos_friendly: ring %d untouched", i);
265  }
266 
267  assert ( ring_out );
268  new_rings[i] = ring_out;
269  }
270 
271  lwfree(poly->rings);
272  poly->rings = new_rings;
273  ret = (LWGEOM*)poly;
274 
275  return ret;
276 }
void lwfree(void *mem)
Definition: lwutil.c:214
int npoints
Definition: liblwgeom.h:355
void ptarray_free(POINTARRAY *pa)
Definition: ptarray.c:330
POINTARRAY ** rings
Definition: liblwgeom.h:441
int nrings
Definition: liblwgeom.h:439
POINTARRAY * ring_make_geos_friendly(POINTARRAY *ring)
void * lwalloc(size_t size)
Definition: lwutil.c:199
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:55
Here is the call graph for this function:
Here is the caller graph for this function: