From d168bf3b34a571f0e07bca7df95aba4ab6d8e03d Mon Sep 17 00:00:00 2001 From: Paul Ramsey Date: Thu, 8 Dec 2011 19:51:04 +0000 Subject: [PATCH] Remove box3d_extent hack git-svn-id: http://svn.osgeo.org/postgis/trunk@8324 b70326c6-7e19-0410-871a-916f4a2858ee --- doc/reference_misc.xml | 4 +- doc/reference_type.xml | 44 ---------- doc/xsl/postgis_aggs_mm.xml.xsl | 2 +- postgis/legacy.sql.in.c | 30 +------ postgis/lwgeom_box3d.c | 132 +++++++++-------------------- postgis/postgis.sql.in.c | 96 +++++---------------- postgis/postgis_drop.sql.in.c | 3 - postgis/uninstall_legacy.sql.in.c | 1 - postgis/uninstall_postgis.sql.in.c | 9 -- 9 files changed, 68 insertions(+), 253 deletions(-) diff --git a/doc/reference_misc.xml b/doc/reference_misc.xml index 893e06049..8d1c20556 100644 --- a/doc/reference_misc.xml +++ b/doc/reference_misc.xml @@ -341,7 +341,7 @@ SELECT ST_Expand(CAST('BOX3D(778783 2951741 1,794875 2970042.61545891 10)' As bo - box3d_extent ST_Extent + box2d ST_Extent geometry set geomfield @@ -365,7 +365,7 @@ SELECT ST_Expand(CAST('BOX3D(778783 2951741 1,794875 2970042.61545891 10)' As bo - Availability: 1.4.0 As of 1.4.0 now returns a box3d_extent instead of box2d object. + Availability: 1.4.0 Enhanced: 2.0.0 support for Polyhedral surfaces, Triangles and TIN was introduced. diff --git a/doc/reference_type.xml b/doc/reference_type.xml index 207063ee0..80573a193 100644 --- a/doc/reference_type.xml +++ b/doc/reference_type.xml @@ -69,50 +69,6 @@ - - - box3d_extent - A box composed of x min, ymin, zmin, xmax, ymax, zmax. Often used to return the extent of a geometry. - - - - Description - box3d_extent is a data type returned by ST_Extent. In versions prior to PostGIS 1.4, ST_Extent would return a box2d. - - - - Casting Behavior - This section lists the automatic as well as explicit casts allowed for this data type - - - - - Cast To - Behavior - - - box2d - automatic - - - box3d - automatic - - - geometry - automatic - - - - - - - - See Also - - - - geometry diff --git a/doc/xsl/postgis_aggs_mm.xml.xsl b/doc/xsl/postgis_aggs_mm.xml.xsl index 856745c54..fc960268a 100644 --- a/doc/xsl/postgis_aggs_mm.xml.xsl +++ b/doc/xsl/postgis_aggs_mm.xml.xsl @@ -163,7 +163,7 @@ PostGIS Box Functions The functions given below are PostGIS functions that take as input or return as output the box* family of PostGIS spatial types. - The box family of types consists of box2d, box3d, box3d_extent + The box family of types consists of box2d, and box3d diff --git a/postgis/legacy.sql.in.c b/postgis/legacy.sql.in.c index cf235441c..a62cc2af0 100644 --- a/postgis/legacy.sql.in.c +++ b/postgis/legacy.sql.in.c @@ -98,18 +98,6 @@ CREATE OR REPLACE FUNCTION st_bytea(geometry) AS 'MODULE_PATHNAME','LWGEOM_to_bytea' LANGUAGE 'C' IMMUTABLE STRICT; ---- Deprecation in 1.5.0 -CREATE OR REPLACE FUNCTION st_box3d_extent(box3d_extent) - RETURNS box3d - AS 'MODULE_PATHNAME', 'BOX3D_extent_to_BOX3D' - LANGUAGE 'C' IMMUTABLE STRICT; - ---- Deprecation in 1.5.0 -CREATE OR REPLACE FUNCTION st_box2d(box3d_extent) - RETURNS box2d - AS 'MODULE_PATHNAME', 'BOX3D_to_BOX2DFLOAT4' - LANGUAGE 'C' IMMUTABLE STRICT; - -- Deprecation in 1.5.0 CREATE OR REPLACE FUNCTION st_box3d_in(cstring) RETURNS box3d @@ -122,12 +110,6 @@ CREATE OR REPLACE FUNCTION st_box3d_out(box3d) AS 'MODULE_PATHNAME', 'BOX3D_out' LANGUAGE 'C' IMMUTABLE STRICT; ---- Deprecation in 1.5.0 -CREATE OR REPLACE FUNCTION st_geometry(box3d_extent) - RETURNS geometry - AS 'MODULE_PATHNAME','BOX3D_to_LWGEOM' - LANGUAGE 'C' IMMUTABLE STRICT; - -- START MANAGEMENT FUNCTIONS -- These are legacy management functions with no place in our 2.0 world ----------------------------------------------------------------------- @@ -782,18 +764,12 @@ CREATE OR REPLACE FUNCTION Expand(geometry,float8) RETURNS geometry AS 'MODULE_PATHNAME', 'LWGEOM_expand' LANGUAGE 'C' IMMUTABLE STRICT; - --- Deprecation in 1.2.3 --- Temporary hack function -CREATE OR REPLACE FUNCTION Combine_Bbox(box3d_extent,geometry) - RETURNS box3d_extent - AS 'MODULE_PATHNAME', 'BOX3D_combine' - LANGUAGE 'C' IMMUTABLE; - + CREATE AGGREGATE Extent( sfunc = ST_combine_bbox, basetype = geometry, - stype = box3d_extent + finalfunc = box2d, + stype = box3d ); -- Deprecation in 1.2.3 diff --git a/postgis/lwgeom_box3d.c b/postgis/lwgeom_box3d.c index beff4830f..4ef40e318 100644 --- a/postgis/lwgeom_box3d.c +++ b/postgis/lwgeom_box3d.c @@ -25,8 +25,6 @@ /* forward defs */ Datum BOX3D_in(PG_FUNCTION_ARGS); Datum BOX3D_out(PG_FUNCTION_ARGS); -Datum BOX3D_extent_out(PG_FUNCTION_ARGS); -Datum BOX3D_extent_to_BOX3D(PG_FUNCTION_ARGS); Datum LWGEOM_to_BOX3D(PG_FUNCTION_ARGS); Datum BOX3D_to_LWGEOM(PG_FUNCTION_ARGS); Datum BOX3D_expand(PG_FUNCTION_ARGS); @@ -139,55 +137,6 @@ Datum BOX3D_out(PG_FUNCTION_ARGS) 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_extent_to_BOX3D); -Datum BOX3D_extent_to_BOX3D(PG_FUNCTION_ARGS) -{ - BOX3D *in = (BOX3D *)PG_GETARG_POINTER(0); - BOX3D *out = palloc(sizeof(BOX3D)); - out->xmin = in->xmin; - out->xmax = in->xmax; - out->ymin = in->ymin; - out->ymax = in->ymax; - - PG_RETURN_POINTER(out); -} PG_FUNCTION_INFO_V1(BOX3D_to_BOX2DFLOAT4); Datum BOX3D_to_BOX2DFLOAT4(PG_FUNCTION_ARGS) @@ -387,69 +336,68 @@ Datum BOX3D_zmax(PG_FUNCTION_ARGS) PG_RETURN_FLOAT8(Max(box->zmin, box->zmax)); } - +/** +* Used in the ST_Extent and ST_Extent3D aggregates, does not read the +* serialized cached bounding box (since that is floating point) +* but calculates the box in full from the underlying geometry. +*/ PG_FUNCTION_INFO_V1(BOX3D_combine); Datum BOX3D_combine(PG_FUNCTION_ARGS) { - Pointer box3d_ptr = PG_GETARG_POINTER(0); - Pointer geom_ptr = PG_GETARG_POINTER(1); - BOX3D *a,*b; - GSERIALIZED *geom; - LWGEOM *lwgeom; - BOX3D *result; + BOX3D *box = (BOX3D*)PG_GETARG_POINTER(0); + GSERIALIZED *geom = (GSERIALIZED*)PG_DETOAST_DATUM(PG_GETARG_POINTER(1)); + LWGEOM *lwgeom = NULL; + BOX3D *result = NULL; GBOX gbox; int rv; - if ( (box3d_ptr == NULL) && (geom_ptr == NULL) ) - { + /* Can't do anything with null inputs */ + if ( (box == NULL) && (geom == NULL) ) PG_RETURN_NULL(); - } - - if (box3d_ptr == NULL) - { - geom = (GSERIALIZED *)PG_DETOAST_DATUM(PG_GETARG_DATUM(1)); - lwgeom = lwgeom_from_gserialized(geom); - rv = lwgeom_calculate_gbox(lwgeom, &gbox); - if ( rv == LW_FAILURE ) - { - lwgeom_free(lwgeom); - PG_FREE_IF_COPY(geom, 1); - PG_RETURN_NULL(); /* must be the empty geom */ - } - result = box3d_from_gbox(&gbox); - PG_RETURN_POINTER(result); - } - - /* combine_bbox(BOX3D, null) => BOX3D */ - if (geom_ptr == NULL) + /* Null geometry but non-null box, return the box */ + if (geom == NULL) { result = palloc(sizeof(BOX3D)); - memcpy(result, (char *)PG_GETARG_DATUM(0), sizeof(BOX3D)); + memcpy(result, box, sizeof(BOX3D)); PG_RETURN_POINTER(result); } - geom = (GSERIALIZED *)PG_DETOAST_DATUM(PG_GETARG_DATUM(1)); + /* Deserialize geometry and *calculate( the box */ + /* We can't use the cached box because it's fload, we *must* calculate */ lwgeom = lwgeom_from_gserialized(geom); rv = lwgeom_calculate_gbox(lwgeom, &gbox); - result = palloc(sizeof(BOX3D)); + lwgeom_free(lwgeom); + + /* If we couldn't calculate the box, return what we know */ if ( rv == LW_FAILURE ) { - lwgeom_free(lwgeom); PG_FREE_IF_COPY(geom, 1); - memcpy(result, (char *)PG_GETARG_DATUM(0), sizeof(BOX3D)); + /* No geom box, no input box, so null return */ + if ( box == NULL ) + PG_RETURN_NULL(); + result = palloc(sizeof(BOX3D)); + memcpy(result, box, sizeof(BOX3D)); PG_RETURN_POINTER(result); } - a = (BOX3D *)PG_GETARG_POINTER(0); - b = box3d_from_gbox(&gbox); - result->xmax = Max(a->xmax, b->xmax); - result->ymax = Max(a->ymax, b->ymax); - result->zmax = Max(a->zmax, b->zmax); - result->xmin = Min(a->xmin, b->xmin); - result->ymin = Min(a->ymin, b->ymin); - result->zmin = Min(a->zmin, b->zmin); + /* Null box and non-null geometry, just return the geometry box */ + if ( box == NULL ) + { + PG_FREE_IF_COPY(geom, 1); + result = box3d_from_gbox(&gbox); + PG_RETURN_POINTER(result); + } + result = palloc(sizeof(BOX3D)); + result->xmax = Max(box->xmax, gbox.xmax); + result->ymax = Max(box->ymax, gbox.ymax); + result->zmax = Max(box->zmax, gbox.zmax); + result->xmin = Min(box->xmin, gbox.xmin); + result->ymin = Min(box->ymin, gbox.ymin); + result->zmin = Min(box->zmin, gbox.zmin); + + PG_FREE_IF_COPY(geom, 1); PG_RETURN_POINTER(result); } diff --git a/postgis/postgis.sql.in.c b/postgis/postgis.sql.in.c index 80815de85..9ac9da418 100644 --- a/postgis/postgis.sql.in.c +++ b/postgis/postgis.sql.in.c @@ -211,39 +211,6 @@ CREATE TYPE box3d ( output = 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. -CREATE OR REPLACE FUNCTION box3d_extent_in(cstring) - RETURNS box3d_extent - AS 'MODULE_PATHNAME', 'BOX3D_in' - LANGUAGE 'C' IMMUTABLE STRICT; - -CREATE OR REPLACE FUNCTION box3d_extent_out(box3d_extent) - RETURNS cstring - AS 'MODULE_PATHNAME', 'BOX3D_extent_out' - LANGUAGE 'C' IMMUTABLE STRICT; - -CREATE TYPE box3d_extent ( - alignment = double, - internallength = 48, - input = box3d_extent_in, - output = box3d_extent_out -); - --- Availability: 1.4.0 -CREATE OR REPLACE FUNCTION box3d_extent(box3d_extent) - RETURNS box3d - AS 'MODULE_PATHNAME', 'BOX3D_extent_to_BOX3D' - LANGUAGE 'C' IMMUTABLE STRICT; - -CREATE OR REPLACE FUNCTION geometry(box3d_extent) - RETURNS geometry - AS 'MODULE_PATHNAME','BOX3D_to_LWGEOM' - LANGUAGE 'C' IMMUTABLE STRICT; - --- End of temporary hack - -- Availability: 1.2.2 CREATE OR REPLACE FUNCTION ST_XMin(box3d) RETURNS FLOAT8 @@ -313,11 +280,6 @@ CREATE OR REPLACE FUNCTION postgis_getbbox(geometry) AS 'MODULE_PATHNAME','LWGEOM_to_BOX2DFLOAT4' LANGUAGE 'C' IMMUTABLE STRICT; -CREATE OR REPLACE FUNCTION box2d(box3d_extent) - RETURNS box2d - AS 'MODULE_PATHNAME', 'BOX3D_to_BOX2DFLOAT4' - LANGUAGE 'C' IMMUTABLE STRICT; - -- Availability: 1.2.2 CREATE OR REPLACE FUNCTION ST_MakeBox2d(geometry, geometry) RETURNS box2d @@ -1324,38 +1286,6 @@ CREATE OR REPLACE FUNCTION ST_DumpPoints(geometry) RETURNS SETOF geometry_dump A $$ LANGUAGE SQL STRICT; ------------------------------------------------------------------------- - --- --- Aggregate functions --- --- Temporary hack function -CREATE OR REPLACE FUNCTION ST_Combine_BBox(box3d_extent,geometry) - RETURNS box3d_extent - AS 'MODULE_PATHNAME', 'BOX3D_combine' - LANGUAGE 'C' IMMUTABLE; - --- Availability: 1.2.2 -CREATE AGGREGATE ST_Extent( - sfunc = ST_combine_bbox, - basetype = geometry, - stype = box3d_extent - ); - --- Availability: 1.2.2 -CREATE OR REPLACE FUNCTION ST_Combine_BBox(box3d,geometry) - RETURNS box3d - AS 'MODULE_PATHNAME', 'BOX3D_combine' - LANGUAGE 'C' IMMUTABLE; - --- Availability: 2.0.0 -CREATE AGGREGATE ST_3DExtent( - sfunc = ST_combine_bbox, - basetype = geometry, - stype = box3d - ); - - ------------------------------------------------------------------- -- SPATIAL_REF_SYS @@ -2357,10 +2287,6 @@ CREATE CAST (geometry AS text) WITH FUNCTION text(geometry) AS IMPLICIT; CREATE CAST (bytea AS geometry) WITH FUNCTION geometry(bytea) AS IMPLICIT; CREATE CAST (geometry AS bytea) WITH FUNCTION bytea(geometry) AS IMPLICIT; --- Casts to allow the box3d_extent type to automatically cast to box3d/box2d in queries -CREATE CAST (box3d_extent AS box3d) WITH FUNCTION box3d_extent(box3d_extent) AS IMPLICIT; -CREATE CAST (box3d_extent AS box2d) WITH FUNCTION box2d(box3d_extent) AS IMPLICIT; -CREATE CAST (box3d_extent AS geometry) WITH FUNCTION geometry(box3d_extent) AS IMPLICIT; --------------------------------------------------------------- -- Algorithms @@ -2789,6 +2715,28 @@ CREATE OR REPLACE FUNCTION ST_Node(g geometry) -- Aggregates and their supporting functions -------------------------------------------------------------------------------- +------------------------------------------------------------------------ +-- Availability: 1.2.2 +CREATE OR REPLACE FUNCTION ST_Combine_BBox(box3d,geometry) + RETURNS box3d + AS 'MODULE_PATHNAME', 'BOX3D_combine' + LANGUAGE 'C' IMMUTABLE; + +-- Availability: 1.2.2 +CREATE AGGREGATE ST_Extent( + sfunc = ST_combine_bbox, + finalfunc = box2d, + basetype = geometry, + stype = box3d + ); + +-- Availability: 2.0.0 +CREATE AGGREGATE ST_3DExtent( + sfunc = ST_combine_bbox, + basetype = geometry, + stype = box3d + ); + -- Availability: 1.2.2 CREATE OR REPLACE FUNCTION ST_Collect(geometry, geometry) RETURNS geometry diff --git a/postgis/postgis_drop.sql.in.c b/postgis/postgis_drop.sql.in.c index 743d29ad4..68a16938f 100644 --- a/postgis/postgis_drop.sql.in.c +++ b/postgis/postgis_drop.sql.in.c @@ -39,7 +39,6 @@ DROP FUNCTION IF EXISTS st_box2d_in(cstring); DROP FUNCTION IF EXISTS st_box2d_out(box2d); DROP FUNCTION IF EXISTS st_box2d(geometry); DROP FUNCTION IF EXISTS st_box2d(box3d); -DROP FUNCTION IF EXISTS st_box2d(box3d_extent); DROP FUNCTION IF EXISTS st_box3d(box2d); DROP FUNCTION IF EXISTS st_box(box3d); DROP FUNCTION IF EXISTS st_box3d(geometry); @@ -51,8 +50,6 @@ DROP FUNCTION IF EXISTS st_geometry(box3d); DROP FUNCTION IF EXISTS st_geometry(text); DROP FUNCTION IF EXISTS st_geometry(bytea); DROP FUNCTION IF EXISTS st_bytea(geometry); -DROP FUNCTION IF EXISTS st_box3d_extent(box3d_extent); -DROP FUNCTION IF EXISTS st_geometry(box3d_extent); DROP FUNCTION IF EXISTS st_addbbox(geometry); DROP FUNCTION IF EXISTS st_dropbbox(geometry); DROP FUNCTION IF EXISTS st_hasbbox(geometry); diff --git a/postgis/uninstall_legacy.sql.in.c b/postgis/uninstall_legacy.sql.in.c index 23cd46624..b4d46875a 100644 --- a/postgis/uninstall_legacy.sql.in.c +++ b/postgis/uninstall_legacy.sql.in.c @@ -55,7 +55,6 @@ DROP FUNCTION IF EXISTS Buffer(geometry,float8,integer); DROP FUNCTION IF EXISTS Buffer(geometry,float8); DROP FUNCTION IF EXISTS BuildArea(geometry); DROP FUNCTION IF EXISTS Centroid(geometry); -DROP FUNCTION IF EXISTS Combine_Bbox(box3d_extent,geometry); DROP FUNCTION IF EXISTS Contains(geometry,geometry); DROP FUNCTION IF EXISTS ConvexHull(geometry); DROP FUNCTION IF EXISTS Crosses(geometry,geometry); diff --git a/postgis/uninstall_postgis.sql.in.c b/postgis/uninstall_postgis.sql.in.c index 8f1f00a8c..8d4b86b2c 100644 --- a/postgis/uninstall_postgis.sql.in.c +++ b/postgis/uninstall_postgis.sql.in.c @@ -422,10 +422,6 @@ DROP FUNCTION Simplify(geometry, float8); -- CASTS --------------------------------------------------------------- -DROP CAST (box3d_extent AS geometry); -DROP CAST (box3d_extent AS box2d); -DROP CAST (box3d_extent AS box3d); - DROP CAST (geometry AS bytea); DROP CAST (bytea AS geometry); DROP CAST (chip AS geometry); @@ -546,8 +542,6 @@ DROP FUNCTION ST_Combine_BBox(box3d,geometry); DROP FUNCTION combine_bbox(box3d,geometry); DROP AGGREGATE ST_Extent(geometry); DROP AGGREGATE Extent(geometry); -DROP FUNCTION ST_Combine_BBox(box3d_extent,geometry); -DROP FUNCTION combine_bbox(box3d_extent,geometry); DROP FUNCTION ST_Combine_BBox(box2d,geometry); DROP FUNCTION combine_bbox(box2d,geometry); @@ -817,9 +811,6 @@ DROP FUNCTION ymin(box3d); DROP FUNCTION ST_XMin(box3d); DROP FUNCTION xmin(box3d); --- This drops box3d_extent_in, box3d_extent_out and the type in an atomic fashion -DROP TYPE box3d_extent CASCADE; - -- This drops ST_box3d_in, ST_box3d_out, box3d_in, box3d_out and the type in an atomic fashion DROP TYPE box3d CASCADE; -- 2.50.1