PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ ptarray_removePoint()

POINTARRAY* ptarray_removePoint ( POINTARRAY pa,
uint32_t  where 
)

Remove a point from a pointarray.

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

Definition at line 574 of file ptarray.c.

575 {
576  POINTARRAY *ret;
577  size_t ptsize = ptarray_point_size(pa);
578 
579  LWDEBUGF(3, "pa %x which %d", pa, which);
580 
581 #if PARANOIA_LEVEL > 0
582  if ( which > pa->npoints-1 )
583  {
584  lwerror("%s [%d] offset (%d) out of range (%d..%d)", __FILE__, __LINE__,
585  which, 0, pa->npoints-1);
586  return NULL;
587  }
588 
589  if ( pa->npoints < 3 )
590  {
591  lwerror("%s [%d] can't remove a point from a 2-vertex POINTARRAY", __FILE__, __LINE__);
592  return NULL;
593  }
594 #endif
595 
597  FLAGS_GET_M(pa->flags), pa->npoints-1);
598 
599  /* copy initial part */
600  if ( which )
601  {
602  memcpy(getPoint_internal(ret, 0), getPoint_internal(pa, 0), ptsize*which);
603  }
604 
605  /* copy final part */
606  if ( which < pa->npoints-1 )
607  {
608  memcpy(getPoint_internal(ret, which), getPoint_internal(pa, which+1),
609  ptsize*(pa->npoints-which-1));
610  }
611 
612  return ret;
613 }
#define FLAGS_GET_Z(flags)
Definition: liblwgeom.h:165
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:166
#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:58
static uint8_t * getPoint_internal(const POINTARRAY *pa, uint32_t n)
Definition: lwinline.h:77
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:431
uint32_t npoints
Definition: liblwgeom.h:427

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: