PostGIS  3.0.0dev-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 549 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().

550 {
551  POINTARRAY *ret;
552  size_t ptsize = ptarray_point_size(pa);
553 
554  LWDEBUGF(3, "pa %x which %d", pa, which);
555 
556 #if PARANOIA_LEVEL > 0
557  if ( which > pa->npoints-1 )
558  {
559  lwerror("%s [%d] offset (%d) out of range (%d..%d)", __FILE__, __LINE__,
560  which, 0, pa->npoints-1);
561  return NULL;
562  }
563 
564  if ( pa->npoints < 3 )
565  {
566  lwerror("%s [%d] can't remove a point from a 2-vertex POINTARRAY", __FILE__, __LINE__);
567  return NULL;
568  }
569 #endif
570 
572  FLAGS_GET_M(pa->flags), pa->npoints-1);
573 
574  /* copy initial part */
575  if ( which )
576  {
577  memcpy(getPoint_internal(ret, 0), getPoint_internal(pa, 0), ptsize*which);
578  }
579 
580  /* copy final part */
581  if ( which < pa->npoints-1 )
582  {
583  memcpy(getPoint_internal(ret, which), getPoint_internal(pa, which+1),
584  ptsize*(pa->npoints-which-1));
585  }
586 
587  return ret;
588 }
uint8_t flags
Definition: liblwgeom.h:371
static size_t ptarray_point_size(const POINTARRAY *pa)
Definition: lwinline.h:48
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:50
#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
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
static uint8_t * getPoint_internal(const POINTARRAY *pa, uint32_t n)
Definition: lwinline.h:67
uint32_t npoints
Definition: liblwgeom.h:373
Here is the call graph for this function:
Here is the caller graph for this function: