PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ encode_mpoly()

static Data__Geometry* encode_mpoly ( struct geobuf_agg_context ctx,
LWMPOLY lwmpoly 
)
static

Definition at line 337 of file geobuf.c.

References geobuf_agg_context::dimensions, encode_coords(), galloc(), LWMPOLY::geoms, LWMPOLY::ngeoms, POINTARRAY::npoints, LWPOLY::nrings, and LWPOLY::rings.

Referenced by encode_geometry().

339 {
340  int i, j, c, len, offset, n_lengths, ngeoms, nrings;
341  POINTARRAY *pa;
342  Data__Geometry *geometry;
343  uint32_t *lengths;
344  int64_t *coords = NULL;
345 
346  geometry = galloc(DATA__GEOMETRY__TYPE__MULTIPOLYGON);
347 
348  ngeoms = lwmpoly->ngeoms;
349 
350  if (ngeoms == 0) return geometry;
351 
352  n_lengths = 1;
353  for (i = 0; i < ngeoms; i++) {
354  nrings = lwmpoly->geoms[i]->nrings;
355  n_lengths++;
356  for (j = 0; j < nrings; j++)
357  n_lengths++;
358  }
359 
360  lengths = palloc (sizeof (uint32_t) * n_lengths);
361 
362  c = 0;
363  offset = 0;
364  lengths[c++] = ngeoms;
365  for (i = 0; i < ngeoms; i++) {
366  nrings = lwmpoly->geoms[i]->nrings;
367  lengths[c++] = nrings;
368  for (j = 0; j < nrings; j++) {
369  pa = lwmpoly->geoms[i]->rings[j];
370  len = pa->npoints - 1;
371  coords = encode_coords(ctx, pa, coords, len, offset);
372  offset += len * ctx->dimensions;
373  lengths[c++] = len;
374  }
375  }
376 
377  if (c > 1) {
378  geometry->n_lengths = n_lengths;
379  geometry->lengths = lengths;
380  }
381 
382  geometry->n_coords = offset;
383  geometry->coords = coords;
384 
385  return geometry;
386 }
int npoints
Definition: liblwgeom.h:371
static Data__Geometry * galloc(Data__Geometry__Type type)
Definition: geobuf.c:36
uint32_t dimensions
Definition: geobuf.h:61
unsigned int uint32_t
Definition: uthash.h:78
LWPOLY ** geoms
Definition: liblwgeom.h:496
static int64_t * encode_coords(struct geobuf_agg_context *ctx, POINTARRAY *pa, int64_t *coords, int len, int offset)
Definition: geobuf.c:168
POINTARRAY ** rings
Definition: liblwgeom.h:457
int nrings
Definition: liblwgeom.h:455
int ngeoms
Definition: liblwgeom.h:494
Here is the call graph for this function:
Here is the caller graph for this function: