]> granicus.if.org Git - postgis/commitdiff
Make ST_Azimuth(p1, p1) return NULL and make ST_Project(p1, 0, NULL) return p1.
authorPaul Ramsey <pramsey@cleverelephant.ca>
Tue, 3 Jan 2012 22:07:34 +0000 (22:07 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Tue, 3 Jan 2012 22:07:34 +0000 (22:07 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@8662 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/lwgeodetic.c
postgis/geography.sql.in.c
postgis/geography_measurement.c
postgis/lwgeom_functions_basic.c

index cd7918b0b01e9e63678acf5f8bfe521f86059db0..83d7db663a4588987679b49184fd029b2c568d9c 100644 (file)
@@ -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 */
index 6ee506879fa8bc74affbae4de9823d54caaf3182..d87d6b6208b9f86ec04108dce1dbe7667bd58603 100644 (file)
@@ -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
index a7a463c03232a01bf1294ce81ce45238d9babce6..9a6383b1488a80fe16fa7906bbbdc01e8397c8ba 100644 (file)
@@ -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);
 }
 
index 62e971d5311f92f76154a98163d5db49cae5267f..0024c12a0c9fb5d8af3734f703eed47eb5b0d0a6 100644 (file)
@@ -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 */