PostGIS  2.1.10dev-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 312 of file lwin_wkb.c.

References double_from_wkb_state(), wkb_parse_state::has_m, wkb_parse_state::has_z, integer_from_wkb_state(), 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().

313 {
314  POINTARRAY *pa = NULL;
315  size_t pa_size;
316  uint32_t ndims = 2;
317  uint32_t npoints = 0;
318 
319  /* Calculate the size of this point array. */
320  npoints = integer_from_wkb_state(s);
321  if( s->has_z ) ndims++;
322  if( s->has_m ) ndims++;
323  pa_size = npoints * ndims * WKB_DOUBLE_SIZE;
324 
325  /* Empty! */
326  if( npoints == 0 )
327  return ptarray_construct(s->has_z, s->has_m, npoints);
328 
329  /* Does the data we want to read exist? */
330  wkb_parse_state_check(s, pa_size);
331 
332  /* If we're in a native endianness, we can just copy the data directly! */
333  if( ! s->swap_bytes )
334  {
335  pa = ptarray_construct_copy_data(s->has_z, s->has_m, npoints, (uint8_t*)s->pos);
336  s->pos += pa_size;
337  }
338  /* Otherwise we have to read each double, separately. */
339  else
340  {
341  int i = 0;
342  double *dlist;
343  pa = ptarray_construct(s->has_z, s->has_m, npoints);
344  dlist = (double*)(pa->serialized_pointlist);
345  for( i = 0; i < npoints * ndims; i++ )
346  {
347  dlist[i] = double_from_wkb_state(s);
348  }
349  }
350 
351  return pa;
352 }
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:49
uint8_t * serialized_pointlist
Definition: liblwgeom.h:322
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:250
#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:294
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:108
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:280
const uint8_t * pos
Definition: lwin_wkb.c:29

Here is the call graph for this function:

Here is the caller graph for this function: