PostGIS  2.5.0beta2dev-r@@SVN_REVISION@@

◆ ptarray_to_wkb_buf()

static uint8_t* ptarray_to_wkb_buf ( const POINTARRAY pa,
uint8_t buf,
uint8_t  variant 
)
static

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

372 {
373  uint32_t dims = 2;
374  uint32_t pa_dims = FLAGS_NDIMS(pa->flags);
375  uint32_t i, j;
376  double *dbl_ptr;
377 
378  /* SFSQL is always 2-d. Extended and ISO use all available dimensions */
379  if ( (variant & WKB_ISO) || (variant & WKB_EXTENDED) )
380  dims = pa_dims;
381 
382  /* Set the number of points (if it's not a POINT type) */
383  if ( ! ( variant & WKB_NO_NPOINTS ) )
384  buf = integer_to_wkb_buf(pa->npoints, buf, variant);
385 
386  /* Bulk copy the coordinates when: dimensionality matches, output format */
387  /* is not hex, and output endian matches internal endian. */
388  if ( pa->npoints && (dims == pa_dims) && ! wkb_swap_bytes(variant) && ! (variant & WKB_HEX) )
389  {
390  size_t size = pa->npoints * dims * WKB_DOUBLE_SIZE;
391  memcpy(buf, getPoint_internal(pa, 0), size);
392  buf += size;
393  }
394  /* Copy coordinates one-by-one otherwise */
395  else
396  {
397  for ( i = 0; i < pa->npoints; i++ )
398  {
399  LWDEBUGF(4, "Writing point #%d", i);
400  dbl_ptr = (double*)getPoint_internal(pa, i);
401  for ( j = 0; j < dims; j++ )
402  {
403  LWDEBUGF(4, "Writing dimension #%d (buf = %p)", j, buf);
404  buf = double_to_wkb_buf(dbl_ptr[j], buf, variant);
405  }
406  }
407  }
408  LWDEBUGF(4, "Done (buf = %p)", buf);
409  return buf;
410 }
uint8_t variant
Definition: cu_in_twkb.c:26
#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:196
unsigned int uint32_t
Definition: uthash.h:78
uint8_t flags
Definition: liblwgeom.h:371
#define WKB_ISO
Definition: liblwgeom.h:2065
#define WKB_EXTENDED
Definition: liblwgeom.h:2067
static int wkb_swap_bytes(uint8_t variant)
Definition: lwout_wkb.c:182
static uint8_t * double_to_wkb_buf(const double d, uint8_t *buf, uint8_t variant)
Definition: lwout_wkb.c:243
uint8_t * getPoint_internal(const POINTARRAY *pa, uint32_t n)
Definition: ptarray.c:1743
#define WKB_NO_NPOINTS
Definition: liblwgeom.h:2071
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
#define FLAGS_NDIMS(flags)
Definition: liblwgeom.h:151
#define WKB_HEX
Definition: liblwgeom.h:2070
uint32_t npoints
Definition: liblwgeom.h:373
Here is the call graph for this function:
Here is the caller graph for this function: