]> granicus.if.org Git - postgis/commitdiff
Added dropBBOX().
authorSandro Santilli <strk@keybit.net>
Mon, 20 Dec 2004 14:01:48 +0000 (14:01 +0000)
committerSandro Santilli <strk@keybit.net>
Mon, 20 Dec 2004 14:01:48 +0000 (14:01 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@1165 b70326c6-7e19-0410-871a-916f4a2858ee

lwgeom/lwgeom_inout.c
lwgeom/lwpostgis.sql.in

index afd6db24b66ef91c9d9fc83bb3f119b5632cbb0b..ad0278a3777209703a78228a4b0aee882620bfb2 100644 (file)
@@ -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
 
index a09aed936812a98c668ba2d3c2d168c9501389ef..de845231a6672ae2f561f6df914518273aba7f3e 100644 (file)
@@ -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