--
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-- $Log$
+-- Revision 1.28 2004/03/26 00:54:09 dblasby
+-- added full support for fluffType(<geom>)
+-- postgis09=# select fluffType('POINT(0 0)');
+-- flufftype
+-- -------------------------
+-- SRID=-1;MULTIPOINT(0 0)
+--
-- Revision 1.27 2004/01/21 19:04:03 strk
-- Added line_interpolate_point function by jsunday@rochgrp.com
--
--
-- Generic operations
--
-
+CREATE FUNCTION fluffType(geometry)
+ RETURNS geometry
+ AS '@MODULE_FILENAME@','fluffType'
+ LANGUAGE 'C' WITH (isstrict);
+
+
CREATE FUNCTION length3d(geometry)
RETURNS FLOAT8
AS '@MODULE_FILENAME@'
AS '@MODULE_FILENAME@'
LANGUAGE 'C' WITH (isstrict);
+
--
-- BBox operations
*
**********************************************************************
* $Log$
+ * Revision 1.43 2004/03/26 00:54:09 dblasby
+ * added full support for fluffType(<geom>)
+ * postgis09=# select fluffType('POINT(0 0)');
+ * flufftype
+ * -------------------------
+ * SRID=-1;MULTIPOINT(0 0)
+ *
* Revision 1.42 2004/02/23 12:18:55 strk
* added skeleton functions for pg75 stats integration
*
Datum simplify(PG_FUNCTION_ARGS);
Datum line_interpolate_point(PG_FUNCTION_ARGS);
+Datum fluffType(PG_FUNCTION_ARGS);
+
/*--------------------------------------------------------------------
* Useful floating point utilities and constants.
* from postgres geo_decls.c
*
**********************************************************************
* $Log$
+ * Revision 1.34 2004/03/26 00:54:09 dblasby
+ * added full support for fluffType(<geom>)
+ * postgis09=# select fluffType('POINT(0 0)');
+ * flufftype
+ * -------------------------
+ * SRID=-1;MULTIPOINT(0 0)
+ *
* Revision 1.33 2004/03/25 00:43:41 dblasby
* added function fluffType() that takes POINT LINESTRING or POLYGON
* type and converts it to a multi*.
}
}
+
// converts single-type (point,linestring,polygon)
// to multi* types with 1 element
// ie. POINT(0 0) --> MULTIPOINT(0 0)
-void fluffType(GEOMETRY *g)
+//
+//postgis09=# select fluffType('POINT(0 0)');
+// flufftype
+//-------------------------
+// SRID=-1;MULTIPOINT(0 0)
+//(1 row)
+//
+//postgis09=# select fluffType('LINESTRING(0 0, 1 1)');
+// flufftype
+//------------------------------------
+// SRID=-1;MULTILINESTRING((0 0,1 1))
+//(1 row)
+
+PG_FUNCTION_INFO_V1(fluffType);
+Datum fluffType(PG_FUNCTION_ARGS)
{
- if (g->type == POINTTYPE)
- {
- g->type = MULTIPOINTTYPE;
- return;
- }
- if (g->type == LINETYPE)
- {
- g->type = MULTILINETYPE;
- return;
- }
- if (g->type == POLYGONTYPE)
- {
- g->type = MULTIPOLYGONTYPE;
- return;
- }
+ GEOMETRY *geom1= (GEOMETRY *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
+ GEOMETRY *g;
+
+ g = (GEOMETRY*) palloc( *((int *) geom1) );
+ memcpy(g,geom1, *((int *) geom1));
+
+ if (g->type == POINTTYPE)
+ {
+ g->type = MULTIPOINTTYPE;
+ }
+ if (g->type == LINETYPE)
+ {
+ g->type = MULTILINETYPE;
+ }
+ if (g->type == POLYGONTYPE)
+ {
+ g->type = MULTIPOLYGONTYPE;
+ }
+
+ PG_FREE_IF_COPY(geom1,0);
+ PG_RETURN_POINTER(g);
}