PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ mvt_agg_transfn()

void mvt_agg_transfn ( struct 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 888 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().

889 {
890  bool isnull = false;
891  Datum datum;
892  GSERIALIZED *gs;
893  LWGEOM *lwgeom;
894  VectorTile__Tile__Feature *feature;
895  VectorTile__Tile__Layer *layer = ctx->layer;
896  POSTGIS_DEBUG(2, "mvt_agg_transfn called");
897 
898  if (layer->n_features >= ctx->features_capacity) {
899  size_t new_capacity = ctx->features_capacity * 2;
900  layer->features = repalloc(layer->features, new_capacity *
901  sizeof(*layer->features));
902  ctx->features_capacity = new_capacity;
903  POSTGIS_DEBUGF(3, "mvt_agg_transfn new_capacity: %zd", new_capacity);
904  }
905 
906  if (ctx->geom_index == UINT32_MAX)
907  parse_column_keys(ctx);
908 
909  datum = GetAttributeByNum(ctx->row, ctx->geom_index + 1, &isnull);
910  POSTGIS_DEBUGF(3, "mvt_agg_transfn ctx->geom_index: %d", ctx->geom_index);
911  POSTGIS_DEBUGF(3, "mvt_agg_transfn isnull: %u", isnull);
912  POSTGIS_DEBUGF(3, "mvt_agg_transfn datum: %lu", datum);
913  if (isnull) /* Skip rows that have null geometry */
914  {
915  POSTGIS_DEBUG(3, "mvt_agg_transfn got null geom");
916  return;
917  }
918 
919  feature = palloc(sizeof(*feature));
920  vector_tile__tile__feature__init(feature);
921 
922  ctx->feature = feature;
923 
924  gs = (GSERIALIZED *) PG_DETOAST_DATUM(datum);
925  lwgeom = lwgeom_from_gserialized(gs);
926 
927  POSTGIS_DEBUGF(3, "mvt_agg_transfn encoded feature count: %zd", layer->n_features);
928  layer->features[layer->n_features++] = feature;
929 
930  encode_geometry(ctx, lwgeom);
931  lwgeom_free(lwgeom);
932  // TODO: free detoasted datum?
933  parse_values(ctx);
934 }
static void parse_values(struct mvt_agg_context *ctx)
Definition: mvt.c:556
HeapTupleHeader row
Definition: mvt.h:54
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1099
static void parse_column_keys(struct mvt_agg_context *ctx)
Definition: mvt.c:304
VectorTile__Tile__Layer * layer
Definition: mvt.h:56
size_t features_capacity
Definition: mvt.h:57
static void encode_geometry(struct mvt_agg_context *ctx, LWGEOM *lwgeom)
Definition: mvt.c:253
#define UINT32_MAX
Definition: lwin_wkt_lex.c:343
uint32_t geom_index
Definition: mvt.h:53
VectorTile__Tile__Feature * feature
Definition: mvt.h:55
Here is the call graph for this function:
Here is the caller graph for this function: