]> granicus.if.org Git - postgis/commitdiff
Added geometrytype(LWGEOM)
authorSandro Santilli <strk@keybit.net>
Tue, 17 Aug 2004 14:21:21 +0000 (14:21 +0000)
committerSandro Santilli <strk@keybit.net>
Tue, 17 Aug 2004 14:21:21 +0000 (14:21 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@678 b70326c6-7e19-0410-871a-916f4a2858ee

lwgeom/lwgeom.sql.in
lwgeom/lwgeom_functions_basic.c

index c94191714a4eb81c8fe10c8abb450e94cd4aa48b..50cd74208e2203223271a02a117adb1bc0d46782 100644 (file)
@@ -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)
index e535ae73ed781cb59755b06e69c391966ec9b253..88ae6ae9833a4922af1e779fab5bab8f7e90f08b 100644 (file)
@@ -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);
+}