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

405 {
406  static uint32_t npoints = 1;
407  POINTARRAY *pa = NULL;
408  size_t pa_size;
409  uint32_t ndims = 2;
410  const POINT2D *pt;
411 
412  /* Count the dimensions. */
413  if( s->has_z ) ndims++;
414  if( s->has_m ) ndims++;
415  pa_size = ndims * WKB_DOUBLE_SIZE;
416 
417  /* Does the data we want to read exist? */
418  wkb_parse_state_check(s, pa_size);
419  if (s->error)
420  return NULL;
421 
422  /* If we're in a native endianness, we can just copy the data directly! */
423  if( ! s->swap_bytes )
424  {
425  pa = ptarray_construct_copy_data(s->has_z, s->has_m, npoints, (uint8_t*)s->pos);
426  s->pos += pa_size;
427  }
428  /* Otherwise we have to read each double, separately */
429  else
430  {
431  uint32_t i = 0;
432  double *dlist;
433  pa = ptarray_construct(s->has_z, s->has_m, npoints);
434  dlist = (double*)(pa->serialized_pointlist);
435  for( i = 0; i < ndims; i++ )
436  {
437  dlist[i] = double_from_wkb_state(s);
438  }
439  }
440 
441  /* Check for POINT(NaN NaN) ==> POINT EMPTY */
442  pt = getPoint2d_cp(pa, 0);
443  if ( isnan(pt->x) && isnan(pt->y) )
444  {
445  ptarray_free(pa);
446  return lwpoint_construct_empty(s->srid, s->has_z, s->has_m);
447  }
448  else
449  {
450  return lwpoint_construct(s->srid, NULL, pa);
451  }
452 }
char * s
Definition: cu_in_wkt.c:23
LWPOINT * lwpoint_construct_empty(int32_t srid, char hasz, char hasm)
Definition: lwpoint.c:151
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
LWPOINT * lwpoint_construct(int32_t srid, GBOX *bbox, POINTARRAY *point)
Definition: lwpoint.c:129
void ptarray_free(POINTARRAY *pa)
Definition: ptarray.c:319
#define WKB_DOUBLE_SIZE
Well-Known Binary (WKB) Output Variant Types.
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
static const POINT2D * getPoint2d_cp(const POINTARRAY *pa, uint32_t n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from.
Definition: lwinline.h:91
double y
Definition: liblwgeom.h:376
double x
Definition: liblwgeom.h:376
uint8_t * serialized_pointlist
Definition: liblwgeom.h:420

References double_from_wkb_state(), getPoint2d_cp(), lwpoint_construct(), lwpoint_construct_empty(), ptarray_construct(), ptarray_construct_copy_data(), ptarray_free(), s, POINTARRAY::serialized_pointlist, WKB_DOUBLE_SIZE, wkb_parse_state_check(), POINT2D::x, and POINT2D::y.

Referenced by lwgeom_from_wkb_state().

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