Hex Artifact Content
Not logged in

Artifact 2ab33a66c03ac8555ef68401edc40aa544612755:

Wiki page [spatialite-android-tutorial] by antonello 2013-01-13 15:45:44.
0000: 44 20 32 30 31 33 2d 30 31 2d 31 33 54 31 35 3a  D 2013-01-13T15:
0010: 34 35 3a 34 34 2e 33 38 30 0a 4c 20 73 70 61 74  45:44.380.L spat
0020: 69 61 6c 69 74 65 2d 61 6e 64 72 6f 69 64 2d 74  ialite-android-t
0030: 75 74 6f 72 69 61 6c 0a 50 20 39 30 64 33 64 61  utorial.P 90d3da
0040: 39 33 33 63 66 63 32 33 61 35 66 65 30 36 34 37  933cfc23a5fe0647
0050: 39 37 65 64 36 35 61 38 65 62 62 36 39 63 38 64  97ed65a8ebb69c8d
0060: 65 61 0a 55 20 61 6e 74 6f 6e 65 6c 6c 6f 0a 57  ea.U antonello.W
0070: 20 31 35 35 31 38 0a 3c 74 61 62 6c 65 20 63 65   15518.<table ce
0080: 6c 6c 73 70 61 63 69 6e 67 3d 22 31 30 22 20 63  llspacing="10" c
0090: 65 6c 6c 70 61 64 64 69 6e 67 3d 22 33 30 22 3e  ellpadding="30">
00a0: 3c 74 72 3e 0d 0a 3c 74 64 20 77 69 64 74 68 3d  <tr>..<td width=
00b0: 22 31 30 30 25 22 3e 0d 0a 0d 0a 3c 68 31 3e 53  "100%">....<h1>S
00c0: 70 61 74 69 61 6c 69 74 65 20 6f 6e 20 41 6e 64  patialite on And
00d0: 72 6f 69 64 3a 20 61 20 71 75 69 63 6b 20 74 75  roid: a quick tu
00e0: 74 6f 72 69 61 6c 3c 2f 68 31 3e 0d 0a 42 61 63  torial</h1>..Bac
00f0: 6b 20 74 6f 20 3c 61 20 68 72 65 66 3d 22 68 74  k to <a href="ht
0100: 74 70 73 3a 2f 2f 77 77 77 2e 67 61 69 61 2d 67  tps://www.gaia-g
0110: 69 73 2e 69 74 2f 66 6f 73 73 69 6c 2f 6c 69 62  is.it/fossil/lib
0120: 73 70 61 74 69 61 6c 69 74 65 2f 77 69 6b 69 3f  spatialite/wiki?
0130: 6e 61 6d 65 3d 73 70 6c 69 74 65 2d 61 6e 64 72  name=splite-andr
0140: 6f 69 64 22 3e 53 70 61 74 69 61 4c 69 74 65 2d  oid">SpatiaLite-
0150: 41 6e 64 72 6f 69 64 3c 2f 61 3e 20 57 69 6b 69  Android</a> Wiki
0160: 20 70 61 67 65 3c 62 72 3e 3c 62 72 3e 0d 0a 3c   page<br><br>..<
0170: 74 61 62 6c 65 20 62 67 63 6f 6c 6f 72 3d 22 66  table bgcolor="f
0180: 66 66 66 64 30 22 20 63 65 6c 6c 70 61 64 64 69  fffd0" cellpaddi
0190: 6e 64 3d 22 38 22 20 63 65 6c 6c 73 70 61 63 69  nd="8" cellspaci
01a0: 6e 67 3d 22 38 22 3e 0d 0a 3c 74 72 3e 3c 74 64  ng="8">..<tr><td
01b0: 3e 3c 69 6d 67 20 73 72 63 3d 22 68 74 74 70 3a  ><img src="http:
01c0: 2f 2f 77 77 77 2e 67 61 69 61 2d 67 69 73 2e 69  //www.gaia-gis.i
01d0: 74 2f 67 61 69 61 2d 73 69 6e 73 2f 73 70 61 74  t/gaia-sins/spat
01e0: 69 61 6c 69 74 65 2d 61 6e 64 72 6f 69 64 2f 73  ialite-android/s
01f0: 70 6c 69 74 65 2d 61 6e 64 72 6f 69 64 2e 70 6e  plite-android.pn
0200: 67 22 20 61 6c 74 3d 22 6c 6f 67 6f 22 3e 3c 2f  g" alt="logo"></
0210: 74 64 3e 0d 0a 3c 74 64 3e 0d 0a 3c 62 3e 43 72  td>..<td>..<b>Cr
0220: 65 64 69 74 73 3c 2f 62 3e 3c 62 72 3e 3c 62 72  edits</b><br><br
0230: 3e 0d 0a 54 68 69 73 20 57 69 6b 69 20 70 61 67  >..This Wiki pag
0240: 65 20 68 61 73 20 62 65 65 6e 20 6b 69 6e 64 6c  e has been kindl
0250: 79 20 63 6f 6e 74 72 69 62 75 74 65 64 20 62 79  y contributed by
0260: 20 3c 61 20 68 72 65 66 3d 22 6d 61 69 6c 74 6f   <a href="mailto
0270: 3a 61 6e 64 72 65 61 2e 61 6e 74 6f 6e 65 6c 6c  :andrea.antonell
0280: 6f 40 67 6d 61 69 6c 2e 63 6f 6d 22 3e 41 6e 64  o@gmail.com">And
0290: 72 65 61 20 41 6e 74 6f 6e 65 6c 6c 6f 3c 2f 61  rea Antonello</a
02a0: 3e 2c 20 61 20 73 6b 69 6c 6c 65 64 20 4a 61 76  >, a skilled Jav
02b0: 61 20 64 65 76 6f 6c 6f 70 65 72 20 77 69 74 68  a devoloper with
02c0: 20 61 20 73 6f 75 6e 64 20 73 70 65 63 69 66 69   a sound specifi
02d0: 63 20 65 78 70 65 72 69 65 6e 63 65 20 6f 6e 20  c experience on 
02e0: 41 6e 64 72 6f 69 64 2c 20 61 6e 64 20 61 63 74  Android, and act
02f0: 69 76 65 6c 79 20 69 6e 76 6f 6c 76 65 64 20 69  ively involved i
0300: 6e 20 73 65 76 65 72 61 6c 20 47 46 4f 53 53 20  n several GFOSS 
0310: 70 72 6f 6a 65 63 74 73 20 28 50 53 43 20 6d 65  projects (PSC me
0320: 6d 62 65 72 20 6f 66 20 3c 61 20 68 72 65 66 3d  mber of <a href=
0330: 22 68 74 74 70 3a 2f 2f 75 64 69 67 2e 72 65 66  "http://udig.ref
0340: 72 61 63 74 69 6f 6e 73 2e 6e 65 74 2f 22 3e 75  ractions.net/">u
0350: 44 69 67 3c 2f 61 3e 20 61 6e 64 20 6d 61 69 6e  Dig</a> and main
0360: 74 61 69 6e 65 72 20 6f 66 20 3c 61 20 68 72 65  tainer of <a hre
0370: 66 3d 22 68 74 74 70 3a 2f 2f 63 6f 64 65 2e 67  f="http://code.g
0380: 6f 6f 67 6c 65 2e 63 6f 6d 2f 70 2f 67 65 6f 70  oogle.com/p/geop
0390: 61 70 61 72 61 7a 7a 69 2f 22 3e 47 65 6f 50 61  aparazzi/">GeoPa
03a0: 70 61 72 61 7a 7a 69 3c 2f 61 3e 29 2e 3c 62 72  parazzi</a>).<br
03b0: 3e 3c 62 72 3e 0d 0a 4d 61 6e 79 20 74 68 61 6e  ><br>..Many than
03c0: 6b 73 20 74 6f 20 41 6e 64 72 65 61 20 66 6f 72  ks to Andrea for
03d0: 20 68 69 73 20 74 68 6f 72 6f 75 67 68 20 64 6f   his thorough do
03e0: 63 75 6d 65 6e 74 61 74 69 6f 6e 20 65 66 66 6f  cumentation effo
03f0: 72 74 20 21 21 21 0d 0a 3c 2f 74 64 3e 3c 2f 74  rt !!!..</td></t
0400: 72 3e 0d 0a 3c 2f 74 61 62 6c 65 3e 0d 0a 0d 0a  r>..</table>....
0410: 3c 68 32 3e 49 6e 74 72 6f 64 75 63 74 69 6f 6e  <h2>Introduction
0420: 3c 2f 68 32 3e 0d 0a 0d 0a 3c 70 3e 54 68 65 20  </h2>....<p>The 
0430: 41 6e 64 72 6f 69 64 20 6f 70 65 72 61 74 69 6e  Android operatin
0440: 67 20 73 79 73 74 65 6d 20 66 6f 72 20 6d 6f 62  g system for mob
0450: 69 6c 65 20 64 65 76 69 63 65 73 20 75 73 65 73  ile devices uses
0460: 20 61 73 20 69 74 73 20 64 65 66 61 75 6c 74 20   as its default 
0470: 72 65 6c 61 74 69 6f 6e 61 6c 20 64 61 74 61 62  relational datab
0480: 61 73 65 20 53 51 4c 69 74 65 2e 20 45 76 65 6e  ase SQLite. Even
0490: 20 69 66 20 73 69 6e 63 65 20 74 68 65 20 61 70   if since the ap
04a0: 70 65 61 72 65 6e 63 65 20 6f 66 20 53 70 61 74  pearence of Spat
04b0: 69 61 4c 69 74 65 20 69 6e 20 74 68 65 20 67 65  iaLite in the ge
04c0: 6f 73 70 61 74 69 61 6c 20 77 6f 72 6c 64 20 69  ospatial world i
04d0: 74 20 6c 6f 6f 6b 65 64 20 6c 69 6b 65 20 61 20  t looked like a 
04e0: 70 65 72 66 65 63 74 20 6d 61 74 63 68 20 74 6f  perfect match to
04f0: 20 68 61 76 65 20 69 74 20 61 76 61 69 6c 61 62   have it availab
0500: 6c 65 20 62 79 20 64 65 66 61 75 6c 74 20 66 6f  le by default fo
0510: 72 20 74 68 65 20 73 79 73 74 65 6d 2c 20 64 65  r the system, de
0520: 76 65 6c 6f 70 65 72 73 20 68 61 64 20 74 6f 20  velopers had to 
0530: 77 61 69 74 20 66 6f 72 20 61 20 77 68 69 6c 65  wait for a while
0540: 20 74 6f 20 75 73 65 20 73 70 61 74 69 61 6c 69   to use spatiali
0550: 74 65 20 6f 6e 20 41 6e 64 72 6f 69 64 2e 0d 0a  te on Android...
0560: 41 6e 64 20 65 76 65 6e 20 6e 6f 77 2c 20 74 68  And even now, th
0570: 61 74 20 69 74 20 69 73 20 61 76 61 69 6c 61 62  at it is availab
0580: 6c 65 2c 20 69 74 20 69 73 20 6e 6f 74 20 69 6e  le, it is not in
0590: 74 65 67 72 61 74 65 64 20 69 6e 20 74 68 65 20  tegrated in the 
05a0: 6f 70 65 72 61 74 69 6e 67 20 73 79 73 74 65 6d  operating system
05b0: 20 61 6e 64 20 69 74 20 69 73 20 6e 6f 74 20 61   and it is not a
05c0: 63 63 65 73 73 69 62 6c 65 20 74 68 72 6f 75 67  ccessible throug
05d0: 68 20 74 68 65 20 73 74 61 6e 64 61 72 64 20 41  h the standard A
05e0: 6e 64 72 6f 69 64 20 70 65 72 73 69 73 74 65 6e  ndroid persisten
05f0: 63 65 20 41 50 49 73 2e 0d 0a 0d 0a 3c 70 3e 54  ce APIs.....<p>T
0600: 68 61 74 20 73 68 6f 75 6c 64 20 6e 6f 74 20 73  hat should not s
0610: 63 61 72 65 20 61 77 61 79 20 61 6e 79 20 64 65  care away any de
0620: 76 65 6c 6f 70 65 72 20 65 61 67 65 72 20 74 6f  veloper eager to
0630: 20 70 6c 61 79 20 72 65 61 6c 20 67 65 6f 73 70   play real geosp
0640: 61 74 69 61 6c 20 6f 6e 20 41 6e 64 72 6f 69 64  atial on Android
0650: 20 64 65 76 69 63 65 73 2e 20 54 68 65 20 3c 61   devices. The <a
0660: 20 68 72 65 66 3d 22 68 74 74 70 3a 2f 2f 63 6f   href="http://co
0670: 64 65 2e 67 6f 6f 67 6c 65 2e 63 6f 6d 2f 70 2f  de.google.com/p/
0680: 73 70 61 74 69 61 6c 69 74 65 2d 61 6e 64 72 6f  spatialite-andro
0690: 69 64 2f 22 3e 53 70 61 74 69 61 6c 69 74 65 2d  id/">Spatialite-
06a0: 41 6e 64 72 6f 69 64 3c 2f 61 3e 20 70 72 6f 6a  Android</a> proj
06b0: 65 63 74 20 69 73 20 73 69 6d 70 6c 65 20 74 6f  ect is simple to
06c0: 20 75 73 65 20 61 6e 64 20 73 74 61 62 6c 65 2e   use and stable.
06d0: 20 0d 0a 0d 0a 3c 70 3e 49 6e 20 74 68 69 73 20   ....<p>In this 
06e0: 64 6f 63 75 6d 65 6e 74 20 77 65 20 77 69 6c 6c  document we will
06f0: 20 68 65 6c 70 20 6e 65 77 20 64 65 76 65 6c 6f   help new develo
0700: 70 65 72 73 20 74 6f 20 67 65 74 20 73 74 61 72  pers to get star
0710: 74 65 64 20 77 69 74 68 20 74 68 65 69 72 20 66  ted with their f
0720: 69 72 73 74 20 53 70 61 74 69 61 6c 69 74 65 20  irst Spatialite 
0730: 65 6e 61 62 6c 65 64 20 61 70 70 6c 69 63 61 74  enabled applicat
0740: 69 6f 6e 2e 20 49 74 20 69 73 20 6d 65 61 6e 74  ion. It is meant
0750: 20 66 6f 72 20 64 65 76 65 6c 6f 70 65 72 73 20   for developers 
0760: 74 68 61 74 20 68 61 76 65 20 61 74 20 6c 65 61  that have at lea
0770: 73 74 20 61 20 6d 69 6e 69 6d 61 6c 20 6b 6e 6f  st a minimal kno
0780: 77 6c 65 64 67 65 20 61 62 6f 75 74 20 41 6e 64  wledge about And
0790: 72 6f 69 64 20 61 70 70 6c 69 63 61 74 69 6f 6e  roid application
07a0: 20 64 65 76 65 6c 6f 70 6d 65 6e 74 20 28 68 61   development (ha
07b0: 76 69 6e 67 20 62 75 69 6c 74 20 61 6e 64 20 72  ving built and r
07c0: 75 6e 20 74 68 65 20 68 65 6c 6c 6f 20 77 6f 72  un the hello wor
07d0: 6c 64 20 61 70 70 20 73 68 6f 75 6c 20 62 65 20  ld app shoul be 
07e0: 65 6e 6f 75 67 68 29 2e 0d 0a 0d 0a 3c 68 32 3e  enough).....<h2>
07f0: 41 75 74 68 6f 72 73 20 61 6e 64 20 4c 69 63 65  Authors and Lice
0800: 6e 73 65 3c 2f 68 32 3e 0d 0a 0d 0a 3c 70 3e 54  nse</h2>....<p>T
0810: 68 65 20 53 70 61 74 69 61 6c 69 74 65 2d 41 6e  he Spatialite-An
0820: 64 72 6f 69 64 20 70 72 6f 6a 65 63 74 20 68 61  droid project ha
0830: 73 20 62 65 65 6e 20 72 65 6c 65 61 73 65 64 20  s been released 
0840: 62 79 20 74 68 65 20 3c 61 20 68 72 65 66 3d 22  by the <a href="
0850: 68 74 74 70 3a 2f 2f 77 77 77 2e 61 67 63 2e 61  http://www.agc.a
0860: 72 6d 79 2e 6d 69 6c 22 3e 55 2e 53 2e 20 41 72  rmy.mil">U.S. Ar
0870: 6d 79 20 47 65 6f 73 70 61 74 69 61 6c 20 43 65  my Geospatial Ce
0880: 6e 74 65 72 3c 2f 61 3e 2e 0d 0a 3c 70 3e 54 68  nter</a>...<p>Th
0890: 65 20 70 72 6f 6a 65 63 74 20 69 73 20 72 65 6c  e project is rel
08a0: 65 61 73 65 64 20 3c 61 20 68 72 65 66 3d 22 68  eased <a href="h
08b0: 74 74 70 3a 2f 2f 77 77 77 2e 67 61 69 61 2d 67  ttp://www.gaia-g
08c0: 69 73 2e 69 74 2f 67 61 69 61 2d 73 69 6e 73 2f  is.it/gaia-sins/
08d0: 73 70 61 74 69 61 6c 69 74 65 2d 61 6e 64 72 6f  spatialite-andro
08e0: 69 64 2f 73 70 61 74 69 61 6c 69 74 65 2d 61 6e  id/spatialite-an
08f0: 64 72 6f 69 64 2d 6c 69 63 65 6e 73 65 2e 74 78  droid-license.tx
0900: 74 22 3e 75 6e 64 65 72 20 4c 47 50 4c 76 33 20  t">under LGPLv3 
0910: 6c 69 63 65 6e 73 65 3c 2f 61 3e 2e 0d 0a 0d 0a  license</a>.....
0920: 3c 68 32 3e 47 65 74 74 69 6e 67 20 73 74 61 72  <h2>Getting star
0930: 74 65 64 20 2d 20 74 68 65 20 71 75 69 63 6b 20  ted - the quick 
0940: 77 61 79 3c 2f 68 32 3e 0d 0a 0d 0a 54 68 65 20  way</h2>....The 
0950: 71 75 69 63 6b 65 73 74 20 77 61 79 20 69 73 20  quickest way is 
0960: 74 6f 20 64 6f 77 6e 6c 6f 61 64 20 74 68 65 20  to download the 
0970: 73 6f 75 72 63 65 20 70 72 6f 6a 65 63 74 20 6f  source project o
0980: 66 20 74 68 69 73 20 64 6f 63 75 6d 65 6e 74 61  f this documenta
0990: 74 69 6f 6e 2c 20 62 72 6f 77 73 65 20 69 74 20  tion, browse it 
09a0: 61 6e 64 20 72 75 6e 20 69 74 2e 20 49 74 20 73  and run it. It s
09b0: 68 6f 75 6c 64 20 77 6f 72 6b 20 6f 75 74 20 6f  hould work out o
09c0: 66 20 74 68 65 20 62 6f 78 20 61 6e 64 20 73 68  f the box and sh
09d0: 6f 77 20 79 6f 75 20 77 68 65 72 65 20 6c 69 62  ow you where lib
09e0: 73 20 6e 65 65 64 20 74 6f 20 62 65 20 70 75 74  s need to be put
09f0: 20 61 6e 64 20 68 6f 77 20 74 6f 20 72 75 6e 20   and how to run 
0a00: 71 75 65 72 69 65 73 2e 0d 0a 0d 0a 54 68 65 20  queries.....The 
0a10: 73 6f 75 72 63 65 20 63 6f 64 65 20 3c 61 20 68  source code <a h
0a20: 72 65 66 3d 22 68 74 74 70 73 3a 2f 2f 62 69 74  ref="https://bit
0a30: 62 75 63 6b 65 74 2e 6f 72 67 2f 6d 6f 6f 76 69  bucket.org/moovi
0a40: 64 61 2f 73 70 61 74 69 61 6c 69 74 65 2d 61 6e  da/spatialite-an
0a50: 64 72 6f 69 64 2d 65 78 61 6d 70 6c 65 2f 73 72  droid-example/sr
0a60: 63 22 3e 63 61 6e 20 62 65 20 66 6f 75 6e 64 20  c">can be found 
0a70: 68 65 72 65 3c 2f 61 3e 2e 0d 0a 0d 0a 54 68 65  here</a>.....The
0a80: 20 73 71 6c 69 74 65 20 64 61 74 61 62 61 73 65   sqlite database
0a90: 20 75 73 65 64 20 66 6f 72 20 74 68 69 73 20 74   used for this t
0aa0: 75 74 6f 72 69 61 6c 20 63 61 6e 20 62 65 20 64  utorial can be d
0ab0: 6f 77 6e 6c 6f 61 64 65 64 20 69 6e 20 74 68 65  ownloaded in the
0ac0: 20 20 3c 61 20 68 72 65 66 3d 22 68 74 74 70 73    <a href="https
0ad0: 3a 2f 2f 62 69 74 62 75 63 6b 65 74 2e 6f 72 67  ://bitbucket.org
0ae0: 2f 6d 6f 6f 76 69 64 61 2f 73 70 61 74 69 61 6c  /moovida/spatial
0af0: 69 74 65 2d 61 6e 64 72 6f 69 64 2d 65 78 61 6d  ite-android-exam
0b00: 70 6c 65 2f 64 6f 77 6e 6c 6f 61 64 73 22 3e 64  ple/downloads">d
0b10: 6f 77 6e 6c 6f 61 64 20 61 72 65 61 20 6f 66 20  ownload area of 
0b20: 74 68 65 20 73 61 6d 65 20 70 72 6f 6a 65 63 74  the same project
0b30: 20 70 61 67 65 2e 3c 2f 61 3e 0d 0a 0d 0a 3c 68   page.</a>....<h
0b40: 32 3e 47 65 74 74 69 6e 67 20 73 74 61 72 74 65  2>Getting starte
0b50: 64 20 2d 20 74 68 65 20 73 6c 6f 77 20 77 61 79  d - the slow way
0b60: 3c 2f 68 32 3e 0d 0a 0d 0a 3c 70 3e 54 6f 20 67  </h2>....<p>To g
0b70: 65 74 20 73 74 61 72 74 65 64 20 77 65 20 6a 75  et started we ju
0b80: 73 74 20 6e 65 65 64 20 74 6f 20 67 65 74 20 74  st need to get t
0b90: 68 65 20 53 70 61 74 69 61 6c 69 74 65 20 6c 69  he Spatialite li
0ba0: 62 72 61 72 69 65 73 20 61 6e 64 20 61 64 64 20  braries and add 
0bb0: 74 68 65 6d 20 74 6f 20 6f 75 72 20 6e 65 77 20  them to our new 
0bc0: 41 6e 64 72 6f 69 64 20 61 70 70 6c 69 63 61 74  Android applicat
0bd0: 69 6f 6e 20 70 72 6f 6a 65 63 74 2e 0d 0a 3c 70  ion project...<p
0be0: 3e 4f 6e 63 65 20 74 68 61 74 20 69 73 20 64 6f  >Once that is do
0bf0: 6e 65 2c 20 74 68 65 72 65 20 61 72 65 20 66 65  ne, there are fe
0c00: 77 20 73 74 65 70 73 20 74 6f 20 70 65 72 66 6f  w steps to perfo
0c10: 72 6d 20 74 6f 20 67 65 74 20 74 68 69 6e 67 73  rm to get things
0c20: 20 77 6f 72 6b 69 6e 67 2e 20 54 68 65 20 41 50   working. The AP
0c30: 49 20 69 73 20 76 65 72 79 20 73 6d 61 6c 6c 20  I is very small 
0c40: 61 6e 64 20 73 69 6d 70 6c 65 20 61 6e 64 20 62  and simple and b
0c50: 61 73 69 63 61 6c 6c 79 20 62 61 73 65 73 20 6f  asically bases o
0c60: 6e 20 61 20 6d 61 6e 75 61 6c 20 62 75 69 6c 64  n a manual build
0c70: 69 6e 67 20 6f 66 20 74 68 65 20 71 75 65 72 69  ing of the queri
0c80: 65 73 20 74 6f 20 73 65 6e 64 20 74 6f 20 74 68  es to send to th
0c90: 65 20 64 61 74 61 62 61 73 65 2e 0d 0a 3c 70 3e  e database...<p>
0ca0: 4e 6f 74 65 20 74 68 61 74 20 69 74 20 77 6f 75  Note that it wou
0cb0: 6c 64 20 62 65 20 70 6f 73 73 69 62 6c 65 20 74  ld be possible t
0cc0: 6f 20 63 72 65 61 74 65 20 61 6e 20 41 6e 64 72  o create an Andr
0cd0: 6f 69 64 20 6c 69 62 72 61 72 79 20 74 6f 20 72  oid library to r
0ce0: 65 66 65 72 65 6e 63 65 20 66 72 6f 6d 20 74 68  eference from th
0cf0: 65 20 70 72 6f 6a 65 63 74 2c 20 62 75 74 20 74  e project, but t
0d00: 6f 20 6b 65 65 70 20 74 68 69 73 20 74 75 74 6f  o keep this tuto
0d10: 72 69 61 6c 20 73 68 6f 72 74 2c 20 77 65 20 77  rial short, we w
0d20: 69 6c 6c 20 6a 75 73 74 20 73 68 6f 77 20 68 6f  ill just show ho
0d30: 77 20 74 6f 20 69 6e 74 65 67 72 61 74 65 20 74  w to integrate t
0d40: 68 65 20 6c 69 62 72 61 72 79 20 64 69 72 65 63  he library direc
0d50: 74 6c 79 20 69 6e 74 6f 20 6f 75 72 20 6e 65 77  tly into our new
0d60: 20 70 72 6f 6a 65 63 74 2e 0d 0a 0d 0a 3c 68 33   project.....<h3
0d70: 3e 44 6f 77 6e 6c 6f 61 64 69 6e 67 20 74 68 65  >Downloading the
0d80: 20 6c 69 62 72 61 72 69 65 73 3c 2f 68 33 3e 0d   libraries</h3>.
0d90: 0a 0d 0a 3c 70 3e 54 68 65 79 20 63 61 6e 20 62  ...<p>They can b
0da0: 65 20 64 6f 77 6e 6c 6f 61 64 65 64 20 66 72 6f  e downloaded fro
0db0: 6d 20 3c 61 20 68 72 65 66 3d 22 68 74 74 70 3a  m <a href="http:
0dc0: 2f 2f 77 77 77 2e 67 61 69 61 2d 67 69 73 2e 69  //www.gaia-gis.i
0dd0: 74 2f 67 61 69 61 2d 73 69 6e 73 2f 73 70 61 74  t/gaia-sins/spat
0de0: 69 61 6c 69 74 65 2d 61 6e 64 72 6f 69 64 2f 73  ialite-android/s
0df0: 70 61 74 69 61 6c 69 74 65 2d 66 6f 72 2d 61 6e  patialite-for-an
0e00: 64 72 6f 69 64 2d 33 2e 30 2e 31 2e 7a 69 70 22  droid-3.0.1.zip"
0e10: 3e 74 68 69 73 20 6c 69 6e 6b 3c 2f 61 3e 2e 0d  >this link</a>..
0e20: 0a 3c 70 3e 54 68 65 20 64 6f 77 6e 6c 6f 61 64  .<p>The download
0e30: 65 64 20 61 72 63 68 69 76 65 20 63 6f 6e 74 61  ed archive conta
0e40: 69 6e 73 20 32 20 62 61 73 69 63 20 63 6f 6d 70  ins 2 basic comp
0e50: 6f 6e 65 6e 74 73 20 6e 65 63 65 73 73 61 72 79  onents necessary
0e60: 20 74 6f 20 65 6e 61 62 6c 65 20 79 6f 75 72 20   to enable your 
0e70: 70 72 6f 6a 65 63 74 20 74 6f 20 75 73 65 20 53  project to use S
0e80: 70 61 74 69 61 6c 69 74 65 3a 0d 0a 3c 75 6c 3e  patialite:..<ul>
0e90: 0d 0a 3c 6c 69 3e 3c 62 3e 74 68 65 20 6e 61 74  ..<li><b>the nat
0ea0: 69 76 65 20 73 70 61 74 69 61 6c 69 74 65 20 6c  ive spatialite l
0eb0: 69 62 72 61 72 69 65 73 3c 2f 62 3e 3a 20 74 68  ibraries</b>: th
0ec0: 65 79 20 61 72 65 20 70 6c 61 63 65 73 20 69 6e  ey are places in
0ed0: 20 61 20 66 6f 6c 64 65 72 20 6e 61 6d 65 64 20   a folder named 
0ee0: 3c 62 3e 6c 69 62 73 3c 2f 62 3e 3c 2f 6c 69 3e  <b>libs</b></li>
0ef0: 20 61 6e 64 20 63 6f 6e 74 61 69 6e 73 20 73 65   and contains se
0f00: 76 65 72 61 6c 20 66 6f 6c 64 65 72 73 20 66 6f  veral folders fo
0f10: 72 20 64 69 66 66 65 72 65 6e 74 20 70 6c 61 74  r different plat
0f20: 66 6f 72 6d 73 20 74 68 61 74 20 68 6f 6c 64 20  forms that hold 
0f30: 74 68 65 20 6d 61 69 6e 20 6c 69 62 72 61 72 79  the main library
0f40: 2c 20 63 61 6c 6c 65 64 20 3c 62 3e 6c 69 62 73  , called <b>libs
0f50: 70 61 74 69 61 6c 69 74 65 2e 73 6f 3c 2f 62 3e  patialite.so</b>
0f60: 0d 0a 3c 6c 69 3e 74 68 65 20 3c 62 3e 62 61 73  ..<li>the <b>bas
0f70: 69 63 20 41 50 49 20 63 6c 61 73 73 65 73 3c 2f  ic API classes</
0f80: 62 3e 2c 20 63 6f 6e 74 61 69 6e 65 64 20 69 6e  b>, contained in
0f90: 20 74 68 65 20 3c 62 3e 6a 73 71 6c 69 74 65 3c   the <b>jsqlite<
0fa0: 2f 62 3e 20 70 61 63 6b 61 67 65 3c 2f 6c 69 3e  /b> package</li>
0fb0: 0d 0a 3c 2f 75 6c 3e 0d 0a 0d 0a 3c 68 33 3e 59  ..</ul>....<h3>Y
0fc0: 6f 75 72 20 66 69 72 73 74 20 53 70 61 74 69 61  our first Spatia
0fd0: 6c 69 74 65 20 65 6e 61 62 6c 65 64 20 70 72 6f  lite enabled pro
0fe0: 6a 65 63 74 3c 2f 68 33 3e 0d 0a 0d 0a 3c 68 34  ject</h3>....<h4
0ff0: 3e 50 72 65 70 61 72 65 20 61 20 64 61 74 61 73  >Prepare a datas
1000: 65 74 3c 2f 68 34 3e 0d 0a 0d 0a 46 6f 6c 6c 6f  et</h4>....Follo
1010: 77 20 3c 61 20 68 72 65 66 3d 22 68 74 74 70 3a  w <a href="http:
1020: 2f 2f 77 77 77 2e 67 61 69 61 2d 67 69 73 2e 69  //www.gaia-gis.i
1030: 74 2f 67 61 69 61 2d 73 69 6e 73 2f 73 70 61 74  t/gaia-sins/spat
1040: 69 61 6c 69 74 65 2d 63 6f 6f 6b 62 6f 6f 6b 2f  ialite-cookbook/
1050: 68 74 6d 6c 2f 66 69 72 73 74 2d 64 62 2e 68 74  html/first-db.ht
1060: 6d 6c 22 3e 74 68 69 73 20 74 75 74 6f 72 69 61  ml">this tutoria
1070: 6c 3c 2f 61 3e 20 74 6f 20 63 72 65 61 74 65 20  l</a> to create 
1080: 61 20 73 70 61 74 69 61 6c 69 74 65 20 64 61 74  a spatialite dat
1090: 61 62 61 73 65 20 74 68 61 74 20 63 6f 6e 74 61  abase that conta
10a0: 69 6e 73 20 74 68 65 20 63 6f 6d 75 6e 69 5f 32  ins the comuni_2
10b0: 30 31 31 2e 73 68 70 20 28 66 69 6e 64 20 72 65  011.shp (find re
10c0: 66 65 72 65 6e 63 65 73 20 74 6f 20 77 68 65 72  ferences to wher
10d0: 65 20 74 6f 20 67 65 74 20 69 74 20 3c 61 20 68  e to get it <a h
10e0: 72 65 66 3d 22 68 74 74 70 3a 2f 2f 77 77 77 2e  ref="http://www.
10f0: 67 61 69 61 2d 67 69 73 2e 69 74 2f 67 61 69 61  gaia-gis.it/gaia
1100: 2d 73 69 6e 73 2f 73 70 61 74 69 61 6c 69 74 65  -sins/spatialite
1110: 2d 63 6f 6f 6b 62 6f 6f 6b 2f 68 74 6d 6c 2f 73  -cookbook/html/s
1120: 74 61 72 74 2e 68 74 6d 6c 22 3e 68 65 72 65 3c  tart.html">here<
1130: 2f 61 3e 29 20 64 61 74 61 2e 20 43 6f 70 79 20  /a>) data. Copy 
1140: 74 68 65 20 63 72 65 61 74 65 64 20 64 61 74 61  the created data
1150: 62 61 73 65 20 6f 6e 20 74 68 65 20 6d 6f 62 69  base on the mobi
1160: 6c 65 20 64 65 76 69 63 65 27 73 20 65 78 74 65  le device's exte
1170: 72 6e 61 6c 20 73 74 6f 72 61 67 65 20 63 61 72  rnal storage car
1180: 64 2e 0d 0a 0d 0a 3c 68 34 3e 43 72 65 61 74 65  d.....<h4>Create
1190: 20 74 68 65 20 62 61 73 69 63 20 68 65 6c 6c 6f   the basic hello
11a0: 20 77 6f 72 6c 64 20 70 72 6f 6a 65 63 74 3c 2f   world project</
11b0: 68 34 3e 0d 0a 0d 0a 3c 70 3e 55 73 65 20 74 68  h4>....<p>Use th
11c0: 65 20 41 6e 64 72 6f 69 64 20 65 63 6c 69 70 73  e Android eclips
11d0: 65 20 6e 65 77 20 70 72 6f 6a 65 63 74 20 77 69  e new project wi
11e0: 7a 61 72 64 20 74 6f 20 63 72 65 61 74 65 20 61  zard to create a
11f0: 20 62 61 73 69 63 20 68 65 6c 6c 6f 20 77 6f 72   basic hello wor
1200: 6c 64 20 65 78 61 6d 70 6c 65 20 66 6f 72 20 41  ld example for A
1210: 6e 64 72 6f 69 64 2e 20 49 74 20 77 69 6c 6c 20  ndroid. It will 
1220: 67 65 6e 65 72 61 74 65 20 79 6f 75 20 61 20 72  generate you a r
1230: 65 61 64 79 20 74 6f 20 75 73 65 20 41 6e 64 72  eady to use Andr
1240: 6f 69 64 20 61 70 70 6c 69 63 61 74 69 6f 6e 20  oid application 
1250: 74 68 61 74 20 73 68 6f 77 73 20 61 20 6e 69 63  that shows a nic
1260: 65 20 56 69 65 77 20 77 69 74 68 20 3c 69 3e 48  e View with <i>H
1270: 65 6c 6c 6f 20 57 6f 72 6c 64 3c 2f 69 3e 20 6f  ello World</i> o
1280: 6e 20 69 74 2e 0d 0a 0d 0a 3c 70 3e 4f 6e 63 65  n it.....<p>Once
1290: 20 74 68 65 20 68 65 6c 6c 6f 20 77 6f 72 6c 64   the hello world
12a0: 20 70 72 6f 6a 65 63 74 20 63 61 6e 20 62 65 20   project can be 
12b0: 72 75 6e 2c 20 77 65 20 63 61 6e 20 73 74 61 72  run, we can star
12c0: 74 20 74 6f 20 61 64 64 20 74 68 65 20 73 70 61  t to add the spa
12d0: 74 69 61 6c 69 74 65 20 70 61 72 74 2e 0d 0a 0d  tialite part....
12e0: 0a 3c 70 3e 54 68 65 20 66 69 72 73 74 20 73 74  .<p>The first st
12f0: 65 70 20 69 73 20 74 6f 20 63 6f 70 79 20 74 68  ep is to copy th
1300: 65 20 6d 61 69 6e 20 63 6f 6d 70 6f 6e 65 6e 74  e main component
1310: 73 20 6f 66 20 74 68 65 20 53 70 61 74 69 61 6c  s of the Spatial
1320: 69 74 65 2d 41 6e 64 72 6f 69 64 20 70 72 6f 6a  ite-Android proj
1330: 65 63 74 20 61 73 20 6d 65 6e 74 69 6f 6e 65 64  ect as mentioned
1340: 20 62 65 66 6f 72 65 2e 0d 0a 0d 0a 3c 75 6c 3e   before.....<ul>
1350: 0d 0a 3c 6c 69 3e 63 6f 70 79 20 74 68 65 20 6e  ..<li>copy the n
1360: 61 74 69 76 65 20 6c 69 62 73 20 69 6e 74 6f 20  ative libs into 
1370: 74 68 65 20 72 6f 6f 74 20 6f 66 20 74 68 65 20  the root of the 
1380: 6e 65 77 6c 79 20 63 72 65 61 74 65 64 20 41 6e  newly created An
1390: 64 72 6f 69 64 20 70 72 6f 6a 65 63 74 3c 2f 6c  droid project</l
13a0: 69 3e 0d 0a 3c 6c 69 3e 63 6f 70 79 20 74 68 65  i>..<li>copy the
13b0: 20 6a 61 76 61 20 70 61 63 6b 61 67 65 20 6f 66   java package of
13c0: 20 74 68 65 20 62 61 73 65 20 41 50 49 20 69 6e   the base API in
13d0: 74 6f 20 79 6f 75 20 6e 65 77 20 70 72 6f 6a 65  to you new proje
13e0: 63 74 27 73 20 73 6f 75 72 63 65 20 66 6f 6c 64  ct's source fold
13f0: 65 72 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 0d 0a  er</li>..</ul>..
1400: 0d 0a 3c 70 3e 41 6e 64 20 74 68 61 74 20 69 73  ..<p>And that is
1410: 20 69 74 2e 20 59 6f 75 72 20 70 72 6f 6a 65 63   it. Your projec
1420: 74 20 69 73 20 61 6c 72 65 61 64 79 20 53 70 61  t is already Spa
1430: 74 69 61 6c 69 74 65 20 65 6e 61 62 6c 65 64 2e  tialite enabled.
1440: 0d 0a 4c 65 74 27 73 20 64 6f 20 73 6f 6d 65 20  ..Let's do some 
1450: 62 61 73 69 63 20 73 74 75 66 66 20 77 69 74 68  basic stuff with
1460: 20 69 74 20 69 6e 20 74 68 65 20 6e 65 78 74 20   it in the next 
1470: 63 68 61 70 74 65 72 73 2e 0d 0a 0d 0a 3c 68 34  chapters.....<h4
1480: 3e 4f 70 65 6e 20 61 6e 20 64 61 74 61 62 61 73  >Open an databas
1490: 65 3c 2f 68 34 3e 0d 0a 0d 0a 3c 70 3e 54 68 65  e</h4>....<p>The
14a0: 20 66 6f 6c 6c 6f 77 69 6e 67 20 77 69 6c 6c 20   following will 
14b0: 6f 70 65 6e 20 74 68 65 20 64 61 74 61 62 61 73  open the databas
14c0: 65 20 6e 61 6d 65 64 20 3c 69 3e 69 74 61 6c 79  e named <i>italy
14d0: 2e 73 71 6c 69 74 65 3c 2f 69 3e 20 74 68 61 74  .sqlite</i> that
14e0: 20 69 73 20 70 6c 61 63 65 64 20 69 6e 20 79 6f   is placed in yo
14f0: 75 72 20 73 64 63 61 72 64 2e 20 49 66 20 74 68  ur sdcard. If th
1500: 65 20 64 61 74 61 62 61 73 65 20 64 6f 65 73 6e  e database doesn
1510: 27 74 20 65 78 69 73 74 2c 20 69 74 20 77 69 6c  't exist, it wil
1520: 6c 20 62 65 20 63 72 65 61 74 65 64 20 65 6d 70  l be created emp
1530: 74 79 20 28 64 75 65 20 74 6f 20 74 68 65 20 53  ty (due to the S
1540: 51 4c 49 54 45 5f 4f 50 45 4e 5f 43 52 45 41 54  QLITE_OPEN_CREAT
1550: 45 20 66 6c 61 67 29 2e 0d 0a 0d 0a 3c 76 65 72  E flag).....<ver
1560: 62 61 74 69 6d 3e 0d 0a 20 20 20 20 20 20 20 20  batim>..        
1570: 74 72 79 20 7b 0d 0a 20 20 20 20 20 20 20 20 20  try {..         
1580: 20 20 20 46 69 6c 65 20 73 64 63 61 72 64 44 69     File sdcardDi
1590: 72 20 3d 20 22 22 3b 20 2f 2f 20 79 6f 75 72 20  r = ""; // your 
15a0: 73 64 63 61 72 64 20 70 61 74 68 0d 0a 20 20 20  sdcard path..   
15b0: 20 20 20 20 20 20 20 20 20 46 69 6c 65 20 73 70           File sp
15c0: 61 74 69 61 6c 44 62 46 69 6c 65 20 3d 20 6e 65  atialDbFile = ne
15d0: 77 20 46 69 6c 65 28 73 64 63 61 72 64 44 69 72  w File(sdcardDir
15e0: 2c 20 22 69 74 61 6c 79 2e 73 71 6c 69 74 65 22  , "italy.sqlite"
15f0: 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 20 20  );....          
1600: 20 20 64 62 20 3d 20 6e 65 77 20 6a 73 71 6c 69    db = new jsqli
1610: 74 65 2e 44 61 74 61 62 61 73 65 28 29 3b 0d 0a  te.Database();..
1620: 20 20 20 20 20 20 20 20 20 20 20 20 64 62 2e 6f              db.o
1630: 70 65 6e 28 73 70 61 74 69 61 6c 44 62 46 69 6c  pen(spatialDbFil
1640: 65 2e 67 65 74 41 62 73 6f 6c 75 74 65 50 61 74  e.getAbsolutePat
1650: 68 28 29 2c 20 6a 73 71 6c 69 74 65 2e 43 6f 6e  h(), jsqlite.Con
1660: 73 74 61 6e 74 73 2e 53 51 4c 49 54 45 5f 4f 50  stants.SQLITE_OP
1670: 45 4e 5f 52 45 41 44 57 52 49 54 45 0d 0a 20 20  EN_READWRITE..  
1680: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
1690: 20 20 7c 20 6a 73 71 6c 69 74 65 2e 43 6f 6e 73    | jsqlite.Cons
16a0: 74 61 6e 74 73 2e 53 51 4c 49 54 45 5f 4f 50 45  tants.SQLITE_OPE
16b0: 4e 5f 43 52 45 41 54 45 29 3b 0d 0a 20 20 20 20  N_CREATE);..    
16c0: 20 20 20 20 7d 20 63 61 74 63 68 20 28 45 78 63      } catch (Exc
16d0: 65 70 74 69 6f 6e 20 65 29 20 7b 0d 0a 20 20 20  eption e) {..   
16e0: 20 20 20 20 20 20 20 20 20 65 2e 70 72 69 6e 74           e.print
16f0: 53 74 61 63 6b 54 72 61 63 65 28 29 3b 0d 0a 20  StackTrace();.. 
1700: 20 20 20 20 20 20 20 7d 0d 0a 3c 2f 76 65 72 62         }..</verb
1710: 61 74 69 6d 3e 0d 0a 0d 0a 4f 6e 63 65 20 79 6f  atim>....Once yo
1720: 75 20 68 61 76 65 20 6f 70 65 6e 65 64 20 74 68  u have opened th
1730: 65 20 64 61 74 61 62 61 73 65 2c 20 79 6f 75 20  e database, you 
1740: 61 72 65 20 72 65 61 64 79 20 74 6f 20 64 6f 20  are ready to do 
1750: 73 6f 6d 65 20 73 70 61 74 69 61 6c 20 6d 61 67  some spatial mag
1760: 69 63 2e 0d 0a 0d 0a 3c 68 34 3e 47 65 74 20 76  ic.....<h4>Get v
1770: 65 72 73 69 6f 6e 73 20 6f 66 20 74 68 65 20 73  ersions of the s
1780: 6f 66 74 77 61 72 65 3c 2f 68 34 3e 0d 0a 0d 0a  oftware</h4>....
1790: 54 6f 20 67 65 74 20 74 68 65 20 76 65 72 73 69  To get the versi
17a0: 6f 6e 73 20 6f 66 20 73 70 61 74 69 61 6c 69 74  ons of spatialit
17b0: 65 2c 20 67 65 6f 73 20 61 6e 64 20 70 72 6f 6a  e, geos and proj
17c0: 20 74 68 61 74 20 61 72 65 20 69 6e 20 75 73 65   that are in use
17d0: 2c 20 79 6f 75 20 63 61 6e 20 75 73 65 20 74 68  , you can use th
17e0: 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 6d 65 74 68  e following meth
17f0: 6f 64 3a 0d 0a 0d 0a 3c 76 65 72 62 61 74 69 6d  od:....<verbatim
1800: 3e 0d 0a 20 20 20 20 70 75 62 6c 69 63 20 53 74  >..    public St
1810: 72 69 6e 67 20 71 75 65 72 79 56 65 72 73 69 6f  ring queryVersio
1820: 6e 73 28 29 20 74 68 72 6f 77 73 20 45 78 63 65  ns() throws Exce
1830: 70 74 69 6f 6e 20 7b 0d 0a 20 20 20 20 20 20 20  ption {..       
1840: 20 53 74 72 69 6e 67 42 75 69 6c 64 65 72 20 73   StringBuilder s
1850: 62 20 3d 20 6e 65 77 20 53 74 72 69 6e 67 42 75  b = new StringBu
1860: 69 6c 64 65 72 28 29 3b 0d 0a 20 20 20 20 20 20  ilder();..      
1870: 20 20 73 62 2e 61 70 70 65 6e 64 28 22 43 68 65    sb.append("Che
1880: 63 6b 20 76 65 72 73 69 6f 6e 73 2e 2e 2e 5c 6e  ck versions...\n
1890: 22 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 53  ");....        S
18a0: 74 6d 74 20 73 74 6d 74 30 31 20 3d 20 64 62 2e  tmt stmt01 = db.
18b0: 70 72 65 70 61 72 65 28 22 53 45 4c 45 43 54 20  prepare("SELECT 
18c0: 73 70 61 74 69 61 6c 69 74 65 5f 76 65 72 73 69  spatialite_versi
18d0: 6f 6e 28 29 3b 22 29 3b 0d 0a 20 20 20 20 20 20  on();");..      
18e0: 20 20 69 66 20 28 73 74 6d 74 30 31 2e 73 74 65    if (stmt01.ste
18f0: 70 28 29 29 20 7b 0d 0a 20 20 20 20 20 20 20 20  p()) {..        
1900: 20 20 20 20 73 62 2e 61 70 70 65 6e 64 28 22 5c      sb.append("\
1910: 74 22 29 2e 61 70 70 65 6e 64 28 22 53 50 41 54  t").append("SPAT
1920: 49 41 4c 49 54 45 5f 56 45 52 53 49 4f 4e 3a 20  IALITE_VERSION: 
1930: 22 20 2b 20 73 74 6d 74 30 31 2e 63 6f 6c 75 6d  " + stmt01.colum
1940: 6e 5f 73 74 72 69 6e 67 28 30 29 29 3b 0d 0a 20  n_string(0));.. 
1950: 20 20 20 20 20 20 20 20 20 20 20 73 62 2e 61 70             sb.ap
1960: 70 65 6e 64 28 22 5c 6e 22 29 3b 0d 0a 20 20 20  pend("\n");..   
1970: 20 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 20 20       }....      
1980: 20 20 73 74 6d 74 30 31 20 3d 20 64 62 2e 70 72    stmt01 = db.pr
1990: 65 70 61 72 65 28 22 53 45 4c 45 43 54 20 70 72  epare("SELECT pr
19a0: 6f 6a 34 5f 76 65 72 73 69 6f 6e 28 29 3b 22 29  oj4_version();")
19b0: 3b 0d 0a 20 20 20 20 20 20 20 20 69 66 20 28 73  ;..        if (s
19c0: 74 6d 74 30 31 2e 73 74 65 70 28 29 29 20 7b 0d  tmt01.step()) {.
19d0: 0a 20 20 20 20 20 20 20 20 20 20 20 20 73 62 2e  .            sb.
19e0: 61 70 70 65 6e 64 28 22 5c 74 22 29 2e 61 70 70  append("\t").app
19f0: 65 6e 64 28 22 50 52 4f 4a 34 5f 56 45 52 53 49  end("PROJ4_VERSI
1a00: 4f 4e 3a 20 22 20 2b 20 73 74 6d 74 30 31 2e 63  ON: " + stmt01.c
1a10: 6f 6c 75 6d 6e 5f 73 74 72 69 6e 67 28 30 29 29  olumn_string(0))
1a20: 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 73  ;..            s
1a30: 62 2e 61 70 70 65 6e 64 28 22 5c 6e 22 29 3b 0d  b.append("\n");.
1a40: 0a 20 20 20 20 20 20 20 20 7d 0d 0a 0d 0a 20 20  .        }....  
1a50: 20 20 20 20 20 20 73 74 6d 74 30 31 20 3d 20 64        stmt01 = d
1a60: 62 2e 70 72 65 70 61 72 65 28 22 53 45 4c 45 43  b.prepare("SELEC
1a70: 54 20 67 65 6f 73 5f 76 65 72 73 69 6f 6e 28 29  T geos_version()
1a80: 3b 22 29 3b 0d 0a 20 20 20 20 20 20 20 20 69 66  ;");..        if
1a90: 20 28 73 74 6d 74 30 31 2e 73 74 65 70 28 29 29   (stmt01.step())
1aa0: 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20   {..            
1ab0: 73 62 2e 61 70 70 65 6e 64 28 22 5c 74 22 29 2e  sb.append("\t").
1ac0: 61 70 70 65 6e 64 28 22 47 45 4f 53 5f 56 45 52  append("GEOS_VER
1ad0: 53 49 4f 4e 3a 20 22 20 2b 20 73 74 6d 74 30 31  SION: " + stmt01
1ae0: 2e 63 6f 6c 75 6d 6e 5f 73 74 72 69 6e 67 28 30  .column_string(0
1af0: 29 29 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 20  ));..           
1b00: 20 73 62 2e 61 70 70 65 6e 64 28 22 5c 6e 22 29   sb.append("\n")
1b10: 3b 0d 0a 20 20 20 20 20 20 20 20 7d 0d 0a 20 20  ;..        }..  
1b20: 20 20 20 20 20 20 73 74 6d 74 30 31 2e 63 6c 6f        stmt01.clo
1b30: 73 65 28 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 20  se();....       
1b40: 20 73 62 2e 61 70 70 65 6e 64 28 22 44 6f 6e 65   sb.append("Done
1b50: 2e 2e 2e 5c 6e 22 29 3b 0d 0a 20 20 20 20 20 20  ...\n");..      
1b60: 20 20 72 65 74 75 72 6e 20 73 62 2e 74 6f 53 74    return sb.toSt
1b70: 72 69 6e 67 28 29 3b 0d 0a 20 20 20 20 7d 0d 0a  ring();..    }..
1b80: 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 0d 0a 0d  </verbatim>.....
1b90: 0a 3c 68 34 3e 43 68 65 63 6b 20 70 6c 61 69 6e  .<h4>Check plain
1ba0: 20 73 71 6c 69 74 65 20 71 75 65 72 69 65 73 3c   sqlite queries<
1bb0: 2f 68 34 3e 0d 0a 0d 0a 54 6f 20 73 65 65 20 69  /h4>....To see i
1bc0: 66 20 69 74 20 61 6c 6c 20 77 6f 72 6b 73 2c 20  f it all works, 
1bd0: 77 65 20 63 61 6e 20 64 6f 20 61 20 70 6c 61 69  we can do a plai
1be0: 6e 20 73 71 6c 69 74 65 20 71 75 65 72 79 20 61  n sqlite query a
1bf0: 6e 64 20 73 65 65 20 69 66 20 77 65 20 68 61 76  nd see if we hav
1c00: 65 20 74 68 65 20 64 61 74 61 62 61 73 65 20 73  e the database s
1c10: 65 74 75 70 20 77 69 74 68 20 74 68 65 20 64 61  etup with the da
1c20: 74 61 2e 0d 0a 41 73 73 75 6d 69 6e 67 20 79 6f  ta...Assuming yo
1c30: 75 20 69 6d 70 6f 72 74 65 64 20 74 68 65 20 73  u imported the s
1c40: 68 61 70 66 69 6c 65 20 43 6f 6d 75 6e 69 5f 32  hapfile Comuni_2
1c50: 30 31 31 20 69 6e 74 6f 20 61 20 74 61 62 6c 65  011 into a table
1c60: 20 6e 61 6d 65 64 20 43 6f 6d 75 6e 69 5f 31 31   named Comuni_11
1c70: 2c 20 77 68 69 63 68 20 68 61 73 20 61 20 66 69  , which has a fi
1c80: 65 6c 64 20 63 61 6c 6c 65 64 20 4e 4f 4d 45 2c  eld called NOME,
1c90: 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 67   the following g
1ca0: 69 76 65 73 20 79 6f 75 20 74 68 65 20 66 69 72  ives you the fir
1cb0: 73 74 20 35 20 65 6e 74 72 69 65 73 3a 0d 0a 0d  st 5 entries:...
1cc0: 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 20 20 20  .<verbatim>..   
1cd0: 20 70 75 62 6c 69 63 20 53 74 72 69 6e 67 20 71   public String q
1ce0: 75 65 72 79 43 6f 6d 75 6e 69 28 29 20 7b 0d 0a  ueryComuni() {..
1cf0: 20 20 20 20 20 20 20 20 73 62 2e 61 70 70 65 6e          sb.appen
1d00: 64 28 22 51 75 65 72 79 20 43 6f 6d 75 6e 69 2e  d("Query Comuni.
1d10: 2e 2e 5c 6e 22 29 3b 0d 0a 0d 0a 20 20 20 20 20  ..\n");....     
1d20: 20 20 20 53 74 72 69 6e 67 20 71 75 65 72 79 20     String query 
1d30: 3d 20 22 53 45 4c 45 43 54 20 4e 4f 4d 45 22 20  = "SELECT NOME" 
1d40: 2b 20 2f 2f 0d 0a 20 20 20 20 20 20 20 20 20 20  + //..          
1d50: 20 20 20 20 20 20 22 20 66 72 6f 6d 20 43 6f 6d        " from Com
1d60: 75 6e 69 5f 31 31 22 20 2b 20 2f 2f 0d 0a 20 20  uni_11" + //..  
1d70: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 22 20                " 
1d80: 6f 72 64 65 72 20 62 79 20 4e 4f 4d 45 3b 22 3b  order by NOME;";
1d90: 0d 0a 20 20 20 20 20 20 20 20 73 62 2e 61 70 70  ..        sb.app
1da0: 65 6e 64 28 22 45 78 65 63 75 74 65 20 71 75 65  end("Execute que
1db0: 72 79 3a 20 22 29 2e 61 70 70 65 6e 64 28 71 75  ry: ").append(qu
1dc0: 65 72 79 29 2e 61 70 70 65 6e 64 28 22 5c 6e 22  ery).append("\n"
1dd0: 29 3b 0d 0a 20 20 20 20 20 20 20 20 74 72 79 20  );..        try 
1de0: 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 53  {..            S
1df0: 74 6d 74 20 73 74 6d 74 20 3d 20 64 62 2e 70 72  tmt stmt = db.pr
1e00: 65 70 61 72 65 28 71 75 65 72 79 29 3b 0d 0a 20  epare(query);.. 
1e10: 20 20 20 20 20 20 20 20 20 20 20 69 6e 74 20 69             int i
1e20: 6e 64 65 78 20 3d 20 30 3b 0d 0a 20 20 20 20 20  ndex = 0;..     
1e30: 20 20 20 20 20 20 20 77 68 69 6c 65 28 20 73 74         while( st
1e40: 6d 74 2e 73 74 65 70 28 29 20 29 20 7b 0d 0a 20  mt.step() ) {.. 
1e50: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 53                 S
1e60: 74 72 69 6e 67 20 6e 6f 6d 65 53 74 72 20 3d 20  tring nomeStr = 
1e70: 73 74 6d 74 2e 63 6f 6c 75 6d 6e 5f 73 74 72 69  stmt.column_stri
1e80: 6e 67 28 30 29 3b 0d 0a 20 20 20 20 20 20 20 20  ng(0);..        
1e90: 20 20 20 20 20 20 20 20 73 62 2e 61 70 70 65 6e          sb.appen
1ea0: 64 28 22 5c 74 22 29 2e 61 70 70 65 6e 64 28 6e  d("\t").append(n
1eb0: 6f 6d 65 53 74 72 29 2e 61 70 70 65 6e 64 28 22  omeStr).append("
1ec0: 5c 6e 22 29 3b 0d 0a 20 20 20 20 20 20 20 20 20  \n");..         
1ed0: 20 20 20 20 20 20 20 69 66 20 28 69 6e 64 65 78         if (index
1ee0: 2b 2b 20 3e 20 35 29 20 7b 0d 0a 20 20 20 20 20  ++ > 5) {..     
1ef0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 62                 b
1f00: 72 65 61 6b 3b 0d 0a 20 20 20 20 20 20 20 20 20  reak;..         
1f10: 20 20 20 20 20 20 20 7d 0d 0a 20 20 20 20 20 20         }..      
1f20: 20 20 20 20 20 20 7d 0d 0a 20 20 20 20 20 20 20        }..       
1f30: 20 20 20 20 20 73 62 2e 61 70 70 65 6e 64 28 22       sb.append("
1f40: 5c 74 2e 2e 2e 22 29 3b 0d 0a 20 20 20 20 20 20  \t...");..      
1f50: 20 20 20 20 20 20 73 74 6d 74 2e 63 6c 6f 73 65        stmt.close
1f60: 28 29 3b 0d 0a 20 20 20 20 20 20 20 20 7d 20 63  ();..        } c
1f70: 61 74 63 68 20 28 45 78 63 65 70 74 69 6f 6e 20  atch (Exception 
1f80: 65 29 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 20  e) {..          
1f90: 20 20 65 72 72 6f 72 28 65 29 3b 0d 0a 20 20 20    error(e);..   
1fa0: 20 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 20 20       }....      
1fb0: 20 20 73 62 2e 61 70 70 65 6e 64 28 22 44 6f 6e    sb.append("Don
1fc0: 65 2e 2e 2e 5c 6e 22 29 3b 0d 0a 0d 0a 20 20 20  e...\n");....   
1fd0: 20 20 20 20 20 72 65 74 75 72 6e 20 73 62 2e 74       return sb.t
1fe0: 6f 53 74 72 69 6e 67 28 29 3b 0d 0a 20 20 20 20  oString();..    
1ff0: 7d 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a  }..</verbatim>..
2000: 0d 0a 3c 68 34 3e 59 6f 75 72 20 66 69 72 73 74  ..<h4>Your first
2010: 20 73 70 61 74 69 61 6c 20 71 75 65 72 79 3c 2f   spatial query</
2020: 68 34 3e 0d 0a 0d 0a 4c 65 74 27 73 20 66 69 6e  h4>....Let's fin
2030: 61 6c 6c 79 20 71 75 65 72 79 20 66 6f 72 20 74  ally query for t
2040: 68 65 20 67 65 6f 6d 65 74 72 69 65 73 2c 20 69  he geometries, i
2050: 66 20 74 68 65 72 65 20 61 72 65 20 61 6e 79 2e  f there are any.
2060: 20 54 68 65 20 72 65 73 75 6c 74 69 6e 67 20 57   The resulting W
2070: 4b 54 20 66 6f 72 6d 61 74 20 6f 66 20 74 68 65  KT format of the
2080: 20 67 65 6f 6d 65 74 72 69 65 73 20 69 73 20 73   geometries is s
2090: 68 6f 72 74 65 6e 65 64 20 69 6e 20 6f 72 64 65  hortened in orde
20a0: 72 20 74 6f 20 62 65 20 70 72 69 6e 74 65 64 3a  r to be printed:
20b0: 0d 0a 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a  ....<verbatim>..
20c0: 20 20 20 20 70 75 62 6c 69 63 20 53 74 72 69 6e      public Strin
20d0: 67 20 71 75 65 72 79 43 6f 6d 75 6e 69 57 69 74  g queryComuniWit
20e0: 68 47 65 6f 6d 28 29 20 7b 0d 0a 20 20 20 20 20  hGeom() {..     
20f0: 20 20 20 73 62 2e 61 70 70 65 6e 64 28 53 45 50     sb.append(SEP
2100: 29 3b 0d 0a 20 20 20 20 20 20 20 20 73 62 2e 61  );..        sb.a
2110: 70 70 65 6e 64 28 22 51 75 65 72 79 20 43 6f 6d  ppend("Query Com
2120: 75 6e 69 20 77 69 74 68 20 41 73 54 65 78 74 28  uni with AsText(
2130: 47 65 6f 6d 65 74 72 79 29 2e 2e 2e 5c 6e 22 29  Geometry)...\n")
2140: 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 53 74 72  ;....        Str
2150: 69 6e 67 20 71 75 65 72 79 20 3d 20 22 53 45 4c  ing query = "SEL
2160: 45 43 54 20 4e 4f 4d 45 22 20 2b 20 2f 2f 0d 0a  ECT NOME" + //..
2170: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
2180: 22 20 2c 20 41 73 54 65 78 74 28 47 65 6f 6d 65  " , AsText(Geome
2190: 74 72 79 29 22 20 2b 20 2f 2f 0d 0a 20 20 20 20  try)" + //..    
21a0: 20 20 20 20 20 20 20 20 20 20 20 20 22 20 61 73              " as
21b0: 20 67 65 6f 6d 20 66 72 6f 6d 20 43 6f 6d 75 6e   geom from Comun
21c0: 69 5f 31 31 22 20 2b 20 20 2f 2f 0d 0a 20 20 20  i_11" +  //..   
21d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 22 20 77               " w
21e0: 68 65 72 65 20 67 65 6f 6d 20 6e 6f 74 20 6e 75  here geom not nu
21f0: 6c 6c 3b 22 3b 0d 0a 20 20 20 20 20 20 20 20 73  ll;";..        s
2200: 62 2e 61 70 70 65 6e 64 28 22 45 78 65 63 75 74  b.append("Execut
2210: 65 20 71 75 65 72 79 3a 20 22 29 2e 61 70 70 65  e query: ").appe
2220: 6e 64 28 71 75 65 72 79 29 2e 61 70 70 65 6e 64  nd(query).append
2230: 28 22 5c 6e 22 29 3b 0d 0a 20 20 20 20 20 20 20  ("\n");..       
2240: 20 74 72 79 20 7b 0d 0a 20 20 20 20 20 20 20 20   try {..        
2250: 20 20 20 20 53 74 6d 74 20 73 74 6d 74 20 3d 20      Stmt stmt = 
2260: 64 62 2e 70 72 65 70 61 72 65 28 71 75 65 72 79  db.prepare(query
2270: 29 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20  );..            
2280: 77 68 69 6c 65 28 20 73 74 6d 74 2e 73 74 65 70  while( stmt.step
2290: 28 29 20 29 20 7b 0d 0a 20 20 20 20 20 20 20 20  () ) {..        
22a0: 20 20 20 20 20 20 20 20 53 74 72 69 6e 67 20 6e          String n
22b0: 6f 6d 65 53 74 72 20 3d 20 73 74 6d 74 2e 63 6f  omeStr = stmt.co
22c0: 6c 75 6d 6e 5f 73 74 72 69 6e 67 28 30 29 3b 0d  lumn_string(0);.
22d0: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20  .               
22e0: 20 53 74 72 69 6e 67 20 67 65 6f 6d 53 74 72 20   String geomStr 
22f0: 3d 20 73 74 6d 74 2e 63 6f 6c 75 6d 6e 5f 73 74  = stmt.column_st
2300: 72 69 6e 67 28 31 29 3b 0d 0a 20 20 20 20 20 20  ring(1);..      
2310: 20 20 20 20 20 20 20 20 20 20 53 74 72 69 6e 67            String
2320: 20 73 75 62 73 74 72 69 6e 67 20 3d 20 67 65 6f   substring = geo
2330: 6d 53 74 72 3b 0d 0a 20 20 20 20 20 20 20 20 20  mStr;..         
2340: 20 20 20 20 20 20 20 69 66 20 28 73 75 62 73 74         if (subst
2350: 72 69 6e 67 2e 6c 65 6e 67 74 68 28 29 20 3e 20  ring.length() > 
2360: 34 30 29 0d 0a 20 20 20 20 20 20 20 20 20 20 20  40)..           
2370: 20 20 20 20 20 20 20 20 20 73 75 62 73 74 72 69           substri
2380: 6e 67 20 3d 20 67 65 6f 6d 53 74 72 2e 73 75 62  ng = geomStr.sub
2390: 73 74 72 69 6e 67 28 30 2c 20 34 30 29 3b 0d 0a  string(0, 40);..
23a0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
23b0: 73 62 2e 61 70 70 65 6e 64 28 22 5c 74 22 29 2e  sb.append("\t").
23c0: 61 70 70 65 6e 64 28 6e 6f 6d 65 53 74 72 29 2e  append(nomeStr).
23d0: 61 70 70 65 6e 64 28 22 20 2d 20 22 29 2e 61 70  append(" - ").ap
23e0: 70 65 6e 64 28 73 75 62 73 74 72 69 6e 67 29 2e  pend(substring).
23f0: 61 70 70 65 6e 64 28 22 2e 2e 2e 5c 6e 22 29 3b  append("...\n");
2400: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20  ..              
2410: 20 20 62 72 65 61 6b 3b 0d 0a 20 20 20 20 20 20    break;..      
2420: 20 20 20 20 20 20 7d 0d 0a 20 20 20 20 20 20 20        }..       
2430: 20 20 20 20 20 73 74 6d 74 2e 63 6c 6f 73 65 28       stmt.close(
2440: 29 3b 0d 0a 20 20 20 20 20 20 20 20 7d 20 63 61  );..        } ca
2450: 74 63 68 20 28 45 78 63 65 70 74 69 6f 6e 20 65  tch (Exception e
2460: 29 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 20  ) {..           
2470: 20 65 2e 70 72 69 6e 74 53 74 61 63 6b 54 72 61   e.printStackTra
2480: 63 65 28 29 3b 0d 0a 20 20 20 20 20 20 20 20 20  ce();..         
2490: 20 20 20 73 62 2e 61 70 70 65 6e 64 28 45 52 52     sb.append(ERR
24a0: 4f 52 29 2e 61 70 70 65 6e 64 28 65 2e 67 65 74  OR).append(e.get
24b0: 4c 6f 63 61 6c 69 7a 65 64 4d 65 73 73 61 67 65  LocalizedMessage
24c0: 28 29 29 2e 61 70 70 65 6e 64 28 22 5c 6e 22 29  ()).append("\n")
24d0: 3b 0d 0a 20 20 20 20 20 20 20 20 7d 0d 0a 20 20  ;..        }..  
24e0: 20 20 20 20 20 20 73 62 2e 61 70 70 65 6e 64 28        sb.append(
24f0: 22 44 6f 6e 65 2e 2e 2e 5c 6e 22 29 3b 0d 0a 0d  "Done...\n");...
2500: 0a 20 20 20 20 20 20 20 20 72 65 74 75 72 6e 20  .        return 
2510: 73 62 2e 74 6f 53 74 72 69 6e 67 28 29 3b 0d 0a  sb.toString();..
2520: 20 20 20 20 7d 0d 0a 3c 2f 76 65 72 62 61 74 69      }..</verbati
2530: 6d 3e 0d 0a 0d 0a 3c 68 34 3e 47 65 74 20 74 68  m>....<h4>Get th
2540: 65 20 61 72 65 61 20 6f 66 20 61 20 70 6f 6c 79  e area of a poly
2550: 67 6f 6e 3c 2f 68 34 3e 0d 0a 0d 0a 54 68 65 20  gon</h4>....The 
2560: 3c 69 3e 53 54 5f 41 72 65 61 3c 2f 69 3e 20 66  <i>ST_Area</i> f
2570: 75 6e 63 74 69 6f 6e 20 69 73 20 61 76 61 69 6c  unction is avail
2580: 61 62 6c 65 20 74 6f 20 67 65 74 20 74 68 65 20  able to get the 
2590: 61 72 65 61 20 66 72 6f 6d 20 61 20 67 65 6f 6d  area from a geom
25a0: 65 74 72 79 3a 0d 0a 0d 0a 3c 76 65 72 62 61 74  etry:....<verbat
25b0: 69 6d 3e 0d 0a 20 20 20 20 70 75 62 6c 69 63 20  im>..    public 
25c0: 53 74 72 69 6e 67 20 71 75 65 72 79 43 6f 6d 75  String queryComu
25d0: 6e 69 41 72 65 61 28 29 20 7b 0d 0a 20 20 20 20  niArea() {..    
25e0: 20 20 20 20 73 62 2e 61 70 70 65 6e 64 28 53 45      sb.append(SE
25f0: 50 29 3b 0d 0a 20 20 20 20 20 20 20 20 73 62 2e  P);..        sb.
2600: 61 70 70 65 6e 64 28 22 51 75 65 72 79 20 43 6f  append("Query Co
2610: 6d 75 6e 69 20 61 72 65 61 20 73 75 6d 2e 2e 2e  muni area sum...
2620: 5c 6e 22 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 20  \n");....       
2630: 20 53 74 72 69 6e 67 20 71 75 65 72 79 20 3d 20   String query = 
2640: 22 53 45 4c 45 43 54 20 53 54 5f 41 72 65 61 28  "SELECT ST_Area(
2650: 47 65 6f 6d 65 74 72 79 29 20 2f 20 31 30 30 30  Geometry) / 1000
2660: 30 30 30 2e 30 20 66 72 6f 6d 20 43 6f 6d 75 6e  000.0 from Comun
2670: 69 5f 31 31 22 20 2b 20 20 2f 2f 0d 0a 20 20 20  i_11" +  //..   
2680: 20 20 20 20 20 20 20 20 20 20 20 20 20 22 3b 22               ";"
2690: 3b 0d 0a 20 20 20 20 20 20 20 20 73 62 2e 61 70  ;..        sb.ap
26a0: 70 65 6e 64 28 22 45 78 65 63 75 74 65 20 71 75  pend("Execute qu
26b0: 65 72 79 3a 20 22 29 2e 61 70 70 65 6e 64 28 71  ery: ").append(q
26c0: 75 65 72 79 29 2e 61 70 70 65 6e 64 28 22 5c 6e  uery).append("\n
26d0: 22 29 3b 0d 0a 20 20 20 20 20 20 20 20 74 72 79  ");..        try
26e0: 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20   {..            
26f0: 53 74 6d 74 20 73 74 6d 74 20 3d 20 64 62 2e 70  Stmt stmt = db.p
2700: 72 65 70 61 72 65 28 71 75 65 72 79 29 3b 0d 0a  repare(query);..
2710: 20 20 20 20 20 20 20 20 20 20 20 20 64 6f 75 62              doub
2720: 6c 65 20 74 6f 74 61 6c 41 72 65 61 20 3d 20 30  le totalArea = 0
2730: 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 77  ;..            w
2740: 68 69 6c 65 28 20 73 74 6d 74 2e 73 74 65 70 28  hile( stmt.step(
2750: 29 20 29 20 7b 0d 0a 20 20 20 20 20 20 20 20 20  ) ) {..         
2760: 20 20 20 20 20 20 20 64 6f 75 62 6c 65 20 61 72         double ar
2770: 65 61 20 3d 20 73 74 6d 74 2e 63 6f 6c 75 6d 6e  ea = stmt.column
2780: 5f 64 6f 75 62 6c 65 28 30 29 3b 0d 0a 20 20 20  _double(0);..   
2790: 20 20 20 20 20 20 20 20 20 20 20 20 20 74 6f 74               tot
27a0: 61 6c 41 72 65 61 20 3d 20 74 6f 74 61 6c 41 72  alArea = totalAr
27b0: 65 61 20 2b 20 61 72 65 61 3b 0d 0a 20 20 20 20  ea + area;..    
27c0: 20 20 20 20 20 20 20 20 7d 0d 0a 20 20 20 20 20          }..     
27d0: 20 20 20 20 20 20 20 73 62 2e 61 70 70 65 6e 64         sb.append
27e0: 28 22 5c 74 54 6f 74 61 6c 20 61 72 65 61 20 62  ("\tTotal area b
27f0: 79 20 73 75 6d 6d 69 6e 67 20 65 61 63 68 20 61  y summing each a
2800: 72 65 61 3a 20 22 29 2e 61 70 70 65 6e 64 28 74  rea: ").append(t
2810: 6f 74 61 6c 41 72 65 61 29 2e 61 70 70 65 6e 64  otalArea).append
2820: 28 22 4b 6d 32 5c 6e 22 29 3b 0d 0a 20 20 20 20  ("Km2\n");..    
2830: 20 20 20 20 20 20 20 20 73 74 6d 74 2e 63 6c 6f          stmt.clo
2840: 73 65 28 29 3b 0d 0a 20 20 20 20 20 20 20 20 7d  se();..        }
2850: 20 63 61 74 63 68 20 28 45 78 63 65 70 74 69 6f   catch (Exceptio
2860: 6e 20 65 29 20 7b 0d 0a 20 20 20 20 20 20 20 20  n e) {..        
2870: 20 20 20 20 65 2e 70 72 69 6e 74 53 74 61 63 6b      e.printStack
2880: 54 72 61 63 65 28 29 3b 0d 0a 20 20 20 20 20 20  Trace();..      
2890: 20 20 20 20 20 20 73 62 2e 61 70 70 65 6e 64 28        sb.append(
28a0: 45 52 52 4f 52 29 2e 61 70 70 65 6e 64 28 65 2e  ERROR).append(e.
28b0: 67 65 74 4c 6f 63 61 6c 69 7a 65 64 4d 65 73 73  getLocalizedMess
28c0: 61 67 65 28 29 29 2e 61 70 70 65 6e 64 28 22 5c  age()).append("\
28d0: 6e 22 29 3b 0d 0a 20 20 20 20 20 20 20 20 7d 0d  n");..        }.
28e0: 0a 20 20 20 20 20 20 20 20 73 62 2e 61 70 70 65  .        sb.appe
28f0: 6e 64 28 22 44 6f 6e 65 2e 2e 2e 5c 6e 22 29 3b  nd("Done...\n");
2900: 0d 0a 0d 0a 20 20 20 20 20 20 20 20 72 65 74 75  ....        retu
2910: 72 6e 20 73 62 2e 74 6f 53 74 72 69 6e 67 28 29  rn sb.toString()
2920: 3b 0d 0a 20 20 20 20 7d 0d 0a 3c 2f 76 65 72 62  ;..    }..</verb
2930: 61 74 69 6d 3e 0d 0a 0d 0a 4f 62 76 69 6f 75 73  atim>....Obvious
2940: 6c 79 20 79 6f 75 20 63 6f 75 6c 64 20 61 6c 73  ly you could als
2950: 6f 20 64 6f 20 74 68 65 20 73 75 6d 20 64 69 72  o do the sum dir
2960: 65 63 74 6c 79 20 69 6e 73 69 64 65 20 74 68 65  ectly inside the
2970: 20 71 75 65 72 79 2e 0d 0a 0d 0a 3c 68 34 3e 53   query.....<h4>S
2980: 69 6d 70 6c 65 20 63 6f 6f 72 64 69 6e 61 74 65  imple coordinate
2990: 20 74 72 61 6e 73 66 6f 72 6d 61 74 69 6f 6e 3c   transformation<
29a0: 2f 68 34 3e 0d 0a 0d 0a 59 6f 75 20 63 61 6e 20  /h4>....You can 
29b0: 61 6c 73 6f 20 64 6f 20 73 6f 6d 65 20 63 6f 6f  also do some coo
29c0: 72 64 69 6e 61 74 65 20 74 72 61 6e 73 66 6f 72  rdinate transfor
29d0: 6d 61 74 69 6f 6e 2e 20 54 72 79 20 77 69 74 68  mation. Try with
29e0: 3a 0d 0a 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d  :....<verbatim>.
29f0: 0a 20 20 20 20 70 75 62 6c 69 63 20 53 74 72 69  .    public Stri
2a00: 6e 67 20 64 6f 53 69 6d 70 6c 65 54 72 61 6e 73  ng doSimpleTrans
2a10: 66 6f 72 6d 28 29 20 7b 0d 0a 0d 0a 0d 0a 20 20  form() {......  
2a20: 20 20 20 20 20 20 73 62 2e 61 70 70 65 6e 64 28        sb.append(
2a30: 22 43 6f 6f 72 64 69 6e 61 74 65 20 74 72 61 6e  "Coordinate tran
2a40: 73 66 6f 72 6d 61 74 69 6f 6e 2e 2e 2e 5c 6e 22  sformation...\n"
2a50: 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 53 74  );....        St
2a60: 72 69 6e 67 20 71 75 65 72 79 20 3d 20 22 53 45  ring query = "SE
2a70: 4c 45 43 54 20 41 73 54 65 78 74 28 54 72 61 6e  LECT AsText(Tran
2a80: 73 66 6f 72 6d 28 4d 61 6b 65 50 6f 69 6e 74 28  sform(MakePoint(
2a90: 22 20 2b 20 54 45 53 54 5f 4c 4f 4e 20 2b 20 22  " + TEST_LON + "
2aa0: 2c 20 22 20 2b 20 54 45 53 54 5f 4c 41 54 20 2b  , " + TEST_LAT +
2ab0: 20 22 2c 20 34 33 32 36 29 2c 20 33 32 36 33 32   ", 4326), 32632
2ac0: 29 29 3b 22 3b 0d 0a 20 20 20 20 20 20 20 20 73  ));";..        s
2ad0: 62 2e 61 70 70 65 6e 64 28 22 45 78 65 63 75 74  b.append("Execut
2ae0: 65 20 71 75 65 72 79 3a 20 22 29 2e 61 70 70 65  e query: ").appe
2af0: 6e 64 28 71 75 65 72 79 29 2e 61 70 70 65 6e 64  nd(query).append
2b00: 28 22 5c 6e 22 29 3b 0d 0a 20 20 20 20 20 20 20  ("\n");..       
2b10: 20 74 72 79 20 7b 0d 0a 20 20 20 20 20 20 20 20   try {..        
2b20: 20 20 20 20 53 74 6d 74 20 73 74 6d 74 20 3d 20      Stmt stmt = 
2b30: 64 62 2e 70 72 65 70 61 72 65 28 71 75 65 72 79  db.prepare(query
2b40: 29 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20  );..            
2b50: 69 66 20 28 73 74 6d 74 2e 73 74 65 70 28 29 29  if (stmt.step())
2b60: 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20   {..            
2b70: 20 20 20 20 53 74 72 69 6e 67 20 70 6f 69 6e 74      String point
2b80: 53 74 72 20 3d 20 73 74 6d 74 2e 63 6f 6c 75 6d  Str = stmt.colum
2b90: 6e 5f 73 74 72 69 6e 67 28 30 29 3b 0d 0a 20 20  n_string(0);..  
2ba0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 73 62                sb
2bb0: 2e 61 70 70 65 6e 64 28 22 5c 74 22 29 2e 61 70  .append("\t").ap
2bc0: 70 65 6e 64 28 54 45 53 54 5f 4c 4f 4e 20 2b 20  pend(TEST_LON + 
2bd0: 22 2f 22 20 2b 20 54 45 53 54 5f 4c 41 54 20 2b  "/" + TEST_LAT +
2be0: 20 22 2f 45 50 53 47 3a 34 33 32 36 22 29 2e 61   "/EPSG:4326").a
2bf0: 70 70 65 6e 64 28 22 20 3d 20 22 29 2f 2f 0d 0a  ppend(" = ")//..
2c00: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
2c10: 20 20 20 20 20 20 20 20 2e 61 70 70 65 6e 64 28          .append(
2c20: 70 6f 69 6e 74 53 74 72 20 2b 20 22 2f 45 50 53  pointStr + "/EPS
2c30: 47 3a 33 32 36 33 32 22 29 2e 61 70 70 65 6e 64  G:32632").append
2c40: 28 22 2e 2e 2e 5c 6e 22 29 3b 0d 0a 20 20 20 20  ("...\n");..    
2c50: 20 20 20 20 20 20 20 20 7d 0d 0a 20 20 20 20 20          }..     
2c60: 20 20 20 20 20 20 20 73 74 6d 74 2e 63 6c 6f 73         stmt.clos
2c70: 65 28 29 3b 0d 0a 20 20 20 20 20 20 20 20 7d 20  e();..        } 
2c80: 63 61 74 63 68 20 28 45 78 63 65 70 74 69 6f 6e  catch (Exception
2c90: 20 65 29 20 7b 0d 0a 20 20 20 20 20 20 20 20 20   e) {..         
2ca0: 20 20 20 65 2e 70 72 69 6e 74 53 74 61 63 6b 54     e.printStackT
2cb0: 72 61 63 65 28 29 3b 0d 0a 20 20 20 20 20 20 20  race();..       
2cc0: 20 20 20 20 20 73 62 2e 61 70 70 65 6e 64 28 45       sb.append(E
2cd0: 52 52 4f 52 29 2e 61 70 70 65 6e 64 28 65 2e 67  RROR).append(e.g
2ce0: 65 74 4c 6f 63 61 6c 69 7a 65 64 4d 65 73 73 61  etLocalizedMessa
2cf0: 67 65 28 29 29 2e 61 70 70 65 6e 64 28 22 5c 6e  ge()).append("\n
2d00: 22 29 3b 0d 0a 20 20 20 20 20 20 20 20 7d 0d 0a  ");..        }..
2d10: 20 20 20 20 20 20 20 20 73 62 2e 61 70 70 65 6e          sb.appen
2d20: 64 28 22 44 6f 6e 65 2e 2e 2e 5c 6e 22 29 3b 0d  d("Done...\n");.
2d30: 0a 0d 0a 20 20 20 20 20 20 20 20 72 65 74 75 72  ...        retur
2d40: 6e 20 73 62 2e 74 6f 53 74 72 69 6e 67 28 29 3b  n sb.toString();
2d50: 0d 0a 0d 0a 20 20 20 20 7d 0d 0a 3c 2f 76 65 72  ....    }..</ver
2d60: 62 61 74 69 6d 3e 0d 0a 0d 0a 73 65 74 74 69 6e  batim>....settin
2d70: 67 20 54 45 53 54 5f 4c 4f 4e 20 20 61 6e 64 20  g TEST_LON  and 
2d80: 54 45 53 54 5f 4c 41 54 20 74 6f 20 74 68 65 20  TEST_LAT to the 
2d90: 63 6f 6f 72 64 69 6e 61 74 65 73 20 74 6f 20 74  coordinates to t
2da0: 72 61 6e 73 66 6f 72 6d 2c 20 69 6e 20 74 68 65  ransform, in the
2db0: 20 61 62 6f 76 65 20 63 61 73 65 20 66 72 6f 6d   above case from
2dc0: 20 53 52 49 44 20 34 33 32 36 20 74 6f 20 33 32   SRID 4326 to 32
2dd0: 36 33 32 2e 0d 0a 0d 0a 3c 68 34 3e 41 20 6d 6f  632.....<h4>A mo
2de0: 72 65 20 63 6f 6d 70 6c 65 78 20 71 75 65 72 79  re complex query
2df0: 3c 2f 68 34 3e 0d 0a 0d 0a 3c 76 65 72 62 61 74  </h4>....<verbat
2e00: 69 6d 3e 0d 0a 20 20 20 20 70 75 62 6c 69 63 20  im>..    public 
2e10: 53 74 72 69 6e 67 20 71 75 65 72 79 43 6f 6d 75  String queryComu
2e20: 6e 69 4e 65 61 72 62 79 28 29 20 7b 0d 0a 20 20  niNearby() {..  
2e30: 20 20 20 20 20 20 73 62 2e 61 70 70 65 6e 64 28        sb.append(
2e40: 53 45 50 29 3b 0d 0a 20 20 20 20 20 20 20 20 73  SEP);..        s
2e50: 62 2e 61 70 70 65 6e 64 28 22 51 75 65 72 79 20  b.append("Query 
2e60: 43 6f 6d 75 6e 69 20 6e 65 61 72 62 79 2e 2e 2e  Comuni nearby...
2e70: 5c 6e 22 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 20  \n");....       
2e80: 20 53 74 72 69 6e 67 20 71 75 65 72 79 20 3d 20   String query = 
2e90: 22 53 45 4c 45 43 54 20 48 65 78 28 53 54 5f 41  "SELECT Hex(ST_A
2ea0: 73 42 69 6e 61 72 79 28 53 54 5f 42 75 66 66 65  sBinary(ST_Buffe
2eb0: 72 28 47 65 6f 6d 65 74 72 79 2c 20 31 2e 30 29  r(Geometry, 1.0)
2ec0: 29 29 2c 20 53 54 5f 53 72 69 64 28 47 65 6f 6d  )), ST_Srid(Geom
2ed0: 65 74 72 79 29 2c 20 53 54 5f 47 65 6f 6d 65 74  etry), ST_Geomet
2ee0: 72 79 54 79 70 65 28 47 65 6f 6d 65 74 72 79 29  ryType(Geometry)
2ef0: 20 66 72 6f 6d 20 43 6f 6d 75 6e 69 5f 31 31 22   from Comuni_11"
2f00: 20 2b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20   +..            
2f10: 20 20 20 20 22 20 77 68 65 72 65 20 4e 4f 4d 45      " where NOME
2f20: 20 3d 20 27 42 6f 6c 7a 61 6e 6f 27 3b 22 3b 0d   = 'Bolzano';";.
2f30: 0a 20 20 20 20 20 20 20 20 73 62 2e 61 70 70 65  .        sb.appe
2f40: 6e 64 28 22 45 78 65 63 75 74 65 20 71 75 65 72  nd("Execute quer
2f50: 79 3a 20 22 29 2e 61 70 70 65 6e 64 28 71 75 65  y: ").append(que
2f60: 72 79 29 2e 61 70 70 65 6e 64 28 22 5c 6e 22 29  ry).append("\n")
2f70: 3b 0d 0a 20 20 20 20 20 20 20 20 53 74 72 69 6e  ;..        Strin
2f80: 67 20 62 75 66 66 65 72 47 65 6f 6d 20 3d 20 22  g bufferGeom = "
2f90: 22 3b 0d 0a 20 20 20 20 20 20 20 20 53 74 72 69  ";..        Stri
2fa0: 6e 67 20 62 75 66 66 65 72 47 65 6f 6d 53 68 6f  ng bufferGeomSho
2fb0: 72 74 20 3d 20 22 22 3b 0d 0a 20 20 20 20 20 20  rt = "";..      
2fc0: 20 20 74 72 79 20 7b 0d 0a 20 20 20 20 20 20 20    try {..       
2fd0: 20 20 20 20 20 53 74 6d 74 20 73 74 6d 74 20 3d       Stmt stmt =
2fe0: 20 64 62 2e 70 72 65 70 61 72 65 28 71 75 65 72   db.prepare(quer
2ff0: 79 29 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 20  y);..           
3000: 20 69 66 20 28 73 74 6d 74 2e 73 74 65 70 28 29   if (stmt.step()
3010: 29 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 20  ) {..           
3020: 20 20 20 20 20 62 75 66 66 65 72 47 65 6f 6d 20       bufferGeom 
3030: 3d 20 73 74 6d 74 2e 63 6f 6c 75 6d 6e 5f 73 74  = stmt.column_st
3040: 72 69 6e 67 28 30 29 3b 0d 0a 20 20 20 20 20 20  ring(0);..      
3050: 20 20 20 20 20 20 20 20 20 20 53 74 72 69 6e 67            String
3060: 20 67 65 6f 6d 53 72 69 64 20 3d 20 73 74 6d 74   geomSrid = stmt
3070: 2e 63 6f 6c 75 6d 6e 5f 73 74 72 69 6e 67 28 31  .column_string(1
3080: 29 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20  );..            
3090: 20 20 20 20 53 74 72 69 6e 67 20 67 65 6f 6d 54      String geomT
30a0: 79 70 65 20 3d 20 73 74 6d 74 2e 63 6f 6c 75 6d  ype = stmt.colum
30b0: 6e 5f 73 74 72 69 6e 67 28 32 29 3b 0d 0a 20 20  n_string(2);..  
30c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 73 62                sb
30d0: 2e 61 70 70 65 6e 64 28 22 5c 74 54 68 65 20 73  .append("\tThe s
30e0: 65 6c 65 63 74 65 64 20 67 65 6f 6d 65 74 72 79  elected geometry
30f0: 20 69 73 20 6f 66 20 74 79 70 65 3a 20 22 29 2e   is of type: ").
3100: 61 70 70 65 6e 64 28 67 65 6f 6d 54 79 70 65 29  append(geomType)
3110: 2e 61 70 70 65 6e 64 28 22 20 61 6e 64 20 6f 66  .append(" and of
3120: 20 53 52 49 44 3a 20 22 29 2e 61 70 70 65 6e 64   SRID: ").append
3130: 28 67 65 6f 6d 53 72 69 64 29 0d 0a 20 20 20 20  (geomSrid)..    
3140: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
3150: 20 20 20 20 2e 61 70 70 65 6e 64 28 22 5c 6e 22      .append("\n"
3160: 29 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20  );..            
3170: 7d 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 62  }..            b
3180: 75 66 66 65 72 47 65 6f 6d 53 68 6f 72 74 20 3d  ufferGeomShort =
3190: 20 62 75 66 66 65 72 47 65 6f 6d 3b 0d 0a 20 20   bufferGeom;..  
31a0: 20 20 20 20 20 20 20 20 20 20 69 66 20 28 62 75            if (bu
31b0: 66 66 65 72 47 65 6f 6d 2e 6c 65 6e 67 74 68 28  fferGeom.length(
31c0: 29 20 3e 20 31 30 29 0d 0a 20 20 20 20 20 20 20  ) > 10)..       
31d0: 20 20 20 20 20 20 20 20 20 62 75 66 66 65 72 47           bufferG
31e0: 65 6f 6d 53 68 6f 72 74 20 3d 20 62 75 66 66 65  eomShort = buffe
31f0: 72 47 65 6f 6d 2e 73 75 62 73 74 72 69 6e 67 28  rGeom.substring(
3200: 30 2c 20 31 30 29 20 2b 20 22 2e 2e 2e 22 3b 0d  0, 10) + "...";.
3210: 0a 20 20 20 20 20 20 20 20 20 20 20 20 73 62 2e  .            sb.
3220: 61 70 70 65 6e 64 28 22 5c 74 42 6f 6c 7a 61 6e  append("\tBolzan
3230: 6f 20 70 6f 6c 79 67 6f 6e 20 62 75 66 66 65 72  o polygon buffer
3240: 20 67 65 6f 6d 65 74 72 79 20 69 6e 20 48 45 58   geometry in HEX
3250: 3a 20 22 29 2e 61 70 70 65 6e 64 28 62 75 66 66  : ").append(buff
3260: 65 72 47 65 6f 6d 53 68 6f 72 74 29 2e 61 70 70  erGeomShort).app
3270: 65 6e 64 28 22 5c 6e 22 29 3b 0d 0a 20 20 20 20  end("\n");..    
3280: 20 20 20 20 20 20 20 20 73 74 6d 74 2e 63 6c 6f          stmt.clo
3290: 73 65 28 29 3b 0d 0a 20 20 20 20 20 20 20 20 7d  se();..        }
32a0: 20 63 61 74 63 68 20 28 45 78 63 65 70 74 69 6f   catch (Exceptio
32b0: 6e 20 65 29 20 7b 0d 0a 20 20 20 20 20 20 20 20  n e) {..        
32c0: 20 20 20 20 65 2e 70 72 69 6e 74 53 74 61 63 6b      e.printStack
32d0: 54 72 61 63 65 28 29 3b 0d 0a 20 20 20 20 20 20  Trace();..      
32e0: 20 20 20 20 20 20 73 62 2e 61 70 70 65 6e 64 28        sb.append(
32f0: 45 52 52 4f 52 29 2e 61 70 70 65 6e 64 28 65 2e  ERROR).append(e.
3300: 67 65 74 4c 6f 63 61 6c 69 7a 65 64 4d 65 73 73  getLocalizedMess
3310: 61 67 65 28 29 29 2e 61 70 70 65 6e 64 28 22 5c  age()).append("\
3320: 6e 22 29 3b 0d 0a 20 20 20 20 20 20 20 20 7d 0d  n");..        }.
3330: 0a 0d 0a 20 20 20 20 20 20 20 20 71 75 65 72 79  ...        query
3340: 20 3d 20 22 53 45 4c 45 43 54 20 22 20 2b 20 4e   = "SELECT " + N
3350: 4f 4d 45 20 2b 20 22 2c 20 41 73 54 65 78 74 28  OME + ", AsText(
3360: 53 54 5f 63 65 6e 74 72 6f 69 64 28 47 65 6f 6d  ST_centroid(Geom
3370: 65 74 72 79 29 29 20 66 72 6f 6d 20 22 20 2b 20  etry)) from " + 
3380: 43 4f 4d 55 4e 49 54 41 42 4c 45 20 2b 20 2f 2f  COMUNITABLE + //
3390: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20  ..              
33a0: 20 20 22 20 77 68 65 72 65 20 53 54 5f 49 6e 74    " where ST_Int
33b0: 65 72 73 65 63 74 73 28 20 53 54 5f 47 65 6f 6d  ersects( ST_Geom
33c0: 46 72 6f 6d 57 4b 42 28 78 27 22 20 2b 20 62 75  FromWKB(x'" + bu
33d0: 66 66 65 72 47 65 6f 6d 20 2b 20 22 27 29 20 2c  fferGeom + "') ,
33e0: 20 47 65 6f 6d 65 74 72 79 20 29 3b 22 3b 0d 0a   Geometry );";..
33f0: 20 20 20 20 20 20 20 20 2f 2f 20 6a 75 73 74 20          // just 
3400: 66 6f 72 20 70 72 69 6e 74 0d 0a 20 20 20 20 20  for print..     
3410: 20 20 20 53 74 72 69 6e 67 20 74 6d 70 51 75 65     String tmpQue
3420: 72 79 20 3d 20 22 53 45 4c 45 43 54 20 22 20 2b  ry = "SELECT " +
3430: 20 4e 4f 4d 45 20 2b 20 22 20 66 72 6f 6d 20 22   NOME + " from "
3440: 20 2b 20 43 4f 4d 55 4e 49 54 41 42 4c 45 20 2b   + COMUNITABLE +
3450: 20 2f 2f 0d 0a 20 20 20 20 20 20 20 20 20 20 20   //..           
3460: 20 20 20 20 20 22 20 77 68 65 72 65 20 53 54 5f       " where ST_
3470: 49 6e 74 65 72 73 65 63 74 73 28 20 53 54 5f 47  Intersects( ST_G
3480: 65 6f 6d 46 72 6f 6d 57 4b 42 28 78 27 22 20 2b  eomFromWKB(x'" +
3490: 20 62 75 66 66 65 72 47 65 6f 6d 53 68 6f 72 74   bufferGeomShort
34a0: 20 2b 20 22 27 29 20 2c 20 47 65 6f 6d 65 74 72   + "') , Geometr
34b0: 79 20 29 3b 22 3b 0d 0a 20 20 20 20 20 20 20 20  y );";..        
34c0: 73 62 2e 61 70 70 65 6e 64 28 22 45 78 65 63 75  sb.append("Execu
34d0: 74 65 20 71 75 65 72 79 3a 20 22 29 2e 61 70 70  te query: ").app
34e0: 65 6e 64 28 74 6d 70 51 75 65 72 79 29 2e 61 70  end(tmpQuery).ap
34f0: 70 65 6e 64 28 22 5c 6e 22 29 3b 0d 0a 20 20 20  pend("\n");..   
3500: 20 20 20 20 20 74 72 79 20 7b 0d 0a 20 20 20 20       try {..    
3510: 20 20 20 20 20 20 20 20 73 62 2e 61 70 70 65 6e          sb.appen
3520: 64 28 22 5c 74 43 6f 6d 75 6e 69 20 6e 65 61 72  d("\tComuni near
3530: 62 79 20 42 6f 6c 7a 61 6e 6f 3a 20 5c 6e 22 29  by Bolzano: \n")
3540: 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 53  ;..            S
3550: 74 6d 74 20 73 74 6d 74 20 3d 20 64 62 2e 70 72  tmt stmt = db.pr
3560: 65 70 61 72 65 28 71 75 65 72 79 29 3b 0d 0a 20  epare(query);.. 
3570: 20 20 20 20 20 20 20 20 20 20 20 77 68 69 6c 65             while
3580: 28 20 73 74 6d 74 2e 73 74 65 70 28 29 20 29 20  ( stmt.step() ) 
3590: 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20  {..             
35a0: 20 20 20 53 74 72 69 6e 67 20 6e 61 6d 65 20 3d     String name =
35b0: 20 73 74 6d 74 2e 63 6f 6c 75 6d 6e 5f 73 74 72   stmt.column_str
35c0: 69 6e 67 28 30 29 3b 0d 0a 20 20 20 20 20 20 20  ing(0);..       
35d0: 20 20 20 20 20 20 20 20 20 53 74 72 69 6e 67 20           String 
35e0: 77 6b 74 20 3d 20 73 74 6d 74 2e 63 6f 6c 75 6d  wkt = stmt.colum
35f0: 6e 5f 73 74 72 69 6e 67 28 31 29 3b 0d 0a 20 20  n_string(1);..  
3600: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 73 62                sb
3610: 2e 61 70 70 65 6e 64 28 22 5c 74 5c 74 22 29 2e  .append("\t\t").
3620: 61 70 70 65 6e 64 28 6e 61 6d 65 29 2e 61 70 70  append(name).app
3630: 65 6e 64 28 22 20 2d 20 77 69 74 68 20 63 65 6e  end(" - with cen
3640: 74 72 6f 69 64 20 69 6e 20 22 29 2e 61 70 70 65  troid in ").appe
3650: 6e 64 28 77 6b 74 29 2e 61 70 70 65 6e 64 28 22  nd(wkt).append("
3660: 5c 6e 22 29 3b 0d 0a 20 20 20 20 20 20 20 20 20  \n");..         
3670: 20 20 20 7d 0d 0a 20 20 20 20 20 20 20 20 20 20     }..          
3680: 20 20 73 74 6d 74 2e 63 6c 6f 73 65 28 29 3b 0d    stmt.close();.
3690: 0a 20 20 20 20 20 20 20 20 7d 20 63 61 74 63 68  .        } catch
36a0: 20 28 45 78 63 65 70 74 69 6f 6e 20 65 29 20 7b   (Exception e) {
36b0: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 65 2e  ..            e.
36c0: 70 72 69 6e 74 53 74 61 63 6b 54 72 61 63 65 28  printStackTrace(
36d0: 29 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20  );..            
36e0: 73 62 2e 61 70 70 65 6e 64 28 45 52 52 4f 52 29  sb.append(ERROR)
36f0: 2e 61 70 70 65 6e 64 28 65 2e 67 65 74 4c 6f 63  .append(e.getLoc
3700: 61 6c 69 7a 65 64 4d 65 73 73 61 67 65 28 29 29  alizedMessage())
3710: 2e 61 70 70 65 6e 64 28 22 5c 6e 22 29 3b 0d 0a  .append("\n");..
3720: 20 20 20 20 20 20 20 20 7d 0d 0a 20 20 20 20 20          }..     
3730: 20 20 20 73 62 2e 61 70 70 65 6e 64 28 22 44 6f     sb.append("Do
3740: 6e 65 2e 2e 2e 5c 6e 22 29 3b 0d 0a 0d 0a 20 20  ne...\n");....  
3750: 20 20 20 20 20 20 72 65 74 75 72 6e 20 73 62 2e        return sb.
3760: 74 6f 53 74 72 69 6e 67 28 29 3b 0d 0a 20 20 20  toString();..   
3770: 20 7d 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d   }..</verbatim>.
3780: 0a 0d 0a 54 68 65 20 61 62 6f 76 65 20 77 69 6c  ...The above wil
3790: 6c 20 65 78 74 72 61 63 74 20 74 68 65 20 70 6f  l extract the po
37a0: 6c 79 67 6f 6e 20 6f 66 20 74 68 65 20 72 65 67  lygon of the reg
37b0: 69 6f 6e 20 42 6f 6c 7a 61 6e 6f 2c 20 62 75 66  ion Bolzano, buf
37c0: 66 65 72 20 69 74 20 61 6e 64 20 74 68 65 6e 20  fer it and then 
37d0: 66 69 6e 64 20 61 6c 6c 20 67 65 6f 6d 65 74 72  find all geometr
37e0: 69 65 73 20 74 68 61 74 20 69 6e 74 65 72 73 65  ies that interse
37f0: 63 74 20 77 69 74 68 20 74 68 61 74 20 62 75 66  ct with that buf
3800: 66 65 72 2e 20 49 74 20 69 73 20 61 20 73 69 6d  fer. It is a sim
3810: 70 6c 65 20 77 61 79 20 74 6f 20 66 69 6e 64 20  ple way to find 
3820: 74 68 65 20 72 65 67 69 6f 6e 73 20 73 75 72 72  the regions surr
3830: 6f 75 6e 64 69 6e 67 20 42 6f 6c 7a 61 6e 6f 2e  ounding Bolzano.
3840: 20 0d 0a 0d 0a 3c 68 34 3e 43 6c 6f 73 65 20 74   ....<h4>Close t
3850: 68 65 20 64 61 74 61 62 61 73 65 3c 2f 68 34 3e  he database</h4>
3860: 0d 0a 0d 0a 4f 6e 63 65 20 79 6f 75 20 64 6f 20  ....Once you do 
3870: 6e 6f 74 20 6e 65 65 64 20 74 68 65 20 63 6f 6e  not need the con
3880: 6e 65 63 74 69 6f 6e 20 74 6f 20 74 68 65 20 64  nection to the d
3890: 61 74 61 62 61 73 65 20 61 6e 79 20 6c 6f 6e 67  atabase any long
38a0: 65 72 2c 20 72 65 6d 65 6d 62 65 72 20 74 6f 20  er, remember to 
38b0: 72 65 6c 65 61 73 65 20 74 68 65 20 72 65 73 6f  release the reso
38c0: 75 72 63 65 20 62 79 20 63 6c 6f 73 69 6e 67 20  urce by closing 
38d0: 74 68 65 20 63 6f 6e 6e 65 63 74 69 6f 6e 3a 0d  the connection:.
38e0: 0a 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 64  ...<verbatim>..d
38f0: 62 2e 63 6c 6f 73 65 28 29 3b 0d 0a 3c 2f 76 65  b.close();..</ve
3900: 72 62 61 74 69 6d 3e 0d 0a 0d 0a 3c 68 33 3e 50  rbatim>....<h3>P
3910: 75 74 74 69 6e 67 20 69 74 20 61 6c 6c 20 74 6f  utting it all to
3920: 67 65 74 68 65 72 3c 2f 68 33 3e 0d 0a 0d 0a 3c  gether</h3>....<
3930: 70 3e 57 65 20 68 61 76 65 20 63 72 65 61 74 65  p>We have create
3940: 64 20 61 20 73 69 6d 70 6c 65 20 41 6e 64 72 6f  d a simple Andro
3950: 69 64 20 70 72 6f 6a 65 63 74 2c 20 77 68 69 63  id project, whic
3960: 68 20 69 6d 70 6c 65 6d 65 6e 74 73 20 74 68 65  h implements the
3970: 20 73 69 6d 70 6c 65 20 71 75 65 72 69 65 73 20   simple queries 
3980: 73 65 65 6e 20 69 6e 20 74 68 65 20 61 62 6f 76  seen in the abov
3990: 65 20 63 68 61 70 74 65 72 73 2e 0d 0a 49 74 20  e chapters...It 
39a0: 77 69 6c 6c 20 68 61 76 65 20 61 20 76 69 65 77  will have a view
39b0: 20 77 69 74 68 20 61 20 62 75 74 74 6f 6e 2c 20   with a button, 
39c0: 77 68 69 63 68 2c 20 6f 6e 63 65 20 70 72 65 73  which, once pres
39d0: 73 65 64 2c 20 77 69 6c 6c 20 65 78 65 63 75 74  sed, will execut
39e0: 65 20 69 6e 20 61 20 72 6f 77 20 61 6c 6c 20 74  e in a row all t
39f0: 68 65 20 71 75 65 72 69 65 73 20 61 6e 64 20 73  he queries and s
3a00: 68 6f 77 20 74 68 65 20 72 65 73 75 6c 74 73 2e  how the results.
3a10: 0d 0a 0d 0a 3c 68 32 3e 50 72 6f 6a 65 63 74 73  ....<h2>Projects
3a20: 20 69 6d 70 6c 65 6d 65 6e 74 69 6e 67 20 69 74   implementing it
3a30: 3c 2f 68 32 3e 0d 0a 0d 0a 3c 68 33 3e 47 65 6f  </h2>....<h3>Geo
3a40: 50 61 70 61 72 61 7a 7a 69 3c 2f 68 33 3e 0d 0a  Paparazzi</h3>..
3a50: 0d 0a 3c 70 3e 54 68 65 20 3c 61 20 68 72 65 66  ..<p>The <a href
3a60: 3d 22 68 74 74 70 3a 2f 2f 77 77 77 2e 67 65 6f  ="http://www.geo
3a70: 70 61 70 61 72 61 7a 7a 69 2e 65 75 22 3e 47 65  paparazzi.eu">Ge
3a80: 6f 50 61 70 61 72 61 7a 7a 69 3c 2f 61 3e 20 70  oPaparazzi</a> p
3a90: 72 6f 6a 65 63 74 20 73 75 70 70 6f 72 74 73 20  roject supports 
3aa0: 74 68 65 20 53 70 61 74 69 61 6c 69 74 65 2d 41  the Spatialite-A
3ab0: 6e 64 72 6f 69 64 20 69 6e 20 61 20 6d 6f 72 65  ndroid in a more
3ac0: 20 63 6f 6d 70 6c 65 78 20 77 61 79 20 74 68 61   complex way tha
3ad0: 6e 20 64 65 73 63 72 69 62 65 64 20 69 6e 20 74  n described in t
3ae0: 68 69 73 20 73 68 6f 72 74 20 74 75 74 6f 72 69  his short tutori
3af0: 61 6c 2e 0d 0a 0d 0a 3c 70 3e 47 65 6f 50 61 70  al.....<p>GeoPap
3b00: 61 72 61 7a 7a 69 20 65 6e 61 62 6c 65 73 20 74  arazzi enables t
3b10: 68 65 20 75 73 65 20 6f 66 20 73 70 61 74 69 61  he use of spatia
3b20: 6c 69 74 65 20 64 61 74 61 62 61 73 65 73 20 61  lite databases a
3b30: 73 20 64 61 74 61 20 73 6f 75 72 63 65 73 20 61  s data sources a
3b40: 6e 64 20 76 69 73 75 61 6c 69 7a 65 73 20 74 68  nd visualizes th
3b50: 65 6d 20 6f 6e 20 74 68 65 20 6d 61 70 20 76 69  em on the map vi
3b60: 65 77 2e 20 42 65 69 6e 67 20 74 68 65 20 6d 61  ew. Being the ma
3b70: 70 76 69 65 77 20 66 6f 72 63 65 64 20 6f 6e 20  pview forced on 
3b80: 61 20 4d 65 72 63 61 74 6f 72 20 70 72 6f 6a 65  a Mercator proje
3b90: 63 74 69 6f 6e 2c 20 74 68 65 20 64 61 74 61 73  ction, the datas
3ba0: 65 74 73 20 61 72 65 20 65 78 74 72 61 63 74 65  ets are extracte
3bb0: 64 20 61 6e 64 20 72 65 70 72 6f 6a 65 63 74 65  d and reprojecte
3bc0: 64 20 64 69 72 65 63 74 6c 79 20 69 6e 20 73 70  d directly in sp
3bd0: 61 74 69 61 6c 69 74 65 2e 20 49 74 20 69 73 20  atialite. It is 
3be0: 61 6c 73 6f 20 70 6f 73 73 69 62 6c 65 20 74 6f  also possible to
3bf0: 20 71 75 65 72 79 20 6c 61 79 65 72 73 20 62 79   query layers by
3c00: 20 74 61 70 70 69 6e 67 20 6f 6e 20 74 68 65 20   tapping on the 
3c10: 6d 61 70 2e 20 0d 0a 0d 0a 3c 70 3e 49 66 20 79  map. ....<p>If y
3c20: 6f 75 20 61 72 65 20 69 6e 74 65 72 65 73 74 65  ou are intereste
3c30: 64 20 69 6e 20 74 68 65 20 71 75 65 72 69 65 73  d in the queries
3c40: 20 75 73 65 64 2c 20 68 61 76 65 20 61 20 6c 6f   used, have a lo
3c50: 6f 6b 20 69 6e 74 6f 20 69 74 73 20 63 6f 64 65  ok into its code
3c60: 20 6f 6e 20 74 68 65 20 68 6f 6d 65 70 61 67 65   on the homepage
3c70: 2c 20 74 68 65 20 70 72 6f 6a 65 63 74 20 69 73  , the project is
3c80: 20 6f 70 65 6e 20 73 6f 75 72 63 65 2e 0d 0a 0d   open source....
3c90: 0a 3c 62 72 3e 3c 68 72 3e 0d 0a 42 61 63 6b 20  .<br><hr>..Back 
3ca0: 74 6f 20 3c 61 20 68 72 65 66 3d 22 68 74 74 70  to <a href="http
3cb0: 73 3a 2f 2f 77 77 77 2e 67 61 69 61 2d 67 69 73  s://www.gaia-gis
3cc0: 2e 69 74 2f 66 6f 73 73 69 6c 2f 6c 69 62 73 70  .it/fossil/libsp
3cd0: 61 74 69 61 6c 69 74 65 2f 77 69 6b 69 3f 6e 61  atialite/wiki?na
3ce0: 6d 65 3d 73 70 6c 69 74 65 2d 61 6e 64 72 6f 69  me=splite-androi
3cf0: 64 22 3e 53 70 61 74 69 61 4c 69 74 65 2d 41 6e  d">SpatiaLite-An
3d00: 64 72 6f 69 64 3c 2f 61 3e 20 57 69 6b 69 20 70  droid</a> Wiki p
3d10: 61 67 65 0d 0a 0a 5a 20 39 32 31 31 35 63 35 62  age...Z 92115c5b
3d20: 35 31 32 38 32 61 35 61 33 38 61 64 39 64 30 32  51282a5a38ad9d02
3d30: 65 64 64 64 64 64 30 32 0a                       eddddd02.