Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9ccaaf6

Browse files
committed
The attached patches change earthdistance to use the new cube functions
in one of the earth functions so that latitude and longitude tocartesian coordinates conversion will be more accurrate. (Previouslya text string was built to provide as input which limited the accuracyto the number of digits printed.)The new functions were included in a recent patch to contrib/cube that has notas yet been accepted as of yet.I also added check constraints to the domain 'earth' since they are nowworking in 7.4.Bruno Wolff III
1 parent80b3513 commit9ccaaf6

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

‎contrib/earthdistance/README.earthdistance

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,22 @@ bounding box usable for index searches.
3939

4040
The functions are all 'sql' functions. If you want to make these functions
4141
executable by other people you will also have to make the referenced
42-
cube functions executable. cube(text), cube_distance(cube,cube),
43-
cube_ll_coord(cube,int) and cube_enlarge(cube,float8,int) are used indirectly
44-
by the earth distance functions. is_point(cube) and cube_dim(cube) are used
45-
in suggested constraints for data in domain earth. cube_ur_coord(cube,int)
46-
is used in the regression tests and might be useful for looking at bounding
47-
box coordinates in user applications.
48-
49-
A domain of type cube named earth is defined. Since check constraints
50-
are not supported for domains yet, this isn't as useful as it might be.
51-
However the checks that should be supplied to all data of type earth are:
52-
53-
constraint not_point check(is_point(earth))
54-
constraint not_3d check(cube_dim(earth) <= 3)
55-
constraint on_surface check(abs(cube_distance(earth, '(0)'::cube) /
56-
earth() - 1) < '10e-12'::float8);
42+
cube functions executable. cube(text), cube(float8), cube(cube,float8),
43+
cube_distance(cube,cube), cube_ll_coord(cube,int) and
44+
cube_enlarge(cube,float8,int) are used indirectly by the earth distance
45+
functions. is_point(cube) and cube_dim(cube) are used in constraints for data
46+
in domain earth. cube_ur_coord(cube,int) is used in the regression tests and
47+
might be useful for looking at bounding box coordinates in user applications.
48+
49+
A domain of type cube named earth is defined.
50+
There are constraints on it defined to make sure the cube is a point,
51+
that it does not have more than 3 dimensions and that it is very near
52+
the surface of a sphere centered about the origin with the radius of
53+
the Earth.
5754

5855
The following functions are provided:
5956

60-
earth() - Returns the radius of theearth in meters.
57+
earth() - Returns the radius of theEarth in meters.
6158

6259
sec_to_gc(float8) - Converts the normal straight line (secant) distance between
6360
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
118115
> look at to create these?
119116

120117
Here's the setup for adding an operator '<@>' to give distance in
121-
statute miles between two points on theearth's surface. Coordinates
118+
statute miles between two points on theEarth's surface. Coordinates
122119
are in degrees. Points are taken as (longitude, latitude) and not vice
123120
versa as longitude is closer to the intuitive idea of x-axis and
124121
latitude to y-axis.

‎contrib/earthdistance/earthdistance.sql.in

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,16 @@ AS 'SELECT \'6378168\'::float8';
2424

2525
-- Define domain for locations on the surface of the earth using a cube
2626
-- datatype with constraints. cube provides 3D indexing.
27-
-- Check constraints aren't currently supported.
27+
-- The cube is restricted to be a point, no more than 3 dimensions
28+
-- (for less than 3 dimensions 0 is assumed for the missing coordinates)
29+
-- and that the point must be very near the surface of the sphere
30+
-- centered about the origin with the radius of the earth.
2831

29-
CREATE DOMAIN earth AS cube;
30-
-- CONSTRAINT not_point check(is_point(earth))
31-
-- CONSTRAINT not_3d check(cube_dim(earth) <= 3)
32-
-- CONSTRAINT on_surface check(abs(cube_distance(earth, '(0)'::cube) /
33-
-- earth() - 1) < '10e-12'::float8);
32+
CREATE DOMAIN earth AS cube
33+
CONSTRAINT not_point check(cube_is_point(value))
34+
CONSTRAINT not_3d check(cube_dim(value) <= 3)
35+
CONSTRAINT on_surface check(abs(cube_distance(value, '(0)'::cube) /
36+
earth() - 1) < '10e-7'::float8);
3437

3538
CREATE OR REPLACE FUNCTION sec_to_gc(float8)
3639
RETURNS float8
@@ -48,7 +51,7 @@ CREATE OR REPLACE FUNCTION ll_to_earth(float8, float8)
4851
RETURNS earth
4952
LANGUAGE 'sql'
5053
IMMUTABLE STRICT
51-
AS 'SELECT cube(\'(\'||earth()*cos(radians($1))*cos(radians($2))||\',\'||earth()*cos(radians($1))*sin(radians($2))||\',\'||earth()*sin(radians($1))||\')\')';
54+
AS 'SELECT cube(cube(cube(earth()*cos(radians($1))*cos(radians($2))),earth()*cos(radians($1))*sin(radians($2))),earth()*sin(radians($1)))';
5255

5356
CREATE OR REPLACE FUNCTION latitude(earth)
5457
RETURNS float8

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp