PostGIS  2.5.0dev-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 172 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().

173 {
174  POINTARRAY *pa = NULL;
175  uint32_t ndims = s->ndims;
176  uint32_t i;
177  double *dlist;
178 
179  LWDEBUG(2,"Entering ptarray_from_twkb_state");
180  LWDEBUGF(4,"Pointarray has %d points", npoints);
181 
182  /* Empty! */
183  if( npoints == 0 )
184  return ptarray_construct_empty(s->has_z, s->has_m, 0);
185 
186  pa = ptarray_construct(s->has_z, s->has_m, npoints);
187  dlist = (double*)(pa->serialized_pointlist);
188  for( i = 0; i < npoints; i++ )
189  {
190  int j = 0;
191  /* X */
192  s->coords[j] += twkb_parse_state_varint(s);
193  dlist[ndims*i + j] = s->coords[j] / s->factor;
194  j++;
195  /* Y */
196  s->coords[j] += twkb_parse_state_varint(s);
197  dlist[ndims*i + j] = s->coords[j] / s->factor;
198  j++;
199  /* Z */
200  if ( s->has_z )
201  {
202  s->coords[j] += twkb_parse_state_varint(s);
203  dlist[ndims*i + j] = s->coords[j] / s->factor_z;
204  j++;
205  }
206  /* M */
207  if ( s->has_m )
208  {
209  s->coords[j] += twkb_parse_state_varint(s);
210  dlist[ndims*i + j] = s->coords[j] / s->factor_m;
211  j++;
212  }
213  }
214 
215  return pa;
216 }
uint8_t has_z
Definition: lwin_twkb.c:49
double factor_z
Definition: lwin_twkb.c:55
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:365
uint8_t has_m
Definition: lwin_twkb.c:50
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:83
unsigned int uint32_t
Definition: uthash.h:78
int64_t * coords
Definition: lwin_twkb.c:65
double factor_m
Definition: lwin_twkb.c:56
static int64_t twkb_parse_state_varint(twkb_parse_state *s)
Definition: lwin_twkb.c:93
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88

Here is the call graph for this function:

Here is the caller graph for this function: