-
Notifications
You must be signed in to change notification settings - Fork 14
/
pgs_point.sql.in
182 lines (142 loc) · 4.11 KB
/
pgs_point.sql.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
-- **************************
--
-- spherical point functions
--
-- **************************
CREATE FUNCTION pg_sphere_version()
RETURNS CSTRING
AS 'MODULE_PATHNAME', 'pg_sphere_version'
LANGUAGE 'c';
CREATE FUNCTION spoint(FLOAT8, FLOAT8)
RETURNS spoint
AS 'MODULE_PATHNAME', 'spherepoint_from_long_lat'
LANGUAGE 'c'
IMMUTABLE STRICT PARALLEL SAFE;
CREATE FUNCTION spoint_deg(FLOAT8, FLOAT8)
RETURNS spoint
AS 'MODULE_PATHNAME', 'spherepoint_from_long_lat_deg'
LANGUAGE 'c'
IMMUTABLE STRICT PARALLEL SAFE;
CREATE FUNCTION set_sphere_output_precision(INT4)
RETURNS CSTRING
AS 'MODULE_PATHNAME', 'set_sphere_output_precision'
LANGUAGE 'c';
CREATE FUNCTION reset_sphere_output_precision()
RETURNS CSTRING
AS 'MODULE_PATHNAME', 'reset_sphere_output_precision'
LANGUAGE 'c';
CREATE FUNCTION set_sphere_output(CSTRING)
RETURNS CSTRING
AS 'MODULE_PATHNAME', 'set_sphere_output'
LANGUAGE 'c';
COMMENT ON FUNCTION spoint(FLOAT8, FLOAT8) IS
'returns a spherical point from longitude (arg1), latitude (arg2)';
COMMENT ON FUNCTION spoint_deg(FLOAT8, FLOAT8) IS
'returns a spherical point from longitude (arg1, in degrees), latitude (arg2, in degrees)';
CREATE FUNCTION long(spoint)
RETURNS FLOAT8
AS 'MODULE_PATHNAME', 'spherepoint_long'
LANGUAGE 'c'
IMMUTABLE STRICT PARALLEL SAFE;
COMMENT ON FUNCTION long(spoint) IS
'longitude of spherical point';
CREATE FUNCTION lat(spoint)
RETURNS FLOAT8
AS 'MODULE_PATHNAME', 'spherepoint_lat'
LANGUAGE 'c'
IMMUTABLE STRICT PARALLEL SAFE;
COMMENT ON FUNCTION lat(spoint) IS
'latitude of spherical point';
CREATE FUNCTION x(spoint)
RETURNS FLOAT8
AS 'MODULE_PATHNAME', 'spherepoint_x'
LANGUAGE 'c'
IMMUTABLE STRICT PARALLEL SAFE;
COMMENT ON FUNCTION x(spoint) IS
'cartesian x value of spherical point';
CREATE FUNCTION y(spoint)
RETURNS FLOAT8
AS 'MODULE_PATHNAME', 'spherepoint_y'
LANGUAGE 'c'
IMMUTABLE STRICT PARALLEL SAFE;
COMMENT ON FUNCTION y(spoint) IS
'cartesian y value of spherical point';
CREATE FUNCTION xyz(spoint)
RETURNS FLOAT8[]
AS 'MODULE_PATHNAME', 'spherepoint_xyz'
LANGUAGE 'c'
IMMUTABLE STRICT PARALLEL SAFE;
COMMENT ON FUNCTION xyz(spoint) IS
'cartesian values of spherical point';
CREATE FUNCTION z(spoint)
RETURNS FLOAT8
AS 'MODULE_PATHNAME', 'spherepoint_z'
LANGUAGE 'c'
IMMUTABLE STRICT PARALLEL SAFE;
COMMENT ON FUNCTION z(spoint) IS
'cartesian z value of spherical point';
-- ***************************
--
-- spherical point operators
--
-- ***************************
--
-- equal
--
CREATE FUNCTION spoint_equal(spoint, spoint)
RETURNS BOOL
AS 'MODULE_PATHNAME', 'spherepoint_equal'
LANGUAGE 'c'
IMMUTABLE STRICT PARALLEL SAFE;
COMMENT ON FUNCTION spoint_equal(spoint, spoint) IS
'returns true, if spherical points are equal';
CREATE OPERATOR = (
LEFTARG = spoint,
RIGHTARG = spoint,
COMMUTATOR = =,
NEGATOR = <>,
PROCEDURE = spoint_equal,
RESTRICT = contsel,
JOIN = contjoinsel
);
COMMENT ON OPERATOR = (spoint, spoint) IS
'true, if spherical points are equal';
--
-- not equal
--
CREATE FUNCTION spoint_equal_neg (spoint, spoint)
RETURNS BOOL
AS 'SELECT NOT spoint_equal($1,$2);'
LANGUAGE 'sql'
IMMUTABLE STRICT PARALLEL SAFE;
COMMENT ON FUNCTION spoint_equal_neg (spoint, spoint) IS
'returns true, if spherical points are not equal';
CREATE OPERATOR <> (
LEFTARG = spoint,
RIGHTARG = spoint,
COMMUTATOR = <>,
NEGATOR = =,
PROCEDURE = spoint_equal_neg,
RESTRICT = contsel,
JOIN = contjoinsel
);
COMMENT ON OPERATOR <> (spoint, spoint) IS
'true, if spherical points are not equal';
--
-- distance between points
--
CREATE FUNCTION dist(spoint, spoint)
RETURNS FLOAT8
AS 'MODULE_PATHNAME', 'spherepoint_distance'
LANGUAGE 'c'
IMMUTABLE STRICT PARALLEL SAFE;
COMMENT ON FUNCTION dist(spoint, spoint) IS
'distance between spherical points';
CREATE OPERATOR <-> (
LEFTARG = spoint,
RIGHTARG = spoint,
COMMUTATOR = '<->',
PROCEDURE = dist
);
COMMENT ON OPERATOR <-> (spoint, spoint) IS
'distance between spherical points';