From af4b2b0318bbb2268b91d610dac249c79704164e Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Mon, 20 Dec 2004 14:01:48 +0000 Subject: [PATCH] Added dropBBOX(). git-svn-id: http://svn.osgeo.org/postgis/trunk@1165 b70326c6-7e19-0410-871a-916f4a2858ee --- lwgeom/lwgeom_inout.c | 41 +++++++++++++++++++++++++++++++++++++++++ lwgeom/lwpostgis.sql.in | 5 +++++ 2 files changed, 46 insertions(+) diff --git a/lwgeom/lwgeom_inout.c b/lwgeom/lwgeom_inout.c index afd6db24b..ad0278a37 100644 --- a/lwgeom/lwgeom_inout.c +++ b/lwgeom/lwgeom_inout.c @@ -38,6 +38,7 @@ Datum WKBFromLWGEOM(PG_FUNCTION_ARGS); Datum LWGEOM_in(PG_FUNCTION_ARGS); Datum LWGEOM_out(PG_FUNCTION_ARGS); Datum LWGEOM_addBBOX(PG_FUNCTION_ARGS); +Datum LWGEOM_dropBBOX(PG_FUNCTION_ARGS); Datum LWGEOM_getBBOX(PG_FUNCTION_ARGS); Datum LWGEOM_to_text(PG_FUNCTION_ARGS); Datum LWGEOM_to_bytea(PG_FUNCTION_ARGS); @@ -404,6 +405,46 @@ Datum LWGEOM_addBBOX(PG_FUNCTION_ARGS) PG_RETURN_POINTER(result); } +// removes a bbox from a geometry +PG_FUNCTION_INFO_V1(LWGEOM_dropBBOX); +Datum LWGEOM_dropBBOX(PG_FUNCTION_ARGS) +{ + PG_LWGEOM *lwgeom = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0)); + PG_LWGEOM *result; + unsigned char old_type; + int size; + +//elog(NOTICE,"in LWGEOM_dropBBOX"); + + if (!lwgeom_hasBBOX( lwgeom->type ) ) + { +//elog(NOTICE,"LWGEOM_dropBBOX -- doesnt have a bbox already"); + result = palloc (lwgeom->size); + memcpy(result, lwgeom, lwgeom->size); + PG_RETURN_POINTER(result); + } + +//elog(NOTICE,"LWGEOM_dropBBOX -- dropping the bbox"); + + //construct new one + old_type = lwgeom->type; + + size = lwgeom->size-sizeof(BOX2DFLOAT4); + + result = palloc(size);// 16 for bbox2d + + memcpy(result,&size,4); // size + result->type = lwgeom_makeType_full( + TYPE_HASZ(old_type), + TYPE_HASM(old_type), + lwgeom_hasSRID(old_type), lwgeom_getType(old_type), 0); + + // everything but the type and length + memcpy(result->data, lwgeom->data+sizeof(BOX2DFLOAT4), lwgeom->size-5-sizeof(BOX2DFLOAT4)); + + PG_RETURN_POINTER(result); +} + //for the wkt parser diff --git a/lwgeom/lwpostgis.sql.in b/lwgeom/lwpostgis.sql.in index a09aed936..de845231a 100644 --- a/lwgeom/lwpostgis.sql.in +++ b/lwgeom/lwpostgis.sql.in @@ -929,6 +929,11 @@ CREATEFUNCTION addBBOX(geometry) AS '@MODULE_FILENAME@','LWGEOM_addBBOX' LANGUAGE 'C' WITH (isstrict,iscachable); +CREATEFUNCTION dropBBOX(geometry) + RETURNS geometry + AS '@MODULE_FILENAME@','LWGEOM_dropBBOX' + LANGUAGE 'C' WITH (isstrict,iscachable); + CREATEFUNCTION getSRID(geometry) RETURNS int4 -- 2.40.0