PostGIS  3.4.0dev-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 1031 of file mvt.c.

1032 {
1033  bool isnull = false;
1034  Datum datum;
1035  GSERIALIZED *gs;
1036  LWGEOM *lwgeom;
1038  VectorTile__Tile__Layer *layer = ctx->layer;
1039  POSTGIS_DEBUG(2, "mvt_agg_transfn called");
1040 
1041  /* geom_index is the cached index of the geometry. if missing, it needs to be initialized */
1042  if (ctx->geom_index == UINT32_MAX)
1043  parse_column_keys(ctx);
1044 
1045  /* Get the geometry column */
1046  datum = GetAttributeByNum(ctx->row, ctx->geom_index + 1, &isnull);
1047  if (isnull) /* Skip rows that have null geometry */
1048  return;
1049 
1050  /* Allocate a new feature object */
1052 
1053  /* Deserialize the geometry */
1054  gs = (GSERIALIZED *) PG_DETOAST_DATUM(datum);
1055  lwgeom = lwgeom_from_gserialized(gs);
1056 
1057  /* Set the geometry of the feature */
1059  lwgeom_free(lwgeom);
1060  // TODO: free detoasted datum?
1061 
1062  /* Parse properties */
1064 
1065  /* Grow the features array of the layer */
1066  POSTGIS_DEBUGF(3, "mvt_agg_transfn encoded feature count: %zd", layer->n_features);
1067  if (layer->n_features >= ctx->features_capacity)
1068  {
1069  size_t new_capacity = ctx->features_capacity * 2;
1070  layer->features = repalloc(layer->features, new_capacity *
1071  sizeof(*layer->features));
1072  ctx->features_capacity = new_capacity;
1073  POSTGIS_DEBUGF(3, "mvt_agg_transfn new_capacity: %zd", new_capacity);
1074  }
1075 
1076  /* Build and add the feature to the layer */
1077  layer->features[layer->n_features++] = feature_build(&feature_builder);
1078 }
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: