PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ geobuf_agg_transfn()

void geobuf_agg_transfn ( struct geobuf_agg_context ctx)

Aggregation step.

Expands features array if needed by a factor of 2. Allocates a new feature, increment feature counter and encode properties into it.  

Definition at line 561 of file geobuf.c.

References analyze_geometry(), analyze_geometry_flags(), geobuf_agg_context::data, encode_feature(), encode_keys(), geobuf_agg_context::features_capacity, geobuf_agg_context::geom_index, lwgeom_from_gserialized(), geobuf_agg_context::lwgeoms, and geobuf_agg_context::row.

Referenced by pgis_asgeobuf_transfn().

562 {
563  LWGEOM *lwgeom;
564  bool isnull = false;
565  Datum datum;
566  Data__FeatureCollection *fc = ctx->data->feature_collection;
567  Data__Feature *feature;
568  GSERIALIZED *gs;
569  if (fc->n_features >= ctx->features_capacity) {
570  size_t new_capacity = ctx->features_capacity * 2;
571  fc->features = repalloc(fc->features, new_capacity *
572  sizeof(*fc->features));
573  ctx->lwgeoms = repalloc(ctx->lwgeoms, new_capacity *
574  sizeof(*ctx->lwgeoms));
575  ctx->features_capacity = new_capacity;
576  }
577 
578  /* inspect row and encode keys assuming static schema */
579  if (fc->n_features == 0)
580  encode_keys(ctx);
581 
582  datum = GetAttributeByNum(ctx->row, ctx->geom_index + 1, &isnull);
583  if (isnull)
584  return;
585 
586  gs = (GSERIALIZED *) PG_DETOAST_DATUM_COPY(datum);
587  lwgeom = lwgeom_from_gserialized(gs);
588 
589  feature = encode_feature(ctx);
590 
591  /* inspect geometry flags assuming static schema */
592  if (fc->n_features == 0)
593  analyze_geometry_flags(ctx, lwgeom);
594 
595  analyze_geometry(ctx, lwgeom);
596 
597  ctx->lwgeoms[fc->n_features] = lwgeom;
598  fc->features[fc->n_features++] = feature;
599 }
HeapTupleHeader row
Definition: geobuf.h:52
static void analyze_geometry_flags(struct geobuf_agg_context *ctx, LWGEOM *lwgeom)
Definition: geobuf.c:496
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
size_t features_capacity
Definition: geobuf.h:56
LWGEOM ** lwgeoms
Definition: geobuf.h:53
uint32_t geom_index
Definition: geobuf.h:51
static void encode_keys(struct geobuf_agg_context *ctx)
Definition: geobuf.c:52
static Data__Feature * encode_feature(struct geobuf_agg_context *ctx)
Definition: geobuf.c:510
static void analyze_geometry(struct geobuf_agg_context *ctx, LWGEOM *lwgeom)
Definition: geobuf.c:463
Here is the call graph for this function:
Here is the caller graph for this function: