Debian Codegraph @

contrib/earthdistance/expected/earthdistance.out

raw
1 --
2 -- Test earthdistance extension
3 --
4 -- In this file we also do some testing of extension create/drop scenarios.
5 -- That's really exercising the core database's dependency logic, so ideally
6 -- we'd do it in the core regression tests, but we can't for lack of suitable
7 -- guaranteed-available extensions. earthdistance is a good test case because
8 -- it has a dependency on the cube extension.
9 --
10 CREATE EXTENSION earthdistance; -- fail, must install cube first
11 ERROR: required extension "cube" is not installed
12 HINT: Use CREATE EXTENSION ... CASCADE to install required extensions too.
13 CREATE EXTENSION cube;
14 CREATE EXTENSION earthdistance;
15 --
16 -- The radius of the Earth we are using.
17 --
18 SELECT earth()::numeric(20,5);
19 earth
20 ---------------
21 6378168.00000
22 (1 row)
23
24 --
25 -- Convert straight line distances to great circle distances.
26 --
27 SELECT (pi()*earth())::numeric(20,5);
28 numeric
29 ----------------
30 20037605.73216
31 (1 row)
32
33 SELECT sec_to_gc(0)::numeric(20,5);
34 sec_to_gc
35 -----------
36 0.00000
37 (1 row)
38
39 SELECT sec_to_gc(2*earth())::numeric(20,5);
40 sec_to_gc
41 ----------------
42 20037605.73216
43 (1 row)
44
45 SELECT sec_to_gc(10*earth())::numeric(20,5);
46 sec_to_gc
47 ----------------
48 20037605.73216
49 (1 row)
50
51 SELECT sec_to_gc(-earth())::numeric(20,5);
52 sec_to_gc
53 -----------
54 0.00000
55 (1 row)
56
57 SELECT sec_to_gc(1000)::numeric(20,5);
58 sec_to_gc
59 ------------
60 1000.00000
61 (1 row)
62
63 SELECT sec_to_gc(10000)::numeric(20,5);
64 sec_to_gc
65 -------------
66 10000.00102
67 (1 row)
68
69 SELECT sec_to_gc(100000)::numeric(20,5);
70 sec_to_gc
71 --------------
72 100001.02426
73 (1 row)
74
75 SELECT sec_to_gc(1000000)::numeric(20,5);
76 sec_to_gc
77 ---------------
78 1001027.07131
79 (1 row)
80
81 --
82 -- Convert great circle distances to straight line distances.
83 --
84 SELECT gc_to_sec(0)::numeric(20,5);
85 gc_to_sec
86 -----------
87 0.00000
88 (1 row)
89
90 SELECT gc_to_sec(sec_to_gc(2*earth()))::numeric(20,5);
91 gc_to_sec
92 ----------------
93 12756336.00000
94 (1 row)
95
96 SELECT gc_to_sec(10*earth())::numeric(20,5);
97 gc_to_sec
98 ----------------
99 12756336.00000
100 (1 row)
101
102 SELECT gc_to_sec(pi()*earth())::numeric(20,5);
103 gc_to_sec
104 ----------------
105 12756336.00000
106 (1 row)
107
108 SELECT gc_to_sec(-1000)::numeric(20,5);
109 gc_to_sec
110 -----------
111 0.00000
112 (1 row)
113
114 SELECT gc_to_sec(1000)::numeric(20,5);
115 gc_to_sec
116 ------------
117 1000.00000
118 (1 row)
119
120 SELECT gc_to_sec(10000)::numeric(20,5);
121 gc_to_sec
122 ------------
123 9999.99898
124 (1 row)
125
126 SELECT gc_to_sec(100000)::numeric(20,5);
127 gc_to_sec
128 -------------
129 99998.97577
130 (1 row)
131
132 SELECT gc_to_sec(1000000)::numeric(20,5);
133 gc_to_sec
134 --------------
135 998976.08618
136 (1 row)
137
138 --
139 -- Set coordinates using latitude and longitude.
140 -- Extract each coordinate separately so we can round them.
141 --
142 SELECT cube_ll_coord(ll_to_earth(0,0),1)::numeric(20,5),
143 cube_ll_coord(ll_to_earth(0,0),2)::numeric(20,5),
144 cube_ll_coord(ll_to_earth(0,0),3)::numeric(20,5);
145 cube_ll_coord | cube_ll_coord | cube_ll_coord
146 ---------------+---------------+---------------
147 6378168.00000 | 0.00000 | 0.00000
148 (1 row)
149
150 SELECT cube_ll_coord(ll_to_earth(360,360),1)::numeric(20,5),
151 cube_ll_coord(ll_to_earth(360,360),2)::numeric(20,5),
152 cube_ll_coord(ll_to_earth(360,360),3)::numeric(20,5);
153 cube_ll_coord | cube_ll_coord | cube_ll_coord
154 ---------------+---------------+---------------
155 6378168.00000 | 0.00000 | 0.00000
156 (1 row)
157
158 SELECT cube_ll_coord(ll_to_earth(180,180),1)::numeric(20,5),
159 cube_ll_coord(ll_to_earth(180,180),2)::numeric(20,5),
160 cube_ll_coord(ll_to_earth(180,180),3)::numeric(20,5);
161 cube_ll_coord | cube_ll_coord | cube_ll_coord
162 ---------------+---------------+---------------
163 6378168.00000 | 0.00000 | 0.00000
164 (1 row)
165
166 SELECT cube_ll_coord(ll_to_earth(180,360),1)::numeric(20,5),
167 cube_ll_coord(ll_to_earth(180,360),2)::numeric(20,5),
168 cube_ll_coord(ll_to_earth(180,360),3)::numeric(20,5);
169 cube_ll_coord | cube_ll_coord | cube_ll_coord
170 ----------------+---------------+---------------
171 -6378168.00000 | 0.00000 | 0.00000
172 (1 row)
173
174 SELECT cube_ll_coord(ll_to_earth(-180,-360),1)::numeric(20,5),
175 cube_ll_coord(ll_to_earth(-180,-360),2)::numeric(20,5),
176 cube_ll_coord(ll_to_earth(-180,-360),3)::numeric(20,5);
177 cube_ll_coord | cube_ll_coord | cube_ll_coord
178 ----------------+---------------+---------------
179 -6378168.00000 | 0.00000 | 0.00000
180 (1 row)
181
182 SELECT cube_ll_coord(ll_to_earth(0,180),1)::numeric(20,5),
183 cube_ll_coord(ll_to_earth(0,180),2)::numeric(20,5),
184 cube_ll_coord(ll_to_earth(0,180),3)::numeric(20,5);
185 cube_ll_coord | cube_ll_coord | cube_ll_coord
186 ----------------+---------------+---------------
187 -6378168.00000 | 0.00000 | 0.00000
188 (1 row)
189
190 SELECT cube_ll_coord(ll_to_earth(0,-180),1)::numeric(20,5),
191 cube_ll_coord(ll_to_earth(0,-180),2)::numeric(20,5),
192 cube_ll_coord(ll_to_earth(0,-180),3)::numeric(20,5);
193 cube_ll_coord | cube_ll_coord | cube_ll_coord
194 ----------------+---------------+---------------
195 -6378168.00000 | 0.00000 | 0.00000
196 (1 row)
197
198 SELECT cube_ll_coord(ll_to_earth(90,0),1)::numeric(20,5),
199 cube_ll_coord(ll_to_earth(90,0),2)::numeric(20,5),
200 cube_ll_coord(ll_to_earth(90,0),3)::numeric(20,5);
201 cube_ll_coord | cube_ll_coord | cube_ll_coord
202 ---------------+---------------+---------------
203 0.00000 | 0.00000 | 6378168.00000
204 (1 row)
205
206 SELECT cube_ll_coord(ll_to_earth(90,180),1)::numeric(20,5),
207 cube_ll_coord(ll_to_earth(90,180),2)::numeric(20,5),
208 cube_ll_coord(ll_to_earth(90,180),3)::numeric(20,5);
209 cube_ll_coord | cube_ll_coord | cube_ll_coord
210 ---------------+---------------+---------------
211 0.00000 | 0.00000 | 6378168.00000
212 (1 row)
213
214 SELECT cube_ll_coord(ll_to_earth(-90,0),1)::numeric(20,5),
215 cube_ll_coord(ll_to_earth(-90,0),2)::numeric(20,5),
216 cube_ll_coord(ll_to_earth(-90,0),3)::numeric(20,5);
217 cube_ll_coord | cube_ll_coord | cube_ll_coord
218 ---------------+---------------+----------------
219 0.00000 | 0.00000 | -6378168.00000
220 (1 row)
221
222 SELECT cube_ll_coord(ll_to_earth(-90,180),1)::numeric(20,5),
223 cube_ll_coord(ll_to_earth(-90,180),2)::numeric(20,5),
224 cube_ll_coord(ll_to_earth(-90,180),3)::numeric(20,5);
225 cube_ll_coord | cube_ll_coord | cube_ll_coord
226 ---------------+---------------+----------------
227 0.00000 | 0.00000 | -6378168.00000
228 (1 row)
229
230 --
231 -- Test getting the latitude of a location.
232 --
233 SELECT latitude(ll_to_earth(0,0))::numeric(20,10);
234 latitude
235 --------------
236 0.0000000000
237 (1 row)
238
239 SELECT latitude(ll_to_earth(45,0))::numeric(20,10);
240 latitude
241 ---------------
242 45.0000000000
243 (1 row)
244
245 SELECT latitude(ll_to_earth(90,0))::numeric(20,10);
246 latitude
247 ---------------
248 90.0000000000
249 (1 row)
250
251 SELECT latitude(ll_to_earth(-45,0))::numeric(20,10);
252 latitude
253 ----------------
254 -45.0000000000
255 (1 row)
256
257 SELECT latitude(ll_to_earth(-90,0))::numeric(20,10);
258 latitude
259 ----------------
260 -90.0000000000
261 (1 row)
262
263 SELECT latitude(ll_to_earth(0,90))::numeric(20,10);
264 latitude
265 --------------
266 0.0000000000
267 (1 row)
268
269 SELECT latitude(ll_to_earth(45,90))::numeric(20,10);
270 latitude
271 ---------------
272 45.0000000000
273 (1 row)
274
275 SELECT latitude(ll_to_earth(90,90))::numeric(20,10);
276 latitude
277 ---------------
278 90.0000000000
279 (1 row)
280
281 SELECT latitude(ll_to_earth(-45,90))::numeric(20,10);
282 latitude
283 ----------------
284 -45.0000000000
285 (1 row)
286
287 SELECT latitude(ll_to_earth(-90,90))::numeric(20,10);
288 latitude
289 ----------------
290 -90.0000000000
291 (1 row)
292
293 SELECT latitude(ll_to_earth(0,180))::numeric(20,10);
294 latitude
295 --------------
296 0.0000000000
297 (1 row)
298
299 SELECT latitude(ll_to_earth(45,180))::numeric(20,10);
300 latitude
301 ---------------
302 45.0000000000
303 (1 row)
304
305 SELECT latitude(ll_to_earth(90,180))::numeric(20,10);
306 latitude
307 ---------------
308 90.0000000000
309 (1 row)
310
311 SELECT latitude(ll_to_earth(-45,180))::numeric(20,10);
312 latitude
313 ----------------
314 -45.0000000000
315 (1 row)
316
317 SELECT latitude(ll_to_earth(-90,180))::numeric(20,10);
318 latitude
319 ----------------
320 -90.0000000000
321 (1 row)
322
323 SELECT latitude(ll_to_earth(0,-90))::numeric(20,10);
324 latitude
325 --------------
326 0.0000000000
327 (1 row)
328
329 SELECT latitude(ll_to_earth(45,-90))::numeric(20,10);
330 latitude
331 ---------------
332 45.0000000000
333 (1 row)
334
335 SELECT latitude(ll_to_earth(90,-90))::numeric(20,10);
336 latitude
337 ---------------
338 90.0000000000
339 (1 row)
340
341 SELECT latitude(ll_to_earth(-45,-90))::numeric(20,10);
342 latitude
343 ----------------
344 -45.0000000000
345 (1 row)
346
347 SELECT latitude(ll_to_earth(-90,-90))::numeric(20,10);
348 latitude
349 ----------------
350 -90.0000000000
351 (1 row)
352
353 --
354 -- Test getting the longitude of a location.
355 --
356 SELECT longitude(ll_to_earth(0,0))::numeric(20,10);
357 longitude
358 --------------
359 0.0000000000
360 (1 row)
361
362 SELECT longitude(ll_to_earth(45,0))::numeric(20,10);
363 longitude
364 --------------
365 0.0000000000
366 (1 row)
367
368 SELECT longitude(ll_to_earth(90,0))::numeric(20,10);
369 longitude
370 --------------
371 0.0000000000
372 (1 row)
373
374 SELECT longitude(ll_to_earth(-45,0))::numeric(20,10);
375 longitude
376 --------------
377 0.0000000000
378 (1 row)
379
380 SELECT longitude(ll_to_earth(-90,0))::numeric(20,10);
381 longitude
382 --------------
383 0.0000000000
384 (1 row)
385
386 SELECT longitude(ll_to_earth(0,90))::numeric(20,10);
387 longitude
388 ---------------
389 90.0000000000
390 (1 row)
391
392 SELECT longitude(ll_to_earth(45,90))::numeric(20,10);
393 longitude
394 ---------------
395 90.0000000000
396 (1 row)
397
398 SELECT longitude(ll_to_earth(90,90))::numeric(20,10);
399 longitude
400 ---------------
401 90.0000000000
402 (1 row)
403
404 SELECT longitude(ll_to_earth(-45,90))::numeric(20,10);
405 longitude
406 ---------------
407 90.0000000000
408 (1 row)
409
410 SELECT longitude(ll_to_earth(-90,90))::numeric(20,10);
411 longitude
412 ---------------
413 90.0000000000
414 (1 row)
415
416 SELECT longitude(ll_to_earth(0,180))::numeric(20,10);
417 longitude
418 ----------------
419 180.0000000000
420 (1 row)
421
422 SELECT longitude(ll_to_earth(45,180))::numeric(20,10);
423 longitude
424 ----------------
425 180.0000000000
426 (1 row)
427
428 SELECT longitude(ll_to_earth(90,180))::numeric(20,10);
429 longitude
430 ----------------
431 180.0000000000
432 (1 row)
433
434 SELECT longitude(ll_to_earth(-45,180))::numeric(20,10);
435 longitude
436 ----------------
437 180.0000000000
438 (1 row)
439
440 SELECT longitude(ll_to_earth(-90,180))::numeric(20,10);
441 longitude
442 ----------------
443 180.0000000000
444 (1 row)
445
446 SELECT longitude(ll_to_earth(0,-90))::numeric(20,10);
447 longitude
448 ----------------
449 -90.0000000000
450 (1 row)
451
452 SELECT longitude(ll_to_earth(45,-90))::numeric(20,10);
453 longitude
454 ----------------
455 -90.0000000000
456 (1 row)
457
458 SELECT longitude(ll_to_earth(90,-90))::numeric(20,10);
459 longitude
460 ----------------
461 -90.0000000000
462 (1 row)
463
464 SELECT longitude(ll_to_earth(-45,-90))::numeric(20,10);
465 longitude
466 ----------------
467 -90.0000000000
468 (1 row)
469
470 SELECT longitude(ll_to_earth(-90,-90))::numeric(20,10);
471 longitude
472 ----------------
473 -90.0000000000
474 (1 row)
475
476 --
477 -- For the distance tests the following is some real life data.
478 --
479 -- Chicago has a latitude of 41.8 and a longitude of 87.6.
480 -- Albuquerque has a latitude of 35.1 and a longitude of 106.7.
481 -- (Note that latitude and longitude are specified differently
482 -- in the cube based functions than for the point based functions.)
483 --
484 --
485 -- Test getting the distance between two points using earth_distance.
486 --
487 SELECT earth_distance(ll_to_earth(0,0),ll_to_earth(0,0))::numeric(20,5);
488 earth_distance
489 ----------------
490 0.00000
491 (1 row)
492
493 SELECT earth_distance(ll_to_earth(0,0),ll_to_earth(0,180))::numeric(20,5);
494 earth_distance
495 ----------------
496 20037605.73216
497 (1 row)
498
499 SELECT earth_distance(ll_to_earth(0,0),ll_to_earth(90,0))::numeric(20,5);
500 earth_distance
501 ----------------
502 10018802.86608
503 (1 row)
504
505 SELECT earth_distance(ll_to_earth(0,0),ll_to_earth(0,90))::numeric(20,5);
506 earth_distance
507 ----------------
508 10018802.86608
509 (1 row)
510
511 SELECT earth_distance(ll_to_earth(0,0),ll_to_earth(0,1))::numeric(20,5);
512 earth_distance
513 ----------------
514 111320.03185
515 (1 row)
516
517 SELECT earth_distance(ll_to_earth(0,0),ll_to_earth(1,0))::numeric(20,5);
518 earth_distance
519 ----------------
520 111320.03185
521 (1 row)
522
523 SELECT earth_distance(ll_to_earth(30,0),ll_to_earth(30,1))::numeric(20,5);
524 earth_distance
525 ----------------
526 96405.66962
527 (1 row)
528
529 SELECT earth_distance(ll_to_earth(30,0),ll_to_earth(31,0))::numeric(20,5);
530 earth_distance
531 ----------------
532 111320.03185
533 (1 row)
534
535 SELECT earth_distance(ll_to_earth(60,0),ll_to_earth(60,1))::numeric(20,5);
536 earth_distance
537 ----------------
538 55659.48608
539 (1 row)
540
541 SELECT earth_distance(ll_to_earth(60,0),ll_to_earth(61,0))::numeric(20,5);
542 earth_distance
543 ----------------
544 111320.03185
545 (1 row)
546
547 SELECT earth_distance(ll_to_earth(41.8,87.6),ll_to_earth(35.1,106.7))::numeric(20,5);
548 earth_distance
549 ----------------
550 1819303.21265
551 (1 row)
552
553 SELECT (earth_distance(ll_to_earth(41.8,87.6),ll_to_earth(35.1,106.7))*
554 100./2.54/12./5280.)::numeric(20,5);
555 numeric
556 ------------
557 1130.46261
558 (1 row)
559
560 --
561 -- Test getting the distance between two points using geo_distance.
562 --
563 SELECT geo_distance('(0,0)'::point,'(0,0)'::point)::numeric(20,5);
564 geo_distance
565 --------------
566 0.00000
567 (1 row)
568
569 SELECT geo_distance('(0,0)'::point,'(180,0)'::point)::numeric(20,5);
570 geo_distance
571 --------------
572 12436.77274
573 (1 row)
574
575 SELECT geo_distance('(0,0)'::point,'(0,90)'::point)::numeric(20,5);
576 geo_distance
577 --------------
578 6218.38637
579 (1 row)
580
581 SELECT geo_distance('(0,0)'::point,'(90,0)'::point)::numeric(20,5);
582 geo_distance
583 --------------
584 6218.38637
585 (1 row)
586
587 SELECT geo_distance('(0,0)'::point,'(1,0)'::point)::numeric(20,5);
588 geo_distance
589 --------------
590 69.09318
591 (1 row)
592
593 SELECT geo_distance('(0,0)'::point,'(0,1)'::point)::numeric(20,5);
594 geo_distance
595 --------------
596 69.09318
597 (1 row)
598
599 SELECT geo_distance('(0,30)'::point,'(1,30)'::point)::numeric(20,5);
600 geo_distance
601 --------------
602 59.83626
603 (1 row)
604
605 SELECT geo_distance('(0,30)'::point,'(0,31)'::point)::numeric(20,5);
606 geo_distance
607 --------------
608 69.09318
609 (1 row)
610
611 SELECT geo_distance('(0,60)'::point,'(1,60)'::point)::numeric(20,5);
612 geo_distance
613 --------------
614 34.54626
615 (1 row)
616
617 SELECT geo_distance('(0,60)'::point,'(0,61)'::point)::numeric(20,5);
618 geo_distance
619 --------------
620 69.09318
621 (1 row)
622
623 SELECT geo_distance('(87.6,41.8)'::point,'(106.7,35.1)'::point)::numeric(20,5);
624 geo_distance
625 --------------
626 1129.18983
627 (1 row)
628
629 SELECT (geo_distance('(87.6,41.8)'::point,'(106.7,35.1)'::point)*5280.*12.*2.54/100.)::numeric(20,5);
630 numeric
631 ---------------
632 1817254.87730
633 (1 row)
634
635 --
636 -- Test getting the distance between two points using the <@> operator.
637 --
638 SELECT ('(0,0)'::point <@> '(0,0)'::point)::numeric(20,5);
639 numeric
640 ---------
641 0.00000
642 (1 row)
643
644 SELECT ('(0,0)'::point <@> '(180,0)'::point)::numeric(20,5);
645 numeric
646 -------------
647 12436.77274
648 (1 row)
649
650 SELECT ('(0,0)'::point <@> '(0,90)'::point)::numeric(20,5);
651 numeric
652 ------------
653 6218.38637
654 (1 row)
655
656 SELECT ('(0,0)'::point <@> '(90,0)'::point)::numeric(20,5);
657 numeric
658 ------------
659 6218.38637
660 (1 row)
661
662 SELECT ('(0,0)'::point <@> '(1,0)'::point)::numeric(20,5);
663 numeric
664 ----------
665 69.09318
666 (1 row)
667
668 SELECT ('(0,0)'::point <@> '(0,1)'::point)::numeric(20,5);
669 numeric
670 ----------
671 69.09318
672 (1 row)
673
674 SELECT ('(0,30)'::point <@> '(1,30)'::point)::numeric(20,5);
675 numeric
676 ----------
677 59.83626
678 (1 row)
679
680 SELECT ('(0,30)'::point <@> '(0,31)'::point)::numeric(20,5);
681 numeric
682 ----------
683 69.09318
684 (1 row)
685
686 SELECT ('(0,60)'::point <@> '(1,60)'::point)::numeric(20,5);
687 numeric
688 ----------
689 34.54626
690 (1 row)
691
692 SELECT ('(0,60)'::point <@> '(0,61)'::point)::numeric(20,5);
693 numeric
694 ----------
695 69.09318
696 (1 row)
697
698 SELECT ('(87.6,41.8)'::point <@> '(106.7,35.1)'::point)::numeric(20,5);
699 numeric
700 ------------
701 1129.18983
702 (1 row)
703
704 SELECT (('(87.6,41.8)'::point <@> '(106.7,35.1)'::point)*5280.*12.*2.54/100.)::numeric(20,5);
705 numeric
706 ---------------
707 1817254.87730
708 (1 row)
709
710 --
711 -- Test getting a bounding box around points.
712 --
713 SELECT cube_ll_coord(earth_box(ll_to_earth(0,0),112000),1)::numeric(20,5),
714 cube_ll_coord(earth_box(ll_to_earth(0,0),112000),2)::numeric(20,5),
715 cube_ll_coord(earth_box(ll_to_earth(0,0),112000),3)::numeric(20,5),
716 cube_ur_coord(earth_box(ll_to_earth(0,0),112000),1)::numeric(20,5),
717 cube_ur_coord(earth_box(ll_to_earth(0,0),112000),2)::numeric(20,5),
718 cube_ur_coord(earth_box(ll_to_earth(0,0),112000),3)::numeric(20,5);
719 cube_ll_coord | cube_ll_coord | cube_ll_coord | cube_ur_coord | cube_ur_coord | cube_ur_coord
720 ---------------+---------------+---------------+---------------+---------------+---------------
721 6266169.43896 | -111998.56104 | -111998.56104 | 6490166.56104 | 111998.56104 | 111998.56104
722 (1 row)
723
724 SELECT cube_ll_coord(earth_box(ll_to_earth(0,0),pi()*earth()),1)::numeric(20,5),
725 cube_ll_coord(earth_box(ll_to_earth(0,0),pi()*earth()),2)::numeric(20,5),
726 cube_ll_coord(earth_box(ll_to_earth(0,0),pi()*earth()),3)::numeric(20,5),
727 cube_ur_coord(earth_box(ll_to_earth(0,0),pi()*earth()),1)::numeric(20,5),
728 cube_ur_coord(earth_box(ll_to_earth(0,0),pi()*earth()),2)::numeric(20,5),
729 cube_ur_coord(earth_box(ll_to_earth(0,0),pi()*earth()),3)::numeric(20,5);
730 cube_ll_coord | cube_ll_coord | cube_ll_coord | cube_ur_coord | cube_ur_coord | cube_ur_coord
731 ----------------+-----------------+-----------------+----------------+----------------+----------------
732 -6378168.00000 | -12756336.00000 | -12756336.00000 | 19134504.00000 | 12756336.00000 | 12756336.00000
733 (1 row)
734
735 SELECT cube_ll_coord(earth_box(ll_to_earth(0,0),10*earth()),1)::numeric(20,5),
736 cube_ll_coord(earth_box(ll_to_earth(0,0),10*earth()),2)::numeric(20,5),
737 cube_ll_coord(earth_box(ll_to_earth(0,0),10*earth()),3)::numeric(20,5),
738 cube_ur_coord(earth_box(ll_to_earth(0,0),10*earth()),1)::numeric(20,5),
739 cube_ur_coord(earth_box(ll_to_earth(0,0),10*earth()),2)::numeric(20,5),
740 cube_ur_coord(earth_box(ll_to_earth(0,0),10*earth()),3)::numeric(20,5);
741 cube_ll_coord | cube_ll_coord | cube_ll_coord | cube_ur_coord | cube_ur_coord | cube_ur_coord
742 ----------------+-----------------+-----------------+----------------+----------------+----------------
743 -6378168.00000 | -12756336.00000 | -12756336.00000 | 19134504.00000 | 12756336.00000 | 12756336.00000
744 (1 row)
745
746 --
747 -- Test for points that should be in bounding boxes.
748 --
749 SELECT earth_box(ll_to_earth(0,0),
750 earth_distance(ll_to_earth(0,0),ll_to_earth(0,1))*1.00001) @>
751 ll_to_earth(0,1);
752 ?column?
753 ----------
754 t
755 (1 row)
756
757 SELECT earth_box(ll_to_earth(0,0),
758 earth_distance(ll_to_earth(0,0),ll_to_earth(0,0.1))*1.00001) @>
759 ll_to_earth(0,0.1);
760 ?column?
761 ----------
762 t
763 (1 row)
764
765 SELECT earth_box(ll_to_earth(0,0),
766 earth_distance(ll_to_earth(0,0),ll_to_earth(0,0.01))*1.00001) @>
767 ll_to_earth(0,0.01);
768 ?column?
769 ----------
770 t
771 (1 row)
772
773 SELECT earth_box(ll_to_earth(0,0),
774 earth_distance(ll_to_earth(0,0),ll_to_earth(0,0.001))*1.00001) @>
775 ll_to_earth(0,0.001);
776 ?column?
777 ----------
778 t
779 (1 row)
780
781 SELECT earth_box(ll_to_earth(0,0),
782 earth_distance(ll_to_earth(0,0),ll_to_earth(0,0.0001))*1.00001) @>
783 ll_to_earth(0,0.0001);
784 ?column?
785 ----------
786 t
787 (1 row)
788
789 SELECT earth_box(ll_to_earth(0,0),
790 earth_distance(ll_to_earth(0,0),ll_to_earth(0.0001,0.0001))*1.00001) @>
791 ll_to_earth(0.0001,0.0001);
792 ?column?
793 ----------
794 t
795 (1 row)
796
797 SELECT earth_box(ll_to_earth(45,45),
798 earth_distance(ll_to_earth(45,45),ll_to_earth(45.0001,45.0001))*1.00001) @>
799 ll_to_earth(45.0001,45.0001);
800 ?column?
801 ----------
802 t
803 (1 row)
804
805 SELECT earth_box(ll_to_earth(90,180),
806 earth_distance(ll_to_earth(90,180),ll_to_earth(90.0001,180.0001))*1.00001) @>
807 ll_to_earth(90.0001,180.0001);
808 ?column?
809 ----------
810 t
811 (1 row)
812
813 --
814 -- Test for points that shouldn't be in bounding boxes. Note that we need
815 -- to make points way outside, since some points close may be in the box
816 -- but further away than the distance we are testing.
817 --
818 SELECT earth_box(ll_to_earth(0,0),
819 earth_distance(ll_to_earth(0,0),ll_to_earth(0,1))*.57735) @>
820 ll_to_earth(0,1);
821 ?column?
822 ----------
823 f
824 (1 row)
825
826 SELECT earth_box(ll_to_earth(0,0),
827 earth_distance(ll_to_earth(0,0),ll_to_earth(0,0.1))*.57735) @>
828 ll_to_earth(0,0.1);
829 ?column?
830 ----------
831 f
832 (1 row)
833
834 SELECT earth_box(ll_to_earth(0,0),
835 earth_distance(ll_to_earth(0,0),ll_to_earth(0,0.01))*.57735) @>
836 ll_to_earth(0,0.01);
837 ?column?
838 ----------
839 f
840 (1 row)
841
842 SELECT earth_box(ll_to_earth(0,0),
843 earth_distance(ll_to_earth(0,0),ll_to_earth(0,0.001))*.57735) @>
844 ll_to_earth(0,0.001);
845 ?column?
846 ----------
847 f
848 (1 row)
849
850 SELECT earth_box(ll_to_earth(0,0),
851 earth_distance(ll_to_earth(0,0),ll_to_earth(0,0.0001))*.57735) @>
852 ll_to_earth(0,0.0001);
853 ?column?
854 ----------
855 f
856 (1 row)
857
858 SELECT earth_box(ll_to_earth(0,0),
859 earth_distance(ll_to_earth(0,0),ll_to_earth(0.0001,0.0001))*.57735) @>
860 ll_to_earth(0.0001,0.0001);
861 ?column?
862 ----------
863 f
864 (1 row)
865
866 SELECT earth_box(ll_to_earth(45,45),
867 earth_distance(ll_to_earth(45,45),ll_to_earth(45.0001,45.0001))*.57735) @>
868 ll_to_earth(45.0001,45.0001);
869 ?column?
870 ----------
871 f
872 (1 row)
873
874 SELECT earth_box(ll_to_earth(90,180),
875 earth_distance(ll_to_earth(90,180),ll_to_earth(90.0001,180.0001))*.57735) @>
876 ll_to_earth(90.0001,180.0001);
877 ?column?
878 ----------
879 f
880 (1 row)
881
882 --
883 -- Test the recommended constraints.
884 --
885 SELECT cube_is_point(ll_to_earth(0,0));
886 cube_is_point
887 ---------------
888 t
889 (1 row)
890
891 SELECT cube_dim(ll_to_earth(0,0)) <= 3;
892 ?column?
893 ----------
894 t
895 (1 row)
896
897 SELECT abs(cube_distance(ll_to_earth(0,0), '(0)'::cube) / earth() - 1) <
898 '10e-12'::float8;
899 ?column?
900 ----------
901 t
902 (1 row)
903
904 SELECT cube_is_point(ll_to_earth(30,60));
905 cube_is_point
906 ---------------
907 t
908 (1 row)
909
910 SELECT cube_dim(ll_to_earth(30,60)) <= 3;
911 ?column?
912 ----------
913 t
914 (1 row)
915
916 SELECT abs(cube_distance(ll_to_earth(30,60), '(0)'::cube) / earth() - 1) <
917 '10e-12'::float8;
918 ?column?
919 ----------
920 t
921 (1 row)
922
923 SELECT cube_is_point(ll_to_earth(60,90));
924 cube_is_point
925 ---------------
926 t
927 (1 row)
928
929 SELECT cube_dim(ll_to_earth(60,90)) <= 3;
930 ?column?
931 ----------
932 t
933 (1 row)
934
935 SELECT abs(cube_distance(ll_to_earth(60,90), '(0)'::cube) / earth() - 1) <
936 '10e-12'::float8;
937 ?column?
938 ----------
939 t
940 (1 row)
941
942 SELECT cube_is_point(ll_to_earth(-30,-90));
943 cube_is_point
944 ---------------
945 t
946 (1 row)
947
948 SELECT cube_dim(ll_to_earth(-30,-90)) <= 3;
949 ?column?
950 ----------
951 t
952 (1 row)
953
954 SELECT abs(cube_distance(ll_to_earth(-30,-90), '(0)'::cube) / earth() - 1) <
955 '10e-12'::float8;
956 ?column?
957 ----------
958 t
959 (1 row)
960
961 --
962 -- Now we are going to test extension create/drop scenarios.
963 --
964 -- list what's installed
965 \dT
966 List of data types
967 Schema | Name | Description
968 --------+-------+---------------------------------------------------------------------------------------------
969 public | cube | multi-dimensional cube '(FLOAT-1, FLOAT-2, ..., FLOAT-N), (FLOAT-1, FLOAT-2, ..., FLOAT-N)'
970 public | earth |
971 (2 rows)
972
973 drop extension cube; -- fail, earthdistance requires it
974 ERROR: cannot drop extension cube because other objects depend on it
975 DETAIL: extension earthdistance depends on extension cube
976 HINT: Use DROP ... CASCADE to drop the dependent objects too.
977 drop extension earthdistance;
978 drop type cube; -- fail, extension cube requires it
979 ERROR: cannot drop type cube because extension cube requires it
980 HINT: You can drop extension cube instead.
981 -- list what's installed
982 \dT
983 List of data types
984 Schema | Name | Description
985 --------+------+---------------------------------------------------------------------------------------------
986 public | cube | multi-dimensional cube '(FLOAT-1, FLOAT-2, ..., FLOAT-N), (FLOAT-1, FLOAT-2, ..., FLOAT-N)'
987 (1 row)
988
989 create table foo (f1 cube, f2 int);
990 drop extension cube; -- fail, foo.f1 requires it
991 ERROR: cannot drop extension cube because other objects depend on it
992 DETAIL: column f1 of table foo depends on type cube
993 HINT: Use DROP ... CASCADE to drop the dependent objects too.
994 drop table foo;
995 drop extension cube;
996 -- list what's installed
997 \dT
998 List of data types
999 Schema | Name | Description
1000 --------+------+-------------
1001 (0 rows)
1002
1003 \df
1004 List of functions
1005 Schema | Name | Result data type | Argument data types | Type
1006 --------+------+------------------+---------------------+------
1007 (0 rows)
1008
1009 \do
1010 List of operators
1011 Schema | Name | Left arg type | Right arg type | Result type | Description
1012 --------+------+---------------+----------------+-------------+-------------
1013 (0 rows)
1014
1015 create schema c;
1016 create extension cube with schema c;
1017 -- list what's installed
1018 \dT public.*
1019 List of data types
1020 Schema | Name | Description
1021 --------+------+-------------
1022 (0 rows)
1023
1024 \df public.*
1025 List of functions
1026 Schema | Name | Result data type | Argument data types | Type
1027 --------+------+------------------+---------------------+------
1028 (0 rows)
1029
1030 \do public.*
1031 List of operators
1032 Schema | Name | Left arg type | Right arg type | Result type | Description
1033 --------+------+---------------+----------------+-------------+-------------
1034 (0 rows)
1035
1036 \dT c.*
1037 List of data types
1038 Schema | Name | Description
1039 --------+--------+---------------------------------------------------------------------------------------------
1040 c | c.cube | multi-dimensional cube '(FLOAT-1, FLOAT-2, ..., FLOAT-N), (FLOAT-1, FLOAT-2, ..., FLOAT-N)'
1041 (1 row)
1042
1043 create table foo (f1 c.cube, f2 int);
1044 drop extension cube; -- fail, foo.f1 requires it
1045 ERROR: cannot drop extension cube because other objects depend on it
1046 DETAIL: column f1 of table foo depends on type c.cube
1047 HINT: Use DROP ... CASCADE to drop the dependent objects too.
1048 drop schema c; -- fail, cube requires it
1049 ERROR: cannot drop schema c because other objects depend on it
1050 DETAIL: extension cube depends on schema c
1051 column f1 of table foo depends on type c.cube
1052 HINT: Use DROP ... CASCADE to drop the dependent objects too.
1053 drop extension cube cascade;
1054 NOTICE: drop cascades to column f1 of table foo
1055 \d foo
1056 Table "public.foo"
1057 Column | Type | Collation | Nullable | Default
1058 --------+---------+-----------+----------+---------
1059 f2 | integer | | |
1060
1061 -- list what's installed
1062 \dT public.*
1063 List of data types
1064 Schema | Name | Description
1065 --------+------+-------------
1066 (0 rows)
1067
1068 \df public.*
1069 List of functions
1070 Schema | Name | Result data type | Argument data types | Type
1071 --------+------+------------------+---------------------+------
1072 (0 rows)
1073
1074 \do public.*
1075 List of operators
1076 Schema | Name | Left arg type | Right arg type | Result type | Description
1077 --------+------+---------------+----------------+-------------+-------------
1078 (0 rows)
1079
1080 \dT c.*
1081 List of data types
1082 Schema | Name | Description
1083 --------+------+-------------
1084 (0 rows)
1085
1086 \df c.*
1087 List of functions
1088 Schema | Name | Result data type | Argument data types | Type
1089 --------+------+------------------+---------------------+------
1090 (0 rows)
1091
1092 \do c.*
1093 List of operators
1094 Schema | Name | Left arg type | Right arg type | Result type | Description
1095 --------+------+---------------+----------------+-------------+-------------
1096 (0 rows)
1097
1098 drop schema c;