From: David Blasby Date: Fri, 26 Mar 2004 00:54:09 +0000 (+0000) Subject: added full support for fluffType() X-Git-Tag: pgis_0_8_2~66 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5512d404133523329cd7a3435568b308b5171608;p=postgis added full support for fluffType() postgis09=# select fluffType('POINT(0 0)'); flufftype ------------------------- SRID=-1;MULTIPOINT(0 0) git-svn-id: http://svn.osgeo.org/postgis/trunk@493 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/Attic/postgis_sql_common.sql.in b/Attic/postgis_sql_common.sql.in index 5595ae837..f6f761d00 100644 --- a/Attic/postgis_sql_common.sql.in +++ b/Attic/postgis_sql_common.sql.in @@ -12,6 +12,13 @@ -- -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- $Log$ +-- Revision 1.28 2004/03/26 00:54:09 dblasby +-- added full support for fluffType() +-- 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 -- @@ -776,7 +783,12 @@ CREATE FUNCTION distance_spheroid(geometry,geometry,spheroid) -- -- 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@' @@ -847,6 +859,7 @@ CREATE FUNCTION pointonsurface(geometry) AS '@MODULE_FILENAME@' LANGUAGE 'C' WITH (isstrict); + -- -- BBox operations diff --git a/postgis.h b/postgis.h index 9d3080001..a01da06b2 100644 --- a/postgis.h +++ b/postgis.h @@ -11,6 +11,13 @@ * ********************************************************************** * $Log$ + * Revision 1.43 2004/03/26 00:54:09 dblasby + * added full support for fluffType() + * 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 * @@ -650,6 +657,8 @@ Datum isempty(PG_FUNCTION_ARGS); 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 diff --git a/postgis_fn.c b/postgis_fn.c index ea50e7396..703584a77 100644 --- a/postgis_fn.c +++ b/postgis_fn.c @@ -11,6 +11,13 @@ * ********************************************************************** * $Log$ + * Revision 1.34 2004/03/26 00:54:09 dblasby + * added full support for fluffType() + * 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*. @@ -3043,24 +3050,45 @@ void compressType(GEOMETRY *g) } } + // 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); }