PostGIS  2.5.0beta2dev-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 839 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(), and mvt_agg_context::row.

Referenced by pgis_asmvt_transfn().

840 {
841  bool isnull = false;
842  Datum datum;
843  GSERIALIZED *gs;
844  LWGEOM *lwgeom;
845  VectorTile__Tile__Feature *feature;
846  VectorTile__Tile__Layer *layer = ctx->layer;
847 /* VectorTile__Tile__Feature **features = layer->features; */
848  POSTGIS_DEBUG(2, "mvt_agg_transfn called");
849 
850  if (layer->n_features >= ctx->features_capacity) {
851  size_t new_capacity = ctx->features_capacity * 2;
852  layer->features = repalloc(layer->features, new_capacity *
853  sizeof(*layer->features));
854  ctx->features_capacity = new_capacity;
855  POSTGIS_DEBUGF(3, "mvt_agg_transfn new_capacity: %zd", new_capacity);
856  }
857 
858  if (layer->n_features == 0)
859  parse_column_keys(ctx);
860 
861  datum = GetAttributeByNum(ctx->row, ctx->geom_index + 1, &isnull);
862  POSTGIS_DEBUGF(3, "mvt_agg_transfn ctx->geom_index: %d", ctx->geom_index);
863  POSTGIS_DEBUGF(3, "mvt_agg_transfn isnull: %u", isnull);
864  POSTGIS_DEBUGF(3, "mvt_agg_transfn datum: %lu", datum);
865  if (isnull) /* Skip rows that have null geometry */
866  {
867  POSTGIS_DEBUG(3, "mvt_agg_transfn got null geom");
868  return;
869  }
870 
871  feature = palloc(sizeof(*feature));
872  vector_tile__tile__feature__init(feature);
873 
874  ctx->feature = feature;
875 
876  gs = (GSERIALIZED *) PG_DETOAST_DATUM(datum);
877  lwgeom = lwgeom_from_gserialized(gs);
878 
879  POSTGIS_DEBUGF(3, "mvt_agg_transfn encoded feature count: %zd", layer->n_features);
880  layer->features[layer->n_features++] = feature;
881 
882  encode_geometry(ctx, lwgeom);
883  lwgeom_free(lwgeom);
884  // TODO: free detoasted datum?
885  parse_values(ctx);
886 }
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:1144
static void parse_values(mvt_agg_context *ctx)
Definition: mvt.c:565
VectorTile__Tile__Layer * layer
Definition: mvt.h:56
size_t features_capacity
Definition: mvt.h:58
uint32_t geom_index
Definition: mvt.h:53
VectorTile__Tile__Feature * feature
Definition: mvt.h:55
static void parse_column_keys(mvt_agg_context *ctx)
Definition: mvt.c:305
static void encode_geometry(mvt_agg_context *ctx, LWGEOM *lwgeom)
Definition: mvt.c:254
Here is the call graph for this function:
Here is the caller graph for this function: