From: Sandro Santilli Date: Wed, 23 Nov 2005 14:52:39 +0000 (+0000) Subject: Changed M() and Z() to return NULL when input doesn't have X-Git-Tag: pgis_1_1_0~146 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=188cb339997275f5decd1ed800e474cbf473a3f8;p=postgis Changed M() and Z() to return NULL when input doesn't have 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 --- diff --git a/CHANGES b/CHANGES index 730a0ba52..f3a14c332 100644 --- 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 diff --git a/lwgeom/lwgeom_ogc.c b/lwgeom/lwgeom_ogc.c index 87724eb21..f717c5718 100644 --- a/lwgeom/lwgeom_ogc.c +++ b/lwgeom/lwgeom_ogc.c @@ -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)); diff --git a/regress/regress.sql b/regress/regress.sql index 8c298fa41..53f6993f2 100644 --- a/regress/regress.sql +++ b/regress/regress.sql @@ -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)'); diff --git a/regress/regress_expected b/regress/regress_expected index 68da3b19d..cda575a21 100644 --- a/regress/regress_expected +++ b/regress/regress_expected @@ -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