[postgis-tickets] r16143 - Add lwgeom_refresh_bbox to replace drop/add twostep
Paul Ramsey
pramsey at cleverelephant.ca
Mon Dec 11 07:04:02 PST 2017
Author: pramsey
Date: 2017-12-11 07:04:01 -0800 (Mon, 11 Dec 2017)
New Revision: 16143
Modified:
trunk/liblwgeom/liblwgeom.h.in
trunk/liblwgeom/lwgeom.c
trunk/liblwgeom/lwline.c
trunk/liblwgeom/lwlinearreferencing.c
trunk/postgis/geography_inout.c
trunk/postgis/lwgeom_functions_basic.c
trunk/postgis/lwgeom_transform.c
Log:
Add lwgeom_refresh_bbox to replace drop/add twostep
Modified: trunk/liblwgeom/liblwgeom.h.in
===================================================================
--- trunk/liblwgeom/liblwgeom.h.in 2017-12-11 14:27:54 UTC (rev 16142)
+++ trunk/liblwgeom/liblwgeom.h.in 2017-12-11 15:04:01 UTC (rev 16143)
@@ -735,6 +735,10 @@
*/
extern void lwgeom_add_bbox(LWGEOM *lwgeom);
/**
+* Drop current bbox and calculate a fresh one.
+*/
+extern void lwgeom_refresh_bbox(LWGEOM *lwgeom);
+/**
* Compute a box for geom and all sub-geometries, if not already computed
*/
extern void lwgeom_add_bbox_deep(LWGEOM *lwgeom, GBOX *gbox);
Modified: trunk/liblwgeom/lwgeom.c
===================================================================
--- trunk/liblwgeom/lwgeom.c 2017-12-11 14:27:54 UTC (rev 16142)
+++ trunk/liblwgeom/lwgeom.c 2017-12-11 15:04:01 UTC (rev 16143)
@@ -688,6 +688,13 @@
}
void
+lwgeom_refresh_bbox(LWGEOM *lwgeom)
+{
+ lwgeom_drop_bbox(lwgeom);
+ lwgeom_add_bbox(lwgeom);
+}
+
+void
lwgeom_add_bbox_deep(LWGEOM *lwgeom, GBOX *gbox)
{
if ( lwgeom_is_empty(lwgeom) ) return;
@@ -1556,8 +1563,7 @@
/* only refresh bbox if X or Y changed */
if ( in->bbox && (o1 < 2 || o2 < 2) )
{
- lwgeom_drop_bbox(in);
- lwgeom_add_bbox(in);
+ lwgeom_refresh_bbox(in);
}
}
Modified: trunk/liblwgeom/lwline.c
===================================================================
--- trunk/liblwgeom/lwline.c 2017-12-11 14:27:54 UTC (rev 16142)
+++ trunk/liblwgeom/lwline.c 2017-12-11 15:04:01 UTC (rev 16143)
@@ -344,8 +344,7 @@
/* Update the bounding box */
if ( line->bbox )
{
- lwgeom_drop_bbox(lwline_as_lwgeom(line));
- lwgeom_add_bbox(lwline_as_lwgeom(line));
+ lwgeom_refresh_bbox((LWGEOM*)line);
}
return LW_SUCCESS;
@@ -377,8 +376,7 @@
/* Update the box, if there is one to update */
if ( line->bbox )
{
- lwgeom_drop_bbox((LWGEOM*)line);
- lwgeom_add_bbox((LWGEOM*)line);
+ lwgeom_refresh_bbox((LWGEOM*)line);
}
}
Modified: trunk/liblwgeom/lwlinearreferencing.c
===================================================================
--- trunk/liblwgeom/lwlinearreferencing.c 2017-12-11 14:27:54 UTC (rev 16142)
+++ trunk/liblwgeom/lwlinearreferencing.c 2017-12-11 15:04:01 UTC (rev 16143)
@@ -400,8 +400,7 @@
/* Set the bbox, if necessary */
if ( lwgeom_out->bbox )
{
- lwgeom_drop_bbox((LWGEOM*)lwgeom_out);
- lwgeom_add_bbox((LWGEOM*)lwgeom_out);
+ lwgeom_refresh_bbox((LWGEOM*)lwgeom_out);
}
return lwgeom_out;
@@ -457,8 +456,7 @@
/* Set the bbox, if necessary */
if ( lwgeom_out->bbox )
{
- lwgeom_drop_bbox((LWGEOM*)lwgeom_out);
- lwgeom_add_bbox((LWGEOM*)lwgeom_out);
+ lwgeom_refresh_bbox((LWGEOM*)lwgeom_out);
}
return lwgeom_out;
@@ -528,8 +526,7 @@
}
if ( lwgeom_out->bbox )
{
- lwgeom_drop_bbox((LWGEOM*)lwgeom_out);
- lwgeom_add_bbox((LWGEOM*)lwgeom_out);
+ lwgeom_refresh_bbox((LWGEOM*)lwgeom_out);
}
if ( ! homogeneous )
@@ -762,8 +759,7 @@
if ( lwgeom_out->bbox && lwgeom_out->ngeoms > 0 )
{
- lwgeom_drop_bbox((LWGEOM*)lwgeom_out);
- lwgeom_add_bbox((LWGEOM*)lwgeom_out);
+ lwgeom_refresh_bbox((LWGEOM*)lwgeom_out);
}
return lwgeom_out;
Modified: trunk/postgis/geography_inout.c
===================================================================
--- trunk/postgis/geography_inout.c 2017-12-11 14:27:54 UTC (rev 16142)
+++ trunk/postgis/geography_inout.c 2017-12-11 15:04:01 UTC (rev 16143)
@@ -638,8 +638,7 @@
/* Recalculate the boxes after re-setting the geodetic bit */
lwgeom_set_geodetic(lwgeom, false);
- lwgeom_drop_bbox(lwgeom);
- lwgeom_add_bbox(lwgeom);
+ lwgeom_refresh_bbox(lwgeom);
/* We want "geometry" to think all our "geography" has an SRID, and the
implied SRID is the default, so we fill that in if our SRID is actually unknown. */
Modified: trunk/postgis/lwgeom_functions_basic.c
===================================================================
--- trunk/postgis/lwgeom_functions_basic.c 2017-12-11 14:27:54 UTC (rev 16142)
+++ trunk/postgis/lwgeom_functions_basic.c 2017-12-11 15:04:01 UTC (rev 16143)
@@ -2632,8 +2632,7 @@
/* COMPUTE_BBOX TAINTING */
if ( lwgeom->bbox )
{
- lwgeom_drop_bbox(lwgeom);
- lwgeom_add_bbox(lwgeom);
+ lwgeom_refresh_bbox(lwgeom);
}
ret = geometry_serialize(lwgeom);
Modified: trunk/postgis/lwgeom_transform.c
===================================================================
--- trunk/postgis/lwgeom_transform.c 2017-12-11 14:27:54 UTC (rev 16142)
+++ trunk/postgis/lwgeom_transform.c 2017-12-11 15:04:01 UTC (rev 16143)
@@ -55,30 +55,27 @@
output_srid = PG_GETARG_INT32(1);
if (output_srid == SRID_UNKNOWN)
{
- elog(ERROR,"%d is an invalid target SRID",SRID_UNKNOWN);
+ elog(ERROR, "%d is an invalid target SRID", SRID_UNKNOWN);
PG_RETURN_NULL();
}
+ /* Input SRID and output SRID are equal, noop */
+ if ( input_srid == output_srid )
+ PG_RETURN_POINTER(PG_GETARG_DATUM(0));
+
geom = PG_GETARG_GSERIALIZED_P_COPY(0);
input_srid = gserialized_get_srid(geom);
if ( input_srid == SRID_UNKNOWN )
{
PG_FREE_IF_COPY(geom, 0);
- elog(ERROR,"Input geometry has unknown (%d) SRID",SRID_UNKNOWN);
+ elog(ERROR, "Input geometry has unknown (%d) SRID", SRID_UNKNOWN);
PG_RETURN_NULL();
}
- /*
- * If input SRID and output SRID are equal, return geometry
- * without transform it
- */
- if ( input_srid == output_srid )
- PG_RETURN_POINTER(PG_GETARG_DATUM(0));
-
if ( GetProjectionsUsingFCInfo(fcinfo, input_srid, output_srid, &input_pj, &output_pj) == LW_FAILURE )
{
PG_FREE_IF_COPY(geom, 0);
- elog(ERROR,"Failure reading projections from spatial_ref_sys.");
+ elog(ERROR, "Failure reading projections from spatial_ref_sys.");
PG_RETURN_NULL();
}
@@ -90,8 +87,7 @@
/* Re-compute bbox if input had one (COMPUTE_BBOX TAINTING) */
if ( lwgeom->bbox )
{
- lwgeom_drop_bbox(lwgeom);
- lwgeom_add_bbox(lwgeom);
+ lwgeom_refresh_bbox(lwgeom);
}
result = geometry_serialize(lwgeom);
@@ -186,8 +182,7 @@
/* Re-compute bbox if input had one (COMPUTE_BBOX TAINTING) */
if ( lwgeom->bbox )
{
- lwgeom_drop_bbox(lwgeom);
- lwgeom_add_bbox(lwgeom);
+ lwgeom_refresh_bbox(lwgeom);
}
result = geometry_serialize(lwgeom);
More information about the postgis-tickets
mailing list