PostGIS  2.3.8dev-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 509 of file ptarray.c.

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(), ptarray_to_GEOSLinearRing(), and ring_make_geos_friendly().

510 {
511  POINTARRAY *ret;
512  POINT4D pbuf;
513  size_t ptsize = ptarray_point_size(pa);
514 
515  LWDEBUGF(3, "pa %x p %x size %d where %d",
516  pa, p, pdims, where);
517 
518  if ( pdims < 2 || pdims > 4 )
519  {
520  lwerror("ptarray_addPoint: point dimension out of range (%d)",
521  pdims);
522  return NULL;
523  }
524 
525  if ( where > pa->npoints )
526  {
527  lwerror("ptarray_addPoint: offset out of range (%d)",
528  where);
529  return NULL;
530  }
531 
532  LWDEBUG(3, "called with a %dD point");
533 
534  pbuf.x = pbuf.y = pbuf.z = pbuf.m = 0.0;
535  memcpy((uint8_t *)&pbuf, p, pdims*sizeof(double));
536 
537  LWDEBUG(3, "initialized point buffer");
538 
540  FLAGS_GET_M(pa->flags), pa->npoints+1);
541 
542  if ( where == -1 ) where = pa->npoints;
543 
544  if ( where )
545  {
546  memcpy(getPoint_internal(ret, 0), getPoint_internal(pa, 0), ptsize*where);
547  }
548 
549  memcpy(getPoint_internal(ret, where), (uint8_t *)&pbuf, ptsize);
550 
551  if ( where+1 != ret->npoints )
552  {
553  memcpy(getPoint_internal(ret, where+1),
554  getPoint_internal(pa, where),
555  ptsize*(pa->npoints-where));
556  }
557 
558  return ret;
559 }
double x
Definition: liblwgeom.h:351
double m
Definition: liblwgeom.h:351
int ptarray_point_size(const POINTARRAY *pa)
Definition: ptarray.c:54
int npoints
Definition: liblwgeom.h:370
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
uint8_t flags
Definition: liblwgeom.h:368
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:139
double z
Definition: liblwgeom.h:351
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:140
double y
Definition: liblwgeom.h:351
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
uint8_t * getPoint_internal(const POINTARRAY *pa, int n)
Definition: ptarray.c:1713
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:102
Here is the call graph for this function:
Here is the caller graph for this function: