File: geo_distance.html

package info (click to toggle)
groonga 11.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 121,576 kB
  • sloc: ansic: 801,209; javascript: 62,121; ruby: 46,206; cpp: 33,790; xml: 24,951; yacc: 13,333; sh: 7,776; python: 3,266; makefile: 2,315; perl: 133
file content (608 lines) | stat: -rw-r--r-- 31,247 bytes parent folder | download
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
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608


<!DOCTYPE html>

<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>7.15.5. geo_distance &#8212; Groonga v10.1.1-31-g1e46ba6 documentation</title>
    <link rel="stylesheet" href="../../_static/groonga.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    
    <script id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
    <script src="../../_static/jquery.js"></script>
    <script src="../../_static/underscore.js"></script>
    <script src="../../_static/doctools.js"></script>
    <script src="../../_static/language_data.js"></script>
    
    <link rel="shortcut icon" href="../../_static/favicon.ico"/>
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" />
    <link rel="next" title="7.15.6. geo_in_circle" href="geo_in_circle.html" />
    <link rel="prev" title="7.15.4. fuzzy_search" href="fuzzy_search.html" /> 
  </head><body>
<div class="header">
  <h1 class="title">
    <a id="top-link" href="../../index.html">
      <span class="project">groonga</span>
      <span class="separator">-</span>
      <span class="description">An open-source fulltext search engine and column store.</span>
    </a>
  </h1>

  <div class="other-language-links">
    <ul>
      <li><a href="../../../../ja/html/reference/functions/geo_distance.html">日本語</a></li>
    </ul>
  </div>
</div>
  

    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="geo_in_circle.html" title="7.15.6. geo_in_circle"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="fuzzy_search.html" title="7.15.4. fuzzy_search"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../index.html">Groonga v10.1.1-31-g1e46ba6 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../reference.html" ><span class="section-number">7. </span>Reference manual</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../function.html" accesskey="U"><span class="section-number">7.15. </span>Function</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href=""><span class="section-number">7.15.5. </span><code class="docutils literal notranslate"><span class="pre">geo_distance</span></code></a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="geo-distance">
<h1><span class="section-number">7.15.5. </span><code class="docutils literal notranslate"><span class="pre">geo_distance</span></code><a class="headerlink" href="#geo-distance" title="Permalink to this headline">¶</a></h1>
<div class="section" id="summary">
<h2><span class="section-number">7.15.5.1. </span>Summary<a class="headerlink" href="#summary" title="Permalink to this headline">¶</a></h2>
<p><code class="docutils literal notranslate"><span class="pre">geo_distance</span></code> calculates the value of distance between specified two points.</p>
</div>
<div class="section" id="syntax">
<h2><span class="section-number">7.15.5.2. </span>Syntax<a class="headerlink" href="#syntax" title="Permalink to this headline">¶</a></h2>
<p><code class="docutils literal notranslate"><span class="pre">geo_distance</span></code> requires two point.
The parameter <code class="docutils literal notranslate"><span class="pre">approximate_type</span></code> is optional:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>geo_distance(point1, point2)
geo_distance(point1, point2, approximate_type)
</pre></div>
</div>
<p>The default value of <code class="docutils literal notranslate"><span class="pre">approximate_type</span></code> is <code class="docutils literal notranslate"><span class="pre">&quot;rectangle&quot;</span></code>.
If you omit <code class="docutils literal notranslate"><span class="pre">approximate_type</span></code>, <code class="docutils literal notranslate"><span class="pre">geo_distance</span></code> calculates the value of
distance as if <code class="docutils literal notranslate"><span class="pre">&quot;rectangle&quot;</span></code> was specified.</p>
</div>
<div class="section" id="usage">
<h2><span class="section-number">7.15.5.3. </span>Usage<a class="headerlink" href="#usage" title="Permalink to this headline">¶</a></h2>
<p><code class="docutils literal notranslate"><span class="pre">geo_distance</span></code> is one of the Groonga builtin functions.</p>
<p>You can call a builtin function in <a class="reference internal" href="../grn_expr.html"><span class="doc">grn_expr</span></a></p>
<p><code class="docutils literal notranslate"><span class="pre">geo_distance</span></code> function calculates the value of distance (approximate value)
between the coordinate of <code class="docutils literal notranslate"><span class="pre">point1</span></code> and the coordinate of <code class="docutils literal notranslate"><span class="pre">point2</span></code>.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Groonga provides three built in functions for calculating the value of distance.
There are <code class="docutils literal notranslate"><span class="pre">geo_distance()</span></code>, <code class="docutils literal notranslate"><span class="pre">geo_distance2()</span></code> and <code class="docutils literal notranslate"><span class="pre">geo_distance3()</span></code>.
The difference of them is the algorithm of calculating distance.
<code class="docutils literal notranslate"><span class="pre">geo_distance2()</span></code> and <code class="docutils literal notranslate"><span class="pre">geo_distance3()</span></code> were deprecated since version 1.2.9.
Use <code class="docutils literal notranslate"><span class="pre">geo_distance(point1,</span> <span class="pre">point2,</span> <span class="pre">&quot;sphere&quot;)</span></code> instead of <code class="docutils literal notranslate"><span class="pre">geo_distance2(point1,</span> <span class="pre">point2)</span></code>.
Use <code class="docutils literal notranslate"><span class="pre">geo_distance(point1,</span> <span class="pre">point2,</span> <span class="pre">&quot;ellipsoid&quot;)</span></code> instead of <code class="docutils literal notranslate"><span class="pre">geo_distance3(point1,</span> <span class="pre">point2)</span></code>.</p>
</div>
<p>Lets’s learn about <code class="docutils literal notranslate"><span class="pre">geo_distance</span></code> usage with examples.
This section shows simple usages.</p>
<p>Here are two schema definition and sample data to show the difference according to the usage.
Those samples show how to calculate the value of distance between New York City and London.</p>
<ol class="arabic simple">
<li><p>Using the column value of location for calculating the distance (<code class="docutils literal notranslate"><span class="pre">Cities</span></code> table)</p></li>
<li><p>Using the explicitly specified coordinates for calculating the distance (<code class="docutils literal notranslate"><span class="pre">Geo</span></code> table)</p></li>
</ol>
<div class="section" id="using-the-column-value-of-location">
<h3><span class="section-number">7.15.5.3.1. </span>Using the column value of location<a class="headerlink" href="#using-the-column-value-of-location" title="Permalink to this headline">¶</a></h3>
<p>Here are a schema definition of <code class="docutils literal notranslate"><span class="pre">Cities</span></code> table and sample data to show usage.</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>table_create Cities TABLE_HASH_KEY ShortText
column_create Cities location COLUMN_SCALAR WGS84GeoPoint
load --table Cities
[
[&quot;_key&quot;, &quot;location&quot;],
[&quot;New York City&quot;, &quot;146566000x-266422000&quot;]
]
</pre></div>
</div>
<p>Execution example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>table_create Cities TABLE_HASH_KEY ShortText
# [[0, 1337566253.89858, 0.000355720520019531], true]
column_create Cities location COLUMN_SCALAR WGS84GeoPoint
# [[0, 1337566253.89858, 0.000355720520019531], true]
load --table Cities
[
[&quot;_key&quot;, &quot;location&quot;],
[&quot;New York City&quot;, &quot;146566000x-266422000&quot;]
]
# [[0, 1337566253.89858, 0.000355720520019531], 1]
</pre></div>
</div>
<p>This execution example creates a table named <code class="docutils literal notranslate"><span class="pre">Cities</span></code> which has one column named <code class="docutils literal notranslate"><span class="pre">location</span></code>.
<code class="docutils literal notranslate"><span class="pre">location</span></code> column stores the value of coordinate.
The coordinate of Tokyo is stored as sample data.</p>
<p>Execution example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>select Cities --output_columns _score --filter 1 --scorer &#39;_score = geo_distance(location, &quot;185428000x-461000&quot;, &quot;rectangle&quot;)&#39;
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         1
#       ],
#       [
#         [
#           &quot;_score&quot;,
#           &quot;Int32&quot;
#         ]
#       ],
#       [
#         5807750
#       ]
#     ]
#   ]
# ]
</pre></div>
</div>
<p>This sample shows that <code class="docutils literal notranslate"><span class="pre">geo_distance</span></code> use the value of <code class="docutils literal notranslate"><span class="pre">location</span></code> column
and the value of coordinate to calculate distance.</p>
<p>The value (“185428000x-461000”) passed to <code class="docutils literal notranslate"><span class="pre">geo_distance</span></code> as the second argument is
the coordinate of London.</p>
</div>
<div class="section" id="using-the-explicitly-specified-value-of-location">
<h3><span class="section-number">7.15.5.3.2. </span>Using the explicitly specified value of location<a class="headerlink" href="#using-the-explicitly-specified-value-of-location" title="Permalink to this headline">¶</a></h3>
<p>Here are a schema definition of <code class="docutils literal notranslate"><span class="pre">Geo</span></code> table and sample data to show usage.</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>table_create Geo TABLE_HASH_KEY ShortText
column_create Geo distance COLUMN_SCALAR Int32
load --table Geo
[
  {
    &quot;_key&quot;: &quot;the record for geo_distance() result&quot;
  }
]
</pre></div>
</div>
<p>Execution example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>table_create Geo TABLE_HASH_KEY ShortText
# [[0, 1337566253.89858, 0.000355720520019531], true]
column_create Geo distance COLUMN_SCALAR Int32
# [[0, 1337566253.89858, 0.000355720520019531], true]
load --table Geo
[
  {
    &quot;_key&quot;: &quot;the record for geo_distance() result&quot;
  }
]
# [[0, 1337566253.89858, 0.000355720520019531], 1]
</pre></div>
</div>
<p>This execution example creates a table named <code class="docutils literal notranslate"><span class="pre">Geo</span></code> which has one column named <code class="docutils literal notranslate"><span class="pre">distance</span></code>.
<code class="docutils literal notranslate"><span class="pre">distance</span></code> column stores the value of distance.</p>
<p>Execution example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>select Geo --output_columns distance --scorer &#39;distance = geo_distance(&quot;146566000x-266422000&quot;, &quot;185428000x-461000&quot;, &quot;rectangle&quot;)&#39;
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         1
#       ],
#       [
#         [
#           &quot;distance&quot;,
#           &quot;Int32&quot;
#         ]
#       ],
#       [
#         5807750
#       ]
#     ]
#   ]
# ]
</pre></div>
</div>
<p>This sample shows that <code class="docutils literal notranslate"><span class="pre">geo_distance</span></code> use the coordinate of London
and the coordinate of New York to calculate distance.</p>
</div>
</div>
<div class="section" id="parameters">
<h2><span class="section-number">7.15.5.4. </span>Parameters<a class="headerlink" href="#parameters" title="Permalink to this headline">¶</a></h2>
<div class="section" id="required-parameters">
<h3><span class="section-number">7.15.5.4.1. </span>Required parameters<a class="headerlink" href="#required-parameters" title="Permalink to this headline">¶</a></h3>
<p>There are two required parameter, <code class="docutils literal notranslate"><span class="pre">point1</span></code> and <code class="docutils literal notranslate"><span class="pre">point2</span></code>.</p>
<div class="section" id="point1">
<h4><span class="section-number">7.15.5.4.1.1. </span><code class="docutils literal notranslate"><span class="pre">point1</span></code><a class="headerlink" href="#point1" title="Permalink to this headline">¶</a></h4>
<p>Specifies the start point that
you want to calculate the value of distance between two points.</p>
<p>You can specify the value of GeoPoint type. <a class="footnote-reference brackets" href="#id2" id="id1">1</a></p>
<p>See <a class="reference internal" href="../types.html"><span class="doc">Data types</span></a> about GeoPoint.</p>
</div>
<div class="section" id="point2">
<h4><span class="section-number">7.15.5.4.1.2. </span><code class="docutils literal notranslate"><span class="pre">point2</span></code><a class="headerlink" href="#point2" title="Permalink to this headline">¶</a></h4>
<p>Specifies the end point that
you want to calculate the value of distance between two points.</p>
<p>You can specify the value of GeoPoint type or
the string indicating the coordinate.</p>
<p>See <a class="reference internal" href="../types.html"><span class="doc">Data types</span></a> about GeoPoint and the coordinate.</p>
</div>
</div>
<div class="section" id="optional-parameter">
<h3><span class="section-number">7.15.5.4.2. </span>Optional parameter<a class="headerlink" href="#optional-parameter" title="Permalink to this headline">¶</a></h3>
<p>There is a optional parameter, <code class="docutils literal notranslate"><span class="pre">approximate_type</span></code>.</p>
<div class="section" id="approximate-type">
<h4><span class="section-number">7.15.5.4.2.1. </span><code class="docutils literal notranslate"><span class="pre">approximate_type</span></code><a class="headerlink" href="#approximate-type" title="Permalink to this headline">¶</a></h4>
<p>Specifies how to approximate the geographical features for calculating
the value of distance.</p>
<p>You can specify the value of <code class="docutils literal notranslate"><span class="pre">approximate_type</span></code> by one of the followings.</p>
<blockquote>
<div><ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">rectangle</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">sphere</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">ellipsoid</span></code></p></li>
</ul>
</div></blockquote>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>There is a limitation about <code class="docutils literal notranslate"><span class="pre">geo_distance</span></code>. <code class="docutils literal notranslate"><span class="pre">geo_distance</span></code> can not
calculate the value of distance between two points across meridian,
equator or the date line if you use <code class="docutils literal notranslate"><span class="pre">sphere</span></code> or <code class="docutils literal notranslate"><span class="pre">ellipsoid</span></code> as
approximate type. There is not such a limitation for <code class="docutils literal notranslate"><span class="pre">rectangle</span></code>.
This is temporary limitation according to the implementation of Groonga,
but it will be fixed in the future release.</p>
</div>
<div class="section" id="rectangle">
<h5><span class="section-number">7.15.5.4.2.1.1. </span><code class="docutils literal notranslate"><span class="pre">rectangle</span></code><a class="headerlink" href="#rectangle" title="Permalink to this headline">¶</a></h5>
<p>This parameter require to approximate the geographical features
by square approximation for calculating the distance.</p>
<p>Since the value of distance is calculated by simple formula,
you can calculate the value of distance fast.
But, the error of distance increases as it approaches the pole.</p>
<p>You can also specify <code class="docutils literal notranslate"><span class="pre">rect</span></code> as abbrev expression.</p>
<p>Here is a sample about calculating the value of distance with column value.</p>
<p>Execution example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>select Cities --output_columns _score --filter 1 --scorer &#39;_score = geo_distance(location, &quot;185428000x-461000&quot;, &quot;rectangle&quot;)&#39;
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         1
#       ],
#       [
#         [
#           &quot;_score&quot;,
#           &quot;Int32&quot;
#         ]
#       ],
#       [
#         5807750
#       ]
#     ]
#   ]
# ]
</pre></div>
</div>
<p>Here is a sample about calculating the value of distance with explicitly specified point.</p>
<p>Execution example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>select Geo --output_columns distance --scorer &#39;distance = geo_distance(&quot;146566000x-266422000&quot;, &quot;185428000x-461000&quot;, &quot;rectangle&quot;)&#39;
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         1
#       ],
#       [
#         [
#           &quot;distance&quot;,
#           &quot;Int32&quot;
#         ]
#       ],
#       [
#         5807750
#       ]
#     ]
#   ]
# ]
</pre></div>
</div>
<p>Here are samples about calculating the value of distance with explicitly specified point across meridian, equator, the date line.</p>
<p>Execution example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>select Geo --output_columns distance --scorer &#39;distance = geo_distance(&quot;175904000x8464000&quot;, &quot;145508000x-13291000&quot;, &quot;rectangle&quot;)&#39;
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         1
#       ],
#       [
#         [
#           &quot;distance&quot;,
#           &quot;Int32&quot;
#         ]
#       ],
#       [
#         1051322
#       ]
#     ]
#   ]
# ]
</pre></div>
</div>
<p>This sample shows the value of distance across meridian.
The return value of <code class="docutils literal notranslate"><span class="pre">geo_distance(&quot;175904000x8464000&quot;,</span> <span class="pre">&quot;145508000x-13291000&quot;,</span> <span class="pre">&quot;rectangle&quot;)</span></code> is the value of distance from Paris, Flance to Madrid, Spain.</p>
<p>Execution example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>select Geo --output_columns distance --scorer &#39;distance = geo_distance(&quot;146566000x-266422000&quot;, &quot;-56880000x-172310000&quot;, &quot;rectangle&quot;)&#39;
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         1
#       ],
#       [
#         [
#           &quot;distance&quot;,
#           &quot;Int32&quot;
#         ]
#       ],
#       [
#         6880439
#       ]
#     ]
#   ]
# ]
</pre></div>
</div>
<p>This sample shows the value of distance across equator.
The return value of <code class="docutils literal notranslate"><span class="pre">geo_distance(&quot;146566000x-266422000&quot;,</span> <span class="pre">&quot;-56880000x-172310000&quot;,</span> <span class="pre">&quot;rectangle&quot;)</span></code> is the value of distance from New York, The United Status to Brasillia, Brasil.</p>
<p>Execution example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>select Geo --output_columns distance --scorer &#39;distance = geo_distance(&quot;143660000x419009000&quot;, &quot;135960000x-440760000&quot;, &quot;rectangle&quot;)&#39;
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         1
#       ],
#       [
#         [
#           &quot;distance&quot;,
#           &quot;Int32&quot;
#         ]
#       ],
#       [
#         10475660
#       ]
#     ]
#   ]
# ]
</pre></div>
</div>
<p>This sample shows the value of distance across the date line.
The return value of <code class="docutils literal notranslate"><span class="pre">geo_distance(&quot;143660000x419009000&quot;,</span> <span class="pre">&quot;135960000x-440760000&quot;,</span> <span class="pre">&quot;rectangle&quot;)</span></code> is the value of distance from Beijin, China to San Francisco, The United States.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p><code class="docutils literal notranslate"><span class="pre">geo_distance</span></code> uses square approximation as default. If you omit <code class="docutils literal notranslate"><span class="pre">approximate_type</span></code>, <code class="docutils literal notranslate"><span class="pre">geo_distance</span></code> behaves like <code class="docutils literal notranslate"><span class="pre">rectangle</span></code> was specified.</p>
</div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p><code class="docutils literal notranslate"><span class="pre">geo_distance</span></code> accepts the string indicating the coordinate as
the value of <code class="docutils literal notranslate"><span class="pre">point1</span></code> when the value of <code class="docutils literal notranslate"><span class="pre">approximate_type</span></code> is
<code class="docutils literal notranslate"><span class="pre">&quot;rectangle&quot;</span></code>.
If you specified the string indicating the coordinate as the value
of <code class="docutils literal notranslate"><span class="pre">point1</span></code> with <code class="docutils literal notranslate"><span class="pre">sphere</span></code> or <code class="docutils literal notranslate"><span class="pre">ellipsoid</span></code>, <code class="docutils literal notranslate"><span class="pre">geo_distance</span></code>
returns 0 as the value of distance.</p>
</div>
</div>
<div class="section" id="sphere">
<h5><span class="section-number">7.15.5.4.2.1.2. </span><code class="docutils literal notranslate"><span class="pre">sphere</span></code><a class="headerlink" href="#sphere" title="Permalink to this headline">¶</a></h5>
<p>This parameter require to approximate the geographical features
by spherical approximation for calculating the distance.</p>
<p>It is slower than <code class="docutils literal notranslate"><span class="pre">rectangle</span></code>, but the error of distance becomes
smaller than <code class="docutils literal notranslate"><span class="pre">rectangle</span></code>.</p>
<p>You can also specify <code class="docutils literal notranslate"><span class="pre">sphr</span></code> as abbrev expression.</p>
<p>Here is a sample about calculating the value of distance with column value.</p>
<p>Execution example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>select Cities --output_columns _score --filter 1 --scorer &#39;_score = geo_distance(location, &quot;185428000x-461000&quot;, &quot;sphere&quot;)&#39;
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         1
#       ],
#       [
#         [
#           &quot;_score&quot;,
#           &quot;Int32&quot;
#         ]
#       ],
#       [
#         5558225
#       ]
#     ]
#   ]
# ]
</pre></div>
</div>
</div>
<div class="section" id="ellipsoid">
<h5><span class="section-number">7.15.5.4.2.1.3. </span><code class="docutils literal notranslate"><span class="pre">ellipsoid</span></code><a class="headerlink" href="#ellipsoid" title="Permalink to this headline">¶</a></h5>
<p>This parameter require to approximate the geographical features
by ellipsoid approximation for calculating the distance.</p>
<p>It uses the calculation of distance by the formula of Hubeny.
It is slower than <code class="docutils literal notranslate"><span class="pre">sphere</span></code>, but the error of distance becomes
smaller than <code class="docutils literal notranslate"><span class="pre">sphere</span></code>.</p>
<p>You can also specify <code class="docutils literal notranslate"><span class="pre">ellip</span></code> as abbrev expression.</p>
<p>Here is a sample about calculating the value of distance with column value.</p>
<p>Execution example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>select Cities --output_columns _score --filter 1 --scorer &#39;_score = geo_distance(location, &quot;185428000x-461000&quot;, &quot;ellipsoid&quot;)&#39;
# [
#   [
#     0,
#     1337566253.89858,
#     0.000355720520019531
#   ],
#   [
#     [
#       [
#         1
#       ],
#       [
#         [
#           &quot;_score&quot;,
#           &quot;Int32&quot;
#         ]
#       ],
#       [
#         5836138
#       ]
#     ]
#   ]
# ]
</pre></div>
</div>
</div>
</div>
</div>
</div>
<div class="section" id="return-value">
<h2><span class="section-number">7.15.5.5. </span>Return value<a class="headerlink" href="#return-value" title="Permalink to this headline">¶</a></h2>
<p><code class="docutils literal notranslate"><span class="pre">geo_distance</span></code> returns the value of distance in float type.
The unit of return value is meter.</p>
<p class="rubric">Footnote</p>
<dl class="footnote brackets">
<dt class="label" id="id2"><span class="brackets"><a class="fn-backref" href="#id1">1</a></span></dt>
<dd><p>You can specify whether TokyoGeoPoint or WGS84GeoPoint.</p>
</dd>
</dl>
</div>
</div>


            <div class="clearer"></div>
          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../../index.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">7.15.5. <code class="docutils literal notranslate"><span class="pre">geo_distance</span></code></a><ul>
