PostGIS  3.0.6dev-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 553 of file ptarray.c.

554 {
555  POINTARRAY *ret;
556  size_t ptsize = ptarray_point_size(pa);
557 
558  LWDEBUGF(3, "pa %x which %d", pa, which);
559 
560 #if PARANOIA_LEVEL > 0
561  if ( which > pa->npoints-1 )
562  {
563  lwerror("%s [%d] offset (%d) out of range (%d..%d)", __FILE__, __LINE__,
564  which, 0, pa->npoints-1);
565  return NULL;
566  }
567 
568  if ( pa->npoints < 3 )
569  {
570  lwerror("%s [%d] can't remove a point from a 2-vertex POINTARRAY", __FILE__, __LINE__);
571  return NULL;
572  }
573 #endif
574 
576  FLAGS_GET_M(pa->flags), pa->npoints-1);
577 
578  /* copy initial part */
579  if ( which )
580  {
581  memcpy(getPoint_internal(ret, 0), getPoint_internal(pa, 0), ptsize*which);
582  }
583 
584  /* copy final part */
585  if ( which < pa->npoints-1 )
586  {
587  memcpy(getPoint_internal(ret, which), getPoint_internal(pa, which+1),
588  ptsize*(pa->npoints-which-1));
589  }
590 
591  return ret;
592 }
#define FLAGS_GET_Z(flags)
Definition: liblwgeom.h:179
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:180
#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
static size_t ptarray_point_size(const POINTARRAY *pa)
Definition: lwinline.h:48
static uint8_t * getPoint_internal(const POINTARRAY *pa, uint32_t n)
Definition: lwinline.h:67
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:51
lwflags_t flags
Definition: liblwgeom.h:417
uint32_t npoints
Definition: liblwgeom.h:413

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().

Here is the call graph for this function:
Here is the caller graph for this function: