PostGIS  3.0.6dev-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 340 of file lwin_wkb.c.

341 {
342  POINTARRAY *pa = NULL;
343  size_t pa_size;
344  uint32_t ndims = 2;
345  uint32_t npoints = 0;
346  static uint32_t maxpoints = UINT_MAX / WKB_DOUBLE_SIZE / 4;
347 
348  /* Calculate the size of this point array. */
349  npoints = integer_from_wkb_state(s);
350  if (s->error)
351  return NULL;
352  if (npoints > maxpoints)
353  {
354  lwerror("Pointarray length (%d) is too large");
355  return NULL;
356  }
357 
358  LWDEBUGF(4,"Pointarray has %d points", npoints);
359 
360  if( s->has_z ) ndims++;
361  if( s->has_m ) ndims++;
362  pa_size = npoints * ndims * WKB_DOUBLE_SIZE;
363 
364  /* Empty! */
365  if( npoints == 0 )
366  return ptarray_construct(s->has_z, s->has_m, npoints);
367 
368  /* Does the data we want to read exist? */
369  wkb_parse_state_check(s, pa_size);
370  if (s->error)
371  return NULL;
372 
373  /* If we're in a native endianness, we can just copy the data directly! */
374  if( ! s->swap_bytes )
375  {
376  pa = ptarray_construct_copy_data(s->has_z, s->has_m, npoints, (uint8_t*)s->pos);
377  s->pos += pa_size;
378  }
379  /* Otherwise we have to read each double, separately. */
380  else
381  {
382  uint32_t i = 0;
383  double *dlist;
384  pa = ptarray_construct(s->has_z, s->has_m, npoints);
385  dlist = (double*)(pa->serialized_pointlist);
386  for( i = 0; i < npoints * ndims; i++ )
387  {
388  dlist[i] = double_from_wkb_state(s);
389  }
390  }
391 
392  return pa;
393 }
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:297
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:51
#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:278
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:131
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:310
uint8_t * serialized_pointlist
Definition: liblwgeom.h:420

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: