From: Sandro Santilli Date: Tue, 17 Aug 2004 14:21:21 +0000 (+0000) Subject: Added geometrytype(LWGEOM) X-Git-Tag: pgis_0_9_1~116 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=13572134cc5a64137a6e18f6ded6435b7fbe1a2c;p=postgis Added geometrytype(LWGEOM) git-svn-id: http://svn.osgeo.org/postgis/trunk@678 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/lwgeom/lwgeom.sql.in b/lwgeom/lwgeom.sql.in index c94191714..50cd74208 100644 --- a/lwgeom/lwgeom.sql.in +++ b/lwgeom/lwgeom.sql.in @@ -330,8 +330,13 @@ CREATEFUNCTION getbbox(LWGEOM) AS '@MODULE_FILENAME@','LWGEOM_to_BOX2DFLOAT4' LANGUAGE 'C' WITH (isstrict,iscachable); +CREATEFUNCTION geometrytype(LWGEOM) + RETURNS text + AS '@MODULE_FILENAME@', 'LWGEOM_getTYPE' + LANGUAGE 'C' WITH (isstrict); -commit; + +COMMIT; begin; -- extra conversions (might not work if there's no postgis install) diff --git a/lwgeom/lwgeom_functions_basic.c b/lwgeom/lwgeom_functions_basic.c index e535ae73e..88ae6ae98 100644 --- a/lwgeom/lwgeom_functions_basic.c +++ b/lwgeom/lwgeom_functions_basic.c @@ -25,6 +25,7 @@ #include "wktparse.h" Datum LWGEOM_getSRID(PG_FUNCTION_ARGS); +Datum LWGEOM_getTYPE(PG_FUNCTION_ARGS); Datum LWGEOM_setSRID(PG_FUNCTION_ARGS); @@ -101,3 +102,41 @@ Datum LWGEOM_setSRID(PG_FUNCTION_ARGS) PG_RETURN_POINTER(result); } } + +//returns a string representation of this geometry's type +PG_FUNCTION_INFO_V1(LWGEOM_getTYPE); +Datum LWGEOM_getTYPE(PG_FUNCTION_ARGS) +{ + char *lwgeom = (char *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0)); + char *text_ob = palloc(20+4); + char *result = text_ob+4; + int32 size; + unsigned char type; + + type = lwgeom_getType(*(lwgeom+4)); + + memset(result, 0, 20); + + if (type == POINTTYPE) + strcpy(result,"POINT"); + else if (type == MULTIPOINTTYPE) + strcpy(result,"MULTIPOINT"); + else if (type == LINETYPE) + strcpy(result,"LINESTRING"); + else if (type == MULTILINETYPE) + strcpy(result,"MULTILINESTRING"); + else if (type == POLYGONTYPE) + strcpy(result,"POLYGON"); + else if (type == MULTIPOLYGONTYPE) + strcpy(result,"MULTIPOLYGON"); + else if (type == COLLECTIONTYPE) + strcpy(result,"GEOMETRYCOLLECTION"); + else + strcpy(result,"UNKNOWN"); + + size = strlen(result) +4 ; + + memcpy(text_ob, &size,4); // size of string + + PG_RETURN_POINTER(text_ob); +}