The attached patches change earthdistance to use the new cube functions

in one of the earth functions so that latitude and longitude to
cartesian coordinates conversion will be more accurrate. (Previously
a text string was built to provide as input which limited the accuracy
to the number of digits printed.)

The new functions were included in a recent patch to contrib/cube that has not
as yet been accepted as of yet.

I also added check constraints to the domain 'earth' since they are now
working in 7.4.

Bruno Wolff III
This commit is contained in:
Bruce Momjian 2003-02-13 05:31:06 +00:00
parent 80b3513d57
commit 9ccaaf676f
2 changed files with 23 additions and 23 deletions

View File

@ -39,25 +39,22 @@ bounding box usable for index searches.
The functions are all 'sql' functions. If you want to make these functions The functions are all 'sql' functions. If you want to make these functions
executable by other people you will also have to make the referenced executable by other people you will also have to make the referenced
cube functions executable. cube(text), cube_distance(cube,cube), cube functions executable. cube(text), cube(float8), cube(cube,float8),
cube_ll_coord(cube,int) and cube_enlarge(cube,float8,int) are used indirectly cube_distance(cube,cube), cube_ll_coord(cube,int) and
by the earth distance functions. is_point(cube) and cube_dim(cube) are used cube_enlarge(cube,float8,int) are used indirectly by the earth distance
in suggested constraints for data in domain earth. cube_ur_coord(cube,int) functions. is_point(cube) and cube_dim(cube) are used in constraints for data
is used in the regression tests and might be useful for looking at bounding in domain earth. cube_ur_coord(cube,int) is used in the regression tests and
box coordinates in user applications. might be useful for looking at bounding box coordinates in user applications.
A domain of type cube named earth is defined. Since check constraints A domain of type cube named earth is defined.
are not supported for domains yet, this isn't as useful as it might be. There are constraints on it defined to make sure the cube is a point,
However the checks that should be supplied to all data of type earth are: that it does not have more than 3 dimensions and that it is very near
the surface of a sphere centered about the origin with the radius of
constraint not_point check(is_point(earth)) the Earth.
constraint not_3d check(cube_dim(earth) <= 3)
constraint on_surface check(abs(cube_distance(earth, '(0)'::cube) /
earth() - 1) < '10e-12'::float8);
The following functions are provided: The following functions are provided:
earth() - Returns the radius of the earth in meters. earth() - Returns the radius of the Earth in meters.
sec_to_gc(float8) - Converts the normal straight line (secant) distance between sec_to_gc(float8) - Converts the normal straight line (secant) distance between
between two points on the surface of the Earth to the great circle distance between two points on the surface of the Earth to the great circle distance
@ -118,7 +115,7 @@ Subject: [QUESTIONS] Re: Spatial data, R-Trees
> look at to create these? > look at to create these?
Here's the setup for adding an operator '<@>' to give distance in Here's the setup for adding an operator '<@>' to give distance in
statute miles between two points on the earth's surface. Coordinates statute miles between two points on the Earth's surface. Coordinates
are in degrees. Points are taken as (longitude, latitude) and not vice are in degrees. Points are taken as (longitude, latitude) and not vice
versa as longitude is closer to the intuitive idea of x-axis and versa as longitude is closer to the intuitive idea of x-axis and
latitude to y-axis. latitude to y-axis.

View File

@ -24,13 +24,16 @@ AS 'SELECT \'6378168\'::float8';
-- Define domain for locations on the surface of the earth using a cube -- Define domain for locations on the surface of the earth using a cube
-- datatype with constraints. cube provides 3D indexing. -- 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; CREATE DOMAIN earth AS cube
-- CONSTRAINT not_point check(is_point(earth)) CONSTRAINT not_point check(cube_is_point(value))
-- CONSTRAINT not_3d check(cube_dim(earth) <= 3) CONSTRAINT not_3d check(cube_dim(value) <= 3)
-- CONSTRAINT on_surface check(abs(cube_distance(earth, '(0)'::cube) / CONSTRAINT on_surface check(abs(cube_distance(value, '(0)'::cube) /
-- earth() - 1) < '10e-12'::float8); earth() - 1) < '10e-7'::float8);
CREATE OR REPLACE FUNCTION sec_to_gc(float8) CREATE OR REPLACE FUNCTION sec_to_gc(float8)
RETURNS float8 RETURNS float8
@ -48,7 +51,7 @@ CREATE OR REPLACE FUNCTION ll_to_earth(float8, float8)
RETURNS earth RETURNS earth
LANGUAGE 'sql' LANGUAGE 'sql'
IMMUTABLE STRICT 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) CREATE OR REPLACE FUNCTION latitude(earth)
RETURNS float8 RETURNS float8