PostGIS  2.2.7dev-r@@SVN_REVISION@@
static POINTARRAY* ptarray_from_twkb_state ( twkb_parse_state s,
uint32_t  npoints 
)
static

POINTARRAY Read a dynamically sized point array and advance the parse state forward.

Definition at line 158 of file lwin_twkb.c.

References twkb_parse_state::coords, twkb_parse_state::factor, twkb_parse_state::factor_m, twkb_parse_state::factor_z, twkb_parse_state::has_m, twkb_parse_state::has_z, LWDEBUG, LWDEBUGF, twkb_parse_state::ndims, ptarray_construct(), ptarray_construct_empty(), POINTARRAY::serialized_pointlist, and twkb_parse_state_varint().

Referenced by lwline_from_twkb_state(), lwpoint_from_twkb_state(), and lwpoly_from_twkb_state().

159 {
160  POINTARRAY *pa = NULL;
161  uint32_t ndims = s->ndims;
162  int i;
163  double *dlist;
164 
165  LWDEBUG(2,"Entering ptarray_from_twkb_state");
166  LWDEBUGF(4,"Pointarray has %d points", npoints);
167 
168  /* Empty! */
169  if( npoints == 0 )
170  return ptarray_construct_empty(s->has_z, s->has_m, 0);
171 
172  pa = ptarray_construct(s->has_z, s->has_m, npoints);
173  dlist = (double*)(pa->serialized_pointlist);
174  for( i = 0; i < npoints; i++ )
175  {
176  int j = 0;
177  /* X */
178  s->coords[j] += twkb_parse_state_varint(s);
179  dlist[ndims*i + j] = s->coords[j] / s->factor;
180  j++;
181  /* Y */
182  s->coords[j] += twkb_parse_state_varint(s);
183  dlist[ndims*i + j] = s->coords[j] / s->factor;
184  j++;
185  /* Z */
186  if ( s->has_z )
187  {
188  s->coords[j] += twkb_parse_state_varint(s);
189  dlist[ndims*i + j] = s->coords[j] / s->factor_z;
190  j++;
191  }
192  /* M */
193  if ( s->has_m )
194  {
195  s->coords[j] += twkb_parse_state_varint(s);
196  dlist[ndims*i + j] = s->coords[j] / s->factor_m;
197  j++;
198  }
199  }
200 
201  return pa;
202 }
uint8_t has_z
Definition: lwin_twkb.c:35
double factor_z
Definition: lwin_twkb.c:41
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:350
uint8_t has_m
Definition: lwin_twkb.c:36
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
Definition: ptarray.c:70
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:50
int64_t * coords
Definition: lwin_twkb.c:51
double factor_m
Definition: lwin_twkb.c:42
static int64_t twkb_parse_state_varint(twkb_parse_state *s)
Definition: lwin_twkb.c:79
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:55

Here is the call graph for this function:

Here is the caller graph for this function: