[postgis-commits] svn - r3811 - in trunk: postgis regress
postgis-commits at postgis.refractions.net
postgis-commits at postgis.refractions.net
Sun Mar 8 15:33:31 PDT 2009
Author: mcayland
Date: 2009-03-08 15:33:31 -0700 (Sun, 08 Mar 2009)
New Revision: 3811
Modified:
trunk/postgis/lwgeom_box3d.c
trunk/postgis/postgis.sql.in.c
trunk/regress/lwgeom_regress_expected
Log:
Fix for GBT#93: ST_Extent() and ST_Estimated_Extent() return BOX2DFLOAT4s. This is currently done using a horrible hack for backwards compatibility which introduces a new type just for ST_Extent(). See GBT email to postgis-devel and code comments for more detail.
Modified: trunk/postgis/lwgeom_box3d.c
===================================================================
--- trunk/postgis/lwgeom_box3d.c 2009-03-08 21:46:25 UTC (rev 3810)
+++ trunk/postgis/lwgeom_box3d.c 2009-03-08 22:33:31 UTC (rev 3811)
@@ -26,6 +26,7 @@
/* forward defs */
Datum BOX3D_in(PG_FUNCTION_ARGS);
Datum BOX3D_out(PG_FUNCTION_ARGS);
+Datum BOX3D_extent_out(PG_FUNCTION_ARGS);
Datum LWGEOM_to_BOX3D(PG_FUNCTION_ARGS);
Datum BOX3D_to_LWGEOM(PG_FUNCTION_ARGS);
Datum BOX3D_expand(PG_FUNCTION_ARGS);
@@ -138,6 +139,43 @@
PG_RETURN_CSTRING(result);
}
+/*
+ * Takes an internal rep of a BOX3D and returns a string rep.
+ * but beginning with BOX(...) and with only 2 dimensions. This
+ * is a temporary hack to allow ST_Extent() to return a result
+ * with the precision of BOX2DFLOAT4 but with the BOX2DFLOAT4
+ * output format.
+ *
+ * example:
+ * "BOX(xmin ymin, xmax ymax)"
+ */
+PG_FUNCTION_INFO_V1(BOX3D_extent_out);
+Datum BOX3D_extent_out(PG_FUNCTION_ARGS)
+{
+ BOX3D *bbox = (BOX3D *) PG_GETARG_POINTER(0);
+ int size;
+ char *result;
+
+ if (bbox == NULL)
+ {
+ result = palloc(5);
+ strcat(result,"NULL");
+ PG_RETURN_CSTRING(result);
+ }
+
+
+ /*double digits+ "BOX3D"+ "()" + commas +null */
+ size = MAX_DIGS_DOUBLE*6+5+2+4+5+1;
+
+ result = (char *) palloc(size);
+
+ sprintf(result, "BOX(%.15g %.15g,%.15g %.15g)",
+ bbox->xmin, bbox->ymin,
+ bbox->xmax,bbox->ymax);
+
+ PG_RETURN_CSTRING(result);
+}
+
PG_FUNCTION_INFO_V1(BOX3D_to_BOX2DFLOAT4);
Datum BOX3D_to_BOX2DFLOAT4(PG_FUNCTION_ARGS)
{
Modified: trunk/postgis/postgis.sql.in.c
===================================================================
--- trunk/postgis/postgis.sql.in.c 2009-03-08 21:46:25 UTC (rev 3810)
+++ trunk/postgis/postgis.sql.in.c 2009-03-08 22:33:31 UTC (rev 3811)
@@ -328,6 +328,27 @@
output = ST_box3d_out
);
+-- Temporary box3d aggregate type to retain full double precision
+-- for ST_Extent(). Should be removed when we change the output
+-- type of ST_Extent() to return something other than BOX2DFLOAT4.
+CREATEFUNCTION box3d_extent_in(cstring)
+ RETURNS box3d_extent
+ AS '$libdir/postgis-1.4', 'BOX3D_in'
+ LANGUAGE 'C' IMMUTABLE STRICT; -- WITH (isstrict);
+
+CREATEFUNCTION box3d_extent_out(box3d_extent)
+ RETURNS cstring
+ AS 'MODULE_PATHNAME', 'BOX3D_extent_out'
+ LANGUAGE 'C' _IMMUTABLE_STRICT; -- WITH (isstrict);
+
+CREATE TYPE box3d_extent (
+ alignment = double,
+ internallength = 48,
+ input = box3d_extent_in,
+ output = box3d_extent_out
+);
+-- End of temporary hack
+
-- Deprecation in 1.2.3
CREATEFUNCTION xmin(box3d)
RETURNS FLOAT8
@@ -2017,18 +2038,30 @@
AS 'MODULE_PATHNAME', 'BOX2DFLOAT4_combine'
LANGUAGE 'C' _IMMUTABLE;
+-- Temporary hack function
+CREATEFUNCTION combine_bbox(box3d_extent,geometry)
+ RETURNS box3d_extent
+ AS 'MODULE_PATHNAME', 'BOX3D_combine'
+ LANGUAGE 'C' _IMMUTABLE;
+
+-- Temporary hack function
+CREATEFUNCTION ST_Combine_BBox(box3d_extent,geometry)
+ RETURNS box3d_extent
+ AS 'MODULE_PATHNAME', 'BOX3D_combine'
+ LANGUAGE 'C' _IMMUTABLE;
+
-- Deprecation in 1.2.3
CREATE AGGREGATE Extent(
sfunc = ST_combine_bbox,
basetype = geometry,
- stype = box2d
+ stype = box3d_extent
);
-- Availability: 1.2.2
CREATE AGGREGATE ST_Extent(
sfunc = ST_combine_bbox,
basetype = geometry,
- stype = box2d
+ stype = box3d_extent
);
-- Deprecation in 1.2.3
Modified: trunk/regress/lwgeom_regress_expected
===================================================================
--- trunk/regress/lwgeom_regress_expected 2009-03-08 21:46:25 UTC (rev 3810)
+++ trunk/regress/lwgeom_regress_expected 2009-03-08 22:33:31 UTC (rev 3811)
@@ -1,11 +1,11 @@
-BOX(0 0.0999999940395355,11 12)
+BOX(0 0.1,11 12)
BOX3D(0 0.1 -55,11 12 12)
10431
15063
19695
15063
10431
-BOX(0 0.0999999940395355,11 12)
+BOX(0 0.1,11 12)
BOX3D(0 0.1 -55,11 12 12)
10431
15063
More information about the postgis-commits
mailing list