diff options
Diffstat (limited to 'contrib/earthdistance/earthdistance.sql.in')
| -rw-r--r-- | contrib/earthdistance/earthdistance.sql.in | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/contrib/earthdistance/earthdistance.sql.in b/contrib/earthdistance/earthdistance.sql.in index de381774ad0..6ee9a87b4ff 100644 --- a/contrib/earthdistance/earthdistance.sql.in +++ b/contrib/earthdistance/earthdistance.sql.in @@ -24,13 +24,16 @@ AS 'SELECT \'6378168\'::float8'; -- Define domain for locations on the surface of the earth using a cube -- datatype with constraints. cube provides 3D indexing. --- Check constraints aren't currently supported. +-- The cube is restricted to be a point, no more than 3 dimensions +-- (for less than 3 dimensions 0 is assumed for the missing coordinates) +-- and that the point must be very near the surface of the sphere +-- centered about the origin with the radius of the earth. -CREATE DOMAIN earth AS cube; --- CONSTRAINT not_point check(is_point(earth)) --- CONSTRAINT not_3d check(cube_dim(earth) <= 3) --- CONSTRAINT on_surface check(abs(cube_distance(earth, '(0)'::cube) / --- earth() - 1) < '10e-12'::float8); +CREATE DOMAIN earth AS cube + CONSTRAINT not_point check(cube_is_point(value)) + CONSTRAINT not_3d check(cube_dim(value) <= 3) + CONSTRAINT on_surface check(abs(cube_distance(value, '(0)'::cube) / + earth() - 1) < '10e-7'::float8); CREATE OR REPLACE FUNCTION sec_to_gc(float8) RETURNS float8 @@ -48,7 +51,7 @@ CREATE OR REPLACE FUNCTION ll_to_earth(float8, float8) RETURNS earth LANGUAGE 'sql' IMMUTABLE STRICT -AS 'SELECT cube(\'(\'||earth()*cos(radians($1))*cos(radians($2))||\',\'||earth()*cos(radians($1))*sin(radians($2))||\',\'||earth()*sin(radians($1))||\')\')'; +AS 'SELECT cube(cube(cube(earth()*cos(radians($1))*cos(radians($2))),earth()*cos(radians($1))*sin(radians($2))),earth()*sin(radians($1)))'; CREATE OR REPLACE FUNCTION latitude(earth) RETURNS float8 |
