From: Paul Ramsey Date: Thu, 5 Nov 2009 20:20:54 +0000 (+0000) Subject: Fix for #157, ST_GeometryType output doesn't correctly identify curved geometries X-Git-Tag: 1.5.0b1~284 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0b8ccb7c2680f9acafd6d822d1ff9321eb420d87;p=postgis Fix for #157, ST_GeometryType output doesn't correctly identify curved geometries git-svn-id: http://svn.osgeo.org/postgis/trunk@4752 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/postgis/lwgeom_ogc.c b/postgis/lwgeom_ogc.c index eea231175..ae41ed5d3 100644 --- a/postgis/lwgeom_ogc.c +++ b/postgis/lwgeom_ogc.c @@ -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 diff --git a/postgis/postgis.sql.in.c b/postgis/postgis.sql.in.c index ea69e52b1..af83dca55 100644 --- a/postgis/postgis.sql.in.c +++ b/postgis/postgis.sql.in.c @@ -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)