-
Notifications
You must be signed in to change notification settings - Fork 14
/
pgs_gist.sql.in
434 lines (373 loc) · 13.9 KB
/
pgs_gist.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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
-- Spherical key definition'
CREATE FUNCTION spherekey_in(CSTRING)
RETURNS spherekey
AS 'MODULE_PATHNAME'
LANGUAGE 'c'
IMMUTABLE STRICT;
CREATE FUNCTION spherekey_out(spherekey)
RETURNS CSTRING
AS 'MODULE_PATHNAME'
LANGUAGE 'c'
IMMUTABLE STRICT;
CREATE TYPE spherekey (
internallength = 24,
input = spherekey_in,
output = spherekey_out
);
CREATE FUNCTION pointkey_in(CSTRING)
RETURNS pointkey
AS 'MODULE_PATHNAME', 'pointkey_in'
LANGUAGE 'c'
IMMUTABLE STRICT;
CREATE FUNCTION pointkey_out(pointkey)
RETURNS CSTRING
AS 'MODULE_PATHNAME', 'pointkey_out'
LANGUAGE 'c'
IMMUTABLE STRICT;
CREATE FUNCTION pointkey_volume(pointkey)
RETURNS float8
AS 'MODULE_PATHNAME', 'pointkey_volume'
LANGUAGE 'c'
IMMUTABLE STRICT PARALLEL SAFE;
CREATE FUNCTION pointkey_area(pointkey)
RETURNS float8
AS 'MODULE_PATHNAME', 'pointkey_area'
LANGUAGE 'c'
IMMUTABLE STRICT PARALLEL SAFE;
CREATE FUNCTION pointkey_perimeter(pointkey)
RETURNS float8
AS 'MODULE_PATHNAME', 'pointkey_perimeter'
LANGUAGE 'c'
IMMUTABLE STRICT PARALLEL SAFE;
CREATE TYPE pointkey (
input = pointkey_in,
output = pointkey_out,
internallength = -1,
ALIGNMENT = int4,
STORAGE = PLAIN
);
-- GIST common
CREATE FUNCTION g_spherekey_decompress(internal)
RETURNS internal
AS 'MODULE_PATHNAME', 'g_spherekey_decompress'
LANGUAGE 'c';
CREATE FUNCTION g_spherekey_union(bytea, internal)
RETURNS spherekey
AS 'MODULE_PATHNAME', 'g_spherekey_union'
LANGUAGE 'c';
CREATE FUNCTION g_spherekey_penalty (internal, internal, internal)
RETURNS internal
AS 'MODULE_PATHNAME', 'g_spherekey_penalty'
LANGUAGE 'c'
STRICT;
CREATE FUNCTION g_spherekey_picksplit(internal, internal)
RETURNS internal
AS 'MODULE_PATHNAME', 'g_spherekey_picksplit'
LANGUAGE 'c';
CREATE FUNCTION g_spherekey_same (spherekey, spherekey, internal)
RETURNS internal
AS 'MODULE_PATHNAME', 'g_spherekey_same'
LANGUAGE 'c';
-- create the operator class for spherical points
CREATE FUNCTION g_spoint_compress(internal)
RETURNS internal
AS 'MODULE_PATHNAME', 'g_spoint_compress'
LANGUAGE 'c';
CREATE FUNCTION g_spoint_consistent(internal, internal, int4, oid, internal)
RETURNS internal
AS 'MODULE_PATHNAME', 'g_spoint_consistent'
LANGUAGE 'c';
CREATE FUNCTION g_spoint_distance(internal, spoint, smallint, oid, internal)
RETURNS internal
AS 'MODULE_PATHNAME', 'g_spoint_distance'
LANGUAGE 'c';
CREATE OPERATOR CLASS spoint
DEFAULT FOR TYPE spoint USING gist AS
OPERATOR 1 = (spoint, spoint),
OPERATOR 11 @ (spoint, scircle),
OPERATOR 12 @ (spoint, sline),
OPERATOR 13 @ (spoint, spath),
OPERATOR 14 @ (spoint, spoly),
OPERATOR 15 @ (spoint, sellipse),
OPERATOR 16 @ (spoint, sbox),
OPERATOR 17 <-> (spoint, spoint) FOR ORDER BY float_ops,
OPERATOR 37 <@ (spoint, scircle),
OPERATOR 38 <@ (spoint, sline),
OPERATOR 39 <@ (spoint, spath),
OPERATOR 40 <@ (spoint, spoly),
OPERATOR 41 <@ (spoint, sellipse),
OPERATOR 42 <@ (spoint, sbox),
FUNCTION 1 g_spoint_consistent (internal, internal, int4, oid, internal),
FUNCTION 2 g_spherekey_union (bytea, internal),
FUNCTION 3 g_spoint_compress (internal),
FUNCTION 4 g_spherekey_decompress (internal),
FUNCTION 5 g_spherekey_penalty (internal, internal, internal),
FUNCTION 6 g_spherekey_picksplit (internal, internal),
FUNCTION 7 g_spherekey_same (spherekey, spherekey, internal),
FUNCTION 8 g_spoint_distance (internal, spoint, smallint, oid, internal),
STORAGE spherekey;
-- create the operator class for spherical circle
CREATE FUNCTION g_scircle_compress(internal)
RETURNS internal
AS 'MODULE_PATHNAME', 'g_scircle_compress'
LANGUAGE 'c';
CREATE FUNCTION g_scircle_consistent(internal, internal, int4, oid, internal)
RETURNS internal
AS 'MODULE_PATHNAME', 'g_scircle_consistent'
LANGUAGE 'c';
CREATE OPERATOR CLASS scircle
DEFAULT FOR TYPE scircle USING gist AS
OPERATOR 1 = (scircle, scircle),
OPERATOR 11 @ (scircle, scircle),
OPERATOR 12 @ (scircle, spoly),
OPERATOR 13 @ (scircle, sellipse),
OPERATOR 14 @ (scircle, sbox),
OPERATOR 21 ~ (scircle, spoint),
OPERATOR 22 ~ (scircle, scircle),
OPERATOR 23 ~ (scircle, sline),
OPERATOR 24 ~ (scircle, spath),
OPERATOR 25 ~ (scircle, spoly),
OPERATOR 26 ~ (scircle, sellipse),
OPERATOR 27 ~ (scircle, sbox),
OPERATOR 31 && (scircle, scircle),
OPERATOR 32 && (scircle, sline),
OPERATOR 33 && (scircle, spath),
OPERATOR 34 && (scircle, spoly),
OPERATOR 35 && (scircle, sellipse),
OPERATOR 36 && (scircle, sbox),
OPERATOR 37 <@ (scircle, scircle),
OPERATOR 38 <@ (scircle, spoly),
OPERATOR 39 <@ (scircle, sellipse),
OPERATOR 40 <@ (scircle, sbox),
OPERATOR 43 @> (scircle, spoint),
OPERATOR 44 @> (scircle, scircle),
OPERATOR 45 @> (scircle, sline),
OPERATOR 46 @> (scircle, spath),
OPERATOR 47 @> (scircle, spoly),
OPERATOR 48 @> (scircle, sellipse),
OPERATOR 49 @> (scircle, sbox),
FUNCTION 1 g_scircle_consistent (internal, internal, int4, oid, internal),
FUNCTION 2 g_spherekey_union (bytea, internal),
FUNCTION 3 g_scircle_compress (internal),
FUNCTION 4 g_spherekey_decompress (internal),
FUNCTION 5 g_spherekey_penalty (internal, internal, internal),
FUNCTION 6 g_spherekey_picksplit (internal, internal),
FUNCTION 7 g_spherekey_same (spherekey, spherekey, internal),
STORAGE spherekey;
-- create the operator class for spherical line
CREATE FUNCTION g_sline_compress(internal)
RETURNS internal
AS 'MODULE_PATHNAME', 'g_sline_compress'
LANGUAGE 'c';
CREATE FUNCTION g_sline_consistent(internal, internal, int4, oid, internal)
RETURNS internal
AS 'MODULE_PATHNAME', 'g_sline_consistent'
LANGUAGE 'c';
CREATE OPERATOR CLASS sline
DEFAULT FOR TYPE sline USING gist AS
OPERATOR 1 = (sline, sline),
OPERATOR 2 # (sline, sline),
OPERATOR 11 @ (sline, scircle),
OPERATOR 12 @ (sline, spoly),
OPERATOR 13 @ (sline, sellipse),
OPERATOR 14 @ (sline, sbox),
OPERATOR 21 ~ (sline, spoint),
OPERATOR 31 && (sline, scircle),
OPERATOR 32 && (sline, sline),
OPERATOR 33 && (sline, spath),
OPERATOR 34 && (sline, spoly),
OPERATOR 35 && (sline, sellipse),
OPERATOR 36 && (sline, sbox),
OPERATOR 37 <@ (sline, scircle),
OPERATOR 38 <@ (sline, spoly),
OPERATOR 39 <@ (sline, sellipse),
OPERATOR 40 <@ (sline, sbox),
OPERATOR 43 @> (sline, spoint),
FUNCTION 1 g_sline_consistent (internal, internal, int4, oid, internal),
FUNCTION 2 g_spherekey_union (bytea, internal),
FUNCTION 3 g_sline_compress (internal),
FUNCTION 4 g_spherekey_decompress (internal),
FUNCTION 5 g_spherekey_penalty (internal, internal, internal),
FUNCTION 6 g_spherekey_picksplit (internal, internal),
FUNCTION 7 g_spherekey_same (spherekey, spherekey, internal),
STORAGE spherekey;
-- create the operator class for spherical ellipse
CREATE FUNCTION g_sellipse_compress(internal)
RETURNS internal
AS 'MODULE_PATHNAME', 'g_sellipse_compress'
LANGUAGE 'c';
CREATE FUNCTION g_sellipse_consistent(internal, internal, int4, oid, internal)
RETURNS internal
AS 'MODULE_PATHNAME', 'g_sellipse_consistent'
LANGUAGE 'c';
CREATE OPERATOR CLASS sellipse
DEFAULT FOR TYPE sellipse USING gist AS
OPERATOR 1 = (sellipse, sellipse),
OPERATOR 11 @ (sellipse, scircle),
OPERATOR 12 @ (sellipse, spoly),
OPERATOR 13 @ (sellipse, sellipse),
OPERATOR 14 @ (sellipse, sbox),
OPERATOR 21 ~ (sellipse, spoint),
OPERATOR 22 ~ (sellipse, scircle),
OPERATOR 23 ~ (sellipse, sline),
OPERATOR 24 ~ (sellipse, spath),
OPERATOR 25 ~ (sellipse, spoly),
OPERATOR 26 ~ (sellipse, sellipse),
OPERATOR 27 ~ (sellipse, sbox),
OPERATOR 31 && (sellipse, scircle),
OPERATOR 32 && (sellipse, sline),
OPERATOR 33 && (sellipse, spath),
OPERATOR 34 && (sellipse, spoly),
OPERATOR 35 && (sellipse, sellipse),
OPERATOR 36 && (sellipse, sbox),
OPERATOR 37 <@ (sellipse, scircle),
OPERATOR 38 <@ (sellipse, spoly),
OPERATOR 39 <@ (sellipse, sellipse),
OPERATOR 40 <@ (sellipse, sbox),
OPERATOR 43 @> (sellipse, spoint),
OPERATOR 44 @> (sellipse, scircle),
OPERATOR 45 @> (sellipse, sline),
OPERATOR 46 @> (sellipse, spath),
OPERATOR 47 @> (sellipse, spoly),
OPERATOR 48 @> (sellipse, sellipse),
OPERATOR 49 @> (sellipse, sbox),
FUNCTION 1 g_sellipse_consistent (internal, internal, int4, oid, internal),
FUNCTION 2 g_spherekey_union (bytea, internal),
FUNCTION 3 g_sellipse_compress (internal),
FUNCTION 4 g_spherekey_decompress (internal),
FUNCTION 5 g_spherekey_penalty (internal, internal, internal),
FUNCTION 6 g_spherekey_picksplit (internal, internal),
FUNCTION 7 g_spherekey_same (spherekey, spherekey, internal),
STORAGE spherekey;
-- create the operator class for spherical polygon
CREATE FUNCTION g_spoly_compress(internal)
RETURNS internal
AS 'MODULE_PATHNAME', 'g_spoly_compress'
LANGUAGE 'c';
CREATE FUNCTION g_spoly_consistent(internal, internal, int4, oid, internal)
RETURNS internal
AS 'MODULE_PATHNAME', 'g_spoly_consistent'
LANGUAGE 'c';
CREATE OPERATOR CLASS spoly
DEFAULT FOR TYPE spoly USING gist AS
OPERATOR 1 = (spoly, spoly),
OPERATOR 11 @ (spoly, scircle),
OPERATOR 12 @ (spoly, spoly),
OPERATOR 13 @ (spoly, sellipse),
OPERATOR 14 @ (spoly, sbox),
OPERATOR 21 ~ (spoly, spoint),
OPERATOR 22 ~ (spoly, scircle),
OPERATOR 23 ~ (spoly, sline),
OPERATOR 24 ~ (spoly, spath),
OPERATOR 25 ~ (spoly, spoly),
OPERATOR 26 ~ (spoly, sellipse),
OPERATOR 27 ~ (spoly, sbox),
OPERATOR 31 && (spoly, scircle),
OPERATOR 32 && (spoly, sline),
OPERATOR 33 && (spoly, spath),
OPERATOR 34 && (spoly, spoly),
OPERATOR 35 && (spoly, sellipse),
OPERATOR 36 && (spoly, sbox),
OPERATOR 37 <@ (spoly, scircle),
OPERATOR 38 <@ (spoly, spoly),
OPERATOR 39 <@ (spoly, sellipse),
OPERATOR 40 <@ (spoly, sbox),
OPERATOR 43 @> (spoly, spoint),
OPERATOR 44 @> (spoly, scircle),
OPERATOR 45 @> (spoly, sline),
OPERATOR 46 @> (spoly, spath),
OPERATOR 47 @> (spoly, spoly),
OPERATOR 48 @> (spoly, sellipse),
OPERATOR 49 @> (spoly, sbox),
FUNCTION 1 g_spoly_consistent (internal, internal, int4, oid, internal),
FUNCTION 2 g_spherekey_union (bytea, internal),
FUNCTION 3 g_spoly_compress (internal),
FUNCTION 4 g_spherekey_decompress (internal),
FUNCTION 5 g_spherekey_penalty (internal, internal, internal),
FUNCTION 6 g_spherekey_picksplit (internal, internal),
FUNCTION 7 g_spherekey_same (spherekey, spherekey, internal),
STORAGE spherekey;
-- create the operator class for spherical path
CREATE FUNCTION g_spath_compress(internal)
RETURNS internal
AS 'MODULE_PATHNAME', 'g_spath_compress'
LANGUAGE 'c';
CREATE FUNCTION g_spath_consistent(internal, internal, int4, oid, internal)
RETURNS internal
AS 'MODULE_PATHNAME', 'g_spath_consistent'
LANGUAGE 'c';
CREATE OPERATOR CLASS spath
DEFAULT FOR TYPE spath USING gist AS
OPERATOR 1 = (spath, spath),
OPERATOR 11 @ (spath, scircle),
OPERATOR 12 @ (spath, spoly),
OPERATOR 13 @ (spath, sellipse),
OPERATOR 14 @ (spath, sbox),
OPERATOR 21 ~ (spath, spoint),
OPERATOR 31 && (spath, scircle),
OPERATOR 32 && (spath, sline),
OPERATOR 33 && (spath, spath),
OPERATOR 34 && (spath, spoly),
OPERATOR 35 && (spath, sellipse),
OPERATOR 36 && (spath, sbox),
OPERATOR 37 <@ (spath, scircle),
OPERATOR 38 <@ (spath, spoly),
OPERATOR 39 <@ (spath, sellipse),
OPERATOR 40 <@ (spath, sbox),
OPERATOR 43 @> (spath, spoint),
FUNCTION 1 g_spath_consistent (internal, internal, int4, oid, internal),
FUNCTION 2 g_spherekey_union (bytea, internal),
FUNCTION 3 g_spath_compress (internal),
FUNCTION 4 g_spherekey_decompress (internal),
FUNCTION 5 g_spherekey_penalty (internal, internal, internal),
FUNCTION 6 g_spherekey_picksplit (internal, internal),
FUNCTION 7 g_spherekey_same (spherekey, spherekey, internal),
STORAGE spherekey;
-- create the operator class for spherical box
CREATE FUNCTION g_sbox_compress(internal)
RETURNS internal
AS 'MODULE_PATHNAME', 'g_sbox_compress'
LANGUAGE 'c';
CREATE FUNCTION g_sbox_consistent(internal, internal, int4, oid, internal)
RETURNS internal
AS 'MODULE_PATHNAME', 'g_sbox_consistent'
LANGUAGE 'c';
CREATE OPERATOR CLASS sbox
DEFAULT FOR TYPE sbox USING gist AS
OPERATOR 1 = (sbox, sbox),
OPERATOR 11 @ (sbox, scircle),
OPERATOR 12 @ (sbox, spoly),
OPERATOR 13 @ (sbox, sellipse),
OPERATOR 14 @ (sbox, sbox),
OPERATOR 21 ~ (sbox, spoint),
OPERATOR 22 ~ (sbox, scircle),
OPERATOR 23 ~ (sbox, sline),
OPERATOR 24 ~ (sbox, spath),
OPERATOR 25 ~ (sbox, spoly),
OPERATOR 26 ~ (sbox, sellipse),
OPERATOR 27 ~ (sbox, sbox),
OPERATOR 31 && (sbox, scircle),
OPERATOR 32 && (sbox, sline),
OPERATOR 33 && (sbox, spath),
OPERATOR 34 && (sbox, spoly),
OPERATOR 35 && (sbox, sellipse),
OPERATOR 36 && (sbox, sbox),
OPERATOR 37 <@ (sbox, scircle),
OPERATOR 38 <@ (sbox, spoly),
OPERATOR 39 <@ (sbox, sellipse),
OPERATOR 40 <@ (sbox, sbox),
OPERATOR 43 @> (sbox, spoint),
OPERATOR 44 @> (sbox, scircle),
OPERATOR 45 @> (sbox, sline),
OPERATOR 46 @> (sbox, spath),
OPERATOR 47 @> (sbox, spoly),
OPERATOR 48 @> (sbox, sellipse),
OPERATOR 49 @> (sbox, sbox),
FUNCTION 1 g_sbox_consistent (internal, internal, int4, oid, internal),
FUNCTION 2 g_spherekey_union (bytea, internal),
FUNCTION 3 g_sbox_compress (internal),
FUNCTION 4 g_spherekey_decompress (internal),
FUNCTION 5 g_spherekey_penalty (internal, internal, internal),
FUNCTION 6 g_spherekey_picksplit (internal, internal),
FUNCTION 7 g_spherekey_same (spherekey, spherekey, internal),
STORAGE spherekey;