PostGIS  2.1.10dev-r@@SVN_REVISION@@
static uint8_t* ptarray_to_wkb_buf ( const POINTARRAY pa,
uint8_t *  buf,
uint8_t  variant 
)
static

Definition at line 332 of file lwout_wkb.c.

References double_to_wkb_buf(), POINTARRAY::flags, FLAGS_NDIMS, getPoint_internal(), integer_to_wkb_buf(), LWDEBUGF, POINTARRAY::npoints, WKB_DOUBLE_SIZE, WKB_EXTENDED, WKB_HEX, WKB_ISO, WKB_NO_NPOINTS, and wkb_swap_bytes().

Referenced by lwline_to_wkb_buf(), lwpoint_to_wkb_buf(), lwpoly_to_wkb_buf(), and lwtriangle_to_wkb_buf().

333 {
334  int dims = 2;
335  int pa_dims = FLAGS_NDIMS(pa->flags);
336  int i, j;
337  double *dbl_ptr;
338 
339  /* SFSQL is always 2-d. Extended and ISO use all available dimensions */
340  if ( (variant & WKB_ISO) || (variant & WKB_EXTENDED) )
341  dims = pa_dims;
342 
343  /* Set the number of points (if it's not a POINT type) */
344  if ( ! ( variant & WKB_NO_NPOINTS ) )
345  buf = integer_to_wkb_buf(pa->npoints, buf, variant);
346 
347  /* Bulk copy the coordinates when: dimensionality matches, output format */
348  /* is not hex, and output endian matches internal endian. */
349  if ( (dims == pa_dims) && ! wkb_swap_bytes(variant) && ! (variant & WKB_HEX) )
350  {
351  size_t size = pa->npoints * dims * WKB_DOUBLE_SIZE;
352  memcpy(buf, getPoint_internal(pa, 0), size);
353  buf += size;
354  }
355  /* Copy coordinates one-by-one otherwise */
356  else
357  {
358  for ( i = 0; i < pa->npoints; i++ )
359  {
360  LWDEBUGF(4, "Writing point #%d", i);
361  dbl_ptr = (double*)getPoint_internal(pa, i);
362  for ( j = 0; j < dims; j++ )
363  {
364  LWDEBUGF(4, "Writing dimension #%d (buf = %p)", j, buf);
365  buf = double_to_wkb_buf(dbl_ptr[j], buf, variant);
366  }
367  }
368  }
369  LWDEBUGF(4, "Done (buf = %p)", buf);
370  return buf;
371 }
int npoints
Definition: liblwgeom.h:327
#define WKB_DOUBLE_SIZE
Well-Known Binary (WKB) Output Variant Types.
static uint8_t * integer_to_wkb_buf(const int ival, uint8_t *buf, uint8_t variant)
Definition: lwout_wkb.c:180
uint8_t flags
Definition: liblwgeom.h:325
uint8_t * getPoint_internal(const POINTARRAY *pa, int n)
Definition: ptarray.c:1645
#define WKB_ISO
Definition: liblwgeom.h:1767
#define WKB_EXTENDED
Definition: liblwgeom.h:1769
static int wkb_swap_bytes(uint8_t variant)
Definition: lwout_wkb.c:166
static uint8_t * double_to_wkb_buf(const double d, uint8_t *buf, uint8_t variant)
Definition: lwout_wkb.c:227
#define WKB_NO_NPOINTS
Definition: liblwgeom.h:1773
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:55
#define FLAGS_NDIMS(flags)
Definition: liblwgeom.h:118
#define WKB_HEX
Definition: liblwgeom.h:1772

Here is the call graph for this function:

Here is the caller graph for this function: