From cebda7b779b913bcf8494894aa3d7fb1f44339de Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Thu, 3 Jun 2004 16:44:56 +0000 Subject: [PATCH] Added expand_geometry - expand(geometry, int8) git-svn-id: http://svn.osgeo.org/postgis/trunk@580 b70326c6-7e19-0410-871a-916f4a2858ee --- postgis.h | 4 ++++ postgis.sql.in | 5 +++++ postgis_fn.c | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+) diff --git a/postgis.h b/postgis.h index a01da06b2..9a31b3a79 100644 --- a/postgis.h +++ b/postgis.h @@ -11,6 +11,9 @@ * ********************************************************************** * $Log$ + * Revision 1.44 2004/06/03 16:44:56 strk + * Added expand_geometry - expand(geometry, int8) + * * Revision 1.43 2004/03/26 00:54:09 dblasby * added full support for fluffType() * postgis09=# select fluffType('POINT(0 0)'); @@ -566,6 +569,7 @@ Datum point_inside_circle(PG_FUNCTION_ARGS); Datum distance(PG_FUNCTION_ARGS); Datum expand_bbox(PG_FUNCTION_ARGS); +Datum expand_geometry(PG_FUNCTION_ARGS); Datum srid_geom(PG_FUNCTION_ARGS); Datum geometry_from_text(PG_FUNCTION_ARGS); diff --git a/postgis.sql.in b/postgis.sql.in index 31dba7206..15fbb1768 100644 --- a/postgis.sql.in +++ b/postgis.sql.in @@ -558,6 +558,11 @@ CREATEFUNCTION expand(box3d,float8) AS '@MODULE_FILENAME@','expand_bbox' LANGUAGE 'C' WITH (iscachable,isstrict); +CREATEFUNCTION expand(geometry,float8) + RETURNS geometry + AS '@MODULE_FILENAME@','expand_geometry' + LANGUAGE 'C' WITH (iscachable,isstrict); + -- -- Functions for converting to WKB -- diff --git a/postgis_fn.c b/postgis_fn.c index 203a61a56..a15a8e871 100644 --- a/postgis_fn.c +++ b/postgis_fn.c @@ -11,6 +11,9 @@ * ********************************************************************** * $Log$ + * Revision 1.36 2004/06/03 16:44:56 strk + * Added expand_geometry - expand(geometry, int8) + * * Revision 1.35 2004/04/28 22:26:02 pramsey * Fixed spelling mistake in header text. * @@ -2186,6 +2189,44 @@ Datum expand_bbox(PG_FUNCTION_ARGS) PG_RETURN_POINTER(result); } +// makes a polygon of the expanded features bvol - 1st point = LL 3rd=UR +// 2d only +// create new geometry of type polygon, 1 ring, 5 points +PG_FUNCTION_INFO_V1(expand_geometry); +Datum expand_geometry(PG_FUNCTION_ARGS) +{ + GEOMETRY *geom = (GEOMETRY *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0)); + double d = PG_GETARG_FLOAT8(1); + GEOMETRY *result; + POLYGON3D *poly; + POINT3D pts[5]; //5 points around box + int pts_per_ring[1]; + int poly_size; + + //use LLB's z value (we're going to set is3d to false) + + //0,1,2,3,4 --> CCW order, 4,3,2,1,0 --> CW order + set_point( &pts[4], geom->bvol.LLB.x - d, geom->bvol.LLB.y - d, + geom->bvol.LLB.z - d ); + set_point( &pts[3], geom->bvol.URT.x + d, geom->bvol.LLB.y - d, + geom->bvol.LLB.z - d ); + set_point( &pts[2], geom->bvol.URT.x + d, geom->bvol.URT.y + d, + geom->bvol.LLB.z - d); + set_point( &pts[1], geom->bvol.LLB.x - d, geom->bvol.URT.y + d, + geom->bvol.LLB.z - d); + memcpy(&pts[0], &pts[4], sizeof(POINT3D)); + + pts_per_ring[0] = 5; //ring has 5 points + + //make a polygon + poly = make_polygon(1, pts_per_ring, pts, 5, &poly_size); + + result = make_oneobj_geometry(poly_size, (char *)poly, POLYGONTYPE, FALSE,geom->SRID, geom->scale, geom->offsetX, geom->offsetY); + + PG_RETURN_POINTER(result); + +} + //startpoint(geometry) :- if geometry is a linestring, return the first //point. Otherwise, return NULL. -- 2.40.0