Hex Artifact Content
Not logged in

Artifact bce1f7e1d78f60c7dbbd90bf12162af7009d3ab6:

Wiki page [KNN] by sandro 2015-12-10 16:39:08.
0000: 44 20 32 30 31 35 2d 31 32 2d 31 30 54 31 36 3a  D 2015-12-10T16:
0010: 33 39 3a 30 38 2e 39 38 30 0a 4c 20 4b 4e 4e 0a  39:08.980.L KNN.
0020: 50 20 33 38 39 32 63 37 64 32 34 32 38 65 62 63  P 3892c7d2428ebc
0030: 63 35 37 62 35 65 33 31 35 64 37 33 34 33 30 36  c57b5e315d734306
0040: 35 33 38 39 62 38 32 65 35 35 0a 55 20 73 61 6e  5389b82e55.U san
0050: 64 72 6f 0a 57 20 31 39 35 37 30 0a 3c 74 61 62  dro.W 19570.<tab
0060: 6c 65 20 63 65 6c 6c 73 70 61 63 69 6e 67 3d 22  le cellspacing="
0070: 31 32 22 20 77 69 64 74 68 3d 22 31 30 30 25 22  12" width="100%"
0080: 3e 0d 0a 3c 74 72 3e 3c 74 64 20 63 6f 6c 73 70  >..<tr><td colsp
0090: 61 6e 3d 22 32 22 3e 0d 0a 3c 74 61 62 6c 65 20  an="2">..<table 
00a0: 77 69 64 74 68 3d 22 31 30 30 25 22 20 62 67 63  width="100%" bgc
00b0: 6f 6c 6f 72 3d 22 23 66 30 66 30 66 38 22 3e 0d  olor="#f0f0f8">.
00c0: 0a 3c 74 72 3e 3c 74 64 20 61 6c 69 67 6e 3d 22  .<tr><td align="
00d0: 63 65 6e 74 65 72 22 3e 0d 0a 3c 68 31 3e 56 69  center">..<h1>Vi
00e0: 72 74 75 61 6c 4b 4e 4e 3a 20 61 20 71 75 69 63  rtualKNN: a quic
00f0: 6b 20 69 6e 74 72 6f 3c 2f 68 31 3e 0d 0a 3c 2f  k intro</h1>..</
0100: 74 64 3e 3c 2f 74 72 3e 3c 2f 74 61 62 6c 65 3e  td></tr></table>
0110: 0d 0a 3c 74 61 62 6c 65 20 77 69 64 74 68 3d 22  ..<table width="
0120: 31 30 30 25 22 3e 3c 74 72 3e 0d 0a 3c 74 64 20  100%"><tr>..<td 
0130: 77 69 64 74 68 3d 22 33 33 25 22 20 61 6c 69 67  width="33%" alig
0140: 6e 3d 22 6c 65 66 74 22 3e 3c 2f 74 64 3e 0d 0a  n="left"></td>..
0150: 3c 74 64 20 61 6c 69 67 6e 3d 22 63 65 6e 74 65  <td align="cente
0160: 72 22 3e 3c 61 20 68 72 65 66 3d 22 68 74 74 70  r"><a href="http
0170: 73 3a 2f 2f 77 77 77 2e 67 61 69 61 2d 67 69 73  s://www.gaia-gis
0180: 2e 69 74 2f 66 6f 73 73 69 6c 2f 6c 69 62 73 70  .it/fossil/libsp
0190: 61 74 69 61 6c 69 74 65 2f 77 69 6b 69 3f 6e 61  atialite/wiki?na
01a0: 6d 65 3d 6d 69 73 63 2d 64 6f 63 73 22 3e 62 61  me=misc-docs">ba
01b0: 63 6b 20 74 6f 20 69 6e 64 65 78 3c 2f 61 3e 3c  ck to index</a><
01c0: 2f 74 64 3e 0d 0a 3c 74 64 20 77 69 64 74 68 3d  /td>..<td width=
01d0: 22 33 33 25 22 20 61 6c 69 67 6e 3d 22 72 69 67  "33%" align="rig
01e0: 68 74 22 3e 3c 2f 74 64 3e 0d 0a 3c 2f 74 72 3e  ht"></td>..</tr>
01f0: 3c 2f 74 61 62 6c 65 3e 3c 62 72 3e 0d 0a 3c 74  </table><br>..<t
0200: 61 62 6c 65 20 62 67 63 6f 6c 6f 72 3d 22 23 64  able bgcolor="#d
0210: 30 65 30 66 66 22 20 77 69 64 74 68 3d 22 31 30  0e0ff" width="10
0220: 30 25 22 3e 0d 0a 3c 74 72 3e 3c 74 64 20 61 6c  0%">..<tr><td al
0230: 69 67 6e 3d 22 63 65 6e 74 65 72 22 3e 0d 0a 3c  ign="center">..<
0240: 62 3e 43 72 65 64 69 74 73 3c 2f 62 3e 3c 62 72  b>Credits</b><br
0250: 3e 0d 0a 44 65 76 65 6c 6f 70 6d 65 6e 74 20 6f  >..Development o
0260: 66 20 3c 62 3e 3c 69 3e 56 69 72 74 75 61 6c 4b  f <b><i>VirtualK
0270: 4e 4e 3c 2f 69 3e 3c 2f 62 3e 20 68 61 73 20 62  NN</i></b> has b
0280: 65 65 6e 20 65 6e 74 69 72 65 6c 79 20 66 75 6e  een entirely fun
0290: 64 65 64 20 62 79 0d 0a 3c 61 20 68 72 65 66 3d  ded by..<a href=
02a0: 22 68 74 74 70 3a 2f 2f 65 6e 2e 77 69 6b 69 70  "http://en.wikip
02b0: 65 64 69 61 2e 6f 72 67 2f 77 69 6b 69 2f 54 75  edia.org/wiki/Tu
02c0: 73 63 61 6e 79 22 3e 54 75 73 63 61 6e 79 20 52  scany">Tuscany R
02d0: 65 67 69 6f 6e 3c 2f 61 3e 20 2d 20 54 65 72 72  egion</a> - Terr
02e0: 69 74 6f 72 69 61 6c 20 61 6e 64 20 45 6e 76 69  itorial and Envi
02f0: 72 6f 6e 6d 65 6e 74 61 6c 20 49 6e 66 6f 72 6d  ronmental Inform
0300: 61 74 69 6f 6e 20 53 79 73 74 65 6d 3c 62 72 3e  ation System<br>
0310: 0d 0a 3c 61 20 68 72 65 66 3d 22 68 74 74 70 3a  ..<a href="http:
0320: 2f 2f 77 77 77 2e 72 65 67 69 6f 6e 65 2e 74 6f  //www.regione.to
0330: 73 63 61 6e 61 2e 69 74 2f 61 6d 62 69 65 6e 74  scana.it/ambient
0340: 65 65 74 65 72 72 69 74 6f 72 69 6f 2f 67 65 6f  eeterritorio/geo
0350: 67 72 61 66 69 61 67 65 6f 6c 6f 67 69 61 2f 69  grafiageologia/i
0360: 6e 64 65 78 2e 68 74 6d 6c 22 3e 52 65 67 69 6f  ndex.html">Regio
0370: 6e 65 20 54 6f 73 63 61 6e 61 3c 2f 61 3e 20 2d  ne Toscana</a> -
0380: 20 53 65 74 74 6f 72 65 20 53 69 73 74 65 6d 61   Settore Sistema
0390: 20 49 6e 66 6f 72 6d 61 74 69 76 6f 20 54 65 72   Informativo Ter
03a0: 72 69 74 6f 72 69 61 6c 65 20 65 64 20 41 6d 62  ritoriale ed Amb
03b0: 69 65 6e 74 61 6c 65 2e 0d 0a 3c 2f 74 64 3e 3c  ientale...</td><
03c0: 2f 74 72 3e 3c 2f 74 61 62 6c 65 3e 3c 62 72 3e  /tr></table><br>
03d0: 0d 0a 3c 68 72 3e 3c 62 72 3e 0d 0a 3c 74 61 62  ..<hr><br>..<tab
03e0: 6c 65 20 77 69 64 74 68 3d 22 31 30 30 25 22 20  le width="100%" 
03f0: 62 67 63 6f 6c 6f 72 3d 22 23 66 66 66 66 64 66  bgcolor="#ffffdf
0400: 22 20 63 65 6c 6c 73 70 61 63 69 6e 67 3d 22 34  " cellspacing="4
0410: 22 20 63 65 6c 6c 70 61 64 64 69 6e 67 3d 22 38  " cellpadding="8
0420: 22 3e 0d 0a 3c 74 72 3e 3c 74 64 3e 3c 62 3e 57  ">..<tr><td><b>W
0430: 68 61 74 20 69 73 20 74 68 65 20 4b 4e 4e 20 28  hat is the KNN (
0440: 3c 69 3e 4b 2d 4e 65 61 72 65 73 74 20 4e 65 69  <i>K-Nearest Nei
0450: 67 68 62 6f 72 73 3c 2f 69 3e 29 20 70 72 6f 62  ghbors</i>) prob
0460: 6c 65 6d 20 3f 3c 2f 62 3e 3c 2f 74 64 3e 3c 2f  lem ?</b></td></
0470: 74 72 3e 0d 0a 3c 74 72 3e 3c 74 64 3e 49 6d 61  tr>..<tr><td>Ima
0480: 67 69 6e 65 20 61 20 73 65 74 20 6f 66 20 61 72  gine a set of ar
0490: 62 69 74 72 61 72 79 20 67 65 6f 6d 65 74 72 69  bitrary geometri
04a0: 65 73 3b 20 6d 61 79 20 77 65 6c 6c 20 62 65 2c  es; may well be,
04b0: 20 77 68 69 63 68 20 6d 61 79 20 77 65 6c 6c 20   which may well 
04c0: 62 65 2c 20 61 20 76 65 72 79 20 68 75 67 65 20  be, a very huge 
04d0: 64 61 74 61 73 65 74 20 63 6f 6e 74 61 69 6e 69  dataset containi
04e0: 6e 67 20 73 6f 6d 65 20 6d 69 6c 6c 69 6f 6e 73  ng some millions
04f0: 20 6f 66 20 66 65 61 74 75 72 65 73 2e 3c 62 72   of features.<br
0500: 3e 0d 0a 4e 6f 77 20 69 6d 61 67 69 6e 65 20 74  >..Now imagine t
0510: 68 61 74 20 66 6f 72 20 66 6f 72 20 77 68 61 74  hat for for what
0520: 65 76 65 72 20 72 65 61 73 6f 6e 20 79 6f 75 20  ever reason you 
0530: 61 72 65 20 69 6e 74 65 72 65 73 74 65 64 20 69  are interested i
0540: 6e 20 71 75 69 63 6b 6c 79 20 69 64 65 6e 74 69  n quickly identi
0550: 66 79 69 6e 67 20 61 6c 6c 20 66 65 61 74 75 72  fying all featur
0560: 65 73 20 77 69 74 68 69 6e 20 61 20 20 63 6c 6f  es within a  clo
0570: 73 65 20 73 70 61 74 69 61 6c 20 70 72 6f 78 69  se spatial proxi
0580: 6d 69 74 79 20 74 6f 20 61 6e 20 61 72 62 69 74  mity to an arbit
0590: 72 61 72 79 20 6c 6f 63 61 74 69 6f 6e 2e 3c 62  rary location.<b
05a0: 72 3e 0d 0a 54 68 69 73 20 69 73 20 74 68 65 20  r>..This is the 
05b0: 74 79 70 69 63 61 6c 20 3c 62 3e 4b 4e 4e 3c 2f  typical <b>KNN</
05c0: 62 3e 20 70 72 6f 62 6c 65 6d 2e 3c 2f 74 64 3e  b> problem.</td>
05d0: 3c 2f 74 72 3e 0d 0a 3c 74 72 3e 3c 74 64 3e 4a  </tr>..<tr><td>J
05e0: 75 73 74 20 66 65 77 20 70 72 61 63 74 69 63 61  ust few practica
05f0: 6c 20 72 65 61 6c 20 77 6f 72 6c 64 20 65 78 61  l real world exa
0600: 6d 70 6c 65 73 3a 0d 0a 3c 75 6c 3e 0d 0a 3c 6c  mples:..<ul>..<l
0610: 69 3e 53 75 70 70 6f 73 65 20 77 68 69 6c 65 20  i>Suppose while 
0620: 75 73 69 6e 67 20 61 20 73 6d 61 72 74 70 68 6f  using a smartpho
0630: 6e 65 20 61 70 70 3a 20 79 6f 75 72 20 63 75 72  ne app: your cur
0640: 72 65 6e 74 20 67 65 6f 67 72 61 70 68 69 63 20  rent geographic 
0650: 6c 6f 63 61 74 69 6f 6e 20 69 73 20 77 65 6c 6c  location is well
0660: 20 6b 6e 6f 77 6e 20 62 79 20 74 68 65 20 69 6e   known by the in
0670: 74 65 67 72 61 74 65 64 20 47 50 53 20 73 65 6e  tegrated GPS sen
0680: 73 6f 72 2c 20 73 6f 20 79 6f 75 20 61 72 65 20  sor, so you are 
0690: 73 69 6d 70 6c 79 20 65 78 70 65 63 74 69 6e 67  simply expecting
06a0: 20 74 68 61 74 20 74 68 65 20 61 70 70 20 77 69   that the app wi
06b0: 6c 6c 20 69 6d 6d 65 64 69 61 74 65 6c 79 20 74  ll immediately t
06c0: 65 6c 6c 20 77 68 65 72 65 20 79 6f 75 20 61 72  ell where you ar
06d0: 65 20 28 61 6e 64 20 74 68 65 20 65 78 61 63 74  e (and the exact
06e0: 20 6c 6f 63 61 74 69 6f 6e 20 6f 66 29 20 74 68   location of) th
06f0: 65 20 6e 65 61 72 65 73 74 20 66 75 65 6c 20 73  e nearest fuel s
0700: 74 61 74 69 6f 6e 73 20 28 68 6f 74 65 6c 73 2c  tations (hotels,
0710: 20 72 65 73 74 61 75 72 61 6e 74 73 20 65 74 63   restaurants etc
0720: 29 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 53 75 70  ).</li>..<li>Sup
0730: 70 6f 73 65 20 61 20 7a 6f 6f 6c 6f 67 69 63 61  pose a zoologica
0740: 6c 2f 65 63 6f 6c 6f 67 69 63 61 6c 20 73 74 75  l/ecological stu
0750: 64 79 3a 20 79 6f 75 20 6b 6e 6f 77 20 77 68 65  dy: you know whe
0760: 72 65 20 61 72 65 20 6c 6f 63 61 74 65 64 20 74  re are located t
0770: 68 65 20 6e 65 73 74 69 6e 67 20 61 72 65 61 73  he nesting areas
0780: 20 6f 66 20 73 6f 6d 65 20 72 61 72 65 20 77 61   of some rare wa
0790: 74 65 72 20 62 69 72 64 20 73 70 65 63 69 65 73  ter bird species
07a0: 2c 20 61 6c 73 6f 20 74 68 65 20 6c 6f 63 61 74  , also the locat
07b0: 69 6f 6e 20 6f 66 20 61 6c 6c 20 72 69 76 65 72  ion of all river
07c0: 73 2c 20 6c 61 6b 65 73 2c 20 70 6f 6e 64 73 20  s, lakes, ponds 
07d0: 61 6e 64 20 6d 61 72 73 68 6c 61 6e 64 73 20 69  and marshlands i
07e0: 6e 20 74 68 65 20 61 72 65 61 20 79 6f 75 20 61  n the area you a
07f0: 72 65 20 69 6e 74 65 72 65 73 74 65 64 20 69 6e  re interested in
0800: 2e 3c 62 72 3e 0d 0a 4e 6f 77 20 79 6f 75 20 61  .<br>..Now you a
0810: 72 65 20 61 74 74 65 6d 70 74 69 6e 67 20 74 6f  re attempting to
0820: 20 67 65 74 20 61 20 72 65 61 73 6f 6e 61 62 6c   get a reasonabl
0830: 65 20 61 73 73 6f 63 69 61 74 69 6f 6e 20 62 65  e association be
0840: 74 77 65 65 6e 20 6e 65 73 74 69 6e 67 20 61 72  tween nesting ar
0850: 65 61 73 20 61 6e 64 20 66 65 65 64 69 6e 67 20  eas and feeding 
0860: 7a 6f 6e 65 73 20 62 61 73 65 64 20 6f 6e 20 6d  zones based on m
0870: 69 6e 69 6d 61 6c 20 64 69 73 74 61 6e 63 65 20  inimal distance 
0880: 63 72 69 74 65 72 69 61 2e 3c 2f 6c 69 3e 0d 0a  criteria.</li>..
0890: 3c 2f 75 6c 3e 0d 0a 3c 2f 74 64 3e 3c 2f 74 72  </ul>..</td></tr
08a0: 3e 0d 0a 3c 74 72 3e 3c 74 64 3e 57 68 65 72 65  >..<tr><td>Where
08b0: 62 79 2c 20 69 6e 20 62 6f 74 68 20 63 61 73 65  by, in both case
08c0: 73 20 79 6f 75 20 63 61 6e 27 74 20 73 61 66 65  s you can't safe
08d0: 6c 79 20 69 64 65 6e 74 69 66 79 20 61 20 72 65  ly identify a re
08e0: 61 73 6f 6e 61 62 6c 65 20 3c 69 3e 3c 75 3e 6d  asonable <i><u>m
08f0: 69 6e 69 6d 61 6c 20 72 61 64 69 75 73 3c 2f 75  inimal radius</u
0900: 3e 3c 2f 69 3e 20 73 6f 20 74 6f 20 75 73 65 66  ></i> so to usef
0910: 75 6c 6c 79 20 72 65 73 74 72 69 63 74 20 79 6f  ully restrict yo
0920: 75 72 20 73 65 61 72 63 68 20 62 79 2c 20 73 69  ur search by, si
0930: 6e 63 65 20 79 6f 75 20 63 61 6e 27 74 20 6d 61  nce you can't ma
0940: 6b 65 20 61 6e 79 20 76 61 6c 69 64 20 61 73 73  ke any valid ass
0950: 75 6d 70 74 69 6f 6e 20 61 62 6f 75 74 20 74 68  umption about th
0960: 65 20 67 65 6f 67 72 61 70 68 69 63 20 64 69 73  e geographic dis
0970: 70 65 72 73 69 6f 6e 20 6f 66 20 79 6f 75 72 20  persion of your 
0980: 74 61 72 67 65 74 73 2e 3c 62 72 3e 0d 0a 54 68  targets.<br>..Th
0990: 65 20 64 69 73 74 61 6e 63 65 73 20 6d 61 79 20  e distances may 
09a0: 6e 6f 74 69 63 65 61 62 6c 79 20 76 61 72 79 20  noticeably vary 
09b0: 66 72 6f 6d 20 63 61 73 65 20 74 6f 20 63 61 73  from case to cas
09c0: 65 2c 20 61 6e 64 20 79 6f 75 20 68 61 76 65 6e  e, and you haven
09d0: 27 74 20 61 6e 79 20 69 64 65 61 20 61 62 6f 75  't any idea abou
09e0: 74 20 74 68 69 73 2c 20 73 69 6e 63 65 20 69 74  t this, since it
09f0: 20 73 74 72 69 63 74 6c 79 20 64 65 70 65 6e 64   strictly depend
0a00: 73 20 6f 6e 20 74 68 65 20 61 63 74 75 61 6c 20  s on the actual 
0a10: 6c 6f 63 61 74 69 6f 6e 20 6f 66 20 74 68 65 20  location of the 
0a20: 73 65 61 72 63 68 20 6f 72 69 67 69 6e 20 61 6e  search origin an
0a30: 64 20 6f 6e 20 74 68 65 20 73 74 61 74 69 73 74  d on the statist
0a40: 69 63 61 6c 20 64 69 73 70 65 72 73 69 6f 6e 20  ical dispersion 
0a50: 6f 66 20 74 68 65 20 74 61 72 67 65 74 73 20 74  of the targets t
0a60: 6f 20 62 65 20 73 65 61 72 63 68 65 64 2e 3c 2f  o be searched.</
0a70: 74 64 3e 3c 2f 74 72 3e 0d 0a 3c 2f 74 61 62 6c  td></tr>..</tabl
0a80: 65 3e 3c 62 72 3e 0d 0a 3c 68 72 3e 3c 62 72 3e  e><br>..<hr><br>
0a90: 0d 0a 3c 74 61 62 6c 65 20 77 69 64 74 68 3d 22  ..<table width="
0aa0: 31 30 30 25 22 3e 0d 0a 3c 74 72 3e 3c 74 64 20  100%">..<tr><td 
0ab0: 76 61 6c 69 67 6e 3d 22 6d 69 64 64 6c 65 22 3e  valign="middle">
0ac0: 0d 0a 59 6f 75 20 63 61 6e 20 65 76 65 6e 74 75  ..You can eventu
0ad0: 61 6c 6c 79 20 3c 61 20 68 72 65 66 3d 22 68 74  ally <a href="ht
0ae0: 74 70 73 3a 2f 2f 77 77 77 2e 67 61 69 61 2d 67  tps://www.gaia-g
0af0: 69 73 2e 69 74 2f 67 61 69 61 2d 73 69 6e 73 2f  is.it/gaia-sins/
0b00: 6b 6e 6e 2f 61 69 72 70 6f 72 74 73 2e 37 7a 22  knn/airports.7z"
0b10: 3e 64 6f 77 6e 6c 6f 61 64 3c 2f 61 3e 20 61 20  >download</a> a 
0b20: 73 61 6d 70 6c 65 20 64 62 2d 66 69 6c 65 20 65  sample db-file e
0b30: 78 61 63 74 6c 79 20 63 6f 72 72 65 73 70 6f 6e  xactly correspon
0b40: 64 69 6e 67 20 74 6f 20 74 68 65 20 70 72 61 63  ding to the prac
0b50: 74 69 63 61 6c 20 65 78 61 6d 70 6c 65 73 20 77  tical examples w
0b60: 65 27 6c 6c 20 75 73 65 20 69 6e 20 74 68 69 73  e'll use in this
0b70: 20 66 69 72 73 74 20 74 75 74 6f 72 69 61 6c 2e   first tutorial.
0b80: 3c 62 72 3e 3c 62 72 3e 0d 0a 54 68 69 73 20 64  <br><br>..This d
0b90: 61 74 61 73 65 74 20 63 6f 72 72 65 73 70 6f 6e  ataset correspon
0ba0: 64 73 20 74 6f 20 61 20 63 6f 6c 6c 65 63 74 69  ds to a collecti
0bb0: 6f 6e 20 6f 66 20 61 62 6f 75 74 20 3c 62 3e 33  on of about <b>3
0bc0: 30 2e 30 30 30 20 61 69 72 70 6f 72 74 73 3c 2f  0.000 airports</
0bd0: 62 3e 20 73 63 61 74 74 65 72 65 64 20 61 6c 6c  b> scattered all
0be0: 20 6f 76 65 72 20 74 68 65 20 77 6f 72 6c 64 3b   over the world;
0bf0: 20 74 68 65 20 6f 72 69 67 69 6e 61 6c 20 69 6e   the original in
0c00: 70 75 74 20 73 68 61 70 65 66 69 6c 65 20 77 61  put shapefile wa
0c10: 73 20 64 6f 77 6e 6c 6f 61 64 65 64 20 66 72 6f  s downloaded fro
0c20: 6d 20 3c 61 20 68 72 65 66 3d 22 68 74 74 70 73  m <a href="https
0c30: 3a 2f 2f 77 77 77 2e 73 68 61 72 65 67 65 6f 2e  ://www.sharegeo.
0c40: 61 63 2e 75 6b 2f 68 61 6e 64 6c 65 2f 31 30 36  ac.uk/handle/106
0c50: 37 32 2f 33 30 33 22 3e 68 65 72 65 3c 2f 61 3e  72/303">here</a>
0c60: 3c 62 72 3e 0d 0a 54 68 65 20 72 65 66 65 72 65  <br>..The refere
0c70: 6e 63 65 20 73 79 73 74 65 6d 20 69 73 20 3c 62  nce system is <b
0c80: 3e 34 33 32 36 20 57 47 53 38 34 3c 2f 62 3e 20  >4326 WGS84</b> 
0c90: 28 62 61 73 65 64 20 6f 6e 20 3c 69 3e 6c 6f 6e  (based on <i>lon
0ca0: 67 69 74 75 64 65 3c 2f 69 3e 20 61 6e 64 20 3c  gitude</i> and <
0cb0: 69 3e 6c 61 74 69 74 75 64 65 3c 2f 69 3e 20 61  i>latitude</i> a
0cc0: 6e 67 6c 65 73 29 2e 0d 0a 3c 62 72 3e 3c 62 72  ngles)...<br><br
0cd0: 3e 3c 62 72 3e 3c 62 72 3e 0d 0a 54 68 65 20 6d  ><br><br>..The m
0ce0: 61 70 20 6f 6e 20 74 68 65 20 72 69 67 68 74 20  ap on the right 
0cf0: 73 68 6f 77 73 20 74 68 65 20 67 65 6f 67 72 61  shows the geogra
0d00: 70 68 69 63 20 63 6f 6e 74 65 78 74 20 6f 66 20  phic context of 
0d10: 74 68 69 73 20 66 69 72 73 74 20 4b 4e 4e 20 65  this first KNN e
0d20: 78 61 6d 70 6c 65 2e 3c 2f 74 64 3e 0d 0a 3c 74  xample.</td>..<t
0d30: 64 3e 3c 69 6d 67 20 73 72 63 3d 22 68 74 74 70  d><img src="http
0d40: 73 3a 2f 2f 77 77 77 2e 67 61 69 61 2d 67 69 73  s://www.gaia-gis
0d50: 2e 69 74 2f 67 61 69 61 2d 73 69 6e 73 2f 6b 6e  .it/gaia-sins/kn
0d60: 6e 2f 74 79 72 72 68 65 6e 69 61 6e 2d 73 65 61  n/tyrrhenian-sea
0d70: 2e 70 6e 67 22 20 61 6c 74 3d 22 54 79 72 72 68  .png" alt="Tyrrh
0d80: 65 6e 69 61 6e 20 53 65 61 22 3e 3c 2f 74 64 3e  enian Sea"></td>
0d90: 0d 0a 3c 2f 74 61 62 6c 65 3e 3c 62 72 3e 0d 0a  ..</table><br>..
0da0: 3c 68 32 3e 41 20 66 69 72 73 74 20 6e 61 69 76  <h2>A first naiv
0db0: 65 20 28 61 6e 64 20 76 65 72 79 20 69 6e 65 66  e (and very inef
0dc0: 66 69 63 69 65 6e 74 29 20 61 70 70 72 6f 61 63  ficient) approac
0dd0: 68 3c 2f 68 32 3e 0d 0a 3c 76 65 72 62 61 74 69  h</h2>..<verbati
0de0: 6d 3e 0d 0a 53 45 4c 45 43 54 20 67 65 6f 6e 61  m>..SELECT geona
0df0: 6d 65 69 64 2c 20 6e 61 6d 65 2c 20 63 6f 75 6e  meid, name, coun
0e00: 74 72 79 2c 20 0d 0a 20 20 20 20 4d 69 6e 28 53  try, ..    Min(S
0e10: 54 5f 44 69 73 74 61 6e 63 65 28 4d 61 6b 65 50  T_Distance(MakeP
0e20: 6f 69 6e 74 28 31 30 2c 20 34 33 29 2c 20 67 65  oint(10, 43), ge
0e30: 6f 6d 2c 20 31 29 29 20 2f 20 31 30 30 30 2e 30  om, 1)) / 1000.0
0e40: 20 41 53 20 64 69 73 74 5f 6b 6d 0d 0a 46 52 4f   AS dist_km..FRO
0e50: 4d 20 61 69 72 70 6f 72 74 73 3b 0d 0a 2d 2d 2d  M airports;..---
0e60: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0e70: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 36  -------------..6
0e80: 32 39 39 36 32 33 09 7c 20 4d 61 72 69 6e 61 20  299623.| Marina 
0e90: 44 69 20 43 61 6d 70 6f 20 7c 20 49 54 20 7c 20  Di Campo | IT | 
0ea0: 33 33 2e 30 34 33 33 32 30 0d 0a 0d 0a 53 45 4c  33.043320....SEL
0eb0: 45 43 54 20 67 65 6f 6e 61 6d 65 69 64 2c 20 6e  ECT geonameid, n
0ec0: 61 6d 65 2c 20 63 6f 75 6e 74 72 79 2c 20 0d 0a  ame, country, ..
0ed0: 20 20 20 20 4d 69 6e 28 53 54 5f 44 69 73 74 61      Min(ST_Dista
0ee0: 6e 63 65 28 4d 61 6b 65 50 6f 69 6e 74 28 31 30  nce(MakePoint(10
0ef0: 2c 20 34 33 29 2c 20 67 65 6f 6d 2c 20 31 29 29  , 43), geom, 1))
0f00: 20 2f 20 31 30 30 30 2e 30 20 41 53 20 64 69 73   / 1000.0 AS dis
0f10: 74 5f 6b 6d 0d 0a 46 52 4f 4d 20 61 69 72 70 6f  t_km..FROM airpo
0f20: 72 74 73 0d 0a 57 48 45 52 45 20 67 65 6f 6e 61  rts..WHERE geona
0f30: 6d 65 69 64 20 4e 4f 54 20 49 4e 20 28 36 32 39  meid NOT IN (629
0f40: 39 36 32 33 29 3b 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d  9623);..--------
0f50: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0f60: 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 36 32 39 39 33  ---------..62993
0f70: 39 32 20 7c 20 42 61 73 74 69 61 2d 50 6f 72 65  92 | Bastia-Pore
0f80: 74 74 61 20 7c 20 46 52 20 7c 20 36 35 2e 32 32  tta | FR | 65.22
0f90: 36 35 37 33 0d 0a 0d 0a 53 45 4c 45 43 54 20 67  6573....SELECT g
0fa0: 65 6f 6e 61 6d 65 69 64 2c 20 6e 61 6d 65 2c 20  eonameid, name, 
0fb0: 63 6f 75 6e 74 72 79 2c 0d 0a 20 20 20 20 4d 69  country,..    Mi
0fc0: 6e 28 53 54 5f 44 69 73 74 61 6e 63 65 28 4d 61  n(ST_Distance(Ma
0fd0: 6b 65 50 6f 69 6e 74 28 31 30 2c 20 34 33 29 2c  kePoint(10, 43),
0fe0: 20 67 65 6f 6d 2c 20 31 29 29 20 2f 20 31 30 30   geom, 1)) / 100
0ff0: 30 2e 30 20 41 53 20 64 69 73 74 5f 6b 6d 0d 0a  0.0 AS dist_km..
1000: 46 52 4f 4d 20 61 69 72 70 6f 72 74 73 0d 0a 57  FROM airports..W
1010: 48 45 52 45 20 67 65 6f 6e 61 6d 65 69 64 20 4e  HERE geonameid N
1020: 4f 54 20 49 4e 20 28 36 32 39 39 36 32 33 2c 20  OT IN (6299623, 
1030: 36 32 39 39 33 39 32 29 3b 0d 0a 2d 2d 2d 2d 2d  6299392);..-----
1040: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1050: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 36 32  ------------..62
1060: 39 39 36 32 38 20 7c 20 50 69 73 61 20 2f 20 53  99628 | Pisa / S
1070: 2e 20 47 69 75 73 74 6f 20 7c 20 49 54 09 7c 20  . Giusto | IT.| 
1080: 38 32 2e 33 38 37 30 31 34 0d 0a 0d 0a 53 45 4c  82.387014....SEL
1090: 45 43 54 20 67 65 6f 6e 61 6d 65 69 64 2c 20 6e  ECT geonameid, n
10a0: 61 6d 65 2c 20 63 6f 75 6e 74 72 79 2c 20 0d 0a  ame, country, ..
10b0: 20 20 20 20 4d 69 6e 28 53 54 5f 44 69 73 74 61      Min(ST_Dista
10c0: 6e 63 65 28 4d 61 6b 65 50 6f 69 6e 74 28 31 30  nce(MakePoint(10
10d0: 2c 20 34 33 29 2c 20 67 65 6f 6d 2c 20 31 29 29  , 43), geom, 1))
10e0: 20 2f 20 31 30 30 30 2e 30 20 41 53 20 64 69 73   / 1000.0 AS dis
10f0: 74 5f 6b 6d 0d 0a 46 52 4f 4d 20 61 69 72 70 6f  t_km..FROM airpo
1100: 72 74 73 0d 0a 57 48 45 52 45 20 67 65 6f 6e 61  rts..WHERE geona
1110: 6d 65 69 64 20 4e 4f 54 20 49 4e 20 28 36 32 39  meid NOT IN (629
1120: 39 36 32 33 2c 20 36 32 39 39 33 39 32 2c 20 36  9623, 6299392, 6
1130: 32 39 39 36 32 38 29 3b 0d 0a 2d 2d 2d 2d 2d 2d  299628);..------
1140: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1150: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 36 32 39  -----------..629
1160: 39 36 33 30 20 7c 20 47 72 6f 73 73 65 74 6f 20  9630 | Grosseto 
1170: 41 69 72 70 6f 72 74 20 7c 20 49 54 20 7c 20 39  Airport | IT | 9
1180: 31 2e 35 34 39 37 37 33 0d 0a 0d 0a 53 45 4c 45  1.549773....SELE
1190: 43 54 20 67 65 6f 6e 61 6d 65 69 64 2c 20 6e 61  CT geonameid, na
11a0: 6d 65 2c 20 63 6f 75 6e 74 72 79 2c 20 0d 0a 20  me, country, .. 
11b0: 20 20 20 4d 69 6e 28 53 54 5f 44 69 73 74 61 6e     Min(ST_Distan
11c0: 63 65 28 4d 61 6b 65 50 6f 69 6e 74 28 31 30 2c  ce(MakePoint(10,
11d0: 20 34 33 29 2c 20 67 65 6f 6d 2c 20 31 29 29 20   43), geom, 1)) 
11e0: 2f 20 31 30 30 30 2e 30 20 41 53 20 64 69 73 74  / 1000.0 AS dist
11f0: 5f 6b 6d 0d 0a 46 52 4f 4d 20 61 69 72 70 6f 72  _km..FROM airpor
1200: 74 73 0d 0a 57 48 45 52 45 20 67 65 6f 6e 61 6d  ts..WHERE geonam
1210: 65 69 64 20 4e 4f 54 20 49 4e 20 28 36 32 39 39  eid NOT IN (6299
1220: 36 32 33 2c 20 36 32 39 39 33 39 32 2c 20 36 32  623, 6299392, 62
1230: 39 39 36 32 38 2c 20 36 32 39 39 36 33 30 29 3b  99628, 6299630);
1240: 0d 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ..--------------
1250: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1260: 2d 2d 2d 0d 0a 36 36 39 34 34 39 35 20 7c 20 43  ---..6694495 | C
1270: 6f 72 74 65 20 7c 20 46 52 20 7c 20 31 30 32 2e  orte | FR | 102.
1280: 38 31 39 37 37 38 0d 0a 3c 2f 76 65 72 62 61 74  819778..</verbat
1290: 69 6d 3e 0d 0a 57 65 20 63 6f 75 6c 64 20 65 66  im>..We could ef
12a0: 66 65 63 74 69 76 65 6c 79 20 65 78 65 63 75 74  fectively execut
12b0: 65 20 61 20 66 69 72 73 74 20 53 51 4c 20 71 75  e a first SQL qu
12c0: 65 72 79 20 75 73 69 6e 67 20 74 68 65 20 3c 62  ery using the <b
12d0: 3e 4d 69 6e 28 29 3c 2f 62 3e 20 61 67 67 72 65  >Min()</b> aggre
12e0: 67 61 74 65 20 66 75 6e 63 74 69 6f 6e 20 69 6e  gate function in
12f0: 20 6f 72 64 65 72 20 74 6f 20 69 64 65 6e 74 69   order to identi
1300: 66 79 20 74 68 65 20 63 6c 6f 73 65 73 74 20 61  fy the closest a
1310: 69 72 70 6f 72 74 20 74 6f 20 61 6e 20 61 72 62  irport to an arb
1320: 69 74 72 61 72 79 20 70 6f 73 69 74 69 6f 6e 20  itrary position 
1330: 28 3c 69 3e 6c 61 74 69 74 75 64 65 3c 2f 69 3e  (<i>latitude</i>
1340: 3d 3c 62 3e 34 33 2e 30 3c 2f 62 3e 2c 20 3c 69  =<b>43.0</b>, <i
1350: 3e 6c 6f 6e 67 69 74 75 64 65 3c 2f 69 3e 3d 3c  >longitude</i>=<
1360: 62 3e 31 30 2e 30 3c 2f 62 3e 29 20 6c 6f 63 61  b>10.0</b>) loca
1370: 74 65 64 20 69 6e 20 74 68 65 20 6d 69 64 64 6c  ted in the middl
1380: 65 20 6f 66 20 74 68 65 20 54 79 72 72 68 65 6e  e of the Tyrrhen
1390: 69 61 6e 20 53 65 61 2e 3c 62 72 3e 0d 0a 54 68  ian Sea.<br>..Th
13a0: 65 6e 20 77 65 20 63 6f 75 6c 64 20 65 76 65 6e  en we could even
13b0: 74 75 61 6c 6c 79 20 72 65 70 65 61 74 61 62 6c  tually repeatabl
13c0: 79 20 65 78 65 63 75 74 65 20 74 68 65 20 69 64  y execute the id
13d0: 65 6e 74 69 63 61 6c 20 71 75 65 72 79 2c 20 65  entical query, e
13e0: 61 63 68 20 74 69 6d 65 20 65 78 63 6c 75 64 69  ach time excludi
13f0: 6e 67 20 61 6c 6c 20 61 69 72 70 6f 72 74 73 20  ng all airports 
1400: 77 65 27 76 65 20 61 6c 72 65 61 64 79 20 69 64  we've already id
1410: 65 6e 74 69 66 69 65 64 20 69 6e 20 74 68 65 20  entified in the 
1420: 70 72 65 76 69 6f 75 73 20 70 72 6f 63 65 73 73  previous process
1430: 65 64 20 73 74 65 70 73 2e 3c 62 72 3e 0d 0a 54  ed steps.<br>..T
1440: 68 65 20 66 69 6e 61 6c 20 72 65 73 75 6c 74 20  he final result 
1450: 77 69 6c 6c 20 62 65 20 74 68 65 20 66 75 6c 6c  will be the full
1460: 20 6c 69 73 74 20 6f 66 20 74 68 65 20 66 69 72   list of the fir
1470: 73 74 20 66 69 76 65 20 61 69 72 70 6f 72 74 73  st five airports
1480: 20 63 6c 6f 73 65 73 74 20 74 6f 20 74 68 65 20   closest to the 
1490: 72 65 66 65 72 65 6e 63 65 20 6c 6f 63 61 74 69  reference locati
14a0: 6f 6e 20 6f 72 64 65 72 65 64 20 62 79 20 69 6e  on ordered by in
14b0: 63 72 65 61 73 69 6e 67 20 64 69 73 74 61 6e 63  creasing distanc
14c0: 65 2e 0d 0a 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 74  e...<br><br>..<t
14d0: 61 62 6c 65 20 62 67 63 6f 6c 6f 72 3d 22 23 64  able bgcolor="#d
14e0: 30 66 66 62 30 22 20 63 65 6c 6c 73 70 61 63 69  0ffb0" cellspaci
14f0: 6e 67 3d 22 34 22 20 63 65 6c 6c 70 61 64 64 69  ng="4" cellpaddi
1500: 6e 67 3d 22 34 22 20 62 6f 72 64 65 72 3d 22 31  ng="4" border="1
1510: 22 3e 0d 0a 3c 74 72 3e 3c 74 64 20 62 67 63 6f  ">..<tr><td bgco
1520: 6c 6f 72 3d 22 23 63 30 64 64 61 6f 22 3e 3c 62  lor="#c0ddao"><b
1530: 3e 72 61 6e 6b 3c 2f 62 3e 3c 2f 74 64 3e 3c 74  >rank</b></td><t
1540: 64 20 62 67 63 6f 6c 6f 72 3d 22 23 63 30 64 64  d bgcolor="#c0dd
1550: 61 6f 22 3e 3c 62 3e 67 65 6f 6e 61 6d 65 69 64  ao"><b>geonameid
1560: 3c 2f 62 3e 3c 2f 74 64 3e 3c 74 64 20 62 67 63  </b></td><td bgc
1570: 6f 6c 6f 72 3d 22 23 63 30 64 64 61 6f 22 3e 3c  olor="#c0ddao"><
1580: 62 3e 6e 61 6d 65 3c 2f 62 3e 3c 2f 74 64 3e 3c  b>name</b></td><
1590: 74 64 20 62 67 63 6f 6c 6f 72 3d 22 23 63 30 64  td bgcolor="#c0d
15a0: 64 61 6f 22 3e 3c 62 3e 63 6f 75 6e 74 72 79 3c  dao"><b>country<
15b0: 2f 62 3e 3c 2f 74 64 3e 3c 74 64 20 62 67 63 6f  /b></td><td bgco
15c0: 6c 6f 72 3d 22 23 63 30 64 64 61 6f 22 3e 3c 62  lor="#c0ddao"><b
15d0: 3e 64 69 73 74 5f 6b 6d 3c 2f 62 3e 3c 2f 74 64  >dist_km</b></td
15e0: 3e 3c 2f 74 72 3e 0d 0a 3c 74 72 3e 3c 74 64 20  ></tr>..<tr><td 
15f0: 61 6c 69 67 6e 3d 22 72 69 67 68 74 22 3e 31 3c  align="right">1<
1600: 2f 74 64 3e 3c 74 64 20 61 6c 69 67 6e 3d 22 72  /td><td align="r
1610: 69 67 68 74 22 3e 36 32 39 39 36 32 33 3c 2f 74  ight">6299623</t
1620: 64 3e 3c 74 64 3e 4d 61 72 69 6e 61 20 44 69 20  d><td>Marina Di 
1630: 43 61 6d 70 6f 3c 2f 74 64 3e 3c 74 64 3e 49 54  Campo</td><td>IT
1640: 3c 2f 74 64 3e 3c 74 64 20 61 6c 69 67 6e 3d 22  </td><td align="
1650: 72 69 67 68 74 22 3e 33 33 2e 30 34 33 33 32 30  right">33.043320
1660: 3c 2f 74 64 3e 3c 2f 74 72 3e 0d 0a 3c 74 72 3e  </td></tr>..<tr>
1670: 3c 74 64 20 61 6c 69 67 6e 3d 22 72 69 67 68 74  <td align="right
1680: 22 3e 32 3c 2f 74 64 3e 3c 74 64 20 61 6c 69 67  ">2</td><td alig
1690: 6e 3d 22 72 69 67 68 74 22 3e 36 32 39 39 33 39  n="right">629939
16a0: 32 3c 2f 74 64 3e 3c 74 64 3e 42 61 73 74 69 61  2</td><td>Bastia
16b0: 2d 50 6f 72 65 74 74 61 3c 2f 74 64 3e 3c 74 64  -Poretta</td><td
16c0: 3e 46 52 3c 2f 74 64 3e 3c 74 64 20 61 6c 69 67  >FR</td><td alig
16d0: 6e 3d 22 72 69 67 68 74 22 3e 36 35 2e 32 32 36  n="right">65.226
16e0: 35 37 33 3c 2f 74 64 3e 3c 2f 74 72 3e 0d 0a 3c  573</td></tr>..<
16f0: 74 72 3e 3c 74 64 20 61 6c 69 67 6e 3d 22 72 69  tr><td align="ri
1700: 67 68 74 22 3e 33 3c 2f 74 64 3e 3c 74 64 20 61  ght">3</td><td a
1710: 6c 69 67 6e 3d 22 72 69 67 68 74 22 3e 36 32 39  lign="right">629
1720: 39 36 32 38 3c 2f 74 64 3e 3c 74 64 3e 50 69 73  9628</td><td>Pis
1730: 61 20 2f 20 53 2e 20 47 69 75 73 74 6f 3c 2f 74  a / S. Giusto</t
1740: 64 3e 3c 74 64 3e 49 54 3c 2f 74 64 3e 3c 74 64  d><td>IT</td><td
1750: 20 61 6c 69 67 6e 3d 22 72 69 67 68 74 22 3e 38   align="right">8
1760: 32 2e 33 38 37 30 31 34 3c 2f 74 64 3e 3c 2f 74  2.387014</td></t
1770: 72 3e 0d 0a 3c 74 72 3e 3c 74 64 20 61 6c 69 67  r>..<tr><td alig
1780: 6e 3d 22 72 69 67 68 74 22 3e 34 3c 2f 74 64 3e  n="right">4</td>
1790: 3c 74 64 20 61 6c 69 67 6e 3d 22 72 69 67 68 74  <td align="right
17a0: 22 3e 36 32 39 39 36 33 30 3c 2f 74 64 3e 3c 74  ">6299630</td><t
17b0: 64 3e 47 72 6f 73 73 65 74 6f 20 41 69 72 70 6f  d>Grosseto Airpo
17c0: 72 74 3c 2f 74 64 3e 3c 74 64 3e 49 54 3c 2f 74  rt</td><td>IT</t
17d0: 64 3e 3c 74 64 20 61 6c 69 67 6e 3d 22 72 69 67  d><td align="rig
17e0: 68 74 22 3e 39 31 2e 35 34 39 37 37 33 3c 2f 74  ht">91.549773</t
17f0: 64 3e 3c 2f 74 72 3e 0d 0a 3c 74 72 3e 3c 74 64  d></tr>..<tr><td
1800: 20 61 6c 69 67 6e 3d 22 72 69 67 68 74 22 3e 35   align="right">5
1810: 3c 2f 74 64 3e 3c 74 64 20 61 6c 69 67 6e 3d 22  </td><td align="
1820: 72 69 67 68 74 22 3e 36 36 39 34 34 39 35 3c 2f  right">6694495</
1830: 74 64 3e 3c 74 64 3e 43 6f 72 74 65 3c 2f 74 64  td><td>Corte</td
1840: 3e 3c 74 64 3e 46 52 3c 2f 74 64 3e 3c 74 64 20  ><td>FR</td><td 
1850: 61 6c 69 67 6e 3d 22 72 69 67 68 74 22 3e 31 30  align="right">10
1860: 32 2e 38 31 39 37 37 38 3c 2f 74 64 3e 3c 2f 74  2.819778</td></t
1870: 72 3e 0d 0a 3c 2f 74 61 62 6c 65 3e 3c 62 72 3e  r>..</table><br>
1880: 0d 0a 53 75 63 68 20 61 20 73 69 6d 70 6c 65 20  ..Such a simple 
1890: 61 70 70 72 6f 61 63 68 20 77 6f 75 6c 64 20 62  approach would b
18a0: 65 20 68 69 67 68 6c 79 20 69 6d 70 72 61 63 74  e highly impract
18b0: 69 63 61 6c 2c 20 62 65 63 61 75 73 65 20 69 74  ical, because it
18c0: 20 73 74 72 69 63 74 6c 79 20 72 65 71 75 69 72   strictly requir
18d0: 65 73 20 74 6f 20 68 61 6e 64 2d 77 72 69 74 65  es to hand-write
18e0: 20 73 65 76 65 72 61 6c 20 3c 69 3e 61 64 20 68   several <i>ad h
18f0: 6f 63 3c 2f 69 3e 20 53 51 4c 20 71 75 65 72 69  oc</i> SQL queri
1900: 65 73 20 6f 6e 65 20 62 79 20 6f 6e 65 2e 3c 62  es one by one.<b
1910: 72 3e 0d 0a 57 72 69 74 69 6e 67 20 61 20 66 75  r>..Writing a fu
1920: 6c 6c 79 20 61 75 74 6f 6d 61 74 65 64 20 53 51  lly automated SQ
1930: 4c 20 73 63 72 69 70 74 20 69 73 6e 27 74 20 61  L script isn't a
1940: 74 20 61 6c 6c 20 61 20 73 69 6d 70 6c 65 20 74  t all a simple t
1950: 61 73 6b 2c 20 61 6e 64 20 73 6f 6d 65 20 6b 69  ask, and some ki
1960: 6e 64 20 6f 66 20 68 69 67 68 65 72 20 6c 65 76  nd of higher lev
1970: 65 6c 20 73 63 72 69 70 74 69 6e 67 20 28 65 2e  el scripting (e.
1980: 67 2e 20 50 79 74 68 6f 6e 29 20 77 6f 75 6c 64  g. Python) would
1990: 20 62 65 20 65 61 73 69 6c 79 20 72 65 71 75 69   be easily requi
19a0: 72 65 64 20 69 6e 20 61 6e 79 20 72 65 61 6c 69  red in any reali
19b0: 73 74 69 63 20 73 63 65 6e 61 72 69 6f 2e 3c 62  stic scenario.<b
19c0: 72 3e 0d 0a 54 68 65 20 61 75 74 6f 6d 61 74 69  r>..The automati
19d0: 6f 6e 20 6f 66 20 61 6c 6c 20 72 65 71 75 69 72  on of all requir
19e0: 65 64 20 53 51 4c 20 71 75 65 72 69 65 73 20 69  ed SQL queries i
19f0: 73 6e 27 74 20 74 68 65 20 6d 6f 73 74 20 63 72  sn't the most cr
1a00: 69 74 69 63 61 6c 20 69 73 73 75 65 20 77 65 20  itical issue we 
1a10: 68 61 76 65 20 74 6f 20 66 61 63 65 3b 20 74 68  have to face; th
1a20: 65 20 72 65 61 6c 2c 20 63 72 69 74 69 63 61 6c  e real, critical
1a30: 2c 20 62 6f 74 74 6c 65 20 6e 65 63 6b 20 77 69  , bottle neck wi
1a40: 74 68 20 74 68 69 73 20 73 69 6d 70 6c 65 20 61  th this simple a
1a50: 70 70 72 6f 61 63 68 2c 20 69 73 20 74 68 61 74  pproach, is that
1a60: 20 65 61 63 68 20 6f 66 20 74 68 65 73 65 20 71   each of these q
1a70: 75 65 72 69 65 73 20 77 69 6c 6c 20 63 61 75 73  ueries will caus
1a80: 65 20 61 6e 20 61 77 66 75 6c 20 3c 61 20 68 72  e an awful <a hr
1a90: 65 66 3d 22 68 74 74 70 73 3a 2f 2f 65 6e 2e 77  ef="https://en.w
1aa0: 69 6b 69 70 65 64 69 61 2e 6f 72 67 2f 77 69 6b  ikipedia.org/wik
1ab0: 69 2f 46 75 6c 6c 5f 74 61 62 6c 65 5f 73 63 61  i/Full_table_sca
1ac0: 6e 22 3e 66 75 6c 6c 20 74 61 62 6c 65 20 73 63  n">full table sc
1ad0: 61 6e 3c 2f 61 3e 3c 62 72 3e 0d 0a 54 68 69 73  an</a><br>..This
1ae0: 20 77 69 6c 6c 20 62 65 20 74 68 65 20 63 61 75   will be the cau
1af0: 73 65 20 6f 66 20 61 6e 20 69 6e 74 6f 6c 65 72  se of an intoler
1b00: 61 62 6c 79 20 73 6c 75 67 67 69 73 68 20 70 65  ably sluggish pe
1b10: 72 66 6f 72 6d 61 6e 63 65 2c 20 61 6e 64 20 74  rformance, and t
1b20: 68 65 20 6f 76 65 72 61 6c 6c 20 70 65 72 66 6f  he overall perfo
1b30: 72 6d 61 6e 63 65 20 77 69 6c 6c 20 71 75 69 63  rmance will quic
1b40: 6b 6c 79 20 62 65 63 6f 6d 65 20 77 6f 72 73 65  kly become worse
1b50: 20 61 73 20 74 68 65 20 64 61 74 61 73 65 74 20   as the dataset 
1b60: 70 72 6f 67 72 65 73 73 69 76 65 6c 79 20 69 6e  progressively in
1b70: 63 72 65 61 73 65 73 20 69 6e 20 73 69 7a 65 2e  creases in size.
1b80: 0d 0a 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 62 3e 43  ..<br><br>..<b>C
1b90: 6f 6e 63 6c 75 73 69 6f 6e 3c 2f 62 3e 3a 3c 62  onclusion</b>:<b
1ba0: 72 3e 0d 0a 53 6f 6d 65 20 73 69 6d 70 6c 65 72  r>..Some simpler
1bb0: 20 61 6e 64 20 73 6d 61 72 74 65 72 20 61 70 70   and smarter app
1bc0: 72 6f 61 63 68 20 69 73 20 73 75 72 65 6c 79 20  roach is surely 
1bd0: 72 65 71 75 69 72 65 64 3a 20 70 6f 73 73 69 62  required: possib
1be0: 6c 79 20 6f 6e 65 20 74 61 6b 69 6e 67 20 66 75  ly one taking fu
1bf0: 6c 6c 20 70 72 6f 66 69 74 20 66 72 6f 6d 20 61  ll profit from a
1c00: 6e 20 3c 62 3e 52 2a 54 52 65 65 20 53 70 61 74  n <b>R*TRee Spat
1c10: 69 61 6c 20 49 6e 64 65 78 3c 2f 62 3e 20 73 75  ial Index</b> su
1c20: 70 70 6f 72 74 69 6e 67 20 74 68 65 20 47 65 6f  pporting the Geo
1c30: 6d 65 74 72 69 65 73 20 74 6f 20 62 65 20 73 65  metries to be se
1c40: 61 72 63 68 65 64 2e 3c 62 72 3e 3c 62 72 3e 0d  arched.<br><br>.
1c50: 0a 3c 68 72 3e 0d 0a 3c 68 32 3e 56 69 72 74 75  .<hr>..<h2>Virtu
1c60: 61 6c 4b 4e 4e 3c 2f 68 32 3e 0d 0a 53 74 61 72  alKNN</h2>..Star
1c70: 74 69 6e 67 20 73 69 6e 63 65 20 76 65 72 73 69  ting since versi
1c80: 6f 6e 20 3c 62 3e 34 2e 34 2e 30 3c 2f 62 3e 20  on <b>4.4.0</b> 
1c90: 53 70 61 74 69 61 4c 69 74 65 20 73 75 70 70 6f  SpatiaLite suppo
1ca0: 72 74 73 20 61 20 3c 62 3e 56 69 72 74 75 61 6c  rts a <b>Virtual
1cb0: 4b 4e 4e 3c 2f 62 3e 20 3c 61 20 68 72 65 66 3d  KNN</b> <a href=
1cc0: 22 68 74 74 70 73 3a 2f 2f 77 77 77 2e 73 71 6c  "https://www.sql
1cd0: 69 74 65 2e 6f 72 67 2f 76 74 61 62 2e 68 74 6d  ite.org/vtab.htm
1ce0: 6c 22 3e 56 69 72 74 75 61 6c 20 54 61 62 6c 65  l">Virtual Table
1cf0: 3c 2f 61 3e 20 73 70 65 63 69 66 69 63 61 6c 6c  </a> specificall
1d00: 79 20 69 6e 74 65 6e 64 65 64 20 61 73 20 61 20  y intended as a 
1d10: 63 6f 6d 70 6c 65 74 65 20 61 6e 64 20 68 69 67  complete and hig
1d20: 68 6c 79 20 65 66 66 69 63 69 65 6e 74 20 73 6f  hly efficient so
1d30: 6c 75 74 69 6f 6e 20 74 6f 20 74 68 65 20 3c 62  lution to the <b
1d40: 3e 4b 4e 4e 3c 2f 62 3e 20 70 72 6f 62 6c 65 6d  >KNN</b> problem
1d50: 2e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 43  ...<verbatim>..C
1d60: 52 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41  REATE VIRTUAL TA
1d70: 42 4c 45 20 6b 6e 6e 20 55 53 49 4e 47 20 56 69  BLE knn USING Vi
1d80: 72 74 75 61 6c 4b 4e 4e 28 29 3b 0d 0a 3c 2f 76  rtualKNN();..</v
1d90: 65 72 62 61 74 69 6d 3e 0d 0a 45 76 65 72 79 20  erbatim>..Every 
1da0: 6e 65 77 20 64 62 2d 66 69 6c 65 20 62 65 69 6e  new db-file bein
1db0: 67 20 63 72 65 61 74 65 64 20 62 79 20 3c 62 3e  g created by <b>
1dc0: 34 2e 34 2e 30 3c 2f 62 3e 20 69 74 73 65 6c 66  4.4.0</b> itself
1dd0: 20 77 69 6c 6c 20 61 6c 77 61 79 73 20 61 75 74   will always aut
1de0: 6f 6d 61 74 69 63 61 6c 6c 79 20 64 65 66 69 6e  omatically defin
1df0: 65 20 61 20 3c 62 3e 4b 4e 4e 3c 2f 62 3e 20 76  e a <b>KNN</b> v
1e00: 69 72 74 75 61 6c 20 74 61 62 6c 65 2e 3c 62 72  irtual table.<br
1e10: 3e 0d 0a 59 6f 75 20 63 6f 75 6c 64 20 65 76 65  >..You could eve
1e20: 6e 74 75 61 6c 6c 79 20 61 64 64 20 66 75 6c 6c  ntually add full
1e30: 20 4b 4e 4e 20 73 75 70 70 6f 72 74 20 74 6f 20   KNN support to 
1e40: 61 6e 79 20 64 62 2d 66 69 6c 65 20 63 72 65 61  any db-file crea
1e50: 74 65 64 20 62 79 20 61 6e 79 20 65 61 72 6c 69  ted by any earli
1e60: 65 72 20 76 65 72 73 69 6f 6e 20 6f 66 20 53 70  er version of Sp
1e70: 61 74 69 61 4c 69 74 65 20 62 79 20 6d 61 6e 75  atiaLite by manu
1e80: 61 6c 6c 79 20 65 78 65 63 75 74 69 6e 67 20 74  ally executing t
1e90: 68 65 20 61 62 6f 76 65 20 53 51 4c 20 73 74 61  he above SQL sta
1ea0: 74 65 6d 65 6e 74 2e 3c 62 72 3e 0d 0a 3c 62 3e  tement.<br>..<b>
1eb0: 4e 6f 74 65 3c 2f 62 3e 3a 20 56 69 72 74 75 61  Note</b>: Virtua
1ec0: 6c 4b 4e 4e 20 6e 65 63 65 73 73 61 72 69 6c 79  lKNN necessarily
1ed0: 20 72 65 71 75 69 72 65 73 20 34 2e 34 2e 30 20   requires 4.4.0 
1ee0: 62 69 6e 61 72 79 20 73 75 70 70 6f 72 74 2c 20  binary support, 
1ef0: 73 6f 20 61 6e 79 20 61 74 74 65 6d 70 74 20 74  so any attempt t
1f00: 6f 20 6f 70 65 6e 20 61 20 64 62 2d 66 69 6c 65  o open a db-file
1f10: 20 69 6e 63 6c 75 64 69 6e 67 20 61 20 56 69 72   including a Vir
1f20: 74 75 61 6c 4b 4e 4e 20 74 61 62 6c 65 20 62 79  tualKNN table by
1f30: 20 75 73 69 6e 67 20 73 6f 6d 65 20 70 72 65 76   using some prev
1f40: 69 6f 75 73 20 76 65 72 73 69 6f 6e 20 28 3c 3d  ious version (<=
1f50: 20 3c 62 3e 34 2e 33 2e 30 61 3c 2f 62 3e 29 20   <b>4.3.0a</b>) 
1f60: 77 69 6c 6c 20 73 75 72 65 6c 79 20 72 61 69 73  will surely rais
1f70: 65 20 61 6e 20 65 72 72 6f 72 20 63 6f 6e 64 69  e an error condi
1f80: 74 69 6f 6e 2e 0d 0a 3c 68 33 3e 41 20 66 69 72  tion...<h3>A fir
1f90: 73 74 20 62 61 73 69 63 61 6c 6c 79 20 73 69 6d  st basically sim
1fa0: 70 6c 65 20 4b 4e 4e 20 71 75 65 72 79 3c 2f 68  ple KNN query</h
1fb0: 33 3e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a  3>..<verbatim>..
1fc0: 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20 6b 6e  SELECT * FROM kn
1fd0: 6e 0d 0a 57 48 45 52 45 20 66 5f 74 61 62 6c 65  n..WHERE f_table
1fe0: 5f 6e 61 6d 65 20 3d 20 27 61 69 72 70 6f 72 74  _name = 'airport
1ff0: 73 27 20 41 4e 44 20 72 65 66 5f 67 65 6f 6d 65  s' AND ref_geome
2000: 74 72 79 20 3d 20 4d 61 6b 65 50 6f 69 6e 74 28  try = MakePoint(
2010: 31 30 2c 20 34 33 29 3b 0d 0a 3c 2f 76 65 72 62  10, 43);..</verb
2020: 61 74 69 6d 3e 0d 0a 3c 74 61 62 6c 65 20 62 67  atim>..<table bg
2030: 63 6f 6c 6f 72 3d 22 23 64 30 66 66 62 30 22 20  color="#d0ffb0" 
2040: 63 65 6c 6c 73 70 61 63 69 6e 67 3d 22 34 22 20  cellspacing="4" 
2050: 63 65 6c 6c 70 61 64 64 69 6e 67 3d 22 34 22 20  cellpadding="4" 
2060: 62 6f 72 64 65 72 3d 22 31 22 3e 0d 0a 3c 74 72  border="1">..<tr
2070: 3e 3c 74 64 20 62 67 63 6f 6c 6f 72 3d 22 23 63  ><td bgcolor="#c
2080: 30 64 64 61 6f 22 3e 3c 62 3e 66 5f 74 61 62 6c  0ddao"><b>f_tabl
2090: 65 5f 6e 61 6d 65 3c 2f 62 3e 3c 2f 74 64 3e 3c  e_name</b></td><
20a0: 74 64 20 62 67 63 6f 6c 6f 72 3d 22 23 63 30 64  td bgcolor="#c0d
20b0: 64 61 6f 22 3e 3c 62 3e 66 5f 67 65 6f 6d 65 74  dao"><b>f_geomet
20c0: 72 79 5f 63 6f 6c 75 6d 6e 3c 2f 62 3e 3c 2f 74  ry_column</b></t
20d0: 64 3e 3c 74 64 20 62 67 63 6f 6c 6f 72 3d 22 23  d><td bgcolor="#
20e0: 63 30 64 64 61 6f 22 3e 3c 62 3e 72 65 66 5f 67  c0ddao"><b>ref_g
20f0: 65 6f 6d 65 74 72 79 3c 2f 62 3e 3c 2f 74 64 3e  eometry</b></td>
2100: 3c 74 64 20 62 67 63 6f 6c 6f 72 3d 22 23 63 30  <td bgcolor="#c0
2110: 64 64 61 6f 22 3e 3c 62 3e 6d 61 78 5f 69 74 65  ddao"><b>max_ite
2120: 6d 73 3c 2f 62 3e 3c 2f 74 64 3e 3c 74 64 20 62  ms</b></td><td b
2130: 67 63 6f 6c 6f 72 3d 22 23 63 30 64 64 61 6f 22  gcolor="#c0ddao"
2140: 3e 3c 62 3e 70 6f 73 3c 2f 62 3e 3c 2f 74 64 3e  ><b>pos</b></td>
2150: 3c 74 64 20 62 67 63 6f 6c 6f 72 3d 22 23 63 30  <td bgcolor="#c0
2160: 64 64 61 6f 22 3e 3c 62 3e 66 69 64 3c 2f 62 3e  ddao"><b>fid</b>
2170: 3c 2f 74 64 3e 3c 74 64 20 62 67 63 6f 6c 6f 72  </td><td bgcolor
2180: 3d 22 23 63 30 64 64 61 6f 22 3e 3c 62 3e 64 69  ="#c0ddao"><b>di
2190: 73 74 61 6e 63 65 3c 2f 62 3e 3c 2f 74 64 3e 3c  stance</b></td><
21a0: 2f 74 72 3e 0d 0a 3c 74 72 3e 3c 74 64 3e 61 69  /tr>..<tr><td>ai
21b0: 72 70 6f 72 74 73 3c 2f 74 64 3e 3c 74 64 3e 67  rports</td><td>g
21c0: 65 6f 6d 3c 2f 74 64 3e 3c 74 64 3e 42 4c 4f 42  eom</td><td>BLOB
21d0: 20 73 7a 3d 36 30 20 47 45 4f 4d 45 54 52 59 3c   sz=60 GEOMETRY<
21e0: 2f 74 64 3e 3c 74 64 20 61 6c 69 67 6e 3d 22 72  /td><td align="r
21f0: 69 67 68 74 22 3e 33 3c 2f 74 64 3e 3c 74 64 20  ight">3</td><td 
2200: 61 6c 69 67 6e 3d 22 72 69 67 68 74 22 3e 31 3c  align="right">1<
2210: 2f 74 64 3e 3c 74 64 20 61 6c 69 67 6e 3d 22 72  /td><td align="r
2220: 69 67 68 74 22 3e 36 32 39 39 36 32 33 3c 2f 74  ight">6299623</t
2230: 64 3e 3c 74 64 20 61 6c 69 67 6e 3d 22 72 69 67  d><td align="rig
2240: 68 74 22 3e 33 33 30 34 33 2e 33 31 39 35 32 30  ht">33043.319520
2250: 3c 2f 74 64 3e 3c 2f 74 72 3e 0d 0a 3c 74 72 3e  </td></tr>..<tr>
2260: 3c 74 64 3e 61 69 72 70 6f 72 74 73 3c 2f 74 64  <td>airports</td
2270: 3e 3c 74 64 3e 67 65 6f 6d 3c 2f 74 64 3e 3c 74  ><td>geom</td><t
2280: 64 3e 42 4c 4f 42 20 73 7a 3d 36 30 20 47 45 4f  d>BLOB sz=60 GEO
2290: 4d 45 54 52 59 3c 2f 74 64 3e 3c 74 64 20 61 6c  METRY</td><td al
22a0: 69 67 6e 3d 22 72 69 67 68 74 22 3e 33 3c 2f 74  ign="right">3</t
22b0: 64 3e 3c 74 64 20 61 6c 69 67 6e 3d 22 72 69 67  d><td align="rig
22c0: 68 74 22 3e 32 3c 2f 74 64 3e 3c 74 64 20 61 6c  ht">2</td><td al
22d0: 69 67 6e 3d 22 72 69 67 68 74 22 3e 36 32 39 39  ign="right">6299
22e0: 33 39 32 3c 2f 74 64 3e 3c 74 64 20 61 6c 69 67  392</td><td alig
22f0: 6e 3d 22 72 69 67 68 74 22 3e 36 35 32 32 36 2e  n="right">65226.
2300: 35 37 33 31 34 39 3c 2f 74 64 3e 3c 2f 74 72 3e  573149</td></tr>
2310: 0d 0a 3c 74 72 3e 3c 74 64 3e 61 69 72 70 6f 72  ..<tr><td>airpor
2320: 74 73 3c 2f 74 64 3e 3c 74 64 3e 67 65 6f 6d 3c  ts</td><td>geom<
2330: 2f 74 64 3e 3c 74 64 3e 42 4c 4f 42 20 73 7a 3d  /td><td>BLOB sz=
2340: 36 30 20 47 45 4f 4d 45 54 52 59 3c 2f 74 64 3e  60 GEOMETRY</td>
2350: 3c 74 64 20 61 6c 69 67 6e 3d 22 72 69 67 68 74  <td align="right
2360: 22 3e 33 3c 2f 74 64 3e 3c 74 64 20 61 6c 69 67  ">3</td><td alig
2370: 6e 3d 22 72 69 67 68 74 22 3e 33 3c 2f 74 64 3e  n="right">3</td>
2380: 3c 74 64 20 61 6c 69 67 6e 3d 22 72 69 67 68 74  <td align="right
2390: 22 3e 36 32 39 39 36 32 38 3c 2f 74 64 3e 3c 74  ">6299628</td><t
23a0: 64 20 61 6c 69 67 6e 3d 22 72 69 67 68 74 22 3e  d align="right">
23b0: 38 32 33 38 37 2e 30 31 34 30 32 38 3c 2f 74 64  82387.014028</td
23c0: 3e 3c 2f 74 72 3e 0d 0a 3c 2f 74 61 62 6c 65 3e  ></tr>..</table>
23d0: 3c 62 72 3e 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e  <br>..<ul>..<li>
23e0: 61 20 56 69 72 74 75 61 6c 4b 4e 4e 20 71 75 65  a VirtualKNN que
23f0: 72 79 20 63 6c 6f 73 65 6c 79 20 72 65 73 65 6d  ry closely resem
2400: 62 6c 65 73 20 61 20 56 69 72 74 75 61 6c 53 70  bles a VirtualSp
2410: 61 74 69 61 6c 49 6e 64 65 78 20 71 75 65 72 79  atialIndex query
2420: 2e 0d 0a 54 68 69 73 20 73 68 6f 75 6c 64 20 6e  ...This should n
2430: 6f 74 20 73 75 72 70 72 69 73 65 20 74 6f 6f 20  ot surprise too 
2440: 6d 75 63 68 2c 20 62 65 63 61 75 73 65 20 62 6f  much, because bo
2450: 74 68 20 74 68 65 6d 20 61 72 65 20 69 6e 74 65  th them are inte
2460: 6e 64 65 64 20 74 6f 20 62 65 20 77 72 61 70 70  nded to be wrapp
2470: 65 64 20 61 72 6f 75 6e 64 20 61 6e 20 75 6e 64  ed around an und
2480: 65 72 6c 79 69 6e 67 20 3c 62 3e 52 2a 54 72 65  erlying <b>R*Tre
2490: 65 20 53 70 61 74 69 61 6c 20 49 6e 64 65 78 3c  e Spatial Index<
24a0: 2f 62 3e 2e 3c 2f 6c 69 3e 20 0d 0a 3c 6c 69 3e  /b>.</li> ..<li>
24b0: 41 6e 79 20 76 61 6c 69 64 20 56 69 72 74 75 61  Any valid Virtua
24c0: 6c 4b 4e 4e 20 71 75 65 72 79 20 73 68 6f 75 6c  lKNN query shoul
24d0: 64 20 6e 65 63 65 73 73 61 72 69 6c 79 20 68 61  d necessarily ha
24e0: 76 65 20 61 20 66 6f 72 6d 20 6c 69 6b 65 3a 0d  ve a form like:.
24f0: 0a 3c 62 3e 57 48 45 52 45 20 3c 69 3e 6b 6e 6e  .<b>WHERE <i>knn
2500: 2d 63 6f 6c 75 6d 6e 3c 2f 69 3e 20 3d 20 3c 69  -column</i> = <i
2510: 3e 76 61 6c 75 65 3c 2f 69 3e 20 41 4e 44 20 3c  >value</i> AND <
2520: 69 3e 6b 6e 6e 2d 63 6f 6c 75 6d 6e 3c 2f 69 3e  i>knn-column</i>
2530: 20 3d 20 3c 69 3e 76 61 6c 75 65 3c 2f 69 3e 20   = <i>value</i> 
2540: 2e 2e 2e 3c 2f 62 3e 3c 2f 6c 69 3e 0d 0a 3c 6c  ...</b></li>..<l
2550: 69 3e 74 68 65 20 69 6e 70 75 74 20 63 6f 6c 75  i>the input colu
2560: 6d 6e 73 20 28 74 68 65 20 6f 6e 65 73 20 79 6f  mns (the ones yo
2570: 75 20 63 61 6e 20 72 65 66 65 72 65 6e 63 65 20  u can reference 
2580: 69 6e 74 6f 20 61 20 3c 62 3e 57 48 45 52 45 3c  into a <b>WHERE<
2590: 2f 62 3e 20 63 6c 61 75 73 65 29 20 61 72 65 3a  /b> clause) are:
25a0: 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 3c 62 3e 66  ..<ul>..<li><b>f
25b0: 5f 74 61 62 6c 65 5f 6e 61 6d 65 3c 2f 62 3e 20  _table_name</b> 
25c0: 28 3c 69 3e 6d 61 6e 64 61 74 6f 72 79 3c 2f 69  (<i>mandatory</i
25d0: 3e 29 3c 62 72 3e 0d 0a 6e 61 6d 65 20 6f 66 20  >)<br>..name of 
25e0: 74 68 65 20 47 65 6f 54 61 62 6c 65 20 63 6f 6e  the GeoTable con
25f0: 74 61 69 6e 69 6e 67 20 74 68 65 20 47 65 6f 6d  taining the Geom
2600: 65 74 72 69 65 73 20 74 6f 20 62 65 20 73 65 61  etries to be sea
2610: 72 63 68 65 64 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69  rched.</li>..<li
2620: 3e 3c 62 3e 66 5f 67 65 6f 6d 65 74 72 79 5f 63  ><b>f_geometry_c
2630: 6f 6c 75 6d 6e 3c 2f 62 3e 20 28 3c 69 3e 6f 70  olumn</b> (<i>op
2640: 74 69 6f 6e 61 6c 3c 2f 69 3e 29 3c 62 72 3e 0d  tional</i>)<br>.
2650: 0a 6e 61 6d 65 20 6f 66 20 74 68 65 20 63 6f 6c  .name of the col
2660: 75 6d 6e 20 6f 66 20 74 68 65 20 61 62 6f 76 65  umn of the above
2670: 20 74 61 62 6c 65 20 63 6f 6e 74 61 69 6e 69 6e   table containin
2680: 67 20 74 68 65 20 47 65 6f 6d 65 74 72 69 65 73  g the Geometries
2690: 20 74 6f 20 62 65 20 73 65 61 72 63 68 65 64 2e   to be searched.
26a0: 0d 0a 3c 6f 6c 3e 0d 0a 3c 6c 69 3e 49 66 20 74  ..<ol>..<li>If t
26b0: 68 65 20 74 61 62 6c 65 20 69 64 65 6e 74 69 66  he table identif
26c0: 69 65 64 20 62 79 20 3c 62 3e 66 5f 74 61 62 6c  ied by <b>f_tabl
26d0: 65 5f 6e 61 6d 65 3c 2f 62 3e 20 6a 75 73 74 20  e_name</b> just 
26e0: 63 6f 6e 74 61 69 6e 73 20 61 20 73 69 6e 67 6c  contains a singl
26f0: 65 20 47 65 6f 6d 65 74 72 79 20 63 6f 6c 75 6d  e Geometry colum
2700: 6e 20 79 6f 75 20 63 61 6e 20 73 61 66 65 6c 79  n you can safely
2710: 20 6f 6d 69 74 20 74 6f 20 73 70 65 63 69 66 79   omit to specify
2720: 20 74 68 65 20 3c 62 3e 66 5f 67 65 6f 6d 65 74   the <b>f_geomet
2730: 72 79 5f 63 6f 6c 75 6d 6e 3c 2f 62 3e 20 61 72  ry_column</b> ar
2740: 67 75 6d 65 6e 74 20 28 69 74 20 77 69 6c 6c 20  gument (it will 
2750: 62 65 20 61 75 74 6f 6d 61 74 69 63 61 6c 6c 79  be automatically
2760: 20 73 65 74 29 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69   set).</li>..<li
2770: 3e 49 66 20 69 6e 73 74 65 61 64 20 74 68 65 20  >If instead the 
2780: 74 61 62 6c 65 20 69 64 65 6e 74 69 66 69 65 64  table identified
2790: 20 62 79 20 3c 62 3e 66 5f 74 61 62 6c 65 5f 6e   by <b>f_table_n
27a0: 61 6d 65 3c 2f 62 3e 20 63 6f 6e 74 61 69 6e 73  ame</b> contains
27b0: 20 74 77 6f 20 28 6f 72 20 6d 6f 72 65 29 20 47   two (or more) G
27c0: 65 6f 6d 65 74 72 79 20 63 6f 6c 75 6d 6e 73 20  eometry columns 
27d0: 65 78 70 6c 69 63 69 74 6c 79 20 73 70 65 63 69  explicitly speci
27e0: 66 79 69 6e 67 20 74 68 65 20 3c 62 3e 66 5f 67  fying the <b>f_g
27f0: 65 6f 6d 65 74 72 79 5f 63 6f 6c 75 6d 6e 3c 2f  eometry_column</
2800: 62 3e 20 61 72 67 75 6d 65 6e 74 20 69 73 20 73  b> argument is s
2810: 74 72 69 63 74 6c 79 20 72 65 71 75 69 72 65 64  trictly required
2820: 2c 20 73 6f 20 74 6f 20 67 65 74 20 61 6e 20 75  , so to get an u
2830: 6e 61 6d 62 69 67 75 6f 75 73 20 64 65 66 69 6e  nambiguous defin
2840: 69 74 69 6f 6e 20 6f 66 20 74 68 65 20 69 6e 74  ition of the int
2850: 65 6e 64 65 64 20 73 65 61 72 63 68 20 63 6f 6e  ended search con
2860: 74 65 78 74 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e  text.</li>..<li>
2870: 49 6e 20 61 6e 79 20 63 61 73 65 20 3c 62 3e 66  In any case <b>f
2880: 5f 74 61 62 6c 65 5f 6e 61 6d 65 3c 2f 62 3e 20  _table_name</b> 
2890: 61 6e 64 20 3c 62 3e 66 5f 67 65 6f 6d 65 74 72  and <b>f_geometr
28a0: 79 5f 63 6f 6c 75 6d 6e 3c 2f 62 3e 20 6d 75 73  y_column</b> mus
28b0: 74 20 65 78 61 63 74 6c 79 20 6d 61 74 63 68 20  t exactly match 
28c0: 61 20 70 72 6f 70 65 72 6c 79 20 64 65 66 69 6e  a properly defin
28d0: 65 64 20 47 65 6f 6d 65 74 72 79 20 63 6f 6c 75  ed Geometry colu
28e0: 6d 6e 20 73 75 70 70 6f 72 74 65 64 20 62 79 20  mn supported by 
28f0: 61 20 63 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20  a corresponding 
2900: 53 70 61 74 69 61 6c 20 49 6e 64 65 78 2e 3c 2f  Spatial Index.</
2910: 6c 69 3e 0d 0a 3c 2f 6f 6c 3e 3c 2f 6c 69 3e 0d  li>..</ol></li>.
2920: 0a 3c 6c 69 3e 3c 62 3e 72 65 66 5f 67 65 6f 6d  .<li><b>ref_geom
2930: 65 74 72 79 3c 2f 62 3e 20 28 3c 69 3e 6d 61 6e  etry</b> (<i>man
2940: 64 61 74 6f 72 79 3c 2f 69 3e 29 3c 62 72 3e 0d  datory</i>)<br>.
2950: 0a 61 6e 79 20 61 72 62 69 74 72 61 72 79 20 47  .any arbitrary G
2960: 65 6f 6d 65 74 72 79 20 28 3c 62 3e 50 4f 49 4e  eometry (<b>POIN
2970: 54 3c 2f 62 3e 2c 20 3c 62 3e 4c 49 4e 45 53 54  T</b>, <b>LINEST
2980: 52 49 4e 47 3c 2f 62 3e 2c 20 3c 62 3e 50 4f 4c  RING</b>, <b>POL
2990: 59 47 4f 4e 3c 2f 62 3e 20 6f 72 20 77 68 61 74  YGON</b> or what
29a0: 65 76 65 72 20 65 6c 73 65 29 20 69 6e 74 65 6e  ever else) inten
29b0: 64 65 64 20 74 6f 20 72 65 70 72 65 73 65 6e 74  ded to represent
29c0: 20 74 68 65 20 6f 72 69 67 69 6e 20 6f 66 20 74   the origin of t
29d0: 68 65 20 4b 4e 4e 20 73 65 61 72 63 68 2e 3c 62  he KNN search.<b
29e0: 72 3e 0d 0a 53 68 6f 75 6c 64 20 6e 65 63 65 73  r>..Should neces
29f0: 73 61 72 69 6c 79 20 62 65 20 69 6e 20 74 68 65  sarily be in the
2a00: 20 73 61 6d 65 20 53 52 49 44 20 6f 66 20 74 68   same SRID of th
2a10: 65 20 74 61 72 67 65 74 20 47 65 6f 6d 65 74 72  e target Geometr
2a20: 69 65 73 20 74 6f 20 62 65 20 73 65 61 72 63 68  ies to be search
2a30: 65 64 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 3c 62  ed.</li>..<li><b
2a40: 3e 6d 61 78 5f 69 74 65 6d 73 3c 2f 62 3e 20 28  >max_items</b> (
2a50: 3c 69 3e 6f 70 74 69 6f 6e 61 6c 3c 2f 69 3e 29  <i>optional</i>)
2a60: 3c 62 72 3e 0d 0a 6d 61 78 69 6d 75 6d 20 6e 75  <br>..maximum nu
2a70: 6d 62 65 72 20 6f 66 20 72 6f 77 73 20 74 6f 20  mber of rows to 
2a80: 62 65 20 72 65 74 75 72 6e 65 64 20 69 6e 74 6f  be returned into
2a90: 20 74 68 65 20 72 65 73 75 6c 74 73 65 74 2e 3c   the resultset.<
2aa0: 62 72 3e 0d 0a 54 68 65 20 76 61 6c 69 64 20 72  br>..The valid r
2ab0: 61 6e 67 65 20 69 73 20 66 72 6f 6d 20 3c 62 3e  ange is from <b>
2ac0: 31 3c 2f 62 3e 20 74 6f 20 3c 62 3e 31 30 32 34  1</b> to <b>1024
2ad0: 3c 2f 62 3e 20 28 68 69 67 68 65 72 20 76 61 6c  </b> (higher val
2ae0: 75 65 73 20 77 69 6c 6c 20 72 65 71 75 69 72 65  ues will require
2af0: 20 61 20 6c 6f 6e 67 65 72 20 74 69 6d 65 20 74   a longer time t
2b00: 6f 20 62 65 20 70 72 6f 63 65 73 73 65 64 29 2e  o be processed).
2b10: 3c 62 72 3e 0d 0a 42 79 20 64 65 66 61 75 6c 74  <br>..By default
2b20: 20 6f 6e 6c 79 20 74 68 65 20 66 69 72 73 74 20   only the first 
2b30: 3c 62 3e 33 3c 2f 62 3e 20 6e 65 61 72 65 73 74  <b>3</b> nearest
2b40: 20 47 65 6f 6d 65 74 72 69 65 73 20 77 69 6c 6c   Geometries will
2b50: 20 62 65 20 69 64 65 6e 74 69 66 69 65 64 2e 3c   be identified.<
2b60: 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 3c 2f 6c 69 3e  /li>..</ul></li>
2b70: 0d 0a 3c 6c 69 3e 74 68 65 20 6f 75 74 70 75 74  ..<li>the output
2b80: 20 63 6f 6c 75 6d 6e 73 20 28 74 68 65 20 6f 6e   columns (the on
2b90: 65 73 20 63 6f 6e 74 61 69 6e 69 6e 67 20 76 61  es containing va
2ba0: 6c 75 65 73 20 72 65 74 72 69 65 76 65 64 20 62  lues retrieved b
2bb0: 79 20 74 68 65 20 4b 4e 4e 20 73 65 61 72 63 68  y the KNN search
2bc0: 29 20 61 72 65 3a 0d 0a 3c 75 6c 3e 0d 0a 3c 6c  ) are:..<ul>..<l
2bd0: 69 3e 3c 62 3e 70 6f 73 3c 2f 62 3e 20 28 3c 69  i><b>pos</b> (<i
2be0: 3e 49 4e 54 45 47 45 52 3c 2f 69 3e 29 3c 62 72  >INTEGER</i>)<br
2bf0: 3e 0d 0a 72 65 6c 61 74 69 76 65 20 72 61 6e 6b  >..relative rank
2c00: 3a 20 74 68 65 20 63 6c 6f 73 65 73 74 20 69 74  : the closest it
2c10: 65 6d 20 77 69 6c 6c 20 62 65 20 3c 62 3e 23 31  em will be <b>#1
2c20: 3c 2f 62 3e 2c 20 74 68 65 20 73 65 63 6f 6e 64  </b>, the second
2c30: 20 63 6c 6f 73 65 73 74 20 69 74 65 6d 20 77 69   closest item wi
2c40: 6c 6c 20 62 65 20 3c 62 3e 23 32 3c 2f 62 3e 20  ll be <b>#2</b> 
2c50: 61 6e 64 20 73 6f 20 6f 6e 2e 3c 2f 6c 69 3e 0d  and so on.</li>.
2c60: 0a 3c 6c 69 3e 3c 62 3e 66 69 64 3c 2f 62 3e 20  .<li><b>fid</b> 
2c70: 28 3c 69 3e 49 4e 54 45 47 45 52 3c 2f 69 3e 29  (<i>INTEGER</i>)
2c80: 3c 62 72 3e 0d 0a 74 68 65 20 75 6e 69 71 75 65  <br>..the unique
2c90: 20 3c 62 3e 52 4f 57 49 44 3c 2f 62 3e 20 76 61   <b>ROWID</b> va
2ca0: 6c 75 65 20 6f 66 20 74 68 65 20 63 6f 72 72 65  lue of the corre
2cb0: 73 70 6f 6e 64 69 6e 67 20 66 65 61 74 75 72 65  sponding feature
2cc0: 20 69 6e 74 6f 20 74 68 65 20 73 65 61 72 63 68   into the search
2cd0: 65 64 20 47 65 6f 54 61 62 6c 65 2e 3c 2f 6c 69  ed GeoTable.</li
2ce0: 3e 0d 0a 3c 6c 69 3e 3c 62 3e 64 69 73 74 61 6e  >..<li><b>distan
2cf0: 63 65 3c 2f 62 3e 20 28 3c 69 3e 44 4f 55 42 4c  ce</b> (<i>DOUBL
2d00: 45 3c 2f 69 3e 29 3c 62 72 3e 0d 0a 74 68 65 20  E</i>)<br>..the 
2d10: 6d 69 6e 69 6d 75 6d 20 64 69 73 74 61 6e 63 65  minimum distance
2d20: 20 62 65 74 77 65 65 6e 20 74 68 65 20 63 6f 72   between the cor
2d30: 72 65 73 70 6f 6e 64 69 6e 67 20 66 65 61 74 75  responding featu
2d40: 72 65 20 69 6e 74 6f 20 74 68 65 20 73 65 61 72  re into the sear
2d50: 63 68 65 64 20 47 65 6f 54 61 62 6c 65 20 61 6e  ched GeoTable an
2d60: 64 20 74 68 65 20 6f 72 69 67 69 6e 20 64 65 66  d the origin def
2d70: 69 6e 65 64 20 62 79 20 3c 62 3e 72 65 66 5f 67  ined by <b>ref_g
2d80: 65 6f 6d 65 74 72 79 3c 2f 62 3e 2e 0d 0a 3c 6f  eometry</b>...<o
2d90: 6c 3e 0d 0a 3c 6c 69 3e 54 68 65 20 75 6e 69 74  l>..<li>The unit
2da0: 20 6d 65 61 73 75 72 65 20 66 6f 72 20 61 6c 6c   measure for all
2db0: 20 64 69 73 74 61 6e 63 65 73 20 77 69 6c 6c 20   distances will 
2dc0: 61 6c 77 61 79 73 20 62 65 20 74 68 65 20 6f 6e  always be the on
2dd0: 65 20 64 65 63 6c 61 72 65 64 20 62 79 20 74 68  e declared by th
2de0: 65 20 63 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20  e corresponding 
2df0: 53 52 49 44 20 64 65 66 69 6e 69 74 69 6f 6e 2c  SRID definition,
2e00: 20 69 66 20 74 68 69 73 20 6f 6e 65 20 63 6f 72   if this one cor
2e10: 72 65 73 70 6f 6e 64 73 20 74 6f 20 73 6f 6d 65  responds to some
2e20: 20 3c 62 3e 70 6c 61 6e 61 72 3c 2f 62 3e 20 28   <b>planar</b> (
2e30: 61 6b 61 20 3c 62 3e 70 72 6f 6a 65 63 74 65 64  aka <b>projected
2e40: 3c 2f 62 3e 29 20 72 65 66 65 72 65 6e 63 65 20  </b>) reference 
2e50: 73 79 73 74 65 6d 2e 3c 2f 6c 69 3e 0d 0a 3c 6c  system.</li>..<l
2e60: 69 3e 49 66 20 69 6e 73 74 65 61 64 20 74 68 65  i>If instead the
2e70: 20 63 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 53   corresponding S
2e80: 52 49 44 20 64 65 66 69 6e 69 74 69 6f 6e 20 69  RID definition i
2e90: 73 20 6f 66 20 74 68 65 20 3c 62 3e 67 65 6f 67  s of the <b>geog
2ea0: 72 61 70 68 69 63 3c 2f 62 3e 20 74 79 70 65 20  raphic</b> type 
2eb0: 28 3c 69 3e 6c 6f 6e 67 69 74 75 64 65 3c 2f 69  (<i>longitude</i
2ec0: 3e 20 61 6e 64 20 3c 69 3e 6c 61 74 69 74 75 64  > and <i>latitud
2ed0: 65 3c 2f 69 3e 20 61 6e 67 6c 65 73 29 20 61 6c  e</i> angles) al
2ee0: 6c 20 64 69 73 74 61 6e 63 65 73 20 77 69 6c 6c  l distances will
2ef0: 20 61 6c 77 61 79 73 20 62 65 20 6d 65 61 73 75   always be measu
2f00: 72 65 64 20 69 6e 20 3c 62 3e 6d 65 74 72 65 73  red in <b>metres
2f10: 3c 2f 62 3e 2c 20 61 6e 64 20 74 68 65 20 6d 6f  </b>, and the mo
2f20: 73 74 20 70 72 65 63 69 73 65 20 67 65 6f 64 65  st precise geode
2f30: 74 69 63 20 66 6f 72 6d 75 6c 61 73 20 77 69 6c  tic formulas wil
2f40: 6c 20 62 65 20 61 75 74 6f 6d 61 74 69 63 61 6c  l be automatical
2f50: 6c 79 20 61 70 70 6c 69 65 64 2e 3c 2f 6c 69 3e  ly applied.</li>
2f60: 0d 0a 3c 2f 6f 6c 3e 3c 2f 6c 69 3e 0d 0a 3c 2f  ..</ol></li>..</
2f70: 75 6c 3e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 3c  ul></li>..</ul><
2f80: 62 72 3e 0d 0a 3c 68 72 3e 0d 0a 3c 68 33 3e 41  br>..<hr>..<h3>A
2f90: 20 73 65 63 6f 6e 64 20 65 78 61 6d 70 6c 65 20   second example 
2fa0: 6f 66 20 61 20 6d 6f 72 65 20 73 6f 70 68 69 73  of a more sophis
2fb0: 74 69 63 61 74 65 64 20 4b 4e 4e 20 71 75 65 72  ticated KNN quer
2fc0: 79 3c 2f 68 33 3e 0d 0a 3c 76 65 72 62 61 74 69  y</h3>..<verbati
2fd0: 6d 3e 0d 0a 53 45 4c 45 43 54 20 61 2e 70 6f 73  m>..SELECT a.pos
2fe0: 2c 20 62 2e 6e 61 6d 65 2c 20 62 2e 63 6f 75 6e  , b.name, b.coun
2ff0: 74 72 79 2c 20 61 2e 64 69 73 74 61 6e 63 65 20  try, a.distance 
3000: 2f 20 31 30 30 30 2e 30 20 41 53 20 64 69 73 74  / 1000.0 AS dist
3010: 5f 6b 6d 0d 0a 46 52 4f 4d 20 6b 6e 6e 20 41 53  _km..FROM knn AS
3020: 20 61 0d 0a 4a 4f 49 4e 20 61 69 72 70 6f 72 74   a..JOIN airport
3030: 73 20 41 53 20 62 20 4f 4e 20 28 62 2e 67 65 6f  s AS b ON (b.geo
3040: 6e 61 6d 65 69 64 20 3d 20 61 2e 66 69 64 29 0d  nameid = a.fid).
3050: 0a 57 48 45 52 45 20 66 5f 74 61 62 6c 65 5f 6e  .WHERE f_table_n
3060: 61 6d 65 20 3d 20 27 61 69 72 70 6f 72 74 73 27  ame = 'airports'
3070: 20 41 4e 44 20 72 65 66 5f 67 65 6f 6d 65 74 72   AND ref_geometr
3080: 79 20 3d 20 4d 61 6b 65 50 6f 69 6e 74 28 31 30  y = MakePoint(10
3090: 2c 20 34 33 29 20 41 4e 44 20 6d 61 78 5f 69 74  , 43) AND max_it
30a0: 65 6d 73 20 3d 20 35 3b 0d 0a 3c 2f 76 65 72 62  ems = 5;..</verb
30b0: 61 74 69 6d 3e 0d 0a 3c 74 61 62 6c 65 20 62 67  atim>..<table bg
30c0: 63 6f 6c 6f 72 3d 22 23 64 30 66 66 62 30 22 20  color="#d0ffb0" 
30d0: 63 65 6c 6c 73 70 61 63 69 6e 67 3d 22 34 22 20  cellspacing="4" 
30e0: 63 65 6c 6c 70 61 64 64 69 6e 67 3d 22 34 22 20  cellpadding="4" 
30f0: 62 6f 72 64 65 72 3d 22 31 22 3e 0d 0a 3c 74 72  border="1">..<tr
3100: 3e 3c 74 64 20 62 67 63 6f 6c 6f 72 3d 22 23 63  ><td bgcolor="#c
3110: 30 64 64 61 6f 22 3e 3c 62 3e 72 61 6e 6b 3c 2f  0ddao"><b>rank</
3120: 62 3e 3c 2f 74 64 3e 3c 74 64 20 62 67 63 6f 6c  b></td><td bgcol
3130: 6f 72 3d 22 23 63 30 64 64 61 6f 22 3e 3c 62 3e  or="#c0ddao"><b>
3140: 67 65 6f 6e 61 6d 65 69 64 3c 2f 62 3e 3c 2f 74  geonameid</b></t
3150: 64 3e 3c 74 64 20 62 67 63 6f 6c 6f 72 3d 22 23  d><td bgcolor="#
3160: 63 30 64 64 61 6f 22 3e 3c 62 3e 6e 61 6d 65 3c  c0ddao"><b>name<
3170: 2f 62 3e 3c 2f 74 64 3e 3c 74 64 20 62 67 63 6f  /b></td><td bgco
3180: 6c 6f 72 3d 22 23 63 30 64 64 61 6f 22 3e 3c 62  lor="#c0ddao"><b
3190: 3e 63 6f 75 6e 74 72 79 3c 2f 62 3e 3c 2f 74 64  >country</b></td
31a0: 3e 3c 74 64 20 62 67 63 6f 6c 6f 72 3d 22 23 63  ><td bgcolor="#c
31b0: 30 64 64 61 6f 22 3e 3c 62 3e 64 69 73 74 5f 6b  0ddao"><b>dist_k
31c0: 6d 3c 2f 62 3e 3c 2f 74 64 3e 3c 2f 74 72 3e 0d  m</b></td></tr>.
31d0: 0a 3c 74 72 3e 3c 74 64 20 61 6c 69 67 6e 3d 22  .<tr><td align="
31e0: 72 69 67 68 74 22 3e 31 3c 2f 74 64 3e 3c 74 64  right">1</td><td
31f0: 20 61 6c 69 67 6e 3d 22 72 69 67 68 74 22 3e 36   align="right">6
3200: 32 39 39 36 32 33 3c 2f 74 64 3e 3c 74 64 3e 4d  299623</td><td>M
3210: 61 72 69 6e 61 20 44 69 20 43 61 6d 70 6f 3c 2f  arina Di Campo</
3220: 74 64 3e 3c 74 64 3e 49 54 3c 2f 74 64 3e 3c 74  td><td>IT</td><t
3230: 64 20 61 6c 69 67 6e 3d 22 72 69 67 68 74 22 3e  d align="right">
3240: 33 33 2e 30 34 33 33 32 30 3c 2f 74 64 3e 3c 2f  33.043320</td></
3250: 74 72 3e 0d 0a 3c 74 72 3e 3c 74 64 20 61 6c 69  tr>..<tr><td ali
3260: 67 6e 3d 22 72 69 67 68 74 22 3e 32 3c 2f 74 64  gn="right">2</td
3270: 3e 3c 74 64 20 61 6c 69 67 6e 3d 22 72 69 67 68  ><td align="righ
3280: 74 22 3e 36 32 39 39 33 39 32 3c 2f 74 64 3e 3c  t">6299392</td><
3290: 74 64 3e 42 61 73 74 69 61 2d 50 6f 72 65 74 74  td>Bastia-Porett
32a0: 61 3c 2f 74 64 3e 3c 74 64 3e 46 52 3c 2f 74 64  a</td><td>FR</td
32b0: 3e 3c 74 64 20 61 6c 69 67 6e 3d 22 72 69 67 68  ><td align="righ
32c0: 74 22 3e 36 35 2e 32 32 36 35 37 33 3c 2f 74 64  t">65.226573</td
32d0: 3e 3c 2f 74 72 3e 0d 0a 3c 74 72 3e 3c 74 64 20  ></tr>..<tr><td 
32e0: 61 6c 69 67 6e 3d 22 72 69 67 68 74 22 3e 33 3c  align="right">3<
32f0: 2f 74 64 3e 3c 74 64 20 61 6c 69 67 6e 3d 22 72  /td><td align="r
3300: 69 67 68 74 22 3e 36 32 39 39 36 32 38 3c 2f 74  ight">6299628</t
3310: 64 3e 3c 74 64 3e 50 69 73 61 20 2f 20 53 2e 20  d><td>Pisa / S. 
3320: 47 69 75 73 74 6f 3c 2f 74 64 3e 3c 74 64 3e 49  Giusto</td><td>I
3330: 54 3c 2f 74 64 3e 3c 74 64 20 61 6c 69 67 6e 3d  T</td><td align=
3340: 22 72 69 67 68 74 22 3e 38 32 2e 33 38 37 30 31  "right">82.38701
3350: 34 3c 2f 74 64 3e 3c 2f 74 72 3e 0d 0a 3c 74 72  4</td></tr>..<tr
3360: 3e 3c 74 64 20 61 6c 69 67 6e 3d 22 72 69 67 68  ><td align="righ
3370: 74 22 3e 34 3c 2f 74 64 3e 3c 74 64 20 61 6c 69  t">4</td><td ali
3380: 67 6e 3d 22 72 69 67 68 74 22 3e 36 32 39 39 36  gn="right">62996
3390: 33 30 3c 2f 74 64 3e 3c 74 64 3e 47 72 6f 73 73  30</td><td>Gross
33a0: 65 74 6f 20 41 69 72 70 6f 72 74 3c 2f 74 64 3e  eto Airport</td>
33b0: 3c 74 64 3e 49 54 3c 2f 74 64 3e 3c 74 64 20 61  <td>IT</td><td a
33c0: 6c 69 67 6e 3d 22 72 69 67 68 74 22 3e 39 31 2e  lign="right">91.
33d0: 35 34 39 37 37 33 3c 2f 74 64 3e 3c 2f 74 72 3e  549773</td></tr>
33e0: 0d 0a 3c 74 72 3e 3c 74 64 20 61 6c 69 67 6e 3d  ..<tr><td align=
33f0: 22 72 69 67 68 74 22 3e 35 3c 2f 74 64 3e 3c 74  "right">5</td><t
3400: 64 20 61 6c 69 67 6e 3d 22 72 69 67 68 74 22 3e  d align="right">
3410: 36 36 39 34 34 39 35 3c 2f 74 64 3e 3c 74 64 3e  6694495</td><td>
3420: 43 6f 72 74 65 3c 2f 74 64 3e 3c 74 64 3e 46 52  Corte</td><td>FR
3430: 3c 2f 74 64 3e 3c 74 64 20 61 6c 69 67 6e 3d 22  </td><td align="
3440: 72 69 67 68 74 22 3e 31 30 32 2e 38 31 39 37 37  right">102.81977
3450: 38 3c 2f 74 64 3e 3c 2f 74 72 3e 0d 0a 3c 2f 74  8</td></tr>..</t
3460: 61 62 6c 65 3e 3c 62 72 3e 0d 0a 54 68 69 73 20  able><br>..This 
3470: 73 65 63 6f 6e 64 20 4b 4e 4e 20 71 75 65 72 79  second KNN query
3480: 20 77 69 6c 6c 20 72 65 74 75 72 6e 20 74 68 65   will return the
3490: 20 73 61 6d 65 20 69 64 65 6e 74 69 63 61 6c 20   same identical 
34a0: 72 65 73 75 6c 74 73 20 77 65 20 61 6c 72 65 61  results we alrea
34b0: 64 79 20 67 6f 74 20 62 65 66 6f 72 65 20 62 79  dy got before by
34c0: 20 75 73 69 6e 67 20 74 68 65 20 73 69 6c 6c 79   using the silly
34d0: 20 6e 61 69 76 65 20 61 70 70 72 6f 61 63 68 2e   naive approach.
34e0: 3c 62 72 3e 0d 0a 54 68 65 20 73 74 72 69 6b 69  <br>..The striki
34f0: 6e 67 20 64 69 66 66 65 72 65 6e 63 65 20 69 73  ng difference is
3500: 20 74 68 61 74 20 74 68 69 73 20 4b 4e 4e 20 71   that this KNN q
3510: 75 65 72 79 20 73 75 63 63 65 73 73 66 75 6c 6c  uery successfull
3520: 79 20 63 6f 6d 70 6c 65 74 65 64 20 69 6e 20 6a  y completed in j
3530: 75 73 74 20 61 20 66 72 61 63 74 69 6f 6e 20 6f  ust a fraction o
3540: 66 20 61 20 73 65 63 6f 6e 64 2c 20 77 68 69 6c  f a second, whil
3550: 73 74 20 65 78 65 63 75 74 69 6e 67 20 74 68 65  st executing the
3560: 20 66 69 72 73 74 20 69 6e 65 66 66 69 63 69 65   first inefficie
3570: 6e 74 20 71 75 65 72 69 65 73 20 72 65 71 75 69  nt queries requi
3580: 72 65 64 20 6d 61 6e 79 20 73 65 63 6f 6e 64 73  red many seconds
3590: 20 28 61 6e 64 20 70 6c 65 61 73 65 20 63 6f 6e   (and please con
35a0: 73 69 64 65 72 20 74 68 61 74 20 74 68 69 73 20  sider that this 
35b0: 6f 6e 65 20 69 73 20 61 20 72 65 6c 61 74 69 76  one is a relativ
35c0: 65 6c 79 20 73 6d 61 6c 6c 20 64 61 74 61 73 65  ely small datase
35d0: 74 29 2e 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 62 3e  t).<br><br>..<b>
35e0: 4c 65 73 73 6f 6e 20 74 6f 20 6c 65 61 72 6e 3c  Lesson to learn<
35f0: 2f 62 3e 3a 20 4b 4e 4e 20 71 75 65 72 69 65 73  /b>: KNN queries
3600: 20 61 72 65 20 72 65 61 6c 6c 79 20 65 66 66 69   are really effi
3610: 63 69 65 6e 74 20 61 6e 64 20 66 61 73 74 2c 20  cient and fast, 
3620: 62 65 63 61 75 73 65 20 74 68 65 79 20 64 69 72  because they dir
3630: 65 63 74 6c 79 20 69 6e 74 65 72 61 63 74 20 77  ectly interact w
3640: 69 74 68 20 74 68 65 20 6c 6f 77 65 72 6d 6f 73  ith the lowermos
3650: 74 20 6c 65 76 65 6c 73 20 6f 66 20 74 68 65 20  t levels of the 
3660: 52 2a 54 72 65 65 20 53 70 61 74 69 61 6c 20 49  R*Tree Spatial I
3670: 6e 64 65 78 20 69 6d 70 6c 65 6d 65 6e 74 61 74  ndex implementat
3680: 69 6f 6e 2e 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 68  ion.<br><br>..<h
3690: 72 3e 0d 0a 3c 68 33 3e 41 20 74 68 69 72 64 20  r>..<h3>A third 
36a0: 65 78 61 6d 70 6c 65 20 6f 66 20 4b 4e 4e 20 71  example of KNN q
36b0: 75 65 72 79 3c 2f 68 33 3e 0d 0a 3c 76 65 72 62  uery</h3>..<verb
36c0: 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 61 2e  atim>..SELECT a.
36d0: 70 6f 73 20 41 53 20 72 61 6e 6b 2c 20 62 2e 67  pos AS rank, b.g
36e0: 65 6f 6e 61 6d 65 69 64 2c 20 62 2e 6e 61 6d 65  eonameid, b.name
36f0: 2c 20 62 2e 63 6f 75 6e 74 72 79 2c 20 61 2e 64  , b.country, a.d
3700: 69 73 74 61 6e 63 65 20 2f 20 31 30 30 30 2e 30  istance / 1000.0
3710: 20 41 53 20 64 69 73 74 5f 6b 6d 0d 0a 46 52 4f   AS dist_km..FRO
3720: 4d 20 6b 6e 6e 20 41 53 20 61 0d 0a 4a 4f 49 4e  M knn AS a..JOIN
3730: 20 61 69 72 70 6f 72 74 73 20 41 53 20 62 20 4f   airports AS b O
3740: 4e 20 28 62 2e 67 65 6f 6e 61 6d 65 69 64 20 3d  N (b.geonameid =
3750: 20 61 2e 66 69 64 29 0d 0a 57 48 45 52 45 20 66   a.fid)..WHERE f
3760: 5f 74 61 62 6c 65 5f 6e 61 6d 65 20 3d 20 27 61  _table_name = 'a
3770: 69 72 70 6f 72 74 73 27 20 41 4e 44 20 72 65 66  irports' AND ref
3780: 5f 67 65 6f 6d 65 74 72 79 20 3d 20 4d 61 6b 65  _geometry = Make
3790: 50 6f 69 6e 74 28 2d 31 37 2e 33 2c 20 2d 34 34  Point(-17.3, -44
37a0: 29 20 41 4e 44 20 6d 61 78 5f 69 74 65 6d 73 20  ) AND max_items 
37b0: 3d 20 35 3b 0d 0a 3c 2f 76 65 72 62 61 74 69 6d  = 5;..</verbatim
37c0: 3e 0d 0a 3c 74 61 62 6c 65 20 62 67 63 6f 6c 6f  >..<table bgcolo
37d0: 72 3d 22 23 64 30 66 66 62 30 22 20 63 65 6c 6c  r="#d0ffb0" cell
37e0: 73 70 61 63 69 6e 67 3d 22 34 22 20 63 65 6c 6c  spacing="4" cell
37f0: 70 61 64 64 69 6e 67 3d 22 34 22 20 62 6f 72 64  padding="4" bord
3800: 65 72 3d 22 31 22 3e 0d 0a 3c 74 72 3e 3c 74 64  er="1">..<tr><td
3810: 20 62 67 63 6f 6c 6f 72 3d 22 23 63 30 64 64 61   bgcolor="#c0dda
3820: 6f 22 3e 3c 62 3e 72 61 6e 6b 3c 2f 62 3e 3c 2f  o"><b>rank</b></
3830: 74 64 3e 3c 74 64 20 62 67 63 6f 6c 6f 72 3d 22  td><td bgcolor="
3840: 23 63 30 64 64 61 6f 22 3e 3c 62 3e 67 65 6f 6e  #c0ddao"><b>geon
3850: 61 6d 65 69 64 3c 2f 62 3e 3c 2f 74 64 3e 3c 74  ameid</b></td><t
3860: 64 20 62 67 63 6f 6c 6f 72 3d 22 23 63 30 64 64  d bgcolor="#c0dd
3870: 61 6f 22 3e 3c 62 3e 6e 61 6d 65 3c 2f 62 3e 3c  ao"><b>name</b><
3880: 2f 74 64 3e 3c 74 64 20 62 67 63 6f 6c 6f 72 3d  /td><td bgcolor=
3890: 22 23 63 30 64 64 61 6f 22 3e 3c 62 3e 63 6f 75  "#c0ddao"><b>cou
38a0: 6e 74 72 79 3c 2f 62 3e 3c 2f 74 64 3e 3c 74 64  ntry</b></td><td
38b0: 20 62 67 63 6f 6c 6f 72 3d 22 23 63 30 64 64 61   bgcolor="#c0dda
38c0: 6f 22 3e 3c 62 3e 64 69 73 74 5f 6b 6d 3c 2f 62  o"><b>dist_km</b
38d0: 3e 3c 2f 74 64 3e 3c 2f 74 72 3e 0d 0a 3c 74 72  ></td></tr>..<tr
38e0: 3e 3c 74 64 20 61 6c 69 67 6e 3d 22 72 69 67 68  ><td align="righ
38f0: 74 22 3e 31 3c 2f 74 64 3e 3c 74 64 20 61 6c 69  t">1</td><td ali
3900: 67 6e 3d 22 72 69 67 68 74 22 3e 37 36 36 38 34  gn="right">76684
3910: 33 33 3c 2f 74 64 3e 3c 74 64 3e 43 61 62 6f 20  33</td><td>Cabo 
3920: 46 72 69 6f 20 41 69 72 70 6f 72 74 3c 2f 74 64  Frio Airport</td
3930: 3e 3c 74 64 3e 42 52 3c 2f 74 64 3e 3c 74 64 20  ><td>BR</td><td 
3940: 61 6c 69 67 6e 3d 22 72 69 67 68 74 22 3e 33 32  align="right">32
3950: 35 36 2e 35 38 39 39 36 34 3c 2f 74 64 3e 3c 2f  56.589964</td></
3960: 74 72 3e 0d 0a 3c 74 72 3e 3c 74 64 20 61 6c 69  tr>..<tr><td ali
3970: 67 6e 3d 22 72 69 67 68 74 22 3e 32 3c 2f 74 64  gn="right">2</td
3980: 3e 3c 74 64 20 61 6c 69 67 6e 3d 22 72 69 67 68  ><td align="righ
3990: 74 22 3e 33 33 35 39 30 30 31 3c 2f 74 64 3e 3c  t">3359001</td><
39a0: 74 64 3e 59 6f 75 6e 67 73 66 69 65 6c 64 3c 2f  td>Youngsfield</
39b0: 74 64 3e 3c 74 64 3e 5a 41 3c 2f 74 64 3e 3c 74  td><td>ZA</td><t
39c0: 64 20 61 6c 69 67 6e 3d 22 72 69 67 68 74 22 3e  d align="right">
39d0: 33 32 36 32 2e 32 37 31 30 32 37 3c 2f 74 64 3e  3262.271027</td>
39e0: 3c 2f 74 72 3e 0d 0a 3c 74 72 3e 3c 74 64 20 61  </tr>..<tr><td a
39f0: 6c 69 67 6e 3d 22 72 69 67 68 74 22 3e 33 3c 2f  lign="right">3</
3a00: 74 64 3e 3c 74 64 20 61 6c 69 67 6e 3d 22 72 69  td><td align="ri
3a10: 67 68 74 22 3e 37 37 33 30 31 35 33 3c 2f 74 64  ght">7730153</td
3a20: 3e 3c 74 64 3e 55 6d 62 65 72 74 6f 20 4d 6f 64  ><td>Umberto Mod
3a30: 69 61 6e 6f 20 41 69 72 70 6f 72 74 3c 2f 74 64  iano Airport</td
3a40: 3e 3c 74 64 3e 42 52 3c 2f 74 64 3e 3c 74 64 20  ><td>BR</td><td 
3a50: 61 6c 69 67 6e 3d 22 72 69 67 68 74 22 3e 33 32  align="right">32
3a60: 36 32 2e 36 39 33 30 33 32 3c 2f 74 64 3e 3c 2f  62.693032</td></
3a70: 74 72 3e 0d 0a 3c 74 72 3e 3c 74 64 20 61 6c 69  tr>..<tr><td ali
3a80: 67 6e 3d 22 72 69 67 68 74 22 3e 34 3c 2f 74 64  gn="right">4</td
3a90: 3e 3c 74 64 20 61 6c 69 67 6e 3d 22 72 69 67 68  ><td align="righ
3aa0: 74 22 3e 33 33 36 32 33 35 35 3c 2f 74 64 3e 3c  t">3362355</td><
3ab0: 74 64 3e 52 6f 62 62 65 6e 20 49 73 6c 61 6e 64  td>Robben Island
3ac0: 3c 2f 74 64 3e 3c 74 64 3e 5a 41 3c 2f 74 64 3e  </td><td>ZA</td>
3ad0: 3c 74 64 20 61 6c 69 67 6e 3d 22 72 69 67 68 74  <td align="right
3ae0: 22 3e 33 32 36 35 2e 33 30 32 35 36 38 3c 2f 74  ">3265.302568</t
3af0: 64 3e 3c 2f 74 72 3e 0d 0a 3c 74 72 3e 3c 74 64  d></tr>..<tr><td
3b00: 20 61 6c 69 67 6e 3d 22 72 69 67 68 74 22 3e 35   align="right">5
3b10: 3c 2f 74 64 3e 3c 74 64 20 61 6c 69 67 6e 3d 22  </td><td align="
3b20: 72 69 67 68 74 22 3e 36 33 30 30 36 32 32 3c 2f  right">6300622</
3b30: 74 64 3e 3c 74 64 3e 53 2e 20 50 2e 20 41 6c 64  td><td>S. P. Ald
3b40: 65 69 61 20 41 65 72 6f 64 72 6f 6d 65 3c 2f 74  eia Aerodrome</t
3b50: 64 3e 3c 74 64 3e 42 52 3c 2f 74 64 3e 3c 74 64  d><td>BR</td><td
3b60: 20 61 6c 69 67 6e 3d 22 72 69 67 68 74 22 3e 33   align="right">3
3b70: 32 36 37 2e 32 33 34 31 34 32 3c 2f 74 64 3e 3c  267.234142</td><
3b80: 2f 74 72 3e 0d 0a 3c 2f 74 61 62 6c 65 3e 3c 62  /tr>..</table><b
3b90: 72 3e 0d 0a 54 68 69 73 20 6c 61 73 74 20 4b 4e  r>..This last KN
3ba0: 4e 20 71 75 65 72 79 20 69 73 20 76 65 72 79 20  N query is very 
3bb0: 73 69 6d 69 6c 61 72 20 74 6f 20 74 68 65 20 70  similar to the p
3bc0: 72 65 76 69 6f 75 73 20 6f 6e 65 2e 3c 62 72 3e  revious one.<br>
3bd0: 0d 0a 54 68 69 73 20 74 69 6d 65 20 77 65 27 76  ..This time we'v
3be0: 65 20 70 6c 61 63 65 64 20 74 68 65 20 6f 72 69  e placed the ori
3bf0: 67 69 6e 20 6c 6f 63 61 74 69 6f 6e 20 73 6f 6d  gin location som
3c00: 65 77 68 65 72 65 20 69 6e 74 6f 20 74 68 65 20  ewhere into the 
3c10: 53 6f 75 74 68 20 41 74 6c 61 6e 74 69 63 20 62  South Atlantic b
3c20: 6c 75 65 20 64 65 65 70 20 77 61 74 65 72 73 20  lue deep waters 
3c30: 28 6d 6f 72 65 20 6f 72 20 6c 65 73 73 20 6d 69  (more or less mi
3c40: 64 77 61 79 20 66 72 6f 6d 20 62 6f 74 68 20 42  dway from both B
3c50: 72 61 7a 69 6c 20 61 6e 64 20 53 6f 75 74 68 20  razil and South 
3c60: 41 66 72 69 63 61 29 20 61 6e 64 20 63 6f 6e 73  Africa) and cons
3c70: 65 71 75 65 6e 74 6c 79 20 74 68 65 20 6e 65 61  equently the nea
3c80: 72 65 73 74 20 61 69 72 70 6f 72 74 73 20 61 72  rest airports ar
3c90: 65 20 6e 6f 74 20 72 65 61 6c 6c 79 20 73 6f 20  e not really so 
3ca0: 6e 65 61 72 2c 20 62 65 63 61 75 73 65 20 74 68  near, because th
3cb0: 65 79 20 61 72 65 20 6c 6f 63 61 74 65 64 20 6d  ey are located m
3cc0: 61 6e 79 20 74 68 6f 75 73 61 6e 64 73 20 4b 6d  any thousands Km
3cd0: 20 61 77 61 79 2e 0d 0a 41 73 20 79 6f 75 20 63   away...As you c
3ce0: 61 6e 20 65 61 73 69 6c 79 20 63 68 65 63 6b 20  an easily check 
3cf0: 62 79 20 79 6f 75 72 73 65 6c 66 20 61 20 4b 4e  by yourself a KN
3d00: 4e 20 71 75 65 72 79 20 77 69 6c 6c 20 62 72 69  N query will bri
3d10: 6c 6c 69 61 6e 74 6c 79 20 70 65 72 66 6f 72 6d  lliantly perform
3d20: 20 65 76 65 6e 20 75 6e 64 65 72 20 73 75 63 68   even under such
3d30: 20 75 6e 75 73 75 61 6c 20 63 6f 6e 64 69 74 69   unusual conditi
3d40: 6f 6e 73 2e 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 69  ons.<br><br>..<i
3d50: 6d 67 20 73 72 63 3d 22 68 74 74 70 73 3a 2f 2f  mg src="https://
3d60: 77 77 77 2e 67 61 69 61 2d 67 69 73 2e 69 74 2f  www.gaia-gis.it/
3d70: 67 61 69 61 2d 73 69 6e 73 2f 6b 6e 6e 2f 73 6f  gaia-sins/knn/so
3d80: 75 74 68 2d 61 74 6c 61 6e 74 69 63 2e 70 6e 67  uth-atlantic.png
3d90: 22 20 61 6c 74 3d 22 53 6f 75 74 68 20 41 74 6c  " alt="South Atl
3da0: 61 6e 74 69 63 22 3e 3c 62 72 3e 3c 62 72 3e 0d  antic"><br><br>.
3db0: 0a 3c 62 3e 4c 65 73 73 6f 6e 20 74 6f 20 6c 65  .<b>Lesson to le
3dc0: 61 72 6e 3c 2f 62 3e 3a 20 4b 4e 4e 20 71 75 65  arn</b>: KNN que
3dd0: 72 69 65 73 20 6e 65 76 65 72 20 61 73 73 75 6d  ries never assum
3de0: 65 20 61 6e 79 20 70 72 65 64 65 66 69 6e 65 64  e any predefined
3df0: 20 64 69 73 74 72 69 62 75 74 69 6f 6e 20 6f 66   distribution of
3e00: 20 74 68 65 20 73 65 61 72 63 68 65 64 20 69 74   the searched it
3e10: 65 6d 73 2c 20 61 6e 64 20 63 61 6e 20 61 75 74  ems, and can aut
3e20: 6f 6d 61 74 69 63 61 6c 6c 79 20 61 64 61 70 74  omatically adapt
3e30: 20 69 6e 20 61 20 76 65 72 79 20 65 66 66 69 63   in a very effic
3e40: 69 65 6e 74 20 77 61 79 20 74 6f 20 74 68 65 20  ient way to the 
3e50: 6d 6f 73 74 20 69 72 72 65 67 75 6c 61 72 20 73  most irregular s
3e60: 61 6d 70 6c 65 20 64 69 73 74 72 69 62 75 74 69  ample distributi
3e70: 6f 6e 73 2e 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 68  ons.<br><br>..<h
3e80: 72 3e 0d 0a 3c 68 32 3e 41 64 76 61 6e 63 65 64  r>..<h2>Advanced
3e90: 20 74 75 74 6f 72 69 61 6c 3c 2f 68 32 3e 0d 0a   tutorial</h2>..
3ea0: 59 6f 75 20 63 61 6e 20 65 76 65 6e 74 75 61 6c  You can eventual
3eb0: 6c 79 20 3c 61 20 68 72 65 66 3d 22 68 74 74 70  ly <a href="http
3ec0: 73 3a 2f 2f 77 77 77 2e 67 61 69 61 2d 67 69 73  s://www.gaia-gis
3ed0: 2e 69 74 2f 67 61 69 61 2d 73 69 6e 73 2f 6b 6e  .it/gaia-sins/kn
3ee0: 6e 2f 74 75 73 63 61 6e 79 5f 68 6f 75 73 65 6e  n/tuscany_housen
3ef0: 75 6d 62 65 72 73 2e 37 7a 22 3e 64 6f 77 6e 6c  umbers.7z">downl
3f00: 6f 61 64 3c 2f 61 3e 20 61 20 73 61 6d 70 6c 65  oad</a> a sample
3f10: 20 64 62 2d 66 69 6c 65 20 65 78 61 63 74 6c 79   db-file exactly
3f20: 20 63 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 74   corresponding t
3f30: 6f 20 74 68 65 20 70 72 61 63 74 69 63 61 6c 20  o the practical 
3f40: 65 78 61 6d 70 6c 65 73 20 77 65 27 6c 6c 20 75  examples we'll u
3f50: 73 65 20 69 6e 20 74 68 69 73 20 61 64 76 61 6e  se in this advan
3f60: 63 65 64 20 74 75 74 6f 72 69 61 6c 2e 3c 62 72  ced tutorial.<br
3f70: 3e 3c 62 72 3e 0d 0a 54 68 69 73 20 69 73 20 61  ><br>..This is a
3f80: 20 6d 75 63 68 20 6d 6f 72 65 20 64 65 6d 61 6e   much more deman
3f90: 64 69 6e 67 20 64 61 74 61 73 65 74 20 63 6f 72  ding dataset cor
3fa0: 72 65 73 70 6f 6e 64 69 6e 67 20 74 6f 20 61 20  responding to a 
3fb0: 63 6f 6c 6c 65 63 74 69 6f 6e 20 6f 66 20 61 62  collection of ab
3fc0: 6f 75 74 20 3c 62 3e 32 2e 34 20 6d 69 6c 6c 69  out <b>2.4 milli
3fd0: 6f 6e 20 68 6f 75 73 65 20 6e 75 6d 62 65 72 73  on house numbers
3fe0: 3c 2f 62 3e 2e 3c 62 72 3e 0d 0a 54 68 65 20 6f  </b>.<br>..The o
3ff0: 72 69 67 69 6e 61 6c 20 69 6e 70 75 74 20 73 68  riginal input sh
4000: 61 70 65 66 69 6c 65 20 77 61 73 20 64 6f 77 6e  apefile was down
4010: 6c 6f 61 64 65 64 20 66 72 6f 6d 20 3c 61 20 68  loaded from <a h
4020: 72 65 66 3d 22 68 74 74 70 3a 2f 2f 77 77 77 35  ref="http://www5
4030: 30 32 2e 72 65 67 69 6f 6e 65 2e 74 6f 73 63 61  02.regione.tosca
4040: 6e 61 2e 69 74 2f 67 65 6f 73 63 6f 70 69 6f 2f  na.it/geoscopio/
4050: 63 61 72 74 6f 74 65 63 61 2e 68 74 6d 6c 22 3e  cartoteca.html">
4060: 54 75 73 63 61 6e 79 20 52 65 67 69 6f 6e 3c 2f  Tuscany Region</
4070: 61 3e 20 28 3c 62 3e 3c 69 3e 47 72 61 66 6f 20  a> (<b><i>Grafo 
4080: 53 74 72 61 64 61 6c 65 20 63 69 76 69 63 69 2e  Stradale civici.
4090: 73 68 70 3c 2f 69 3e 3c 2f 62 3e 29 20 61 6e 64  shp</i></b>) and
40a0: 20 77 61 73 20 73 75 62 73 65 71 75 65 6e 74 6c   was subsequentl
40b0: 79 20 72 65 61 72 72 61 6e 67 65 64 20 69 6e 74  y rearranged int
40c0: 6f 20 61 20 6d 6f 72 65 20 63 6f 6e 76 65 6e 69  o a more conveni
40d0: 65 6e 74 20 66 6f 72 6d 2e 3c 62 72 3e 0d 0a 54  ent form.<br>..T
40e0: 68 65 20 64 61 74 61 73 65 74 20 69 73 20 72 65  he dataset is re
40f0: 6c 65 61 73 65 64 20 75 6e 64 65 72 20 74 68 65  leased under the
4100: 20 3c 62 3e 43 43 2d 42 59 2d 53 41 20 34 2e 30   <b>CC-BY-SA 4.0
4110: 3c 2f 62 3e 20 6c 69 63 65 6e 73 65 20 74 65 72  </b> license ter
4120: 6d 73 2e 3c 62 72 3e 0d 0a 54 68 65 20 72 65 66  ms.<br>..The ref
4130: 65 72 65 6e 63 65 20 73 79 73 74 65 6d 20 69 73  erence system is
4140: 20 3c 62 3e 33 30 30 33 20 4d 6f 6e 74 65 20 4d   <b>3003 Monte M
4150: 61 72 69 6f 20 2f 20 49 74 61 6c 79 20 7a 6f 6e  ario / Italy zon
4160: 65 20 31 3c 2f 62 3e 3b 20 74 68 69 73 20 69 73  e 1</b>; this is
4170: 20 61 20 3c 62 3e 70 6c 61 6e 61 72 3c 2f 62 3e   a <b>planar</b>
4180: 20 28 3c 69 3e 70 72 6f 6a 65 63 74 65 64 3c 2f   (<i>projected</
4190: 69 3e 29 20 72 65 66 65 72 65 6e 63 65 20 73 79  i>) reference sy
41a0: 73 74 65 6d 20 6d 65 61 73 75 72 65 64 20 69 6e  stem measured in
41b0: 20 3c 62 3e 6d 65 74 72 65 73 3c 2f 62 3e 2e 0d   <b>metres</b>..
41c0: 0a 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 76 65 72 62  .<br><br>..<verb
41d0: 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 61 2e  atim>..SELECT a.
41e0: 70 6f 73 20 41 53 20 72 61 6e 6b 2c 20 61 2e 66  pos AS rank, a.f
41f0: 69 64 20 41 53 20 66 69 64 2c 20 61 2e 64 69 73  id AS fid, a.dis
4200: 74 61 6e 63 65 20 41 53 20 64 69 73 74 5f 6d 2c  tance AS dist_m,
4210: 20 64 2e 70 72 6f 76 20 41 53 20 70 72 6f 76 69   d.prov AS provi
4220: 6e 63 65 2c 0d 0a 20 20 20 20 20 20 20 64 2e 6e  nce,..       d.n
4230: 6f 6d 65 20 41 53 20 6d 75 6e 69 63 69 70 61 6c  ome AS municipal
4240: 69 74 79 2c 20 63 2e 74 6f 70 6f 6e 69 6d 6f 20  ity, c.toponimo 
4250: 41 53 20 73 74 72 65 65 74 5f 6e 61 6d 65 2c 20  AS street_name, 
4260: 62 2e 63 69 76 69 63 6f 20 41 53 20 68 6f 75 73  b.civico AS hous
4270: 65 5f 6e 75 6d 2c 0d 0a 20 20 20 20 20 20 20 62  e_num,..       b
4280: 2e 67 65 6f 6d 20 41 53 20 67 65 6f 6d 0d 0a 46  .geom AS geom..F
4290: 52 4f 4d 20 6b 6e 6e 20 41 53 20 61 0d 0a 4a 4f  ROM knn AS a..JO
42a0: 49 4e 20 63 69 76 69 63 69 20 41 53 20 62 20 4f  IN civici AS b O
42b0: 4e 20 28 62 2e 72 6f 77 69 64 20 3d 20 61 2e 66  N (b.rowid = a.f
42c0: 69 64 29 0d 0a 4a 4f 49 4e 20 74 6f 70 6f 6e 69  id)..JOIN toponi
42d0: 6d 69 20 41 53 20 63 20 4f 4e 20 28 63 2e 66 69  mi AS c ON (c.fi
42e0: 64 20 3d 20 62 2e 69 64 5f 74 6f 70 6f 6e 69 6d  d = b.id_toponim
42f0: 6f 29 0d 0a 4a 4f 49 4e 20 63 6f 6d 75 6e 69 20  o)..JOIN comuni 
4300: 41 53 20 64 20 4f 4e 20 28 64 2e 66 69 64 20 3d  AS d ON (d.fid =
4310: 20 63 2e 69 64 5f 63 6f 6d 75 6e 65 29 0d 0a 57   c.id_comune)..W
4320: 48 45 52 45 20 61 2e 66 5f 74 61 62 6c 65 5f 6e  HERE a.f_table_n
4330: 61 6d 65 20 3d 20 27 63 69 76 69 63 69 27 20 41  ame = 'civici' A
4340: 4e 44 20 61 2e 72 65 66 5f 67 65 6f 6d 65 74 72  ND a.ref_geometr
4350: 79 20 3d 20 4d 61 6b 65 50 6f 69 6e 74 28 31 37  y = MakePoint(17
4360: 33 33 30 30 33 2c 20 34 38 31 36 33 33 32 2c 20  33003, 4816332, 
4370: 33 30 30 33 29 20 41 4e 44 20 61 2e 6d 61 78 5f  3003) AND a.max_
4380: 69 74 65 6d 73 20 3d 20 31 30 3b 0d 0a 0d 0a 53  items = 10;....S
4390: 45 4c 45 43 54 20 61 2e 70 6f 73 20 41 53 20 72  ELECT a.pos AS r
43a0: 61 6e 6b 2c 20 61 2e 66 69 64 20 41 53 20 66 69  ank, a.fid AS fi
43b0: 64 2c 20 61 2e 64 69 73 74 61 6e 63 65 20 41 53  d, a.distance AS
43c0: 20 64 69 73 74 5f 6d 2c 20 62 2e 70 72 6f 76 20   dist_m, b.prov 
43d0: 41 53 20 70 72 6f 76 69 6e 63 65 2c 0d 0a 20 20  AS province,..  
43e0: 20 20 20 20 20 62 2e 63 6f 6d 75 6e 65 20 41 53       b.comune AS
43f0: 20 6d 75 6e 69 63 69 70 61 6c 69 74 79 2c 20 62   municipality, b
4400: 2e 74 6f 70 6f 6e 69 6d 6f 20 41 53 20 73 74 72  .toponimo AS str
4410: 65 65 74 5f 6e 61 6d 65 2c 20 62 2e 63 69 76 69  eet_name, b.civi
4420: 63 6f 20 41 53 20 68 6f 75 73 65 5f 6e 75 6d 2c  co AS house_num,
4430: 20 0d 0a 20 20 20 20 20 20 20 62 2e 67 65 6f 6d   ..       b.geom
4440: 20 41 53 20 67 65 6f 6d 0d 0a 46 52 4f 4d 20 6b   AS geom..FROM k
4450: 6e 6e 20 41 53 20 61 0d 0a 4a 4f 49 4e 20 76 77  nn AS a..JOIN vw
4460: 5f 63 69 76 69 63 69 20 41 53 20 62 20 4f 4e 20  _civici AS b ON 
4470: 28 62 2e 72 6f 77 69 64 20 3d 20 61 2e 66 69 64  (b.rowid = a.fid
4480: 29 0d 0a 57 48 45 52 45 20 61 2e 66 5f 74 61 62  )..WHERE a.f_tab
4490: 6c 65 5f 6e 61 6d 65 20 3d 20 27 76 77 5f 63 69  le_name = 'vw_ci
44a0: 76 69 63 69 27 20 41 4e 44 20 61 2e 72 65 66 5f  vici' AND a.ref_
44b0: 67 65 6f 6d 65 74 72 79 20 3d 20 4d 61 6b 65 50  geometry = MakeP
44c0: 6f 69 6e 74 28 31 37 33 33 30 30 33 2c 20 34 38  oint(1733003, 48
44d0: 31 36 33 33 32 2c 20 33 30 30 33 29 20 41 4e 44  16332, 3003) AND
44e0: 20 61 2e 6d 61 78 5f 69 74 65 6d 73 20 3d 20 31   a.max_items = 1
44f0: 30 3b 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d  0;..</verbatim>.
4500: 0a 54 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 6d  .The following m
4510: 61 70 20 63 6f 72 72 65 73 70 6f 6e 64 73 20 74  ap corresponds t
4520: 6f 20 74 68 65 20 61 62 6f 76 65 20 71 75 65 72  o the above quer
4530: 69 65 73 3a 20 74 68 65 20 6f 72 69 67 69 6e 20  ies: the origin 
4540: 70 6f 69 6e 74 20 69 73 20 70 6f 73 69 74 69 6f  point is positio
4550: 6e 65 64 20 6f 6e 20 61 20 72 6f 61 64 20 6a 75  ned on a road ju
4560: 6e 63 74 69 6f 6e 20 69 6e 20 74 68 65 20 63 65  nction in the ce
4570: 6e 74 72 61 6c 20 61 72 65 61 20 6f 66 20 61 20  ntral area of a 
4580: 64 65 6e 73 65 6c 79 20 70 6f 70 75 6c 61 74 65  densely populate
4590: 64 20 74 6f 77 6e 20 28 41 72 65 7a 7a 6f 29 2e  d town (Arezzo).
45a0: 3c 62 72 3e 0d 0a 4e 6f 74 20 73 75 72 70 72 69  <br>..Not surpri
45b0: 73 69 6e 67 6c 79 20 74 68 65 20 74 65 6e 20 6e  singly the ten n
45c0: 65 61 72 65 73 74 20 68 6f 75 73 65 20 6e 75 6d  earest house num
45d0: 62 65 72 73 20 68 61 76 65 20 62 65 65 6e 20 6c  bers have been l
45e0: 6f 63 61 74 65 64 20 77 69 74 68 69 6e 20 61 20  ocated within a 
45f0: 72 61 64 69 75 73 20 6f 66 20 61 62 6f 75 74 20  radius of about 
4600: 31 30 6d 2e 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 69  10m.<br><br>..<i
4610: 6d 67 20 73 72 63 3d 22 68 74 74 70 73 3a 2f 2f  mg src="https://
4620: 77 77 77 2e 67 61 69 61 2d 67 69 73 2e 69 74 2f  www.gaia-gis.it/
4630: 67 61 69 61 2d 73 69 6e 73 2f 6b 6e 6e 2f 68 6f  gaia-sins/knn/ho
4640: 75 73 65 6e 75 6d 31 2e 6a 70 67 22 20 61 6c 74  usenum1.jpg" alt
4650: 3d 22 48 6f 75 73 65 20 4e 75 6d 62 65 72 73 20  ="House Numbers 
4660: 23 31 22 3e 0d 0a 3c 62 72 3e 3c 62 72 3e 0d 0a  #1">..<br><br>..
4670: 42 6f 74 68 20 71 75 65 72 69 65 73 20 77 69 6c  Both queries wil
4680: 6c 20 72 65 74 75 72 6e 20 74 68 65 20 73 61 6d  l return the sam
4690: 65 20 69 64 65 6e 74 69 63 61 6c 20 72 65 73 75  e identical resu
46a0: 6c 74 73 20 28 79 6f 75 20 63 61 6e 20 65 61 73  lts (you can eas
46b0: 69 6c 79 20 63 68 65 63 6b 20 62 79 20 79 6f 75  ily check by you
46c0: 72 73 65 6c 66 29 2e 3c 62 72 3e 0d 0a 41 6e 79  rself).<br>..Any
46d0: 77 61 79 20 69 66 20 79 6f 75 20 70 61 79 20 63  way if you pay c
46e0: 6c 6f 73 65 20 61 74 74 65 6e 74 69 6f 6e 20 79  lose attention y
46f0: 6f 75 27 6c 6c 20 65 61 73 69 6c 79 20 64 69 73  ou'll easily dis
4700: 63 6f 76 65 72 20 74 68 61 74 20 74 68 65 20 73  cover that the s
4710: 65 63 6f 6e 64 20 71 75 65 72 79 20 69 73 20 63  econd query is c
4720: 6f 6d 70 6c 65 74 65 6c 79 20 62 61 73 65 64 20  ompletely based 
4730: 6f 6e 20 61 20 3c 62 3e 53 70 61 74 69 61 6c 20  on a <b>Spatial 
4740: 56 69 65 77 3c 2f 62 3e 3c 62 72 3e 3c 62 72 3e  View</b><br><br>
4750: 0d 0a 3c 62 3e 4c 65 73 73 6f 6e 20 74 6f 20 6c  ..<b>Lesson to l
4760: 65 61 72 6e 3c 2f 62 3e 3a 20 61 20 56 69 72 74  earn</b>: a Virt
4770: 75 61 6c 4b 4e 4e 20 71 75 65 72 79 20 63 61 6e  ualKNN query can
4780: 20 69 6e 64 69 66 66 65 72 65 6e 74 6c 79 20 74   indifferently t
4790: 61 72 67 65 74 20 65 69 74 68 65 72 20 61 20 47  arget either a G
47a0: 65 6f 54 61 62 6c 65 20 6f 72 20 61 20 70 72 6f  eoTable or a pro
47b0: 70 65 72 6c 79 20 72 65 67 69 73 74 65 72 65 64  perly registered
47c0: 20 53 70 61 74 69 61 6c 20 56 69 65 77 2e 3c 62   Spatial View.<b
47d0: 72 3e 3c 62 72 3e 0d 0a 3c 76 65 72 62 61 74 69  r><br>..<verbati
47e0: 6d 3e 0d 0a 53 45 4c 45 43 54 20 61 2e 70 6f 73  m>..SELECT a.pos
47f0: 20 41 53 20 72 61 6e 6b 2c 20 61 2e 66 69 64 20   AS rank, a.fid 
4800: 41 53 20 66 69 64 2c 20 61 2e 64 69 73 74 61 6e  AS fid, a.distan
4810: 63 65 20 41 53 20 64 69 73 74 5f 6d 2c 20 62 2e  ce AS dist_m, b.
4820: 70 72 6f 76 20 41 53 20 70 72 6f 76 69 6e 63 65  prov AS province
4830: 2c 0d 0a 20 20 20 20 20 20 20 62 2e 63 6f 6d 75  ,..       b.comu
4840: 6e 65 20 41 53 20 6d 75 6e 69 63 69 70 61 6c 69  ne AS municipali
4850: 74 79 2c 20 62 2e 74 6f 70 6f 6e 69 6d 6f 20 41  ty, b.toponimo A
4860: 53 20 73 74 72 65 65 74 5f 6e 61 6d 65 2c 20 62  S street_name, b
4870: 2e 63 69 76 69 63 6f 20 41 53 20 68 6f 75 73 65  .civico AS house
4880: 5f 6e 75 6d 2c 20 0d 0a 20 20 20 20 20 20 20 62  _num, ..       b
4890: 2e 67 65 6f 6d 20 41 53 20 67 65 6f 6d 0d 0a 46  .geom AS geom..F
48a0: 52 4f 4d 20 6b 6e 6e 20 41 53 20 61 0d 0a 4a 4f  ROM knn AS a..JO
48b0: 49 4e 20 76 77 5f 63 69 76 69 63 69 20 41 53 20  IN vw_civici AS 
48c0: 62 20 4f 4e 20 28 62 2e 72 6f 77 69 64 20 3d 20  b ON (b.rowid = 
48d0: 61 2e 66 69 64 29 57 48 45 52 45 20 61 2e 66 5f  a.fid)WHERE a.f_
48e0: 74 61 62 6c 65 5f 6e 61 6d 65 20 3d 20 27 63 69  table_name = 'ci
48f0: 76 69 63 69 27 20 41 4e 44 20 61 2e 72 65 66 5f  vici' AND a.ref_
4900: 67 65 6f 6d 65 74 72 79 20 3d 20 4d 61 6b 65 50  geometry = MakeP
4910: 6f 69 6e 74 28 31 35 39 35 36 32 35 2c 20 34 37  oint(1595625, 47
4920: 36 37 34 32 30 2c 20 33 30 30 33 29 20 41 4e 44  67420, 3003) AND
4930: 20 6d 61 78 5f 69 74 65 6d 73 20 3d 20 32 30 3b   max_items = 20;
4940: 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 54  ..</verbatim>..T
4950: 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 6d 61 70  he following map
4960: 20 63 6f 72 72 65 73 70 6f 6e 64 73 20 74 6f 20   corresponds to 
4970: 74 68 65 20 61 62 6f 76 65 20 71 75 65 72 79 2e  the above query.
4980: 20 4e 6f 77 20 74 68 65 20 6f 72 69 67 69 6e 20   Now the origin 
4990: 70 6f 69 6e 74 20 69 73 20 70 6f 73 69 74 69 6f  point is positio
49a0: 6e 65 64 20 69 6e 20 74 68 65 20 54 79 72 72 68  ned in the Tyrrh
49b0: 65 6e 69 61 6e 20 53 65 61 3b 20 74 68 65 20 54  enian Sea; the T
49c0: 75 73 63 61 6e 79 20 6d 61 69 6e 6c 61 6e 64 2c  uscany mainland,
49d0: 20 74 68 65 20 49 73 6c 61 6e 64 20 6f 66 20 45   the Island of E
49e0: 6c 62 61 20 61 6e 64 20 74 68 65 20 49 73 6c 61  lba and the Isla
49f0: 6e 64 20 6f 66 20 43 61 70 72 61 69 61 20 61 72  nd of Capraia ar
4a00: 65 20 61 73 20 66 61 72 20 61 73 20 61 62 6f 75  e as far as abou
4a10: 74 20 3c 62 3e 32 36 20 4b 6d 3c 2f 62 3e 2e 3c  t <b>26 Km</b>.<
4a20: 62 72 3e 0d 0a 41 6e 79 77 61 79 20 69 6e 20 74  br>..Anyway in t
4a30: 68 69 73 20 63 61 73 65 20 74 6f 6f 20 56 69 72  his case too Vir
4a40: 74 75 61 6c 4b 4e 4e 20 63 6f 6e 66 69 72 6d 73  tualKNN confirms
4a50: 20 74 6f 20 62 65 20 61 62 6c 65 20 74 6f 20 69   to be able to i
4a60: 64 65 6e 74 69 66 79 20 74 68 65 20 6e 65 61 72  dentify the near
4a70: 65 73 74 20 68 6f 75 73 65 20 6e 75 6d 62 65 72  est house number
4a80: 73 20 69 6e 20 6a 75 73 74 20 61 20 66 72 61 63  s in just a frac
4a90: 74 69 6f 6e 20 6f 66 20 61 20 73 65 63 6f 6e 64  tion of a second
4aa0: 2e 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 69 6d 67 20  .<br><br>..<img 
4ab0: 73 72 63 3d 22 68 74 74 70 73 3a 2f 2f 77 77 77  src="https://www
4ac0: 2e 67 61 69 61 2d 67 69 73 2e 69 74 2f 67 61 69  .gaia-gis.it/gai
4ad0: 61 2d 73 69 6e 73 2f 6b 6e 6e 2f 68 6f 75 73 65  a-sins/knn/house
4ae0: 6e 75 6d 32 2e 70 6e 67 22 20 61 6c 74 3d 22 48  num2.png" alt="H
4af0: 6f 75 73 65 20 4e 75 6d 62 65 72 73 20 23 32 22  ouse Numbers #2"
4b00: 3e 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 62 3e 4c 65  ><br><br>..<b>Le
4b10: 73 73 6f 6e 20 74 6f 20 6c 65 61 72 6e 3c 2f 62  sson to learn</b
4b20: 3e 3a 20 56 69 72 74 75 61 6c 4b 4e 4e 20 69 73  >: VirtualKNN is
4b30: 20 61 6c 77 61 79 73 20 68 69 67 68 6c 79 20 65   always highly e
4b40: 66 66 69 63 69 65 6e 74 20 61 6e 64 20 76 65 72  fficient and ver
4b50: 79 20 66 61 73 74 2e 20 45 76 65 6e 20 77 68 65  y fast. Even whe
4b60: 6e 20 71 75 65 72 79 69 6e 67 20 61 6e 20 68 75  n querying an hu
4b70: 67 65 20 64 61 74 61 73 65 74 2c 20 61 6e 64 20  ge dataset, and 
4b80: 77 68 65 6e 20 65 78 70 6c 6f 72 69 6e 67 20 74  when exploring t
4b90: 68 65 20 6d 6f 73 74 20 63 6f 6e 74 72 61 73 74  he most contrast
4ba0: 69 6e 67 20 64 61 74 61 20 64 69 73 74 72 69 62  ing data distrib
4bb0: 75 74 69 6f 6e 73 20 28 76 65 72 79 20 68 69 67  utions (very hig
4bc0: 68 20 64 65 6e 73 69 74 79 20 2f 20 76 65 72 79  h density / very
4bd0: 20 6c 6f 77 20 64 65 6e 73 69 74 79 29 2e 3c 62   low density).<b
4be0: 72 3e 3c 62 72 3e 0d 0a 3c 74 61 62 6c 65 20 77  r><br>..<table w
4bf0: 69 64 74 68 3d 22 31 30 30 25 22 3e 3c 74 72 3e  idth="100%"><tr>
4c00: 0d 0a 3c 74 64 20 77 69 64 74 68 3d 22 33 33 25  ..<td width="33%
4c10: 22 20 61 6c 69 67 6e 3d 22 6c 65 66 74 22 3e 3c  " align="left"><
4c20: 2f 74 64 3e 0d 0a 3c 74 64 20 61 6c 69 67 6e 3d  /td>..<td align=
4c30: 22 63 65 6e 74 65 72 22 3e 3c 61 20 68 72 65 66  "center"><a href
4c40: 3d 22 68 74 74 70 73 3a 2f 2f 77 77 77 2e 67 61  ="https://www.ga
4c50: 69 61 2d 67 69 73 2e 69 74 2f 66 6f 73 73 69 6c  ia-gis.it/fossil
4c60: 2f 6c 69 62 73 70 61 74 69 61 6c 69 74 65 2f 77  /libspatialite/w
4c70: 69 6b 69 3f 6e 61 6d 65 3d 6d 69 73 63 2d 64 6f  iki?name=misc-do
4c80: 63 73 22 3e 62 61 63 6b 20 74 6f 20 69 6e 64 65  cs">back to inde
4c90: 78 3c 2f 61 3e 3c 2f 74 64 3e 0d 0a 3c 74 64 20  x</a></td>..<td 
4ca0: 77 69 64 74 68 3d 22 33 33 25 22 20 61 6c 69 67  width="33%" alig
4cb0: 6e 3d 22 72 69 67 68 74 22 3e 3c 2f 74 64 3e 0d  n="right"></td>.
4cc0: 0a 3c 2f 74 72 3e 3c 2f 74 61 62 6c 65 3e 0a 5a  .</tr></table>.Z
4cd0: 20 30 39 38 30 34 65 63 31 37 37 62 33 64 30 30   09804ec177b3d00
4ce0: 36 38 39 38 31 30 37 39 32 31 64 64 36 35 30 35  6898107921dd6505
4cf0: 38 0a                                            8.