]> granicus.if.org Git - postgis/commitdiff
MVT: Uniformize style and rename mvt_agg_context 'c'
authorRaúl Marín Rodríguez <rmrodriguez@carto.com>
Fri, 10 Aug 2018 11:33:36 +0000 (11:33 +0000)
committerRaúl Marín Rodríguez <rmrodriguez@carto.com>
Fri, 10 Aug 2018 11:33:36 +0000 (11:33 +0000)
References #4145
Closes https://github.com/postgis/postgis/pull/285

git-svn-id: http://svn.osgeo.org/postgis/trunk@16684 b70326c6-7e19-0410-871a-916f4a2858ee

postgis/mvt.c
postgis/mvt.h

index d36191135be83be78ad16e57c9aab41a330b0871..475e797098af84802f19ee4263d69963c7325dda 100644 (file)
 
 #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;
@@ -113,7 +122,8 @@ static uint32_t encode_ptarray(__attribute__((__unused__)) mvt_agg_context *ctx,
        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++;
@@ -133,10 +143,13 @@ static uint32_t encode_ptarray(__attribute__((__unused__)) mvt_agg_context *ctx,
        }
 
        /* 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 */
@@ -255,7 +268,8 @@ static void encode_geometry(mvt_agg_context *ctx, LWGEOM *lwgeom)
 {
        int type = lwgeom->type;
 
-       switch (type) {
+       switch (type)
+       {
        case POINTTYPE:
                return encode_point(ctx, (LWPOINT*)lwgeom);
        case LINETYPE:
@@ -311,7 +325,8 @@ static void parse_column_keys(mvt_agg_context *ctx)
        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;
@@ -324,14 +339,19 @@ static void parse_column_keys(mvt_agg_context *ctx)
                        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;
@@ -386,7 +406,8 @@ static void encode_values(mvt_agg_context *ctx)
        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;
@@ -420,7 +441,8 @@ static void encode_values(mvt_agg_context *ctx)
        { \
                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", \
@@ -429,19 +451,22 @@ static void encode_values(mvt_agg_context *ctx)
                        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, \
@@ -468,7 +493,8 @@ static void add_value_as_string(mvt_agg_context *ctx,
        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",
@@ -478,8 +504,8 @@ static void add_value_as_string(mvt_agg_context *ctx,
                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,
@@ -510,17 +536,20 @@ static uint32_t *parse_jsonb(mvt_agg_context *ctx, Jsonb *jb,
 
        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);
@@ -528,18 +557,23 @@ static uint32_t *parse_jsonb(mvt_agg_context *ctx, Jsonb *jb,
 
                        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;
@@ -547,13 +581,16 @@ static uint32_t *parse_jsonb(mvt_agg_context *ctx, Jsonb *jb,
                                        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++;
                        }
                }
        }
@@ -570,12 +607,13 @@ static void parse_values(mvt_agg_context *ctx)
        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;
@@ -592,14 +630,16 @@ static void parse_values(mvt_agg_context *ctx)
 #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;
                }
@@ -608,7 +648,8 @@ static void parse_values(mvt_agg_context *ctx)
                        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,
@@ -637,12 +678,12 @@ static void parse_values(mvt_agg_context *ctx)
                        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);
@@ -678,7 +719,6 @@ lwgeom_to_basic_type(LWGEOM *geom)
                gc = lwcollection_extract(g, maxtype);
                *g = *gc;
        }
-       return;
 }
 
 /**
@@ -847,7 +887,8 @@ void mvt_agg_transfn(mvt_agg_context *ctx)
 /*     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));
@@ -948,7 +989,8 @@ static void mvt_deallocator(__attribute__((__unused__)) void *data, void *ptr)
 
 mvt_agg_context * mvt_ctx_deserialize(const bytea *ba)
 {
-       ProtobufCAllocator allocator = {
+       ProtobufCAllocator allocator =
+       {
                mvt_allocator,
                mvt_deallocator,
                NULL
index 86c56a914b5102f89a21131a1e3eb29e0e39ee5e..48fbc79469ea590c0f7ddb3acc695595e2c8f1b1 100644 (file)
@@ -46,7 +46,8 @@
 
 #include "vector_tile.pb-c.h"
 
-typedef struct mvt_agg_context {
+typedef struct mvt_agg_context
+{
        char *name;
        uint32_t extent;
        char *geom_name;
@@ -65,7 +66,7 @@ typedef struct mvt_agg_context {
        struct mvt_kv_bool_value *bool_values_hash;
        uint32_t values_hash_i;
        uint32_t keys_hash_i;
-       uint32_t c;
+       uint32_t row_columns;
 } mvt_agg_context;
 
 /* Prototypes */