From: Sandro Santilli Date: Fri, 9 Dec 2011 14:37:16 +0000 (+0000) Subject: Add a public lwgeom_get_bbox function (#1324) X-Git-Tag: 2.0.0alpha1~538 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=26fbbe94579d83863795ff02ddd3c86630b16ade;p=postgis Add a public lwgeom_get_bbox function (#1324) git-svn-id: http://svn.osgeo.org/postgis/trunk@8335 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/liblwgeom/liblwgeom.h.in b/liblwgeom/liblwgeom.h.in index 1a522853a..ca3e20597 100644 --- a/liblwgeom/liblwgeom.h.in +++ b/liblwgeom/liblwgeom.h.in @@ -653,10 +653,22 @@ extern void lwgeom_drop_bbox(LWGEOM *lwgeom); extern void lwgeom_drop_srid(LWGEOM *lwgeom); /** -* Compute a bbox if not already computed -*/ + * Compute a bbox if not already computed + * + * After calling this function lwgeom->bbox is only + * NULL if the geometry is empty. + */ extern void lwgeom_add_bbox(LWGEOM *lwgeom); +/** + * Get a non-empty geometry bounding box, computing and + * caching it if not already there + * + * NOTE: empty geometries don't have a bounding box so + * you'd still get a NULL for them. + */ +extern const GBOX *lwgeom_get_bbox(const LWGEOM *lwgeom); + /** * Determine whether a LWGEOM can contain sub-geometries or not */ diff --git a/liblwgeom/lwgeom.c b/liblwgeom/lwgeom.c index 20bab78f2..da3904552 100644 --- a/liblwgeom/lwgeom.c +++ b/liblwgeom/lwgeom.c @@ -551,6 +551,15 @@ lwgeom_add_bbox(LWGEOM *lwgeom) lwgeom_calculate_gbox(lwgeom, lwgeom->bbox); } +const GBOX * +lwgeom_get_bbox(const LWGEOM *lwg) +{ + /* add it if not already there */ + lwgeom_add_bbox((LWGEOM *)lwg); + return lwg->bbox; +} + + /** * Calculate the gbox for this goemetry, a cartesian box or * geodetic box, depending on how it is flagged. diff --git a/liblwgeom/lwout_gml.c b/liblwgeom/lwout_gml.c index df7b83f42..79046a597 100644 --- a/liblwgeom/lwout_gml.c +++ b/liblwgeom/lwout_gml.c @@ -53,14 +53,6 @@ static size_t pointArray_toGML3(POINTARRAY *pa, char *buf, int precision, int op static size_t pointArray_GMLsize(POINTARRAY *pa, int precision); -static const GBOX * -lwgeom_get_bbox(const LWGEOM *lwg) -{ - /* if ( ! lwg->bbox ) lwnotice("Adding a bbox"); */ - lwgeom_add_bbox((LWGEOM *)lwg); /* adds one if not already there */ - return lwg->bbox; -} - static char * gbox_to_gml2(const GBOX *bbox, const char *srs, int precision, const char *prefix) {