#define FEATURES_CAPACITY_INITIAL 50
-enum mvt_cmd_id {
+enum mvt_cmd_id
+{
CMD_MOVE_TO = 1,
CMD_LINE_TO = 2,
CMD_CLOSE_PATH = 7
};
-enum mvt_type {
+enum mvt_type
+{
MVT_POINT = 1,
MVT_LINE = 2,
MVT_RING = 3
};
-struct mvt_kv_key {
+struct mvt_kv_key
+{
char *name;
uint32_t id;
UT_hash_handle hh;
};
-struct mvt_kv_string_value {
+struct mvt_kv_string_value
+{
char *string_value;
uint32_t id;
UT_hash_handle hh;
};
-struct mvt_kv_float_value {
+struct mvt_kv_float_value
+{
float float_value;
uint32_t id;
UT_hash_handle hh;
};
-struct mvt_kv_double_value {
+struct mvt_kv_double_value
+{
double double_value;
uint32_t id;
UT_hash_handle hh;
};
-struct mvt_kv_uint_value {
+struct mvt_kv_uint_value
+{
uint64_t uint_value;
uint32_t id;
UT_hash_handle hh;
};
-struct mvt_kv_sint_value {
+struct mvt_kv_sint_value
+{
int64_t sint_value;
uint32_t id;
UT_hash_handle hh;
};
-struct mvt_kv_bool_value {
+struct mvt_kv_bool_value
+{
protobuf_c_boolean bool_value;
uint32_t id;
UT_hash_handle hh;
const POINT2D *p;
/* loop points and add to buffer */
- for (i = 0; i < pa->npoints; i++) {
+ for (i = 0; i < pa->npoints; i++)
+ {
/* move offset for command */
if (i == 0 || (i == 1 && type > MVT_POINT))
offset++;
}
/* determine initial move and eventual line command */
- if (type == MVT_POINT) {
+ if (type == MVT_POINT)
+ {
/* point or multipoint, use actual number of point count */
buffer[0] = c_int(CMD_MOVE_TO, c);
- } else {
+ }
+ else
+ {
/* line or polygon, assume count 1 */
buffer[0] = c_int(CMD_MOVE_TO, 1);
/* line command with move point subtracted from count */
{
int type = lwgeom->type;
- switch (type) {
+ switch (type)
+ {
case POINTTYPE:
return encode_point(ctx, (LWPOINT*)lwgeom);
case LINETYPE:
char *key;
POSTGIS_DEBUG(2, "parse_column_keys called");
- for (i = 0; i < natts; i++) {
+ for (i = 0; i < natts; i++)
+ {
#if POSTGIS_PGSQL_VERSION < 110
Oid typoid = getBaseType(tupdesc->attrs[i]->atttypid);
char *tkey = tupdesc->attrs[i]->attname.data;
continue;
#endif
key = pstrdup(tkey);
- if (ctx->geom_name == NULL) {
- if (!geom_found && typoid == TypenameGetTypid("geometry")) {
+ if (ctx->geom_name == NULL)
+ {
+ if (!geom_found && typoid == TypenameGetTypid("geometry"))
+ {
ctx->geom_index = i;
geom_found = true;
continue;
}
- } else {
- if (!geom_found && strcmp(key, ctx->geom_name) == 0) {
+ }
+ else
+ {
+ if (!geom_found && strcmp(key, ctx->geom_name) == 0)
+ {
ctx->geom_index = i;
geom_found = true;
continue;
POSTGIS_DEBUG(2, "encode_values called");
values = palloc(ctx->values_hash_i * sizeof(*values));
- for (kv = ctx->string_values_hash; kv != NULL; kv=kv->hh.next) {
+ for (kv = ctx->string_values_hash; kv != NULL; kv=kv->hh.next)
+ {
VectorTile__Tile__Value *value = create_value();
value->string_value = kv->string_value;
values[kv->id] = value;
{ \
struct kvtype *kv; \
HASH_FIND(hh, ctx->hash, &value, size, kv); \
- if (!kv) { \
+ if (!kv) \
+ { \
POSTGIS_DEBUG(4, "MVT_PARSE_VALUE value not found"); \
kv = palloc(sizeof(*kv)); \
POSTGIS_DEBUGF(4, "MVT_PARSE_VALUE new hash key: %d", \
kv->valuefield = value; \
HASH_ADD(hh, ctx->hash, valuefield, size, kv); \
} \
- tags[ctx->c*2] = k; \
- tags[ctx->c*2+1] = kv->id; \
+ tags[ctx->row_columns*2] = k; \
+ tags[ctx->row_columns*2+1] = kv->id; \
} \
}
#define MVT_PARSE_INT_VALUE(value) \
{ \
- if (value >= 0) { \
+ if (value >= 0) \
+ { \
uint64_t cvalue = value; \
MVT_PARSE_VALUE(cvalue, mvt_kv_uint_value, \
uint_values_hash, uint_value, \
sizeof(uint64_t)) \
- } else { \
+ } \
+ else \
+ { \
int64_t cvalue = value; \
MVT_PARSE_VALUE(cvalue, mvt_kv_sint_value, \
sint_values_hash, sint_value, \
size_t size = strlen(value);
POSTGIS_DEBUG(2, "add_value_as_string called");
HASH_FIND(hh, ctx->string_values_hash, value, size, kv);
- if (!kv) {
+ if (!kv)
+ {
POSTGIS_DEBUG(4, "add_value_as_string value not found");
kv = palloc(sizeof(*kv));
POSTGIS_DEBUGF(4, "add_value_as_string new hash key: %d",
HASH_ADD_KEYPTR(hh, ctx->string_values_hash, kv->string_value,
size, kv);
}
- tags[ctx->c*2] = k;
- tags[ctx->c*2+1] = kv->id;
+ tags[ctx->row_columns*2] = k;
+ tags[ctx->row_columns*2+1] = kv->id;
}
static void parse_datum_as_string(mvt_agg_context *ctx, Oid typoid,
it = JsonbIteratorInit(&jb->root);
- while ((r = JsonbIteratorNext(&it, &v, skipNested)) != WJB_DONE) {
+ while ((r = JsonbIteratorNext(&it, &v, skipNested)) != WJB_DONE)
+ {
skipNested = true;
- if (r == WJB_KEY && v.type != jbvNull) {
+ if (r == WJB_KEY && v.type != jbvNull)
+ {
char *key;
key = palloc(v.val.string.len + 1 * sizeof(char));
memcpy(key, v.val.string.val, v.val.string.len);
key[v.val.string.len] = '\0';
k = get_key_index(ctx, key);
- if (k == UINT32_MAX) {
+ if (k == UINT32_MAX)
+ {
uint32_t newSize = ctx->keys_hash_i + 1;
tags = repalloc(tags, newSize * 2 * sizeof(*tags));
k = add_key(ctx, key);
r = JsonbIteratorNext(&it, &v, skipNested);
- if (v.type == jbvString) {
+ if (v.type == jbvString)
+ {
char *value;
value = palloc(v.val.string.len + 1 * sizeof(char));
memcpy(value, v.val.string.val, v.val.string.len);
value[v.val.string.len] = '\0';
add_value_as_string(ctx, value, tags, k);
- ctx->c++;
- } else if (v.type == jbvBool) {
+ ctx->row_columns++;
+ }
+ else if (v.type == jbvBool)
+ {
MVT_PARSE_VALUE(v.val.boolean, mvt_kv_bool_value,
bool_values_hash, bool_value, sizeof(protobuf_c_boolean));
- ctx->c++;
- } else if (v.type == jbvNumeric) {
+ ctx->row_columns++;
+ }
+ else if (v.type == jbvNumeric)
+ {
char *str;
double d;
long l;
PointerGetDatum(v.val.numeric)));
d = strtod(str, NULL);
l = strtol(str, NULL, 10);
- if ((long) d != l) {
+ if ((long) d != l)
+ {
MVT_PARSE_VALUE(d, mvt_kv_double_value, double_values_hash,
double_value, sizeof(double));
- } else {
+ }
+ else
+ {
MVT_PARSE_INT_VALUE(l);
}
- ctx->c++;
+ ctx->row_columns++;
}
}
}
uint32_t i, k;
TupleDesc tupdesc = get_tuple_desc(ctx);
uint32_t natts = (uint32_t) tupdesc->natts;
- ctx->c = 0;
+ ctx->row_columns = 0;
POSTGIS_DEBUG(2, "parse_values called");
POSTGIS_DEBUGF(3, "parse_values natts: %d", natts);
- for (i = 0; i < natts; i++) {
+ for (i = 0; i < natts; i++)
+ {
char *key;
Oid typoid;
Datum datum;
#endif
datum = GetAttributeByNum(ctx->row, i+1, &isnull);
k = get_key_index(ctx, key);
- if (isnull) {
+ if (isnull)
+ {
POSTGIS_DEBUG(3, "parse_values isnull detected");
continue;
}
#if POSTGIS_PGSQL_VERSION >= 94
if (k == UINT32_MAX && typoid != JSONBOID)
elog(ERROR, "parse_values: unexpectedly could not find parsed key name '%s'", key);
- if (typoid == JSONBOID) {
+ if (typoid == JSONBOID)
+ {
tags = parse_jsonb(ctx, DatumGetJsonbP(datum), tags);
continue;
}
elog(ERROR, "parse_values: unexpectedly could not find parsed key name '%s'", key);
#endif
- switch (typoid) {
+ switch (typoid)
+ {
case BOOLOID:
MVT_PARSE_DATUM(protobuf_c_boolean, mvt_kv_bool_value,
bool_values_hash, bool_value,
parse_datum_as_string(ctx, typoid, datum, tags, k);
break;
}
- ctx->c++;
+ ctx->row_columns++;
}
ReleaseTupleDesc(tupdesc);
- ctx->feature->n_tags = ctx->c * 2;
+ ctx->feature->n_tags = ctx->row_columns * 2;
ctx->feature->tags = tags;
POSTGIS_DEBUGF(3, "parse_values n_tags %zd", ctx->feature->n_tags);
gc = lwcollection_extract(g, maxtype);
*g = *gc;
}
- return;
}
/**
/* VectorTile__Tile__Feature **features = layer->features; */
POSTGIS_DEBUG(2, "mvt_agg_transfn called");
- if (layer->n_features >= ctx->features_capacity) {
+ if (layer->n_features >= ctx->features_capacity)
+ {
size_t new_capacity = ctx->features_capacity * 2;
layer->features = repalloc(layer->features, new_capacity *
sizeof(*layer->features));
mvt_agg_context * mvt_ctx_deserialize(const bytea *ba)
{
- ProtobufCAllocator allocator = {
+ ProtobufCAllocator allocator =
+ {
mvt_allocator,
mvt_deallocator,
NULL