PostGIS  2.2.7dev-r@@SVN_REVISION@@
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 315 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().

316 {
317  POINTARRAY *pa = NULL;
318  size_t pa_size;
319  uint32_t ndims = 2;
320  uint32_t npoints = 0;
321  static uint32_t maxpoints = 4294967295 / WKB_DOUBLE_SIZE / 4;
322 
323  /* Calculate the size of this point array. */
324  npoints = integer_from_wkb_state(s);
325  if (npoints > maxpoints)
326  {
327  lwerror("point array length (%d) is too large");
328  }
329 
330  LWDEBUGF(4,"Pointarray has %d points", npoints);
331 
332  if( s->has_z ) ndims++;
333  if( s->has_m ) ndims++;
334  pa_size = npoints * ndims * WKB_DOUBLE_SIZE;
335 
336  /* Empty! */
337  if( npoints == 0 )
338  return ptarray_construct(s->has_z, s->has_m, npoints);
339 
340  /* Does the data we want to read exist? */
341  wkb_parse_state_check(s, pa_size);
342 
343  /* If we're in a native endianness, we can just copy the data directly! */
344  if( ! s->swap_bytes )
345  {
346  pa = ptarray_construct_copy_data(s->has_z, s->has_m, npoints, (uint8_t*)s->pos);
347  s->pos += pa_size;
348  }
349  /* Otherwise we have to read each double, separately. */
350  else
351  {
352  int i = 0;
353  double *dlist;
354  pa = ptarray_construct(s->has_z, s->has_m, npoints);
355  dlist = (double*)(pa->serialized_pointlist);
356  for( i = 0; i < npoints * ndims; i++ )
357  {
358  dlist[i] = double_from_wkb_state(s);
359  }
360  }
361 
362  return pa;
363 }
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:350
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:253
#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:111
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:55
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:283
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:74
const uint8_t * pos
Definition: lwin_wkb.c:32

Here is the call graph for this function:

Here is the caller graph for this function: