PostGIS  2.1.10dev-r@@SVN_REVISION@@
int ptarray_remove_point ( POINTARRAY pa,
int  where 
)

Remove a point from an existing POINTARRAY.

Zero is the index of the start of the array.

Definition at line 246 of file ptarray.c.

References getPoint_internal(), LW_FAILURE, LW_SUCCESS, lwerror(), POINTARRAY::npoints, and ptarray_point_size().

Referenced by gbox_to_gml3().

247 {
248  size_t ptsize = ptarray_point_size(pa);
249 
250  /* Check for pathology */
251  if( ! pa )
252  {
253  lwerror("ptarray_remove_point: null input");
254  return LW_FAILURE;
255  }
256 
257  /* Error on invalid offset value */
258  if ( where >= pa->npoints || where < 0)
259  {
260  lwerror("ptarray_remove_point: offset out of range (%d)", where);
261  return LW_FAILURE;
262  }
263 
264  /* If the point is any but the last, we need to copy the data back one point */
265  if( where < pa->npoints - 1 )
266  {
267  memmove(getPoint_internal(pa, where), getPoint_internal(pa, where+1), ptsize * (pa->npoints - where - 1));
268  }
269 
270  /* We have one less point */
271  pa->npoints--;
272 
273  return LW_SUCCESS;
274 }
int ptarray_point_size(const POINTARRAY *pa)
Definition: ptarray.c:41
int npoints
Definition: liblwgeom.h:327
#define LW_SUCCESS
Definition: liblwgeom.h:55
#define LW_FAILURE
Definition: liblwgeom.h:54
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:67
uint8_t * getPoint_internal(const POINTARRAY *pa, int n)
Definition: ptarray.c:1645

Here is the call graph for this function:

Here is the caller graph for this function: