]> granicus.if.org Git - postgis/commitdiff
Added ndims(geometry) function, used in a 3rd constraint set
authorSandro Santilli <strk@keybit.net>
Fri, 5 Nov 2004 08:16:46 +0000 (08:16 +0000)
committerSandro Santilli <strk@keybit.net>
Fri, 5 Nov 2004 08:16:46 +0000 (08:16 +0000)
by AddGeometryColumn, documented.

git-svn-id: http://svn.osgeo.org/postgis/trunk@1082 b70326c6-7e19-0410-871a-916f4a2858ee

doc/postgis.xml
lwgeom/TODO
lwgeom/lwgeom_functions_basic.c
lwgeom/lwpostgis.sql.in

index 75b6c71b4140a7dddec970f561378d47579a2eba..0fdd95944f588a5c0bb4e2857ae68bcd5540b3cd 100644 (file)
@@ -3917,6 +3917,16 @@ FROM geometry_table;</literallayout>
           </listitem>
         </varlistentry>
 
+        <varlistentry id="ndims">
+          <term>ndims(geometry)</term>
+
+          <listitem>
+            <para>Returns number of dimensions of the geometry as
+           a small int. Values are: 2,3 or 4.
+           </para>
+          </listitem>
+        </varlistentry>
+
 
         <varlistentry>
           <term>mem_size(geometry)</term>
index 76a230957bf9063ed5deec0d15dc134bce485e27..026fa6e9f10b3a07845d3dbaad4d596911775a91 100644 (file)
@@ -1,4 +1,3 @@
-- Add enforce_dims_<geomfield> constraints to spatial table
 
 - research on extent() extracting output from an existing index.
 
index 2059b6a2e49aff4f91b2be9bc7557b20bf1a4e2f..e474d4a610d260ed385e7c4d69a96779bc4bc291 100644 (file)
@@ -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)
index a748cc84f37ecc2589a6a8041dc3c50a1810abd5..2b035d9bfc91325accc94e4ca3db34a5f7fb7fad 100644 (file)
@@ -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);