~ubuntu-branches/ubuntu/lucid/postgresql-8.4/lucid-security

« back to all changes in this revision

Viewing changes to contrib/earthdistance/expected/earthdistance.out

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-03-20 12:00:13 UTC
  • Revision ID: james.westby@ubuntu.com-20090320120013-hogj7egc5mjncc5g
Tags: upstream-8.4~0cvs20090328
ImportĀ upstreamĀ versionĀ 8.4~0cvs20090328

Show diffs side-by-side

added added

removed removed

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