31 #include "pgsql_compat.h"
33 #ifdef HAVE_LIBPROTOBUF
34 #include "utils/jsonb.h"
36 #if POSTGIS_PGSQL_VERSION < 110
38 # define DatumGetJsonbP DatumGetJsonb
41 #define uthash_fatal(msg) lwerror("uthash: fatal error (out of memory)")
42 #define uthash_malloc(sz) palloc(sz)
43 #define uthash_free(ptr,sz) pfree(ptr)
47 #define FEATURES_CAPACITY_INITIAL 50
114 return (
id & 0x7) | (
count << 3);
124 int32_t *px, int32_t *py)
128 int32_t dx, dy,
x,
y;
132 for (i = 0; i < pa->
npoints; i++)
177 int32_t px = 0, py = 0;
183 VectorTile__Tile__Feature *feature = ctx->
feature;
184 feature->type = VECTOR_TILE__TILE__GEOM_TYPE__POINT;
185 feature->has_type = 1;
186 feature->n_geometry = 3;
187 feature->geometry = palloc(
sizeof(*feature->geometry) * 3);
194 VectorTile__Tile__Feature *feature = ctx->
feature;
197 feature->type = VECTOR_TILE__TILE__GEOM_TYPE__POINT;
198 feature->has_type = 1;
200 feature->geometry = palloc(
sizeof(*feature->geometry) * c);
202 lwline->
points, feature->geometry);
208 VectorTile__Tile__Feature *feature = ctx->
feature;
209 feature->type = VECTOR_TILE__TILE__GEOM_TYPE__LINESTRING;
210 feature->has_type = 1;
212 feature->geometry = palloc(
sizeof(*feature->geometry) * c);
214 lwline->
points, feature->geometry);
220 int32_t px = 0, py = 0;
221 size_t c = 0, offset = 0;
222 VectorTile__Tile__Feature *feature = ctx->
feature;
223 feature->type = VECTOR_TILE__TILE__GEOM_TYPE__LINESTRING;
224 feature->has_type = 1;
225 for (i = 0; i < lwmline->
ngeoms; i++)
227 feature->geometry = palloc(
sizeof(*feature->geometry) * c);
228 for (i = 0; i < lwmline->
ngeoms; i++)
231 feature->geometry + offset, &px, &py);
232 feature->n_geometry = offset;
238 int32_t px = 0, py = 0;
239 size_t c = 0, offset = 0;
240 VectorTile__Tile__Feature *feature = ctx->
feature;
241 feature->type = VECTOR_TILE__TILE__GEOM_TYPE__POLYGON;
242 feature->has_type = 1;
243 for (i = 0; i < lwpoly->
nrings; i++)
245 feature->geometry = palloc(
sizeof(*feature->geometry) * c);
246 for (i = 0; i < lwpoly->
nrings; i++)
249 feature->geometry + offset, &px, &py);
250 feature->n_geometry = offset;
256 int32_t px = 0, py = 0;
257 size_t c = 0, offset = 0;
259 VectorTile__Tile__Feature *feature = ctx->
feature;
260 feature->type = VECTOR_TILE__TILE__GEOM_TYPE__POLYGON;
261 feature->has_type = 1;
262 for (i = 0; i < lwmpoly->
ngeoms; i++)
263 for (j = 0; poly = lwmpoly->
geoms[i], j < poly->
nrings; j++)
265 feature->geometry = palloc(
sizeof(*feature->geometry) * c);
266 for (i = 0; i < lwmpoly->
ngeoms; i++)
267 for (j = 0; poly = lwmpoly->
geoms[i], j < poly->
nrings; j++)
269 poly->
rings[j], feature->geometry + offset,
271 feature->n_geometry = offset;
292 default: elog(ERROR,
"encode_geometry: '%s' geometry type not supported",
299 Oid tupType = HeapTupleHeaderGetTypeId(ctx->
row);
300 int32 tupTypmod = HeapTupleHeaderGetTypMod(ctx->
row);
301 TupleDesc tupdesc = lookup_rowtype_tupdesc(tupType, tupTypmod);
317 size_t size = strlen(
name);
318 kv = palloc(
sizeof(*kv));
328 bool geom_found =
false;
330 POSTGIS_DEBUG(2,
"parse_column_keys called");
340 for (i = 0; i < natts; i++)
347 if (typoid == JSONBOID)
355 if (!geom_found && typoid == postgis_oid(GEOMETRYOID))
364 if (!geom_found && strcmp(tkey, ctx->
geom_name) == 0)
374 (strcmp(tkey, ctx->
id_name) == 0) &&
375 (typoid == INT2OID || typoid == INT4OID || typoid == INT8OID))
386 elog(ERROR,
"parse_column_keys: no geometry column found");
389 elog(ERROR,
"mvt_agg_transfn: Could not find column '%s' of integer type", ctx->
id_name);
396 char **keys = palloc(n_keys *
sizeof(*keys));
397 for (kv = ctx->
keys_hash; kv != NULL; kv=kv->
hh.next)
399 ctx->
layer->n_keys = n_keys;
400 ctx->
layer->keys = keys;
407 VectorTile__Tile__Value *
value = palloc(
sizeof(*
value));
408 vector_tile__tile__value__init(
value);
412 #define MVT_CREATE_VALUES(kvtype, hash, hasfield, valuefield) \
414 POSTGIS_DEBUG(2, "MVT_CREATE_VALUES called"); \
417 for (kv = ctx->hash; kv != NULL; kv=kv->hh.next) \
419 VectorTile__Tile__Value *value = create_value(); \
420 value->hasfield = 1; \
421 value->valuefield = kv->valuefield; \
422 values[kv->id] = value; \
429 VectorTile__Tile__Value **values;
432 POSTGIS_DEBUG(2,
"encode_values called");
442 float_values_hash, has_float_value, float_value);
444 double_values_hash, has_double_value, double_value);
446 uint_values_hash, has_uint_value, uint_value);
448 sint_values_hash, has_sint_value, sint_value);
450 bool_values_hash, has_bool_value, bool_value);
452 POSTGIS_DEBUGF(3,
"encode_values n_values: %d", ctx->
values_hash_i);
454 ctx->
layer->values = values;
472 #define MVT_PARSE_VALUE(value, kvtype, hash, valuefield, size) \
474 POSTGIS_DEBUG(2, "MVT_PARSE_VALUE called"); \
477 HASH_FIND(hh, ctx->hash, &value, size, kv); \
480 POSTGIS_DEBUG(4, "MVT_PARSE_VALUE value not found"); \
481 kv = palloc(sizeof(*kv)); \
482 POSTGIS_DEBUGF(4, "MVT_PARSE_VALUE new hash key: %d", \
483 ctx->values_hash_i); \
484 kv->id = ctx->values_hash_i++; \
485 kv->valuefield = value; \
486 HASH_ADD(hh, ctx->hash, valuefield, size, kv); \
488 tags[ctx->row_columns*2] = k; \
489 tags[ctx->row_columns*2+1] = kv->id; \
493 #define MVT_PARSE_INT_VALUE(value) \
497 uint64_t cvalue = value; \
498 MVT_PARSE_VALUE(cvalue, mvt_kv_uint_value, \
499 uint_values_hash, uint_value, \
504 int64_t cvalue = value; \
505 MVT_PARSE_VALUE(cvalue, mvt_kv_sint_value, \
506 sint_values_hash, sint_value, \
511 #define MVT_PARSE_DATUM(type, kvtype, hash, valuefield, datumfunc, size) \
513 type value = datumfunc(datum); \
514 MVT_PARSE_VALUE(value, kvtype, hash, valuefield, size); \
517 #define MVT_PARSE_INT_DATUM(type, datumfunc) \
519 type value = datumfunc(datum); \
520 MVT_PARSE_INT_VALUE(value); \
524 char *
value,
size_t size, uint32_t *tags, uint32_t k)
527 POSTGIS_DEBUG(2,
"add_value_as_string called");
531 POSTGIS_DEBUG(4,
"add_value_as_string value not found");
532 kv = palloc(
sizeof(*kv));
533 POSTGIS_DEBUGF(4,
"add_value_as_string new hash key: %d",
545 char *
value, uint32_t *tags, uint32_t k)
551 Datum datum, uint32_t *tags, uint32_t k)
556 POSTGIS_DEBUG(2,
"parse_value_as_string called");
557 getTypeOutputInfo(typoid, &foutoid, &typisvarlena);
558 value = OidOutputFunctionCall(foutoid, datum);
559 POSTGIS_DEBUGF(4,
"parse_value_as_string value: %s",
value);
568 bool skipNested =
false;
569 JsonbIteratorToken
r;
572 if (!JB_ROOT_IS_OBJECT(jb))
575 it = JsonbIteratorInit(&jb->root);
577 while ((
r = JsonbIteratorNext(&it, &v, skipNested)) != WJB_DONE)
581 if (
r == WJB_KEY && v.type != jbvNull)
590 key = palloc(v.val.string.len + 1);
591 memcpy(key, v.val.string.val, v.val.string.len);
592 key[v.val.string.len] =
'\0';
594 tags = repalloc(tags, newSize * 2 *
sizeof(*tags));
598 r = JsonbIteratorNext(&it, &v, skipNested);
600 if (v.type == jbvString)
603 value = palloc(v.val.string.len + 1);
604 memcpy(
value, v.val.string.val, v.val.string.len);
605 value[v.val.string.len] =
'\0';
609 else if (v.type == jbvBool)
612 bool_values_hash, bool_value,
sizeof(protobuf_c_boolean));
615 else if (v.type == jbvNumeric)
620 str = DatumGetCString(DirectFunctionCall1(numeric_out,
621 PointerGetDatum(v.val.numeric)));
622 d = strtod(
str, NULL);
623 l = strtol(
str, NULL, 10);
625 if (fabs(d - (
double)l) > FLT_EPSILON)
628 double_value,
sizeof(
double));
648 int64_t
value = INT64_MIN;
652 POSTGIS_DEBUG(3,
"set_feature_id: Ignored null value");
659 value = DatumGetInt16(datum);
662 value = DatumGetInt32(datum);
665 value = DatumGetInt64(datum);
668 elog(ERROR,
"set_feature_id: Feature id type does not match");
673 POSTGIS_DEBUG(3,
"set_feature_id: Ignored negative value");
684 uint32_t *tags = palloc(n_keys * 2 *
sizeof(*tags));
687 uint32_t natts = (uint32_t) cc.
tupdesc->natts;
691 POSTGIS_DEBUG(2,
"parse_values called");
695 tuple.t_len = HeapTupleHeaderGetDatumLength(ctx->
row);
696 ItemPointerSetInvalid(&(tuple.t_self));
697 tuple.t_tableOid = InvalidOid;
698 tuple.t_data = ctx->
row;
703 POSTGIS_DEBUGF(3,
"parse_values natts: %d", natts);
705 for (i = 0; i < natts; i++)
710 Datum datum = cc.
values[i];
723 POSTGIS_DEBUG(3,
"parse_values isnull detected");
727 key = TupleDescAttr(cc.
tupdesc, i)->attname.data;
732 elog(ERROR,
"parse_values: unexpectedly could not find parsed key name '%s'", key);
733 if (typoid == JSONBOID)
743 bool_values_hash, bool_value,
744 DatumGetBool,
sizeof(protobuf_c_boolean));
757 float_values_hash, float_value,
758 DatumGetFloat4,
sizeof(
float));
762 double_values_hash, double_value,
763 DatumGetFloat8,
sizeof(
double));
777 POSTGIS_DEBUGF(3,
"parse_values n_tags %zd", ctx->
feature->n_tags);
796 return geom->
type - 3;
803 for (i = 0; i < g->
ngeoms; i++)
811 elog(ERROR,
"%s: Invalid type (%d)", __func__, geom->
type);
838 geom_out = g->
geoms[0];
859 POSTGIS_DEBUG(3,
"mvt_geom: geometry outside clip box");
865 POSTGIS_DEBUG(3,
"mvt_geom: geometry contained fully inside the box");
885 LWGEOM *geom_clipped, *envelope;
887 GEOSGeometry *geos_input, *geos_box, *geos_result;
895 POSTGIS_DEBUG(3,
"mvt_geom: geometry outside clip box");
901 POSTGIS_DEBUG(3,
"mvt_geom: geometry contained fully inside the box");
915 GEOSGeom_destroy(geos_input);
919 geos_result = GEOSIntersection(geos_input, geos_box);
922 POSTGIS_DEBUG(3,
"mvt_geom: no geometry after intersection. Retrying after validation");
923 GEOSGeom_destroy(geos_input);
927 GEOSGeom_destroy(geos_box);
930 geos_result = GEOSIntersection(geos_input, geos_box);
933 GEOSGeom_destroy(geos_box);
934 GEOSGeom_destroy(geos_input);
939 GEOSSetSRID(geos_result, lwg_in->
srid);
942 GEOSGeom_destroy(geos_box);
943 GEOSGeom_destroy(geos_input);
944 GEOSGeom_destroy(geos_result);
948 POSTGIS_DEBUG(3,
"mvt_geom: no geometry after clipping");
987 for (i = 0; i < lwmg->
ngeoms; i++)
1003 for (j = 0; j < ((
LWCOLLECTION *)clipped)->ngeoms; j++)
1022 gridspec grid = {0, 0, 0, 0, 1, 1, 0, 0};
1038 uint32_t iterations = 0;
1039 static const uint32_t max_iterations = 3;
1049 valid = GEOSisValid(geo) == 1;
1051 while (!valid && iterations < max_iterations)
1053 #if POSTGIS_GEOS_VERSION < 38
1054 GEOSGeometry *geo_valid = LWGEOM_GEOS_makeValid(geo);
1056 GEOSGeometry *geo_valid = GEOSMakeValid(geo);
1059 GEOSGeom_destroy(geo);
1064 GEOSGeom_destroy(geo_valid);
1071 valid = GEOSisValid(geo) == 1;
1074 GEOSGeom_destroy(geo);
1078 POSTGIS_DEBUG(1,
"mvt_geom: Could not transform into a valid MVT geometry");
1108 POSTGIS_DEBUG(3,
"mvt_geom: no geometry after clip");
1119 POSTGIS_DEBUG(1,
"mvt_geom: Dropping geometry after type change");
1128 #include "lwgeom_wagyu.h"
1133 GBOX clip_box = {0};
1154 clipped_lwgeom = lwgeom_wagyu_clip_by_box(lwgeom, &clip_box);
1156 return clipped_lwgeom;
1179 AFFINE affine = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
1180 gridspec grid = {0, 0, 0, 0, 1, 1, 0, 0};
1181 double width = gbox->
xmax - gbox->
xmin;
1182 double height = gbox->
ymax - gbox->
ymin;
1183 double resx, resy,
res, fx, fy;
1186 POSTGIS_DEBUG(2,
"mvt_geom called");
1195 resx = width / extent;
1196 resy = height / extent;
1197 res = (resx < resy ? resx : resy)/2;
1198 fx = extent / width;
1199 fy = -(extent / height);
1235 VectorTile__Tile__Layer *layer;
1237 POSTGIS_DEBUG(2,
"mvt_agg_init_context called");
1240 elog(ERROR,
"mvt_agg_init_context: extent cannot be 0");
1258 layer = palloc(
sizeof(*layer));
1259 vector_tile__tile__layer__init(layer);
1261 layer->name = ctx->
name;
1262 layer->has_extent = 1;
1263 layer->extent = ctx->
extent;
1265 sizeof(*layer->features));
1279 bool isnull =
false;
1283 VectorTile__Tile__Feature *feature;
1284 VectorTile__Tile__Layer *layer = ctx->
layer;
1286 POSTGIS_DEBUG(2,
"mvt_agg_transfn called");
1291 layer->features = repalloc(layer->features, new_capacity *
1292 sizeof(*layer->features));
1294 POSTGIS_DEBUGF(3,
"mvt_agg_transfn new_capacity: %zd", new_capacity);
1300 datum = GetAttributeByNum(ctx->
row, ctx->
geom_index + 1, &isnull);
1301 POSTGIS_DEBUGF(3,
"mvt_agg_transfn ctx->geom_index: %d", ctx->
geom_index);
1302 POSTGIS_DEBUGF(3,
"mvt_agg_transfn isnull: %u", isnull);
1303 POSTGIS_DEBUGF(3,
"mvt_agg_transfn datum: %lu", datum);
1306 POSTGIS_DEBUG(3,
"mvt_agg_transfn got null geom");
1310 feature = palloc(
sizeof(*feature));
1311 vector_tile__tile__feature__init(feature);
1318 POSTGIS_DEBUGF(3,
"mvt_agg_transfn encoded feature count: %zd", layer->n_features);
1319 layer->features[layer->n_features++] = feature;
1330 VectorTile__Tile *tile;
1334 tile = palloc(
sizeof(VectorTile__Tile));
1335 vector_tile__tile__init(tile);
1336 tile->layers = palloc(
sizeof(VectorTile__Tile__Layer*) * n_layers);
1337 tile->layers[0] = ctx->
layer;
1338 tile->n_layers = n_layers;
1357 if (ctx && ctx->
layer && ctx->
layer->n_features == 0)
1359 bytea *ba = palloc(VARHDRSZ);
1360 SET_VARSIZE(ba, VARHDRSZ);
1365 len = VARHDRSZ + vector_tile__tile__get_packed_size(ctx->
tile);
1367 vector_tile__tile__pack(ctx->
tile, (uint8_t*)VARDATA(ba));
1368 SET_VARSIZE(ba, len);
1380 return palloc(size);
1390 ProtobufCAllocator allocator =
1397 size_t len = VARSIZE_ANY_EXHDR(ba);
1398 VectorTile__Tile *tile = vector_tile__tile__unpack(&allocator, len, (uint8_t*)VARDATA(ba));
1405 static VectorTile__Tile__Value *
1408 VectorTile__Tile__Value *nvalue = palloc(
sizeof(VectorTile__Tile__Value));
1409 memcpy(nvalue,
value,
sizeof(VectorTile__Tile__Value));
1410 if (
value->string_value)
1411 nvalue->string_value = pstrdup(
value->string_value);
1415 static VectorTile__Tile__Feature *
1419 VectorTile__Tile__Feature *nfeature;
1422 if (!feature)
return NULL;
1425 nfeature = palloc(
sizeof(VectorTile__Tile__Feature));
1426 vector_tile__tile__feature__init(nfeature);
1429 nfeature->has_id = feature->has_id;
1430 nfeature->id = feature->id;
1431 nfeature->has_type = feature->has_type;
1432 nfeature->type = feature->type;
1436 if (feature->n_tags > 0)
1438 nfeature->n_tags = feature->n_tags;
1439 nfeature->tags = palloc(
sizeof(uint32_t)*feature->n_tags);
1440 for (i = 0; i < feature->n_tags/2; i++)
1442 nfeature->tags[2*i] = feature->tags[2*i] + key_offset;
1443 nfeature->tags[2*i+1] = feature->tags[2*i+1] + value_offset;
1448 if (feature->n_geometry > 0)
1450 nfeature->n_geometry = feature->n_geometry;
1451 nfeature->geometry = palloc(
sizeof(uint32_t)*feature->n_geometry);
1452 memcpy(nfeature->geometry, feature->geometry,
sizeof(uint32_t)*feature->n_geometry);
1459 static VectorTile__Tile__Layer *
1463 int key2_offset, value2_offset;
1464 VectorTile__Tile__Layer *layer = palloc(
sizeof(VectorTile__Tile__Layer));
1465 vector_tile__tile__layer__init(layer);
1468 layer->version = layer1->version;
1469 layer->name = pstrdup(layer1->name);
1470 layer->has_extent = layer1->has_extent;
1471 layer->extent = layer1->extent;
1475 layer->n_keys = layer1->n_keys + layer2->n_keys;
1476 layer->keys = layer->n_keys ? palloc(layer->n_keys *
sizeof(
void*)) : NULL;
1477 for (i = 0; i < layer1->n_keys; i++)
1478 layer->keys[j++] = pstrdup(layer1->keys[i]);
1480 for (i = 0; i < layer2->n_keys; i++)
1481 layer->keys[j++] = pstrdup(layer2->keys[i]);
1486 layer->n_values = layer1->n_values + layer2->n_values;
1487 layer->values = layer->n_values ? palloc(layer->n_values *
sizeof(
void*)) : NULL;
1489 for (i = 0; i < layer1->n_values; i++)
1492 for (i = 0; i < layer2->n_values; i++)
1496 layer->n_features = layer1->n_features + layer2->n_features;
1497 layer->features = layer->n_features ? palloc(layer->n_features *
sizeof(
void*)) : NULL;
1499 for (i = 0; i < layer1->n_features; i++)
1501 for (i = 0; i < layer2->n_features; i++)
1502 layer->features[j++] =
tile_feature_copy(layer2->features[i], key2_offset, value2_offset);
1508 static VectorTile__Tile *
1512 VectorTile__Tile *tile;
1515 if (tile1->n_layers == 0 && tile2->n_layers == 0)
1517 else if (tile1->n_layers == 0)
1519 else if (tile2->n_layers == 0)
1522 tile = palloc(
sizeof(VectorTile__Tile));
1523 vector_tile__tile__init(tile);
1524 tile->layers = palloc(
sizeof(
void*));
1528 for (i = 0; i < tile1->n_layers; i++)
1530 for (j = 0; j < tile2->n_layers; j++)
1532 VectorTile__Tile__Layer *l1 = tile1->layers[i];
1533 VectorTile__Tile__Layer *l2 = tile2->layers[j];
1534 if (strcmp(l1->name, l2->name)==0)
1539 tile->layers[tile->n_layers++] = layer;
1541 tile->layers = repalloc(tile->layers, (tile->n_layers+1) *
sizeof(
void*));
1552 if (ctx1 && ! ctx2)
return ctx1;
1553 if (ctx2 && ! ctx1)
return ctx2;
1554 if (ctx1 && ctx2 && ctx1->
tile && ctx2->
tile)
1563 elog(DEBUG2,
"ctx1->tile = %p", ctx1->
tile);
1564 elog(DEBUG2,
"ctx2->tile = %p", ctx2->
tile);
1565 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)
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_extract(LWCOLLECTION *col, int type)
Takes a potentially heterogeneous collection and returns a homogeneous collection consisting only of ...
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 VectorTile__Tile__Value * create_value()
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 void add_value_as_string_with_size(mvt_agg_context *ctx, char *value, size_t size, uint32_t *tags, uint32_t k)
#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)
static VectorTile__Tile__Feature * tile_feature_copy(const VectorTile__Tile__Feature *feature, int key_offset, int value_offset)
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)
bytea * mvt_agg_finalfn(mvt_agg_context *ctx)
Finalize aggregation.
static uint8 lwgeom_get_basic_type(LWGEOM *geom)
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 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 VectorTile__Tile__Value * tile_value_copy(const VectorTile__Tile__Value *value)
static LWGEOM * mvt_clip_and_validate_geos(LWGEOM *lwgeom, uint8_t basic_type, uint32_t extent, uint32_t buffer, bool clip_geom)
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)
#define MVT_CREATE_VALUES(kvtype, hash, hasfield, valuefield)
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)
static LWGEOM * lwgeom_to_basic_type(LWGEOM *geom, uint8 original_type)
In place process a collection to find a concrete geometry object and expose that as the actual object...
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)
#define MVT_PARSE_VALUE(value, kvtype, hash, valuefield, size)
static VectorTile__Tile__Layer * vectortile_layer_combine(const VectorTile__Tile__Layer *layer1, const VectorTile__Tile__Layer *layer2)
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)
#define MVT_PARSE_DATUM(type, kvtype, hash, valuefield, datumfunc, size)
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_string_value * string_values_hash
struct mvt_kv_bool_value * bool_values_hash
struct mvt_kv_uint_value * uint_values_hash
VectorTile__Tile__Layer * layer
struct mvt_kv_float_value * float_values_hash
struct mvt_kv_sint_value * sint_values_hash
VectorTile__Tile__Feature * feature
struct mvt_kv_key * keys_hash
struct mvt_kv_double_value * double_values_hash
mvt_column_cache column_cache
uint32_t * column_keys_index
protobuf_c_boolean bool_value