From: Paul Ramsey Date: Tue, 3 Jan 2012 22:07:34 +0000 (+0000) Subject: Make ST_Azimuth(p1, p1) return NULL and make ST_Project(p1, 0, NULL) return p1. X-Git-Tag: 2.0.0alpha1~213 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=343f318428ed090d0311a7032ae1973c3ddd6166;p=postgis Make ST_Azimuth(p1, p1) return NULL and make ST_Project(p1, 0, NULL) return p1. git-svn-id: http://svn.osgeo.org/postgis/trunk@8662 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/liblwgeom/lwgeodetic.c b/liblwgeom/lwgeodetic.c index cd7918b0b..83d7db663 100644 --- a/liblwgeom/lwgeodetic.c +++ b/liblwgeom/lwgeodetic.c @@ -1849,8 +1849,7 @@ LWPOINT* lwgeom_project_spheroid(const LWPOINT *r, const SPHEROID *spheroid, dou * @param r - location of first point. * @param s - location of second point. * @param spheroid - spheroid definition. -* @param azimuth - azimuth in radians. -* @return +* @return azimuth - azimuth in radians. * */ double lwgeom_azumith_spheroid(const LWPOINT *r, const LWPOINT *s, const SPHEROID *spheroid) @@ -1868,10 +1867,10 @@ double lwgeom_azumith_spheroid(const LWPOINT *r, const LWPOINT *s, const SPHEROI y2 = lwpoint_get_y(s); geographic_point_init(x2, y2, &g2); - /* Same point, return a standard azimuth instead of NULL or NaN */ + /* Same point, return NaN */ if ( FP_EQUALS(x1, x2) && FP_EQUALS(y1, y2) ) { - return 0.0; + return NAN; } /* Do the direction calculation */ diff --git a/postgis/geography.sql.in.c b/postgis/geography.sql.in.c index 6ee506879..d87d6b620 100644 --- a/postgis/geography.sql.in.c +++ b/postgis/geography.sql.in.c @@ -575,7 +575,7 @@ CREATE OR REPLACE FUNCTION ST_Length(text) CREATE OR REPLACE FUNCTION ST_Project(geog geography, distance float8, azimuth float8) RETURNS geography AS 'MODULE_PATHNAME','geography_project' - LANGUAGE 'C' IMMUTABLE STRICT + LANGUAGE 'C' IMMUTABLE COST 100; -- Availability: 2.0.0 diff --git a/postgis/geography_measurement.c b/postgis/geography_measurement.c index a7a463c03..9a6383b14 100644 --- a/postgis/geography_measurement.c +++ b/postgis/geography_measurement.c @@ -624,7 +624,12 @@ Datum geography_project(PG_FUNCTION_ARGS) elog(ERROR, "ST_Project(geography) is only valid for point inputs"); PG_RETURN_NULL(); } + + /* Return NULL on NULL distance */ + if ( PG_ARGISNULL(1) ) + PG_RETURN_NULL(); + distance = PG_GETARG_FLOAT8(1); /* Distance in Meters */ lwgeom = lwgeom_from_gserialized(g); /* EMPTY things cannot be projected from */ @@ -635,13 +640,20 @@ Datum geography_project(PG_FUNCTION_ARGS) PG_RETURN_NULL(); } - /* Read the other parameters */ - distance = PG_GETARG_FLOAT8(1); /* Meters */ - azimuth = PG_GETARG_FLOAT8(2); /* Radians */ + if ( PG_ARGISNULL(2) ) + azimuth = 0.0; + else + azimuth = PG_GETARG_FLOAT8(2); /* Azimuth in Radians */ /* Initialize spheroid */ spheroid_init(&s, WGS84_MAJOR_AXIS, WGS84_MINOR_AXIS); + /* Handle the zero distance case */ + if( FP_EQUALS(distance, 0.0) ) + { + PG_RETURN_POINTER(g); + } + /* Calculate the length */ lwp_projected = lwgeom_project_spheroid(lwgeom_as_lwpoint(lwgeom), &s, distance, azimuth); @@ -715,6 +727,13 @@ Datum geography_azimuth(PG_FUNCTION_ARGS) PG_FREE_IF_COPY(g1, 0); PG_FREE_IF_COPY(g2, 1); + + /* Return NULL for unknown (same point) azimuth */ + if( isnan(azimuth) ) + { + PG_RETURN_NULL(); + } + PG_RETURN_FLOAT8(azimuth); } diff --git a/postgis/lwgeom_functions_basic.c b/postgis/lwgeom_functions_basic.c index 62e971d53..0024c12a0 100644 --- a/postgis/lwgeom_functions_basic.c +++ b/postgis/lwgeom_functions_basic.c @@ -2355,7 +2355,7 @@ Datum LWGEOM_azimuth(PG_FUNCTION_ARGS) /* Standard return value for equality case */ if ( FP_EQUALS(p1.x, p2.x) && FP_EQUALS(p1.y, p2.y) ) { - PG_RETURN_FLOAT8(0.0); + PG_RETURN_NULL(); } /* Compute azimuth */