PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ getPoint3dm_p()

int getPoint3dm_p ( const POINTARRAY pa,
int  n,
POINT3DM op 
)

Definition at line 266 of file lwgeom_api.c.

References POINTARRAY::flags, FLAGS_GET_ZM, FLAGS_NDIMS, getPoint_internal(), LWDEBUGF, lwerror(), lwnotice(), POINT3DM::m, NO_M_VALUE, and POINTARRAY::npoints.

Referenced by getPoint3dm(), LWGEOM_m_point(), lwline_is_trajectory(), and lwpoint_getPoint3dm_p().

267 {
268  uint8_t *ptr;
269  int zmflag;
270 
271  if ( ! pa )
272  {
273  lwerror("%s [%d] NULL POINTARRAY input", __FILE__, __LINE__);
274  return 0;
275  }
276 
277  if ( (n<0) || (n>=pa->npoints))
278  {
279  lwnotice("%s [%d] called with n=%d and npoints=%d", __FILE__, __LINE__, n, pa->npoints);
280  return 0;
281  }
282 
283  LWDEBUGF(2, "getPoint3dm_p(%d) called on array of %d-dimensions / %u pts",
284  n, FLAGS_NDIMS(pa->flags), pa->npoints);
285 
286 
287  /* Get a pointer to nth point offset and zmflag */
288  ptr=getPoint_internal(pa, n);
289  zmflag=FLAGS_GET_ZM(pa->flags);
290 
291  /*
292  * if input POINTARRAY has the M and NO Z,
293  * we can issue a single memcpy
294  */
295  if ( zmflag == 1 )
296  {
297  memcpy(op, ptr, sizeof(POINT3DM));
298  return 1;
299  }
300 
301  /*
302  * Otherwise copy the 2d part and
303  * initialize M to NO_M_VALUE
304  */
305  memcpy(op, ptr, sizeof(POINT2D));
306 
307  /*
308  * Then, if input has Z skip it and
309  * copy next double, otherwise initialize
310  * M to NO_M_VALUE
311  */
312  if ( zmflag == 3 )
313  {
314  ptr+=sizeof(POINT3DZ);
315  memcpy(&(op->m), ptr, sizeof(double));
316  }
317  else
318  {
319  op->m=NO_M_VALUE;
320  }
321 
322  return 1;
323 }
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
Definition: lwutil.c:177
int npoints
Definition: liblwgeom.h:371
#define FLAGS_GET_ZM(flags)
Definition: liblwgeom.h:153
double m
Definition: liblwgeom.h:346
uint8_t flags
Definition: liblwgeom.h:369
uint8_t * getPoint_internal(const POINTARRAY *pa, int n)
Definition: ptarray.c:1753
#define NO_M_VALUE
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
#define FLAGS_NDIMS(flags)
Definition: liblwgeom.h:152
unsigned char uint8_t
Definition: uthash.h:79
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: