PostGIS  2.3.8dev-r@@SVN_REVISION@@

◆ ptarray_removePoint()

POINTARRAY* ptarray_removePoint ( POINTARRAY pa,
uint32_t  where 
)

Remove a point from a pointarray.

Parameters
which- is the offset (starting at 0)
Returns
POINTARRAY is newly allocated

Definition at line 562 of file ptarray.c.

References POINTARRAY::flags, FLAGS_GET_M, FLAGS_GET_Z, getPoint_internal(), LWDEBUGF, lwerror(), POINTARRAY::npoints, ptarray_construct(), and ptarray_point_size().

Referenced by lwcircstring_removepoint(), and lwline_removepoint().

563 {
564  POINTARRAY *ret;
565  size_t ptsize = ptarray_point_size(pa);
566 
567  LWDEBUGF(3, "pa %x which %d", pa, which);
568 
569 #if PARANOIA_LEVEL > 0
570  if ( which > pa->npoints-1 )
571  {
572  lwerror("ptarray_removePoint: offset (%d) out of range (%d..%d)",
573  which, 0, pa->npoints-1);
574  return NULL;
575  }
576 
577  if ( pa->npoints < 3 )
578  {
579  lwerror("ptarray_removePointe: can't remove a point from a 2-vertex POINTARRAY");
580  }
581 #endif
582 
584  FLAGS_GET_M(pa->flags), pa->npoints-1);
585 
586  /* copy initial part */
587  if ( which )
588  {
589  memcpy(getPoint_internal(ret, 0), getPoint_internal(pa, 0), ptsize*which);
590  }
591 
592  /* copy final part */
593  if ( which < pa->npoints-1 )
594  {
595  memcpy(getPoint_internal(ret, which), getPoint_internal(pa, which+1),
596  ptsize*(pa->npoints-which-1));
597  }
598 
599  return ret;
600 }
int ptarray_point_size(const POINTARRAY *pa)
Definition: ptarray.c:54
int npoints
Definition: liblwgeom.h:370
uint8_t flags
Definition: liblwgeom.h:368
POINTARRAY * ptarray_construct(char hasz, char hasm, uint32_t npoints)
Construct an empty pointarray, allocating storage and setting the npoints, but not filling in any inf...
Definition: ptarray.c:62
#define FLAGS_GET_Z(flags)
Macros for manipulating the &#39;flags&#39; byte.
Definition: liblwgeom.h:139
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:140
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
uint8_t * getPoint_internal(const POINTARRAY *pa, int n)
Definition: ptarray.c:1713
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:102
Here is the call graph for this function:
Here is the caller graph for this function: