]> granicus.if.org Git - postgis/commitdiff
Changed M() and Z() to return NULL when input doesn't have
authorSandro Santilli <strk@keybit.net>
Wed, 23 Nov 2005 14:52:39 +0000 (14:52 +0000)
committerSandro Santilli <strk@keybit.net>
Wed, 23 Nov 2005 14:52:39 +0000 (14:52 +0000)
the requested dimension. Updated regress tests with a few
of these cases.

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

CHANGES
lwgeom/lwgeom_ogc.c
regress/regress.sql
regress/regress_expected

diff --git a/CHANGES b/CHANGES
index 730a0ba52dd71db876325a021358df61ddbb0fb9..f3a14c332068a5bd07f5c2b79f5dd95cb56fc4bd 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -23,6 +23,8 @@ PostGIS 1.1.0CVS
          AddGeometryColumns() and update_geometry_stats()
        - Initial support for topology modelling
        - Stricter mapping between DBF and SQL integer and string attributes
+       - Changed M() and Z() functions to return NULL if requested
+         dimension is not available
 
 PostGIS 1.0.5CVS
 2005/11/25
index 87724eb21ff48c5fbbf8c140abbf150a044dc184..f717c5718b8fa3f6f3f096c2e7e9936d2f66b309 100644 (file)
@@ -616,7 +616,7 @@ Datum LWGEOM_y_point(PG_FUNCTION_ARGS)
 
 // Z(GEOMETRY) -- find the first POINT(..) in GEOMETRY, returns its Z value.
 // Return NULL if there is no POINT(..) in GEOMETRY.
-// Return 0 if there is no Z in this geometry.
+// Return NULL if there is no Z in this geometry.
 PG_FUNCTION_INFO_V1(LWGEOM_z_point);
 Datum LWGEOM_z_point(PG_FUNCTION_ARGS)
 {
@@ -628,8 +628,8 @@ Datum LWGEOM_z_point(PG_FUNCTION_ARGS)
 
        geom = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
 
-       // if there's no Z return 0
-       if ( ! TYPE_HASZ(geom->type) ) PG_RETURN_FLOAT8(0.0);
+       // if there's no Z return NULL
+       if ( ! TYPE_HASZ(geom->type) ) PG_RETURN_NULL();
 
        inspected = lwgeom_inspect(SERIALIZED_FORM(geom));
 
@@ -655,7 +655,7 @@ Datum LWGEOM_z_point(PG_FUNCTION_ARGS)
 
 // M(GEOMETRY) -- find the first POINT(..) in GEOMETRY, returns its M value.
 // Return NULL if there is no POINT(..) in GEOMETRY.
-// Return 0 if there is no M in this geometry.
+// Return NULL if there is no M in this geometry.
 PG_FUNCTION_INFO_V1(LWGEOM_m_point);
 Datum LWGEOM_m_point(PG_FUNCTION_ARGS)
 {
@@ -667,8 +667,8 @@ Datum LWGEOM_m_point(PG_FUNCTION_ARGS)
 
        geom = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
 
-       // if there's no M return 0
-       if ( ! TYPE_HASM(geom->type) ) PG_RETURN_FLOAT8(0.0);
+       // if there's no M return NULL
+       if ( ! TYPE_HASM(geom->type) ) PG_RETURN_NULL();
 
        inspected = lwgeom_inspect(SERIALIZED_FORM(geom));
 
index 8c298fa41c77e0b8b323cfa6f4019b923946a2f4..53f6993f2fea50d6d7aac68e828712a37fc3cc8d 100644 (file)
@@ -223,6 +223,11 @@ select '130', geosnoop('POLYGON((0 0, 1 1, 0 0))');
 select '131', X('POINT(1 2)');
 select '132', Y('POINT(1 2)');
 select '133', Z('POINT(1 2)');
+select '133a', Z('POINT(1 2 3)');
+select '133b', Z('POINTM(1 2 3)');
+select '133c', M('POINT(1 2)');
+select '133d', M('POINTM(1 2 4)');
+select '133e', M('POINT(1 2 4)');
 
 select '134', distance('POINT(1 2)', 'POINT(1 2)');
 select '135', distance('POINT(5 0)', 'POINT(10 12)');
index 68da3b19d51f2720ad795c0c128ce343c828b816..cda575a21f1d0404a01b2de95e6d559e18898aa5 100644 (file)
@@ -132,7 +132,12 @@ NOTICE:  IllegalArgumentException: Number of points must be 0 or >3
 ERROR:  POSTGIS2GEOS conversion failed
 131|1
 132|2
-133|0
+133|
+133a|3
+133b|
+133c|
+133d|4
+133e|
 134|0
 135|13
 136|13