PostGIS  2.5.7dev-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 337 of file lwin_wkb.c.

338 {
339  POINTARRAY *pa = NULL;
340  size_t pa_size;
341  uint32_t ndims = 2;
342  uint32_t npoints = 0;
343  static uint32_t maxpoints = UINT_MAX / WKB_DOUBLE_SIZE / 4;
344 
345  /* Calculate the size of this point array. */
346  npoints = integer_from_wkb_state(s);
347  if (npoints > maxpoints)
348  {
349  lwerror("Pointarray length (%d) is too large");
350  return NULL;
351  }
352 
353  LWDEBUGF(4,"Pointarray has %d points", npoints);
354 
355  if( s->has_z ) ndims++;
356  if( s->has_m ) ndims++;
357  pa_size = npoints * ndims * WKB_DOUBLE_SIZE;
358 
359  /* Empty! */
360  if( npoints == 0 )
361  return ptarray_construct(s->has_z, s->has_m, npoints);
362 
363  /* Does the data we want to read exist? */
364  wkb_parse_state_check(s, pa_size);
365 
366  /* If we're in a native endianness, we can just copy the data directly! */
367  if( ! s->swap_bytes )
368  {
369  pa = ptarray_construct_copy_data(s->has_z, s->has_m, npoints, (uint8_t*)s->pos);
370  s->pos += pa_size;
371  }
372  /* Otherwise we have to read each double, separately. */
373  else
374  {
375  uint32_t i = 0;
376  double *dlist;
377  pa = ptarray_construct(s->has_z, s->has_m, npoints);
378  dlist = (double*)(pa->serialized_pointlist);
379  for( i = 0; i < npoints * ndims; i++ )
380  {
381  dlist[i] = double_from_wkb_state(s);
382  }
383  }
384 
385  return pa;
386 }
char * s
Definition: cu_in_wkt.c:23
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:307
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
#define WKB_DOUBLE_SIZE
Well-Known Binary (WKB) Output Variant Types.
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
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:275
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:130
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:305
uint8_t * serialized_pointlist
Definition: liblwgeom.h:369
unsigned int uint32_t
Definition: uthash.h:78
unsigned char uint8_t
Definition: uthash.h:79

References double_from_wkb_state(), integer_from_wkb_state(), LWDEBUGF, lwerror(), ptarray_construct(), ptarray_construct_copy_data(), s, POINTARRAY::serialized_pointlist, 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().

Here is the call graph for this function:
Here is the caller graph for this function: