~vcs-imports/mammoth-replicator/trunk

« back to all changes in this revision

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

  • Committer: alvherre
  • Date: 2005-12-16 21:24:52 UTC
  • Revision ID: svn-v4:db760fc0-0f08-0410-9d63-cc6633f64896:trunk:1
Initial import of the REL8_0_3 sources from the Pgsql CVS repository.

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