32 #include "pgsql_compat.h"
34 #ifdef HAVE_LIBPROTOBUF
35 #include "utils/jsonb.h"
37 #if POSTGIS_PGSQL_VERSION < 110
39 # define DatumGetJsonbP DatumGetJsonb
42 #define uthash_fatal(msg) lwerror("uthash: fatal error (out of memory)")
43 #define uthash_malloc(sz) palloc(sz)
44 #define uthash_free(ptr,sz) pfree(ptr)
48 #include "vector_tile.pb-c.h"
50 #define FEATURES_CAPACITY_INITIAL 50
74 VectorTile__Tile__Value
value[1];
81 return (
id & 0x7) | (
count << 3);
91 int32_t *px, int32_t *py)
99 for (i = 0; i < pa->
npoints; i++)
144 int32_t px = 0, py = 0;
150 VectorTile__Tile__Feature *feature = ctx->
feature;
151 feature->type = VECTOR_TILE__TILE__GEOM_TYPE__POINT;
152 feature->n_geometry = 3;
153 feature->geometry = palloc(
sizeof(*feature->geometry) * 3);
160 VectorTile__Tile__Feature *feature = ctx->
feature;
163 feature->type = VECTOR_TILE__TILE__GEOM_TYPE__POINT;
165 feature->geometry = palloc(
sizeof(*feature->geometry) * c);
167 lwline->
points, feature->geometry);
173 VectorTile__Tile__Feature *feature = ctx->
feature;
174 feature->type = VECTOR_TILE__TILE__GEOM_TYPE__LINESTRING;
176 feature->geometry = palloc(
sizeof(*feature->geometry) * c);
178 lwline->
points, feature->geometry);
184 int32_t px = 0, py = 0;
185 size_t c = 0, offset = 0;
186 VectorTile__Tile__Feature *feature = ctx->
feature;
187 feature->type = VECTOR_TILE__TILE__GEOM_TYPE__LINESTRING;
188 for (i = 0; i < lwmline->
ngeoms; i++)
190 feature->geometry = palloc(
sizeof(*feature->geometry) * c);
191 for (i = 0; i < lwmline->
ngeoms; i++)
194 feature->geometry + offset, &px, &py);
195 feature->n_geometry = offset;
201 int32_t px = 0, py = 0;
202 size_t c = 0, offset = 0;
203 VectorTile__Tile__Feature *feature = ctx->
feature;
204 feature->type = VECTOR_TILE__TILE__GEOM_TYPE__POLYGON;
205 for (i = 0; i < lwpoly->
nrings; i++)
207 feature->geometry = palloc(
sizeof(*feature->geometry) * c);
208 for (i = 0; i < lwpoly->
nrings; i++)
211 feature->geometry + offset, &px, &py);
212 feature->n_geometry = offset;
218 int32_t px = 0, py = 0;
219 size_t c = 0, offset = 0;
221 VectorTile__Tile__Feature *feature = ctx->
feature;
222 feature->type = VECTOR_TILE__TILE__GEOM_TYPE__POLYGON;
223 for (i = 0; i < lwmpoly->
ngeoms; i++)
224 for (j = 0; poly = lwmpoly->
geoms[i], j < poly->
nrings; j++)
226 feature->geometry = palloc(
sizeof(*feature->geometry) * c);
227 for (i = 0; i < lwmpoly->
ngeoms; i++)
228 for (j = 0; poly = lwmpoly->
geoms[i], j < poly->
nrings; j++)
230 poly->
rings[j], feature->geometry + offset,
232 feature->n_geometry = offset;
253 default: elog(ERROR,
"encode_geometry: '%s' geometry type not supported",
260 Oid tupType = HeapTupleHeaderGetTypeId(ctx->
row);
261 int32 tupTypmod = HeapTupleHeaderGetTypMod(ctx->
row);
262 TupleDesc tupdesc = lookup_rowtype_tupdesc(tupType, tupTypmod);
278 size_t size = strlen(
name);
279 kv = palloc(
sizeof(*kv));
289 bool geom_found =
false;
291 POSTGIS_DEBUG(2,
"parse_column_keys called");
301 for (i = 0; i < natts; i++)
308 if (typoid == JSONBOID)
316 if (!geom_found && typoid == postgis_oid(GEOMETRYOID))
325 if (!geom_found && strcmp(tkey, ctx->
geom_name) == 0)
335 (strcmp(tkey, ctx->
id_name) == 0) &&
336 (typoid == INT2OID || typoid == INT4OID || typoid == INT8OID))
347 elog(ERROR,
"parse_column_keys: no geometry column found");
350 elog(ERROR,
"mvt_agg_transfn: Could not find column '%s' of integer type", ctx->
id_name);
357 char **keys = palloc(n_keys *
sizeof(*keys));
358 for (kv = ctx->
keys_hash; kv != NULL; kv=kv->
hh.next)
360 ctx->
layer->n_keys = n_keys;
361 ctx->
layer->keys = keys;
366 #define MVT_CREATE_VALUES(hash) \
368 struct mvt_kv_value *kv; \
369 for (kv = hash; kv != NULL; kv = kv->hh.next) \
371 values[kv->id] = kv->value; \
377 VectorTile__Tile__Value **values;
378 POSTGIS_DEBUG(2,
"encode_values called");
388 POSTGIS_DEBUGF(3,
"encode_values n_values: %d", ctx->
values_hash_i);
390 ctx->
layer->values = values;
399 #define MVT_PARSE_VALUE(hash, newvalue, size, pfvaluefield, pftype) \
401 POSTGIS_DEBUG(2, "MVT_PARSE_VALUE called"); \
403 struct mvt_kv_value *kv; \
405 HASH_VALUE(&newvalue, size, hashv); \
406 HASH_FIND_BYHASHVALUE(hh, ctx->hash, &newvalue, size, hashv, kv); \
409 POSTGIS_DEBUG(4, "MVT_PARSE_VALUE value not found"); \
410 kv = palloc(sizeof(*kv)); \
411 POSTGIS_DEBUGF(4, "MVT_PARSE_VALUE new hash key: %d", ctx->values_hash_i); \
412 kv->id = ctx->values_hash_i++; \
413 vector_tile__tile__value__init(kv->value); \
414 kv->value->pfvaluefield = newvalue; \
415 kv->value->test_oneof_case = pftype; \
416 HASH_ADD_KEYPTR_BYHASHVALUE(hh, ctx->hash, &kv->value->pfvaluefield, size, hashv, kv); \
418 tags[ctx->row_columns * 2] = k; \
419 tags[ctx->row_columns * 2 + 1] = kv->id; \
423 #define MVT_PARSE_INT_VALUE(value) \
427 uint64_t cvalue = value; \
428 MVT_PARSE_VALUE(uint_values_hash, \
432 VECTOR_TILE__TILE__VALUE__TEST_ONEOF_UINT_VALUE); \
436 int64_t cvalue = value; \
437 MVT_PARSE_VALUE(sint_values_hash, \
441 VECTOR_TILE__TILE__VALUE__TEST_ONEOF_SINT_VALUE); \
445 #define MVT_PARSE_DATUM(type, datumfunc, hash, size, pfvaluefield, pftype) \
447 type value = datumfunc(datum); \
448 MVT_PARSE_VALUE(hash, value, size, pfvaluefield, pftype); \
451 #define MVT_PARSE_INT_DATUM(type, datumfunc) \
453 type value = datumfunc(datum); \
454 MVT_PARSE_INT_VALUE(value); \
463 HASH_VALUE(
value, size, hashv);
464 POSTGIS_DEBUG(2,
"add_value_as_string called");
468 POSTGIS_DEBUG(4,
"add_value_as_string value not found");
469 kv = palloc(
sizeof(*kv));
470 POSTGIS_DEBUGF(4,
"add_value_as_string new hash key: %d",
473 vector_tile__tile__value__init(kv->
value);
475 kv->
value->test_oneof_case = VECTOR_TILE__TILE__VALUE__TEST_ONEOF_STRING_VALUE;
500 POSTGIS_DEBUG(2,
"parse_value_as_string called");
501 getTypeOutputInfo(typoid, &foutoid, &typisvarlena);
502 value = OidOutputFunctionCall(foutoid, datum);
503 POSTGIS_DEBUGF(4,
"parse_value_as_string value: %s",
value);
512 bool skipNested =
false;
513 JsonbIteratorToken
r;
516 if (!JB_ROOT_IS_OBJECT(jb))
519 it = JsonbIteratorInit(&jb->root);
521 while ((
r = JsonbIteratorNext(&it, &v, skipNested)) != WJB_DONE)
525 if (
r == WJB_KEY && v.type != jbvNull)
534 key = palloc(v.val.string.len + 1);
535 memcpy(key, v.val.string.val, v.val.string.len);
536 key[v.val.string.len] =
'\0';
538 tags = repalloc(tags, newSize * 2 *
sizeof(*tags));
542 r = JsonbIteratorNext(&it, &v, skipNested);
544 if (v.type == jbvString)
546 char *
value = palloc(v.val.string.len + 1);
547 memcpy(
value, v.val.string.val, v.val.string.len);
548 value[v.val.string.len] =
'\0';
552 else if (v.type == jbvBool)
556 sizeof(protobuf_c_boolean),
558 VECTOR_TILE__TILE__VALUE__TEST_ONEOF_BOOL_VALUE);
561 else if (v.type == jbvNumeric)
566 str = DatumGetCString(DirectFunctionCall1(numeric_out,
567 PointerGetDatum(v.val.numeric)));
568 d = strtod(
str, NULL);
569 l = strtol(
str, NULL, 10);
571 if (fabs(d - (
double)l) > FLT_EPSILON)
577 VECTOR_TILE__TILE__VALUE__TEST_ONEOF_DOUBLE_VALUE);
597 int64_t
value = INT64_MIN;
601 POSTGIS_DEBUG(3,
"set_feature_id: Ignored null value");
608 value = DatumGetInt16(datum);
611 value = DatumGetInt32(datum);
614 value = DatumGetInt64(datum);
617 elog(ERROR,
"set_feature_id: Feature id type does not match");
622 POSTGIS_DEBUG(3,
"set_feature_id: Ignored negative value");
633 uint32_t *tags = palloc(n_keys * 2 *
sizeof(*tags));
636 uint32_t natts = (uint32_t) cc.
tupdesc->natts;
640 POSTGIS_DEBUG(2,
"parse_values called");
644 tuple.t_len = HeapTupleHeaderGetDatumLength(ctx->
row);
645 ItemPointerSetInvalid(&(tuple.t_self));
646 tuple.t_tableOid = InvalidOid;
647 tuple.t_data = ctx->
row;
652 POSTGIS_DEBUGF(3,
"parse_values natts: %d", natts);
654 for (i = 0; i < natts; i++)
659 Datum datum = cc.
values[i];
672 POSTGIS_DEBUG(3,
"parse_values isnull detected");
676 key = TupleDescAttr(cc.
tupdesc, i)->attname.data;
681 elog(ERROR,
"parse_values: unexpectedly could not find parsed key name '%s'", key);
682 if (typoid == JSONBOID)
694 sizeof(protobuf_c_boolean),
696 VECTOR_TILE__TILE__VALUE__TEST_ONEOF_BOOL_VALUE);
713 VECTOR_TILE__TILE__VALUE__TEST_ONEOF_FLOAT_VALUE);
721 VECTOR_TILE__TILE__VALUE__TEST_ONEOF_DOUBLE_VALUE);
741 POSTGIS_DEBUGF(3,
"parse_values n_tags %zd", ctx->
feature->n_tags);
760 return geom->
type - 3;
767 for (i = 0; i < g->
ngeoms; i++)
775 elog(ERROR,
"%s: Invalid type (%d)", __func__, geom->
type);
802 geom_out = g->
geoms[0];
823 POSTGIS_DEBUG(3,
"mvt_geom: geometry outside clip box");
829 POSTGIS_DEBUG(3,
"mvt_geom: geometry contained fully inside the box");
849 LWGEOM *geom_clipped, *envelope;
851 GEOSGeometry *geos_input, *geos_box, *geos_result;
859 POSTGIS_DEBUG(3,
"mvt_geom: geometry outside clip box");
865 POSTGIS_DEBUG(3,
"mvt_geom: geometry contained fully inside the box");
879 GEOSGeom_destroy(geos_input);
883 geos_result = GEOSIntersection(geos_input, geos_box);
886 POSTGIS_DEBUG(3,
"mvt_geom: no geometry after intersection. Retrying after validation");
887 GEOSGeom_destroy(geos_input);
891 GEOSGeom_destroy(geos_box);
894 geos_result = GEOSIntersection(geos_input, geos_box);
897 GEOSGeom_destroy(geos_box);
898 GEOSGeom_destroy(geos_input);
903 GEOSSetSRID(geos_result, lwg_in->
srid);
906 GEOSGeom_destroy(geos_box);
907 GEOSGeom_destroy(geos_input);
908 GEOSGeom_destroy(geos_result);
912 POSTGIS_DEBUG(3,
"mvt_geom: no geometry after clipping");
951 for (i = 0; i < lwmg->
ngeoms; i++)
986 gridspec grid = {0, 0, 0, 0, 1, 1, 0, 0};
1002 uint32_t iterations = 0;
1003 static const uint32_t max_iterations = 3;
1013 valid = GEOSisValid(geo) == 1;
1015 while (!valid && iterations < max_iterations)
1017 #if POSTGIS_GEOS_VERSION < 38
1018 GEOSGeometry *geo_valid = LWGEOM_GEOS_makeValid(geo);
1020 GEOSGeometry *geo_valid = GEOSMakeValid(geo);
1023 GEOSGeom_destroy(geo);
1028 GEOSGeom_destroy(geo_valid);
1035 valid = GEOSisValid(geo) == 1;
1038 GEOSGeom_destroy(geo);
1042 POSTGIS_DEBUG(1,
"mvt_geom: Could not transform into a valid MVT geometry");
1072 POSTGIS_DEBUG(3,
"mvt_geom: no geometry after clip");
1083 POSTGIS_DEBUG(1,
"mvt_geom: Dropping geometry after type change");
1092 #include "lwgeom_wagyu.h"
1097 GBOX clip_box = {0};
1118 clipped_lwgeom = lwgeom_wagyu_clip_by_box(lwgeom, &clip_box);
1120 return clipped_lwgeom;
1143 AFFINE affine = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
1144 gridspec grid = {0, 0, 0, 0, 1, 1, 0, 0};
1145 double width = gbox->
xmax - gbox->
xmin;
1146 double height = gbox->
ymax - gbox->
ymin;
1147 double resx, resy,
res, fx, fy;
1150 POSTGIS_DEBUG(2,
"mvt_geom called");
1159 resx = width / extent;
1160 resy = height / extent;
1161 res = (resx < resy ? resx : resy)/2;
1162 fx = extent / width;
1163 fy = -(extent / height);
1199 VectorTile__Tile__Layer *layer;
1201 POSTGIS_DEBUG(2,
"mvt_agg_init_context called");
1204 elog(ERROR,
"mvt_agg_init_context: extent cannot be 0");
1222 layer = palloc(
sizeof(*layer));
1223 vector_tile__tile__layer__init(layer);
1225 layer->name = ctx->
name;
1226 layer->extent = ctx->
extent;
1241 bool isnull =
false;
1245 VectorTile__Tile__Feature *feature;
1246 VectorTile__Tile__Layer *layer = ctx->
layer;
1248 POSTGIS_DEBUG(2,
"mvt_agg_transfn called");
1253 layer->features = repalloc(layer->features, new_capacity *
1254 sizeof(*layer->features));
1256 POSTGIS_DEBUGF(3,
"mvt_agg_transfn new_capacity: %zd", new_capacity);
1262 datum = GetAttributeByNum(ctx->
row, ctx->
geom_index + 1, &isnull);
1263 POSTGIS_DEBUGF(3,
"mvt_agg_transfn ctx->geom_index: %d", ctx->
geom_index);
1264 POSTGIS_DEBUGF(3,
"mvt_agg_transfn isnull: %u", isnull);
1265 POSTGIS_DEBUGF(3,
"mvt_agg_transfn datum: %lu", datum);
1268 POSTGIS_DEBUG(3,
"mvt_agg_transfn got null geom");
1272 feature = palloc(
sizeof(*feature));
1273 vector_tile__tile__feature__init(feature);
1280 POSTGIS_DEBUGF(3,
"mvt_agg_transfn encoded feature count: %zd", layer->n_features);
1281 layer->features[layer->n_features++] = feature;
1292 VectorTile__Tile *tile;
1296 tile = palloc(
sizeof(VectorTile__Tile));
1297 vector_tile__tile__init(tile);
1298 tile->layers = palloc(
sizeof(VectorTile__Tile__Layer*) * n_layers);
1299 tile->layers[0] = ctx->
layer;
1300 tile->n_layers = n_layers;
1319 if (ctx && ctx->
layer && ctx->
layer->n_features == 0)
1321 bytea *ba = palloc(VARHDRSZ);
1322 SET_VARSIZE(ba, VARHDRSZ);
1327 len = VARHDRSZ + vector_tile__tile__get_packed_size(ctx->
tile);
1329 vector_tile__tile__pack(ctx->
tile, (uint8_t*)VARDATA(ba));
1330 SET_VARSIZE(ba, len);
1342 return palloc(size);
1352 ProtobufCAllocator allocator =
1359 size_t len = VARSIZE_ANY_EXHDR(ba);
1360 VectorTile__Tile *tile = vector_tile__tile__unpack(&allocator, len, (uint8_t*)VARDATA(ba));
1374 static VectorTile__Tile__Layer *
1377 const uint32_t key_offset = layer->n_keys;
1378 const uint32_t value_offset = layer->n_values;
1379 const uint32_t feature_offset = layer->n_features;
1383 layer->keys = layer2->keys;
1384 layer->n_keys = layer2->n_keys;
1386 else if (layer2->n_keys)
1388 layer->keys = repalloc(layer->keys,
sizeof(
char *) * (layer->n_keys + layer2->n_keys));
1389 memcpy(&layer->keys[key_offset], layer2->keys,
sizeof(
char *) * layer2->n_keys);
1390 layer->n_keys += layer2->n_keys;
1393 if (!layer->n_values)
1395 layer->values = layer2->values;
1396 layer->n_values = layer2->n_values;
1398 else if (layer2->n_values)
1401 repalloc(layer->values,
sizeof(VectorTile__Tile__Value *) * (layer->n_values + layer2->n_values));
1403 &layer->values[value_offset], layer2->values,
sizeof(VectorTile__Tile__Value *) * layer2->n_values);
1404 layer->n_values += layer2->n_values;
1407 if (!layer->n_features)
1409 layer->features = layer2->features;
1410 layer->n_features = layer2->n_features;
1412 else if (layer2->n_features)
1414 layer->features = repalloc(
1415 layer->features,
sizeof(VectorTile__Tile__Feature *) * (layer->n_features + layer2->n_features));
1416 memcpy(&layer->features[feature_offset], layer2->features,
sizeof(
char *) * layer2->n_features);
1417 layer->n_features += layer2->n_features;
1419 for (uint32_t i = feature_offset; i < layer->n_features; i++)
1421 for (uint32_t t = 0; t < layer->features[i]->n_tags; t += 2)
1423 layer->features[i]->tags[t] += key_offset;
1424 layer->features[i]->tags[t + 1] += value_offset;
1433 static VectorTile__Tile *
1437 VectorTile__Tile *tile;
1440 if (tile1->n_layers == 0 && tile2->n_layers == 0)
1442 else if (tile1->n_layers == 0)
1444 else if (tile2->n_layers == 0)
1447 tile = palloc(
sizeof(VectorTile__Tile));
1448 vector_tile__tile__init(tile);
1449 tile->layers = palloc(
sizeof(
void*));
1453 for (i = 0; i < tile1->n_layers; i++)
1455 for (j = 0; j < tile2->n_layers; j++)
1457 VectorTile__Tile__Layer *l1 = tile1->layers[i];
1458 VectorTile__Tile__Layer *l2 = tile2->layers[j];
1459 if (strcmp(l1->name, l2->name)==0)
1464 tile->layers[tile->n_layers++] = layer;
1466 tile->layers = repalloc(tile->layers, (tile->n_layers+1) *
sizeof(
void*));
1477 if (ctx1 && ! ctx2)
return ctx1;
1478 if (ctx2 && ! ctx1)
return ctx2;
1479 if (ctx1 && ctx2 && ctx1->
tile && ctx2->
tile)
1488 elog(DEBUG2,
"ctx1->tile = %p", ctx1->
tile);
1489 elog(DEBUG2,
"ctx2->tile = %p", ctx2->
tile);
1490 elog(ERROR,
"%s: unable to combine contexts where tile attribute is null", __func__);
int gbox_overlaps_2d(const GBOX *g1, const GBOX *g2)
Return LW_TRUE if the GBOX overlaps on the 2d plane, LW_FALSE otherwise.
void gbox_init(GBOX *gbox)
Zero out all the entries in the GBOX.
int gbox_contains_2d(const GBOX *g1, const GBOX *g2)
Return LW_TRUE if the first GBOX contains the second on the 2d plane, LW_FALSE otherwise.
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
GEOSGeometry * LWGEOM2GEOS(const LWGEOM *lwgeom, uint8_t autofix)
LWGEOM * GEOS2LWGEOM(const GEOSGeometry *geom, uint8_t want3d)
void lwgeom_geos_error(const char *fmt,...)
LWGEOM * lwcollection_as_lwgeom(const LWCOLLECTION *obj)
int lwgeom_simplify_in_place(LWGEOM *igeom, double dist, int preserve_collapsed)
void lwgeom_free(LWGEOM *geom)
LWGEOM * lwcollection_getsubgeom(LWCOLLECTION *col, int gnum)
int lwgeom_remove_repeated_points_in_place(LWGEOM *in, double tolerance)
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
#define FLAGS_GET_Z(flags)
LWPOLY * lwpoly_construct_envelope(int32_t srid, double x1, double y1, double x2, double y2)
LWCOLLECTION * lwcollection_extract(const LWCOLLECTION *col, uint32_t type)
int lwgeom_is_collection(const LWGEOM *lwgeom)
Determine whether a LWGEOM can contain sub-geometries or not.
void lwgeom_affine(LWGEOM *geom, const AFFINE *affine)
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int32_t srid, char hasz, char hasm)
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
#define FLAGS_GET_M(flags)
void lwgeom_force_clockwise(LWGEOM *lwgeom)
Force Right-hand-rule on LWGEOM polygons.
LWLINE * lwline_from_lwmpoint(int32_t srid, const LWMPOINT *mpoint)
int lwgeom_calculate_gbox(const LWGEOM *lwgeom, GBOX *gbox)
Calculate bounding box of a geometry, automatically taking into account whether it is cartesian or ge...
LWCOLLECTION * lwcollection_add_lwgeom(LWCOLLECTION *col, const LWGEOM *geom)
Appends geom to the collection managed by col.
#define FLAGS_SET_GEODETIC(flags, value)
LWGEOM * lwgeom_clip_by_rect(const LWGEOM *geom1, double x0, double y0, double x1, double y1)
LWGEOM * lwgeom_make_valid(LWGEOM *geom)
Attempts to make an invalid geometries valid w/out losing points.
void lwgeom_grid_in_place(LWGEOM *lwgeom, const gridspec *grid)
void lwgeom_reverse_in_place(LWGEOM *lwgeom)
Reverse vertex order of LWGEOM.
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
static const POINT2D * getPoint2d_cp(const POINTARRAY *pa, uint32_t n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from.
static uint32_t lwgeom_get_type(const LWGEOM *geom)
Return LWTYPE number.
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
static void encode_poly(mvt_agg_context *ctx, LWPOLY *lwpoly)
static uint32_t get_key_index_with_size(mvt_agg_context *ctx, const char *name, size_t size)
static LWGEOM * mvt_iterate_clip_by_box_geos(LWGEOM *lwgeom, GBOX *clip_gbox, uint8_t basic_type)
Clips the geometry using GEOSIntersection in a "safe way", cleaning the input if necessary and clippi...
static void encode_mline(mvt_agg_context *ctx, LWMLINE *lwmline)
static void parse_datum_as_string(mvt_agg_context *ctx, Oid typoid, Datum datum, uint32_t *tags, uint32_t k)
static void encode_geometry(mvt_agg_context *ctx, LWGEOM *lwgeom)
static VectorTile__Tile__Layer * vectortile_layer_combine(VectorTile__Tile__Layer *layer, VectorTile__Tile__Layer *layer2)
Combine 2 layers.
#define MVT_PARSE_INT_VALUE(value)
mvt_agg_context * mvt_ctx_combine(mvt_agg_context *ctx1, mvt_agg_context *ctx2)
static void encode_mpoly(mvt_agg_context *ctx, LWMPOLY *lwmpoly)
mvt_agg_context * mvt_ctx_deserialize(const bytea *ba)
#define MVT_PARSE_DATUM(type, datumfunc, hash, size, pfvaluefield, pftype)
LWGEOM * mvt_geom(LWGEOM *lwgeom, const GBOX *gbox, uint32_t extent, uint32_t buffer, bool clip_geom)
Transform a geometry into vector tile coordinate space.
static void encode_mpoint(mvt_agg_context *ctx, LWMPOINT *mpoint)
#define FEATURES_CAPACITY_INITIAL
static void set_feature_id(mvt_agg_context *ctx, Datum datum, bool isNull)
Sets the feature id.
static void encode_keys(mvt_agg_context *ctx)
static LWGEOM * mvt_unsafe_clip_by_box(LWGEOM *lwg_in, GBOX *clip_box)
static void encode_point(mvt_agg_context *ctx, LWPOINT *point)
#define MVT_PARSE_INT_DATUM(type, datumfunc)
#define MVT_CREATE_VALUES(hash)
bytea * mvt_agg_finalfn(mvt_agg_context *ctx)
Finalize aggregation.
bytea * mvt_ctx_serialize(mvt_agg_context *ctx)
static LWGEOM * mvt_safe_clip_polygon_by_box(LWGEOM *lwg_in, GBOX *clip_box)
Clips an input geometry using GEOSIntersection It used to try to use GEOSClipByRect (as mvt_unsafe_cl...
static void mvt_deallocator(__attribute__((__unused__)) void *data, void *ptr)
static uint32_t * parse_jsonb(mvt_agg_context *ctx, Jsonb *jb, uint32_t *tags)
static void parse_column_keys(mvt_agg_context *ctx)
static bool add_value_as_string_with_size(mvt_agg_context *ctx, char *value, size_t size, uint32_t *tags, uint32_t k)
static uint32_t c_int(enum mvt_cmd_id id, uint32_t count)
static VectorTile__Tile * mvt_ctx_to_tile(mvt_agg_context *ctx)
static uint32_t add_key(mvt_agg_context *ctx, char *name)
static LWGEOM * mvt_clip_and_validate_geos(LWGEOM *lwgeom, uint8_t basic_type, uint32_t extent, uint32_t buffer, bool clip_geom)
static LWGEOM * lwgeom_to_basic_type(LWGEOM *geom, uint8_t original_type)
In place process a collection to find a concrete geometry object and expose that as the actual object...
static void * mvt_allocator(__attribute__((__unused__)) void *data, size_t size)
void mvt_agg_init_context(mvt_agg_context *ctx)
Initialize aggregation context.
static bytea * mvt_ctx_to_bytea(mvt_agg_context *ctx)
static TupleDesc get_tuple_desc(mvt_agg_context *ctx)
static uint32_t encode_ptarray_initial(mvt_agg_context *ctx, enum mvt_type type, POINTARRAY *pa, uint32_t *buffer)
#define MVT_PARSE_VALUE(hash, newvalue, size, pfvaluefield, pftype)
static uint8_t lwgeom_get_basic_type(LWGEOM *geom)
static LWGEOM * mvt_clip_and_validate(LWGEOM *lwgeom, uint8_t basic_type, uint32_t extent, uint32_t buffer, bool clip_geom)
static VectorTile__Tile * vectortile_tile_combine(VectorTile__Tile *tile1, VectorTile__Tile *tile2)
void mvt_agg_transfn(mvt_agg_context *ctx)
Aggregation step.
static void parse_values(mvt_agg_context *ctx)
static void add_value_as_string(mvt_agg_context *ctx, char *value, uint32_t *tags, uint32_t k)
static void encode_values(mvt_agg_context *ctx)
static uint32_t p_int(int32_t value)
static void encode_line(mvt_agg_context *ctx, LWLINE *lwline)
static uint32_t encode_ptarray(__attribute__((__unused__)) mvt_agg_context *ctx, enum mvt_type type, POINTARRAY *pa, uint32_t *buffer, int32_t *px, int32_t *py)
static LWGEOM * mvt_grid_and_validate_geos(LWGEOM *ng, uint8_t basic_type)
Given a geometry, it uses GEOS operations to make sure that it's valid according to the MVT spec and ...
Datum buffer(PG_FUNCTION_ARGS)
struct mvt_kv_value * uint_values_hash
VectorTile__Tile__Layer * layer
VectorTile__Tile__Feature * feature
struct mvt_kv_key * keys_hash
struct mvt_kv_value * float_values_hash
struct mvt_kv_value * bool_values_hash
struct mvt_kv_value * string_values_hash
struct mvt_kv_value * double_values_hash
mvt_column_cache column_cache
struct mvt_kv_value * sint_values_hash
uint32_t * column_keys_index
VectorTile__Tile__Value value[1]