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

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

358 {
359  int dims = 2;
360  int pa_dims = FLAGS_NDIMS(pa->flags);
361  int i, j;
362  double *dbl_ptr;
363 
364  /* SFSQL is always 2-d. Extended and ISO use all available dimensions */
365  if ( (variant & WKB_ISO) || (variant & WKB_EXTENDED) )
366  dims = pa_dims;
367 
368  /* Set the number of points (if it's not a POINT type) */
369  if ( ! ( variant & WKB_NO_NPOINTS ) )
370  buf = integer_to_wkb_buf(pa->npoints, buf, variant);
371 
372  /* Bulk copy the coordinates when: dimensionality matches, output format */
373  /* is not hex, and output endian matches internal endian. */
374  if ( pa->npoints && (dims == pa_dims) && ! wkb_swap_bytes(variant) && ! (variant & WKB_HEX) )
375  {
376  size_t size = pa->npoints * dims * WKB_DOUBLE_SIZE;
377  memcpy(buf, getPoint_internal(pa, 0), size);
378  buf += size;
379  }
380  /* Copy coordinates one-by-one otherwise */
381  else
382  {
383  for ( i = 0; i < pa->npoints; i++ )
384  {
385  LWDEBUGF(4, "Writing point #%d", i);
386  dbl_ptr = (double*)getPoint_internal(pa, i);
387  for ( j = 0; j < dims; j++ )
388  {
389  LWDEBUGF(4, "Writing dimension #%d (buf = %p)", j, buf);
390  buf = double_to_wkb_buf(dbl_ptr[j], buf, variant);
391  }
392  }
393  }
394  LWDEBUGF(4, "Done (buf = %p)", buf);
395  return buf;
396 }
uint8_t variant
Definition: cu_in_twkb.c:26
int npoints
Definition: liblwgeom.h:355
#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:182
uint8_t flags
Definition: liblwgeom.h:353
uint8_t * getPoint_internal(const POINTARRAY *pa, int n)
Definition: ptarray.c:1706
#define WKB_ISO
Definition: liblwgeom.h:1930
#define WKB_EXTENDED
Definition: liblwgeom.h:1932
static int wkb_swap_bytes(uint8_t variant)
Definition: lwout_wkb.c:168
static uint8_t * double_to_wkb_buf(const double d, uint8_t *buf, uint8_t variant)
Definition: lwout_wkb.c:229
#define WKB_NO_NPOINTS
Definition: liblwgeom.h:1936
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:55
#define FLAGS_NDIMS(flags)
Definition: liblwgeom.h:136
#define WKB_HEX
Definition: liblwgeom.h:1935

Here is the call graph for this function:

Here is the caller graph for this function: