PostGIS  2.5.1dev-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 963 of file mvt.c.

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().

964 {
965  bool isnull = false;
966  Datum datum;
967  GSERIALIZED *gs;
968  LWGEOM *lwgeom;
969  VectorTile__Tile__Feature *feature;
970  VectorTile__Tile__Layer *layer = ctx->layer;
971 /* VectorTile__Tile__Feature **features = layer->features; */
972  POSTGIS_DEBUG(2, "mvt_agg_transfn called");
973 
974  if (layer->n_features >= ctx->features_capacity)
975  {
976  size_t new_capacity = ctx->features_capacity * 2;
977  layer->features = repalloc(layer->features, new_capacity *
978  sizeof(*layer->features));
979  ctx->features_capacity = new_capacity;
980  POSTGIS_DEBUGF(3, "mvt_agg_transfn new_capacity: %zd", new_capacity);
981  }
982 
983  if (ctx->geom_index == UINT32_MAX)
984  parse_column_keys(ctx);
985 
986  datum = GetAttributeByNum(ctx->row, ctx->geom_index + 1, &isnull);
987  POSTGIS_DEBUGF(3, "mvt_agg_transfn ctx->geom_index: %d", ctx->geom_index);
988  POSTGIS_DEBUGF(3, "mvt_agg_transfn isnull: %u", isnull);
989  POSTGIS_DEBUGF(3, "mvt_agg_transfn datum: %lu", datum);
990  if (isnull) /* Skip rows that have null geometry */
991  {
992  POSTGIS_DEBUG(3, "mvt_agg_transfn got null geom");
993  return;
994  }
995 
996  feature = palloc(sizeof(*feature));
997  vector_tile__tile__feature__init(feature);
998 
999  ctx->feature = feature;
1000 
1001  gs = (GSERIALIZED *) PG_DETOAST_DATUM(datum);
1002  lwgeom = lwgeom_from_gserialized(gs);
1003 
1004  POSTGIS_DEBUGF(3, "mvt_agg_transfn encoded feature count: %zd", layer->n_features);
1005  layer->features[layer->n_features++] = feature;
1006 
1007  encode_geometry(ctx, lwgeom);
1008  lwgeom_free(lwgeom);
1009  // TODO: free detoasted datum?
1010  parse_values(ctx);
1011 }
HeapTupleHeader row
Definition: mvt.h:64
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1144
static void parse_values(mvt_agg_context *ctx)
Definition: mvt.c:629
VectorTile__Tile__Layer * layer
Definition: mvt.h:66
size_t features_capacity
Definition: mvt.h:68
#define UINT32_MAX
Definition: lwin_wkt_lex.c:343
uint32_t geom_index
Definition: mvt.h:63
VectorTile__Tile__Feature * feature
Definition: mvt.h:65
static void parse_column_keys(mvt_agg_context *ctx)
Definition: mvt.c:318
static void encode_geometry(mvt_agg_context *ctx, LWGEOM *lwgeom)
Definition: mvt.c:267
Here is the call graph for this function:
Here is the caller graph for this function: