PostGIS  3.3.9dev-r@@SVN_REVISION@@

◆ mvt_agg_transfn()

void mvt_agg_transfn ( mvt_agg_context ctx)

Aggregation step.

Parse a row, turn it into a feature, and add it to the layer.

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

Definition at line 1032 of file mvt.c.

1033 {
1034  bool isnull = false;
1035  Datum datum;
1036  GSERIALIZED *gs;
1037  LWGEOM *lwgeom;
1039  VectorTile__Tile__Layer *layer = ctx->layer;
1040  POSTGIS_DEBUG(2, "mvt_agg_transfn called");
1041 
1042  /* geom_index is the cached index of the geometry. if missing, it needs to be initialized */
1043  if (ctx->geom_index == UINT32_MAX)
1044  parse_column_keys(ctx);
1045 
1046  /* Get the geometry column */
1047  datum = GetAttributeByNum(ctx->row, ctx->geom_index + 1, &isnull);
1048  if (isnull) /* Skip rows that have null geometry */
1049  return;
1050 
1051  /* Allocate a new feature object */
1053 
1054  /* Deserialize the geometry */
1055  gs = (GSERIALIZED *) PG_DETOAST_DATUM(datum);
1056  lwgeom = lwgeom_from_gserialized(gs);
1057 
1058  /* Set the geometry of the feature */
1060  lwgeom_free(lwgeom);
1061  // TODO: free detoasted datum?
1062 
1063  /* Parse properties */
1065 
1066  /* Grow the features array of the layer */
1067  POSTGIS_DEBUGF(3, "mvt_agg_transfn encoded feature count: %zd", layer->n_features);
1068  if (layer->n_features >= ctx->features_capacity)
1069  {
1070  size_t new_capacity = ctx->features_capacity * 2;
1071  layer->features = repalloc(layer->features, new_capacity *
1072  sizeof(*layer->features));
1073  ctx->features_capacity = new_capacity;
1074  POSTGIS_DEBUGF(3, "mvt_agg_transfn new_capacity: %zd", new_capacity);
1075  }
1076 
1077  /* Build and add the feature to the layer */
1078  layer->features[layer->n_features++] = feature_build(&feature_builder);
1079 }
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
Definition: gserialized.c:239
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1155
#define UINT32_MAX
Definition: lwin_wkt_lex.c:343
static void parse_values(mvt_agg_context *ctx, struct feature_builder *feature)
Definition: mvt.c:669
static void parse_column_keys(mvt_agg_context *ctx)
Definition: mvt.c:337
static void feature_init(struct feature_builder *builder)
Definition: mvt.c:98
static VectorTile__Tile__Feature * feature_build(struct feature_builder *builder)
Definition: mvt.c:109
static void encode_feature_geometry(struct feature_builder *feature, LWGEOM *lwgeom)
Definition: mvt.c:286
uint32_t geom_index
Definition: mvt.h:72
size_t features_capacity
Definition: mvt.h:78
VectorTile__Tile__Layer * layer
Definition: mvt.h:76
HeapTupleHeader row
Definition: mvt.h:74

References encode_feature_geometry(), feature_build(), feature_init(), mvt_agg_context::features_capacity, mvt_agg_context::geom_index, mvt_agg_context::layer, lwgeom_free(), lwgeom_from_gserialized(), parse_column_keys(), parse_values(), mvt_agg_context::row, and UINT32_MAX.

Referenced by pgis_asmvt_transfn().

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