<li><a class="reference internal" href="#summary">7.15.5.1. Summary</a></li>
<li><a class="reference internal" href="#syntax">7.15.5.2. Syntax</a></li>
<li><a class="reference internal" href="#usage">7.15.5.3. Usage</a><ul>
<li><a class="reference internal" href="#using-the-column-value-of-location">7.15.5.3.1. Using the column value of location</a></li>
<li><a class="reference internal" href="#using-the-explicitly-specified-value-of-location">7.15.5.3.2. Using the explicitly specified value of location</a></li>
</ul>
</li>
<li><a class="reference internal" href="#parameters">7.15.5.4. Parameters</a><ul>
<li><a class="reference internal" href="#required-parameters">7.15.5.4.1. Required parameters</a><ul>
<li><a class="reference internal" href="#point1">7.15.5.4.1.1. <code class="docutils literal notranslate"><span class="pre">point1</span></code></a></li>
<li><a class="reference internal" href="#point2">7.15.5.4.1.2. <code class="docutils literal notranslate"><span class="pre">point2</span></code></a></li>
</ul>
</li>
<li><a class="reference internal" href="#optional-parameter">7.15.5.4.2. Optional parameter</a><ul>
<li><a class="reference internal" href="#approximate-type">7.15.5.4.2.1. <code class="docutils literal notranslate"><span class="pre">approximate_type</span></code></a><ul>
<li><a class="reference internal" href="#rectangle">7.15.5.4.2.1.1. <code class="docutils literal notranslate"><span class="pre">rectangle</span></code></a></li>
<li><a class="reference internal" href="#sphere">7.15.5.4.2.1.2. <code class="docutils literal notranslate"><span class="pre">sphere</span></code></a></li>
<li><a class="reference internal" href="#ellipsoid">7.15.5.4.2.1.3. <code class="docutils literal notranslate"><span class="pre">ellipsoid</span></code></a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><a class="reference internal" href="#return-value">7.15.5.5. Return value</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="fuzzy_search.html"
                        title="previous chapter"><span class="section-number">7.15.4. </span><code class="docutils literal notranslate"><span class="pre">fuzzy_search</span></code></a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="geo_in_circle.html"
                        title="next chapter"><span class="section-number">7.15.6. </span>geo_in_circle</a></p>
<div id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="../../search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" />
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script>$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="geo_in_circle.html" title="7.15.6. geo_in_circle"
             >next</a> |</li>
        <li class="right" >
          <a href="fuzzy_search.html" title="7.15.4. fuzzy_search"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../index.html">Groonga v10.1.1-31-g1e46ba6 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../reference.html" ><span class="section-number">7. </span>Reference manual</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../function.html" ><span class="section-number">7.15. </span>Function</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href=""><span class="section-number">7.15.5. </span><code class="docutils literal notranslate"><span class="pre">geo_distance</span></code></a></li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2009-2021, Brazil, Inc.
    </div>
  </body>
</html>