PostGIS  3.1.6dev-r@@SVN_REVISION@@

◆ mvt_agg_transfn()

void mvt_agg_transfn ( mvt_agg_context ctx)

Aggregation step.

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

1240 {
1241  bool isnull = false;
1242  Datum datum;
1243  GSERIALIZED *gs;
1244  LWGEOM *lwgeom;
1245  VectorTile__Tile__Feature *feature;
1246  VectorTile__Tile__Layer *layer = ctx->layer;
1247 /* VectorTile__Tile__Feature **features = layer->features; */
1248  POSTGIS_DEBUG(2, "mvt_agg_transfn called");
1249 
1250  if (layer->n_features >= ctx->features_capacity)
1251  {
1252  size_t new_capacity = ctx->features_capacity * 2;
1253  layer->features = repalloc(layer->features, new_capacity *
1254  sizeof(*layer->features));
1255  ctx->features_capacity = new_capacity;
1256  POSTGIS_DEBUGF(3, "mvt_agg_transfn new_capacity: %zd", new_capacity);
1257  }
1258 
1259  if (ctx->geom_index == UINT32_MAX)
1260  parse_column_keys(ctx);
1261 
1262  datum = GetAttributeByNum(ctx->row, ctx->geom_index + 1, &isnull);
1263  POSTGIS_DEBUGF(3, "mvt_agg_transfn ctx->geom_index: %d", ctx->geom_index);
1264  POSTGIS_DEBUGF(3, "mvt_agg_transfn isnull: %u", isnull);
1265  POSTGIS_DEBUGF(3, "mvt_agg_transfn datum: %lu", datum);
1266  if (isnull) /* Skip rows that have null geometry */
1267  {
1268  POSTGIS_DEBUG(3, "mvt_agg_transfn got null geom");
1269  return;
1270  }
1271 
1272  feature = palloc(sizeof(*feature));
1273  vector_tile__tile__feature__init(feature);
1274 
1275  ctx->feature = feature;
1276 
1277  gs = (GSERIALIZED *) PG_DETOAST_DATUM(datum);
1278  lwgeom = lwgeom_from_gserialized(gs);
1279 
1280  POSTGIS_DEBUGF(3, "mvt_agg_transfn encoded feature count: %zd", layer->n_features);
1281  layer->features[layer->n_features++] = feature;
1282 
1283  encode_geometry(ctx, lwgeom);
1284  lwgeom_free(lwgeom);
1285  // TODO: free detoasted datum?
1286  parse_values(ctx);
1287 }
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:1138
#define UINT32_MAX
Definition: lwin_wkt_lex.c:343
static void encode_geometry(mvt_agg_context *ctx, LWGEOM *lwgeom)
Definition: mvt.c:235
static void parse_column_keys(mvt_agg_context *ctx)
Definition: mvt.c:286
static void parse_values(mvt_agg_context *ctx)
Definition: mvt.c:630
uint32_t geom_index
Definition: mvt.h:72
size_t features_capacity
Definition: mvt.h:78
VectorTile__Tile__Layer * layer
Definition: mvt.h:76
VectorTile__Tile__Feature * feature
Definition: mvt.h:75
HeapTupleHeader row
Definition: mvt.h:74

References encode_geometry(), mvt_agg_context::feature, 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: