PostGIS  2.4.9dev-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 557 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().

558 {
559  POINTARRAY *ret;
560  size_t ptsize = ptarray_point_size(pa);
561 
562  LWDEBUGF(3, "pa %x which %d", pa, which);
563 
564 #if PARANOIA_LEVEL > 0
565  if ( which > pa->npoints-1 )
566  {
567  lwerror("%s [%d] offset (%d) out of range (%d..%d)", __FILE__, __LINE__,
568  which, 0, pa->npoints-1);
569  return NULL;
570  }
571 
572  if ( pa->npoints < 3 )
573  {
574  lwerror("%s [%d] can't remove a point from a 2-vertex POINTARRAY", __FILE__, __LINE__);
575  return NULL;
576  }
577 #endif
578 
580  FLAGS_GET_M(pa->flags), pa->npoints-1);
581 
582  /* copy initial part */
583  if ( which )
584  {
585  memcpy(getPoint_internal(ret, 0), getPoint_internal(pa, 0), ptsize*which);
586  }
587 
588  /* copy final part */
589  if ( which < pa->npoints-1 )
590  {
591  memcpy(getPoint_internal(ret, which), getPoint_internal(pa, which+1),
592  ptsize*(pa->npoints-which-1));
593  }
594 
595  return ret;
596 }
int ptarray_point_size(const POINTARRAY *pa)
Definition: ptarray.c:54
int npoints
Definition: liblwgeom.h:371
uint8_t flags
Definition: liblwgeom.h:369
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:140
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:141
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
uint8_t * getPoint_internal(const POINTARRAY *pa, int n)
Definition: ptarray.c:1753
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
Here is the call graph for this function:
Here is the caller graph for this function: