From 0215d64908c9ad08762ca77e9ca78da75dfe3c49 Mon Sep 17 00:00:00 2001 From: Paul Ramsey Date: Tue, 11 Jun 2019 18:24:40 +0000 Subject: [PATCH] Pull gserialized_read_gbox_p and gserialized_peek_gbox_p back in favour of a public gserialized_fast_gbox_p. Pull liblwgeom_internal out of mvt.c git-svn-id: http://svn.osgeo.org/postgis/trunk@17498 b70326c6-7e19-0410-871a-916f4a2858ee --- liblwgeom/g_serialized.c | 25 +++++++++++++++++++++++++ liblwgeom/liblwgeom.h.in | 31 ++++++++++++++++++++++++++++++- liblwgeom/liblwgeom_internal.h | 19 ------------------- postgis/gserialized_gist_2d.c | 7 ++++--- postgis/lwgeom_out_mvt.c | 3 +-- postgis/mvt.c | 4 +++- postgis/mvt.h | 1 - 7 files changed, 63 insertions(+), 27 deletions(-) diff --git a/liblwgeom/g_serialized.c b/liblwgeom/g_serialized.c index 2a525620d..9e1f8cbab 100644 --- a/liblwgeom/g_serialized.c +++ b/liblwgeom/g_serialized.c @@ -677,6 +677,31 @@ int gserialized_get_gbox_p(const GSERIALIZED *g, GBOX *box) } } +/** +* Read the bounding box off a serialization and fail if +* it is not already there. +*/ +int gserialized_fast_gbox_p(const GSERIALIZED *g, GBOX *box) +{ + /* Try to just read the serialized box. */ + if ( gserialized_read_gbox_p(g, box) == LW_SUCCESS ) + { + return LW_SUCCESS; + } + /* No box? Try to peek into simpler geometries and */ + /* derive a box without creating an lwgeom */ + else if ( gserialized_peek_gbox_p(g, box) == LW_SUCCESS ) + { + return LW_SUCCESS; + } + else + { + return LW_FAILURE; + } +} + + + /*********************************************************************** * Calculate the GSERIALIZED size for an LWGEOM. diff --git a/liblwgeom/liblwgeom.h.in b/liblwgeom/liblwgeom.h.in index 9242e8d3f..b4e3cd1ec 100644 --- a/liblwgeom/liblwgeom.h.in +++ b/liblwgeom/liblwgeom.h.in @@ -1239,9 +1239,32 @@ extern void interpolate_point4d(const POINT4D *A, const POINT4D *B, POINT4D *I, extern int lwgeom_is_clockwise(LWGEOM *lwgeom); +/** +* Simplification +*/ extern LWGEOM* lwgeom_simplify(const LWGEOM *igeom, double dist, int preserve_collapsed); extern LWGEOM* lwgeom_remove_repeated_points(const LWGEOM *in, double tolerance); +/** +* Snap-to-grid +*/ +typedef struct gridspec_t +{ + double ipx; + double ipy; + double ipz; + double ipm; + double xsize; + double ysize; + double zsize; + double msize; +} +gridspec; + +extern LWGEOM* lwgeom_grid(const LWGEOM *lwgeom, const gridspec *grid); +extern void lwgeom_grid_in_place(LWGEOM *lwgeom, const gridspec *grid); + + /**************************************************************** * READ/WRITE FUNCTIONS * @@ -1951,7 +1974,13 @@ extern LWGEOM* lwgeom_from_gserialized(const GSERIALIZED *g); * it is not, calculate it from the geometry. If that doesn't work (null * or empty) return LW_FAILURE. */ -extern int gserialized_get_gbox_p(const GSERIALIZED *g, GBOX *gbox); +extern int gserialized_get_gbox_p(const GSERIALIZED *g, GBOX *box); + +/** +* Pull a #GBOX from the header of a #GSERIALIZED, if one is available. If +* it is not, return LW_FAILURE. +*/ +extern int gserialized_fast_gbox_p(const GSERIALIZED *g, GBOX *box); /** diff --git a/liblwgeom/liblwgeom_internal.h b/liblwgeom/liblwgeom_internal.h index 3819fcddc..ad21114d9 100644 --- a/liblwgeom/liblwgeom_internal.h +++ b/liblwgeom/liblwgeom_internal.h @@ -398,25 +398,6 @@ int lwtin_is_closed(const LWTIN *tin); /** * Snap to grid */ - -/** -* Snap-to-grid Support -*/ -typedef struct gridspec_t -{ - double ipx; - double ipy; - double ipz; - double ipm; - double xsize; - double ysize; - double zsize; - double msize; -} -gridspec; - -LWGEOM* lwgeom_grid(const LWGEOM *lwgeom, const gridspec *grid); -void lwgeom_grid_in_place(LWGEOM *lwgeom, const gridspec *grid); void ptarray_grid_in_place(POINTARRAY *pa, const gridspec *grid); /* diff --git a/postgis/gserialized_gist_2d.c b/postgis/gserialized_gist_2d.c index 8cf396d48..65d2c600b 100644 --- a/postgis/gserialized_gist_2d.c +++ b/postgis/gserialized_gist_2d.c @@ -571,9 +571,10 @@ gserialized_datum_get_box2df_p(Datum gsdatum, BOX2DF *box2df) ** enough to take serious advantage of PG_DETOAST_DATUM_SLICE will have ** already been compressed, which means the entire object will be ** fetched and decompressed before a slice is taken, thus removing - ** any efficiencies gained from slicing. We need to move to - ** "storage = external" and implement our own geometry compressor - ** before we can take advantage of sliced retrieval. + ** any efficiencies gained from slicing. + ** As of Pg12 we can partially decompress a toasted object + ** (though we still need to fully retrieve it from TOAST) + ** which makes slicing worthwhile. */ gpart = (GSERIALIZED*)PG_DETOAST_DATUM(gsdatum); flags = gpart->flags; diff --git a/postgis/lwgeom_out_mvt.c b/postgis/lwgeom_out_mvt.c index 6e992b00e..f1c72af07 100644 --- a/postgis/lwgeom_out_mvt.c +++ b/postgis/lwgeom_out_mvt.c @@ -89,8 +89,7 @@ Datum ST_AsMVTGeom(PG_FUNCTION_ARGS) { GBOX gserialized_box; /* We only apply the optimization if the bounding box is available */ - if ((gserialized_read_gbox_p(geom_in, &gserialized_box) == LW_SUCCESS) || - (gserialized_peek_gbox_p(geom_in, &gserialized_box) == LW_SUCCESS)) + if (gserialized_fast_gbox_p(geom_in, &gserialized_box) == LW_SUCCESS) { /* Shortcut to drop geometries smaller than the resolution */ double geom_width = gserialized_box.xmax - gserialized_box.xmin; diff --git a/postgis/mvt.c b/postgis/mvt.c index 336c15b70..7bd1863fa 100644 --- a/postgis/mvt.c +++ b/postgis/mvt.c @@ -23,6 +23,7 @@ **********************************************************************/ #include +#include #include "mvt.h" #include "lwgeom_geos.h" @@ -619,7 +620,8 @@ 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 (FP_NEQUALS(d, (double)l)) + + if (fabs(d - (double)l) > FLT_EPSILON) { MVT_PARSE_VALUE(d, mvt_kv_double_value, double_values_hash, double_value, sizeof(double)); diff --git a/postgis/mvt.h b/postgis/mvt.h index c596437ab..b2ada4226 100644 --- a/postgis/mvt.h +++ b/postgis/mvt.h @@ -38,7 +38,6 @@ #include "access/htup.h" #include "../postgis_config.h" #include "liblwgeom.h" -#include "liblwgeom_internal.h" #include "lwgeom_pg.h" #include "lwgeom_log.h" -- 2.40.0