From f08541a6cfbdba05ac993497efae58486023b0e5 Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Fri, 5 Nov 2004 08:16:46 +0000 Subject: [PATCH] Added ndims(geometry) function, used in a 3rd constraint set by AddGeometryColumn, documented. git-svn-id: http://svn.osgeo.org/postgis/trunk@1082 b70326c6-7e19-0410-871a-916f4a2858ee --- doc/postgis.xml | 10 ++++++++++ lwgeom/TODO | 1 - lwgeom/lwgeom_functions_basic.c | 13 +++++++++++++ lwgeom/lwpostgis.sql.in | 18 +++++++++++++++++- 4 files changed, 40 insertions(+), 2 deletions(-) diff --git a/doc/postgis.xml b/doc/postgis.xml index 75b6c71b4..0fdd95944 100644 --- a/doc/postgis.xml +++ b/doc/postgis.xml @@ -3917,6 +3917,16 @@ FROM geometry_table; + + ndims(geometry) + + + Returns number of dimensions of the geometry as + a small int. Values are: 2,3 or 4. + + + + mem_size(geometry) diff --git a/lwgeom/TODO b/lwgeom/TODO index 76a230957..026fa6e9f 100644 --- a/lwgeom/TODO +++ b/lwgeom/TODO @@ -1,4 +1,3 @@ -- Add enforce_dims_ constraints to spatial table - research on extent() extracting output from an existing index. diff --git a/lwgeom/lwgeom_functions_basic.c b/lwgeom/lwgeom_functions_basic.c index 2059b6a2e..e474d4a61 100644 --- a/lwgeom/lwgeom_functions_basic.c +++ b/lwgeom/lwgeom_functions_basic.c @@ -50,6 +50,7 @@ Datum LWGEOM_reverse(PG_FUNCTION_ARGS); Datum LWGEOM_forceRHR_poly(PG_FUNCTION_ARGS); Datum LWGEOM_noop(PG_FUNCTION_ARGS); Datum LWGEOM_zmflag(PG_FUNCTION_ARGS); +Datum LWGEOM_ndims(PG_FUNCTION_ARGS); Datum LWGEOM_makepoint(PG_FUNCTION_ARGS); Datum LWGEOM_makepoint3dm(PG_FUNCTION_ARGS); Datum LWGEOM_makeline_garray(PG_FUNCTION_ARGS); @@ -2328,6 +2329,18 @@ Datum LWGEOM_zmflag(PG_FUNCTION_ARGS) PG_RETURN_INT16(ret); } +// Return: 2,3 or 4 +PG_FUNCTION_INFO_V1(LWGEOM_ndims); +Datum LWGEOM_ndims(PG_FUNCTION_ARGS) +{ + PG_LWGEOM *in; + int ret; + + in = (PG_LWGEOM *)PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0)); + ret = (TYPE_NDIMS(in->type)); + PG_RETURN_INT16(ret); +} + // lwgeom_same(lwgeom1, lwgeom2) PG_FUNCTION_INFO_V1(LWGEOM_same); Datum LWGEOM_same(PG_FUNCTION_ARGS) diff --git a/lwgeom/lwpostgis.sql.in b/lwgeom/lwpostgis.sql.in index a748cc84f..2b035d9bf 100644 --- a/lwgeom/lwpostgis.sql.in +++ b/lwgeom/lwpostgis.sql.in @@ -1653,6 +1653,11 @@ CREATEFUNCTION zmflag(geometry) AS '@MODULE_FILENAME@', 'LWGEOM_zmflag' LANGUAGE 'C' WITH (iscachable,isstrict); +CREATEFUNCTION ndims(geometry) + RETURNS smallint + AS '@MODULE_FILENAME@', 'LWGEOM_ndims' + LANGUAGE 'C' WITH (iscachable,isstrict); + ------------------------------------------------------------------------ -- CONSTRUCTORS ------------------------------------------------------------------------ @@ -2282,6 +2287,16 @@ BEGIN column_name || ''" CHECK (SRID('' || quote_ident(column_name) || '') = '' || new_srid || '')'' ; + EXECUTE ''ALTER TABLE '' || +#if USE_VERSION >= 73 + quote_ident(real_schema) || ''.'' || quote_ident(table_name) +#else + quote_ident(table_name) +#endif + || '' ADD CONSTRAINT "enforce_dims_'' || + column_name || ''" CHECK (ndims('' || quote_ident(column_name) || + '') = '' || new_dim || '')'' ; + IF (not(new_type = ''GEOMETRY'')) THEN EXECUTE ''ALTER TABLE '' || #if USE_VERSION >= 73 @@ -2304,7 +2319,8 @@ BEGIN #endif table_name || ''.'' || column_name || '' SRID:'' || new_srid || - '' TYPE:'' || new_type || ''\n '' || + '' TYPE:'' || new_type || + '' DIMS:'' || new_dim || ''\n '' || ''geometry_column '' || fixgeomres; END; ' LANGUAGE 'plpgsql' WITH (isstrict); -- 2.40.0