]> granicus.if.org Git - postgis/commitdiff
Fix for #157, ST_GeometryType output doesn't correctly identify curved geometries
authorPaul Ramsey <pramsey@cleverelephant.ca>
Thu, 5 Nov 2009 20:20:54 +0000 (20:20 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Thu, 5 Nov 2009 20:20:54 +0000 (20:20 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@4752 b70326c6-7e19-0410-871a-916f4a2858ee

postgis/lwgeom_ogc.c
postgis/postgis.sql.in.c

index eea2311752b2b5266432c30004132170a3b3c1b0..ae41ed5d3e3b13a7b7b0b46c65f6ed2ff17d3ac1 100644 (file)
@@ -34,6 +34,7 @@ Datum LWGEOM_getSRID(PG_FUNCTION_ARGS);
 Datum LWGEOM_setSRID(PG_FUNCTION_ARGS);
 /* ---- GeometryType(geometry) */
 Datum LWGEOM_getTYPE(PG_FUNCTION_ARGS);
+Datum geometry_geometrytype(PG_FUNCTION_ARGS);
 /* ---- NumPoints(geometry) */
 Datum LWGEOM_numpoints_linestring(PG_FUNCTION_ARGS);
 /* ---- NumGeometries(geometry) */
@@ -164,6 +165,36 @@ Datum LWGEOM_getTYPE(PG_FUNCTION_ARGS)
        PG_RETURN_POINTER(text_ob);
 }
 
+
+/* returns a string representation of this geometry's type */
+PG_FUNCTION_INFO_V1(geometry_geometrytype);
+Datum geometry_geometrytype(PG_FUNCTION_ARGS)
+{
+       PG_LWGEOM *lwgeom;
+       char *type_text;
+       char *type_str = palloc(32);
+       size_t size;
+
+       lwgeom = (PG_LWGEOM*)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
+       
+       /* Make it empty string to start */
+       *type_str = 0;
+
+       /* Build up the output string */
+       strncat(type_str, "ST_", 32);
+       strncat(type_str, lwgeom_typename(lwgeom_getType(lwgeom->type)), 32);
+       size = strlen(type_str) + VARHDRSZ;
+       
+       /* Build a text type to store things in */
+       type_text = lwalloc(size);
+       memcpy(VARDATA(type_text),type_str, size - VARHDRSZ);
+       pfree(type_str);
+       SET_VARSIZE(type_text, size);
+       PG_FREE_IF_COPY(lwgeom, 0);
+       PG_RETURN_POINTER(type_text);
+}
+       
+
 /**
  * Find first linestring in serialized geometry and return
  * the number of points in it. If no linestrings are found
index ea69e52b14c15e50f87e273596d940c85a7d7970..af83dca55d8a28e052720d8dbdd37edfb7ca3fba 100644 (file)
@@ -4527,29 +4527,8 @@ CREATE OR REPLACE FUNCTION GeometryType(geometry)
 -- Not quite equivalent to GeometryType
 CREATE OR REPLACE FUNCTION ST_GeometryType(geometry)
        RETURNS text
-       AS $$
-       DECLARE
-       gtype text := geometrytype($1);
-       BEGIN
-       IF (gtype IN ('POINT', 'POINTM')) THEN
-               gtype := 'Point';
-       ELSIF (gtype IN ('LINESTRING', 'LINESTRINGM')) THEN
-               gtype := 'LineString';
-       ELSIF (gtype IN ('POLYGON', 'POLYGONM')) THEN
-               gtype := 'Polygon';
-       ELSIF (gtype IN ('MULTIPOINT', 'MULTIPOINTM')) THEN
-               gtype := 'MultiPoint';
-       ELSIF (gtype IN ('MULTILINESTRING', 'MULTILINESTRINGM')) THEN
-               gtype := 'MultiLineString';
-       ELSIF (gtype IN ('MULTIPOLYGON', 'MULTIPOLYGONM')) THEN
-               gtype := 'MultiPolygon';
-       ELSE
-               gtype := 'Geometry';
-       END IF;
-       RETURN 'ST_' || gtype;
-       END
-$$
-LANGUAGE 'plpgsql' IMMUTABLE STRICT;
+       AS 'MODULE_PATHNAME', 'geometry_geometrytype'
+       LANGUAGE 'C' IMMUTABLE STRICT;
 
 -- Deprecation in 1.2.3
 CREATE OR REPLACE FUNCTION PointN(geometry,integer)