PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ 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 1030 of file mvt.c.

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