44 #ifndef HAVE_LIBPROTOBUF
45 elog(ERROR,
"Missing libprotobuf-c");
51 bool clip_geom =
true;
53 LWGEOM *lwgeom_in, *lwgeom_out;
63 elog(ERROR,
"%s: Geometric bounds cannot be null", __func__);
66 bounds = (
GBOX *)PG_GETARG_POINTER(1);
69 elog(ERROR,
"%s: Geometric bounds are too small", __func__);
73 extent = PG_ARGISNULL(2) ? 4096 : PG_GETARG_INT32(2);
76 elog(ERROR,
"%s: Extent must be greater than 0", __func__);
80 buffer = PG_ARGISNULL(3) ? 256 : PG_GETARG_INT32(3);
81 clip_geom = PG_ARGISNULL(4) ? true : PG_GETARG_BOOL(4);
83 geom_in = PG_GETARG_GSERIALIZED_P_COPY(0);
95 double geom_width = gserialized_box.
xmax - gserialized_box.
xmin;
96 double geom_height = gserialized_box.
ymax - gserialized_box.
ymin;
100 double bounds_width = ((bounds->
xmax - bounds->
xmin) / extent) / 2.0;
101 double bounds_height = ((bounds->
ymax - bounds->
ymin) / extent) / 2.0;
102 if (geom_width < bounds_width && geom_height < bounds_height)
111 lwgeom_out =
mvt_geom(lwgeom_in, bounds, extent,
buffer, clip_geom);
112 if (lwgeom_out == NULL)
117 PG_FREE_IF_COPY(geom_in, 0);
118 PG_RETURN_POINTER(geom_out);
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
uint32_t gserialized_get_type(const GSERIALIZED *g)
Extract the geometry type from the serialized form (it hides in the anonymous data area,...
int gserialized_fast_gbox_p(const GSERIALIZED *g, GBOX *gbox)
Read the box from the GSERIALIZED or return #LWFAILURE if box is unavailable.
void lwgeom_free(LWGEOM *geom)
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.
Datum buffer(PG_FUNCTION_ARGS)
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)