PostGIS  2.5.1dev-r@@SVN_REVISION@@

◆ getPoint3dm_p()

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

Definition at line 257 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().

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