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

◆ inspect_table()

static void inspect_table ( struct flatgeobuf_agg_ctx ctx)
static

Definition at line 68 of file flatgeobuf.c.

69{
70 flatgeobuf_column *c;
71 flatgeobuf_column **columns;
72 uint32_t columns_size = 0;
73 Oid tupType = HeapTupleHeaderGetTypeId(ctx->row);
74 int32 tupTypmod = HeapTupleHeaderGetTypMod(ctx->row);
75 TupleDesc tupdesc = lookup_rowtype_tupdesc(tupType, tupTypmod);
76 int natts = tupdesc->natts;
77 bool geom_found = false;
78
79 POSTGIS_DEBUG(2, "calling inspect_table");
80
81 columns = palloc(sizeof(flatgeobuf_column *) * natts);
82 ctx->tupdesc = tupdesc;
83
84 // inspect columns
85 // NOTE: last element will be unused if geom attr is found
86 for (int i = 0; i < natts; i++) {
87 Oid typoid = getBaseType(TupleDescAttr(tupdesc, i)->atttypid);
88 const char *key = TupleDescAttr(tupdesc, i)->attname.data;
89 POSTGIS_DEBUGF(2, "inspecting column definition for %s with oid %d", key, typoid);
90 if (ctx->geom_name == NULL) {
91 if (!geom_found && typoid == postgis_oid(GEOMETRYOID)) {
92 ctx->geom_index = i;
93 geom_found = true;
94 continue;
95 }
96 } else {
97 if (!geom_found && strcmp(key, ctx->geom_name) == 0) {
98 ctx->geom_index = i;
99 geom_found = true;
100 continue;
101 }
102 }
103 POSTGIS_DEBUGF(2, "creating column definition for %s with oid %d", key, typoid);
104
105 c = (flatgeobuf_column *) palloc0(sizeof(flatgeobuf_column));
106 c->name = pstrdup(key);
107 c->type = get_column_type(typoid);
108 columns[columns_size] = c;
109 columns_size++;
110 }
111
112 if (!geom_found)
113 elog(ERROR, "no geom column found");
114
115 if (columns_size > 0) {
116 ctx->ctx->columns = columns;
117 ctx->ctx->columns_size = columns_size;
118 }
119}
static uint8_t get_column_type(Oid typoid)
Definition flatgeobuf.c:36
unsigned int int32
Definition shpopen.c:54
HeapTupleHeader row
Definition flatgeobuf.h:52
const char * geom_name
Definition flatgeobuf.h:49
flatgeobuf_ctx * ctx
Definition flatgeobuf.h:48
uint32_t geom_index
Definition flatgeobuf.h:50
TupleDesc tupdesc
Definition flatgeobuf.h:51

References flatgeobuf_agg_ctx::ctx, flatgeobuf_agg_ctx::geom_index, flatgeobuf_agg_ctx::geom_name, get_column_type(), flatgeobuf_agg_ctx::row, and flatgeobuf_agg_ctx::tupdesc.

Referenced by flatgeobuf_agg_transfn().

Here is the call graph for this function:
Here is the caller graph for this function: