PostGIS  2.3.8dev-r@@SVN_REVISION@@

◆ ptarray_from_wkb_state()

static POINTARRAY* ptarray_from_wkb_state ( wkb_parse_state s)
static

POINTARRAY Read a dynamically sized point array and advance the parse state forward.

First read the number of points, then read the points.

Definition at line 329 of file lwin_wkb.c.

References double_from_wkb_state(), wkb_parse_state::has_m, wkb_parse_state::has_z, integer_from_wkb_state(), LWDEBUGF, lwerror(), wkb_parse_state::pos, ptarray_construct(), ptarray_construct_copy_data(), POINTARRAY::serialized_pointlist, wkb_parse_state::swap_bytes, WKB_DOUBLE_SIZE, and wkb_parse_state_check().

Referenced by lwcircstring_from_wkb_state(), lwline_from_wkb_state(), lwpoly_from_wkb_state(), and lwtriangle_from_wkb_state().

330 {
331  POINTARRAY *pa = NULL;
332  size_t pa_size;
333  uint32_t ndims = 2;
334  uint32_t npoints = 0;
335  static uint32_t maxpoints = 4294967295 / WKB_DOUBLE_SIZE / 4;
336 
337  /* Calculate the size of this point array. */
338  npoints = integer_from_wkb_state(s);
339  if (npoints > maxpoints)
340  {
341  lwerror("point array length (%d) is too large");
342  }
343 
344  LWDEBUGF(4,"Pointarray has %d points", npoints);
345 
346  if( s->has_z ) ndims++;
347  if( s->has_m ) ndims++;
348  pa_size = npoints * ndims * WKB_DOUBLE_SIZE;
349 
350  /* Empty! */
351  if( npoints == 0 )
352  return ptarray_construct(s->has_z, s->has_m, npoints);
353 
354  /* Does the data we want to read exist? */
355  wkb_parse_state_check(s, pa_size);
356 
357  /* If we're in a native endianness, we can just copy the data directly! */
358  if( ! s->swap_bytes )
359  {
360  pa = ptarray_construct_copy_data(s->has_z, s->has_m, npoints, (uint8_t*)s->pos);
361  s->pos += pa_size;
362  }
363  /* Otherwise we have to read each double, separately. */
364  else
365  {
366  int i = 0;
367  double *dlist;
368  pa = ptarray_construct(s->has_z, s->has_m, npoints);
369  dlist = (double*)(pa->serialized_pointlist);
370  for( i = 0; i < npoints * ndims; i++ )
371  {
372  dlist[i] = double_from_wkb_state(s);
373  }
374  }
375 
376  return pa;
377 }
POINTARRAY * ptarray_construct(char hasz, char hasm, uint32_t npoints)
Construct an empty pointarray, allocating storage and setting the npoints, but not filling in any inf...
Definition: ptarray.c:62
uint8_t * serialized_pointlist
Definition: liblwgeom.h:365
static uint32_t integer_from_wkb_state(wkb_parse_state *s)
Int32 Read 4-byte integer and advance the parse state forward.
Definition: lwin_wkb.c:267
#define WKB_DOUBLE_SIZE
Well-Known Binary (WKB) Output Variant Types.
POINTARRAY * ptarray_construct_copy_data(char hasz, char hasm, uint32_t npoints, const uint8_t *ptlist)
Construct a new POINTARRAY, copying in the data from ptlist.
Definition: ptarray.c:309
static void wkb_parse_state_check(wkb_parse_state *s, size_t next)
Check that we are not about to read off the end of the WKB array.
Definition: lwin_wkb.c:125
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
static double double_from_wkb_state(wkb_parse_state *s)
Double Read an 8-byte double and advance the parse state forward.
Definition: lwin_wkb.c:297
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:102
const uint8_t * pos
Definition: lwin_wkb.c:46
Here is the call graph for this function:
Here is the caller graph for this function: