PostGIS  2.5.1dev-r@@SVN_REVISION@@

◆ lwpoint_from_wkb_state()

static LWPOINT* lwpoint_from_wkb_state ( wkb_parse_state s)
static

POINT Read a WKB point, starting just after the endian byte, type number and optional srid number.

Advance the parse state forward appropriately. WKB point has just a set of doubles, with the quantity depending on the dimension of the point, so this looks like a special case of the above with only one point.

Definition at line 393 of file lwin_wkb.c.

References double_from_wkb_state(), getPoint2d_cp(), wkb_parse_state::has_m, wkb_parse_state::has_z, lwpoint_construct(), lwpoint_construct_empty(), wkb_parse_state::pos, ptarray_construct(), ptarray_construct_copy_data(), ptarray_free(), POINTARRAY::serialized_pointlist, wkb_parse_state::srid, wkb_parse_state::swap_bytes, WKB_DOUBLE_SIZE, wkb_parse_state_check(), POINT2D::x, and POINT2D::y.

Referenced by lwgeom_from_wkb_state().

394 {
395  static uint32_t npoints = 1;
396  POINTARRAY *pa = NULL;
397  size_t pa_size;
398  uint32_t ndims = 2;
399  const POINT2D *pt;
400 
401  /* Count the dimensions. */
402  if( s->has_z ) ndims++;
403  if( s->has_m ) ndims++;
404  pa_size = ndims * WKB_DOUBLE_SIZE;
405 
406  /* Does the data we want to read exist? */
407  wkb_parse_state_check(s, pa_size);
408 
409  /* If we're in a native endianness, we can just copy the data directly! */
410  if( ! s->swap_bytes )
411  {
412  pa = ptarray_construct_copy_data(s->has_z, s->has_m, npoints, (uint8_t*)s->pos);
413  s->pos += pa_size;
414  }
415  /* Otherwise we have to read each double, separately */
416  else
417  {
418  uint32_t i = 0;
419  double *dlist;
420  pa = ptarray_construct(s->has_z, s->has_m, npoints);
421  dlist = (double*)(pa->serialized_pointlist);
422  for( i = 0; i < ndims; i++ )
423  {
424  dlist[i] = double_from_wkb_state(s);
425  }
426  }
427 
428  /* Check for POINT(NaN NaN) ==> POINT EMPTY */
429  pt = getPoint2d_cp(pa, 0);
430  if ( isnan(pt->x) && isnan(pt->y) )
431  {
432  ptarray_free(pa);
433  return lwpoint_construct_empty(s->srid, s->has_z, s->has_m);
434  }
435  else
436  {
437  return lwpoint_construct(s->srid, NULL, pa);
438  }
439 }
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:368
void ptarray_free(POINTARRAY *pa)
Definition: ptarray.c:328
#define WKB_DOUBLE_SIZE
Well-Known Binary (WKB) Output Variant Types.
LWPOINT * lwpoint_construct_empty(int srid, char hasz, char hasm)
Definition: lwpoint.c:151
unsigned int uint32_t
Definition: uthash.h:78
double x
Definition: liblwgeom.h:330
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
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:126
double y
Definition: liblwgeom.h:330
uint32_t srid
Definition: lwin_wkb.c:43
LWPOINT * lwpoint_construct(int srid, GBOX *bbox, POINTARRAY *point)
Definition: lwpoint.c:129
unsigned char uint8_t
Definition: uthash.h:79
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:301
const uint8_t * pos
Definition: lwin_wkb.c:47
const POINT2D * getPoint2d_cp(const POINTARRAY *pa, uint32_t n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from...
Definition: lwgeom_api.c:364
Here is the call graph for this function:
Here is the caller graph for this function: