PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ ptarray_addPoint()

POINTARRAY* ptarray_addPoint ( const POINTARRAY pa,
uint8_t *  p,
size_t  pdims,
uint32_t  where 
)

Add a point in a pointarray.

Parameters
pathe source POINTARRAY
pthe point to add
pdimsnumber of ordinates in p (2..4)
whereto insert the point. 0 prepends, pa->npoints appends
Returns
a newly constructed POINTARRAY using a newly allocated buffer for the actual points, or NULL on error.

Definition at line 522 of file ptarray.c.

523 {
524  POINTARRAY *ret;
525  POINT4D pbuf;
526  size_t ptsize = ptarray_point_size(pa);
527 
528  LWDEBUGF(3, "pa %x p %x size %d where %d",
529  pa, p, pdims, where);
530 
531  if ( pdims < 2 || pdims > 4 )
532  {
533  lwerror("ptarray_addPoint: point dimension out of range (%d)",
534  pdims);
535  return NULL;
536  }
537 
538  if ( where > pa->npoints )
539  {
540  lwerror("ptarray_addPoint: offset out of range (%d)",
541  where);
542  return NULL;
543  }
544 
545  LWDEBUG(3, "called with a %dD point");
546 
547  pbuf.x = pbuf.y = pbuf.z = pbuf.m = 0.0;
548  memcpy((uint8_t *)&pbuf, p, pdims*sizeof(double));
549 
550  LWDEBUG(3, "initialized point buffer");
551 
553  FLAGS_GET_M(pa->flags), pa->npoints+1);
554 
555 
556  if ( where )
557  {
558  memcpy(getPoint_internal(ret, 0), getPoint_internal(pa, 0), ptsize*where);
559  }
560 
561  memcpy(getPoint_internal(ret, where), (uint8_t *)&pbuf, ptsize);
562 
563  if ( where+1 != ret->npoints )
564  {
565  memcpy(getPoint_internal(ret, where+1),
566  getPoint_internal(pa, where),
567  ptsize*(pa->npoints-where));
568  }
569 
570  return ret;
571 }
#define FLAGS_GET_Z(flags)
Definition: liblwgeom.h:165
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:166
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
#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
double m
Definition: liblwgeom.h:414
double x
Definition: liblwgeom.h:414
double z
Definition: liblwgeom.h:414
double y
Definition: liblwgeom.h:414
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(), LWDEBUG, LWDEBUGF, lwerror(), POINT4D::m, POINTARRAY::npoints, ptarray_construct(), ptarray_point_size(), POINT4D::x, POINT4D::y, and POINT4D::z.

Referenced by lwcircstring_addpoint(), LWGEOM2GEOS(), lwline_make_geos_friendly(), ptarray_close2d(), and ring_make_geos_friendly().

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