From e1deb273980052b5495fa85384bfdb4d50bd528a Mon Sep 17 00:00:00 2001 From: Paul Ramsey Date: Thu, 11 Jun 2015 19:20:42 +0000 Subject: [PATCH] #3159, only add boxes to geometries that are input with them git-svn-id: http://svn.osgeo.org/postgis/trunk@13656 b70326c6-7e19-0410-871a-916f4a2858ee --- liblwgeom/lwgeom.c | 2 +- liblwgeom/lwline.c | 7 +++++-- liblwgeom/lwlinearreferencing.c | 28 +++++++++++++++++++--------- postgis/geography_inout.c | 2 ++ postgis/lwgeom_functions_basic.c | 7 +++++-- 5 files changed, 32 insertions(+), 14 deletions(-) diff --git a/liblwgeom/lwgeom.c b/liblwgeom/lwgeom.c index 44ca7798c..a9bb312d8 100644 --- a/liblwgeom/lwgeom.c +++ b/liblwgeom/lwgeom.c @@ -1524,7 +1524,7 @@ void lwgeom_swap_ordinates(LWGEOM *in, LWORD o1, LWORD o2) } /* only refresh bbox if X or Y changed */ - if ( o1 < 2 || o2 < 2 ) { + if ( in->bbox && (o1 < 2 || o2 < 2) ) { lwgeom_drop_bbox(in); lwgeom_add_bbox(in); } diff --git a/liblwgeom/lwline.c b/liblwgeom/lwline.c index 620ce8202..b787eedca 100644 --- a/liblwgeom/lwline.c +++ b/liblwgeom/lwline.c @@ -319,8 +319,11 @@ lwline_add_lwpoint(LWLINE *line, LWPOINT *point, int where) return LW_FAILURE; /* Update the bounding box */ - lwgeom_drop_bbox(lwline_as_lwgeom(line)); - lwgeom_add_bbox(lwline_as_lwgeom(line)); + if ( line->bbox ) + { + lwgeom_drop_bbox(lwline_as_lwgeom(line)); + lwgeom_add_bbox(lwline_as_lwgeom(line)); + } return LW_SUCCESS; } diff --git a/liblwgeom/lwlinearreferencing.c b/liblwgeom/lwlinearreferencing.c index 29bf0a9c3..ca4ce2f3d 100644 --- a/liblwgeom/lwlinearreferencing.c +++ b/liblwgeom/lwlinearreferencing.c @@ -382,9 +382,12 @@ lwpoint_clip_to_ordinate_range(const LWPOINT *point, char ordinate, double from, lwcollection_add_lwgeom(lwgeom_out, lwpoint_as_lwgeom(lwp)); } - /* Set the bbox */ - lwgeom_drop_bbox((LWGEOM*)lwgeom_out); - lwgeom_add_bbox((LWGEOM*)lwgeom_out); + /* Set the bbox, if necessary */ + if ( lwgeom_out->bbox ) + { + lwgeom_drop_bbox((LWGEOM*)lwgeom_out); + lwgeom_add_bbox((LWGEOM*)lwgeom_out); + } return lwgeom_out; } @@ -436,9 +439,12 @@ lwmpoint_clip_to_ordinate_range(const LWMPOINT *mpoint, char ordinate, double fr } } - /* Set the bbox */ - lwgeom_drop_bbox((LWGEOM*)lwgeom_out); - lwgeom_add_bbox((LWGEOM*)lwgeom_out); + /* Set the bbox, if necessary */ + if ( lwgeom_out->bbox ) + { + lwgeom_drop_bbox((LWGEOM*)lwgeom_out); + lwgeom_add_bbox((LWGEOM*)lwgeom_out); + } return lwgeom_out; } @@ -505,8 +511,12 @@ lwmline_clip_to_ordinate_range(const LWMLINE *mline, char ordinate, double from, lwfree(col); } } - lwgeom_drop_bbox((LWGEOM*)lwgeom_out); - lwgeom_add_bbox((LWGEOM*)lwgeom_out); + if ( lwgeom_out->bbox ) + { + lwgeom_drop_bbox((LWGEOM*)lwgeom_out); + lwgeom_add_bbox((LWGEOM*)lwgeom_out); + } + if ( ! homogeneous ) { lwgeom_out->type = COLLECTIONTYPE; @@ -740,7 +750,7 @@ lwline_clip_to_ordinate_range(const LWLINE *line, char ordinate, double from, do lwfree(q); lwfree(r); - if ( lwgeom_out->ngeoms > 0 ) + if ( lwgeom_out->bbox && lwgeom_out->ngeoms > 0 ) { lwgeom_drop_bbox((LWGEOM*)lwgeom_out); lwgeom_add_bbox((LWGEOM*)lwgeom_out); diff --git a/postgis/geography_inout.c b/postgis/geography_inout.c index e615327c5..c80662603 100644 --- a/postgis/geography_inout.c +++ b/postgis/geography_inout.c @@ -597,9 +597,11 @@ Datum geography_from_geometry(PG_FUNCTION_ARGS) ** functions do the right thing. */ lwgeom_set_geodetic(lwgeom, true); + /* Recalculate the boxes after re-setting the geodetic bit */ lwgeom_drop_bbox(lwgeom); lwgeom_add_bbox(lwgeom); + g_ser = geography_serialize(lwgeom); /* diff --git a/postgis/lwgeom_functions_basic.c b/postgis/lwgeom_functions_basic.c index dffd39ca8..45884790c 100644 --- a/postgis/lwgeom_functions_basic.c +++ b/postgis/lwgeom_functions_basic.c @@ -2536,8 +2536,11 @@ Datum LWGEOM_affine(PG_FUNCTION_ARGS) lwgeom_affine(lwgeom, &affine); /* COMPUTE_BBOX TAINTING */ - lwgeom_drop_bbox(lwgeom); - lwgeom_add_bbox(lwgeom); + if ( lwgeom->bbox ) + { + lwgeom_drop_bbox(lwgeom); + lwgeom_add_bbox(lwgeom); + } ret = geometry_serialize(lwgeom); /* Release memory */ -- 2.40.0