PostGIS  2.5.7dev-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 555 of file ptarray.c.

556 {
557  POINTARRAY *ret;
558  size_t ptsize = ptarray_point_size(pa);
559 
560  LWDEBUGF(3, "pa %x which %d", pa, which);
561 
562 #if PARANOIA_LEVEL > 0
563  if ( which > pa->npoints-1 )
564  {
565  lwerror("%s [%d] offset (%d) out of range (%d..%d)", __FILE__, __LINE__,
566  which, 0, pa->npoints-1);
567  return NULL;
568  }
569 
570  if ( pa->npoints < 3 )
571  {
572  lwerror("%s [%d] can't remove a point from a 2-vertex POINTARRAY", __FILE__, __LINE__);
573  return NULL;
574  }
575 #endif
576 
578  FLAGS_GET_M(pa->flags), pa->npoints-1);
579 
580  /* copy initial part */
581  if ( which )
582  {
583  memcpy(getPoint_internal(ret, 0), getPoint_internal(pa, 0), ptsize*which);
584  }
585 
586  /* copy final part */
587  if ( which < pa->npoints-1 )
588  {
589  memcpy(getPoint_internal(ret, which), getPoint_internal(pa, which+1),
590  ptsize*(pa->npoints-which-1));
591  }
592 
593  return ret;
594 }
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:140
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:141
#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
uint8_t * getPoint_internal(const POINTARRAY *pa, uint32_t n)
Definition: ptarray.c:1750
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
size_t ptarray_point_size(const POINTARRAY *pa)
Definition: ptarray.c:54
uint32_t npoints
Definition: liblwgeom.h:374
uint8_t flags
Definition: liblwgeom.h:372

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: