]> granicus.if.org Git - postgis/commitdiff
Added expand_geometry - expand(geometry, int8)
authorSandro Santilli <strk@keybit.net>
Thu, 3 Jun 2004 16:44:56 +0000 (16:44 +0000)
committerSandro Santilli <strk@keybit.net>
Thu, 3 Jun 2004 16:44:56 +0000 (16:44 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@580 b70326c6-7e19-0410-871a-916f4a2858ee

postgis.h
postgis.sql.in
postgis_fn.c

index a01da06b2d943462ab4d41d4da89d6c25fbdfe85..9a31b3a7935c3e668ea13943390c685130556d65 100644 (file)
--- 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(<geom>)
  * 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);
 
index 31dba72068b2702a36a5ccc62b807cf49406c214..15fbb176805c692ecdccfcf9cf6c507f9a78aac4 100644 (file)
@@ -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
 --
index 203a61a56ac2f92c8e6c8586d90786568f2ab645..a15a8e871f675f1325ac862779846101318252d5 100644 (file)
@@ -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.