Hex Artifact Content
Not logged in

Artifact 3742a72b666b5c9fd937754090264f4587f5ee63:

Wiki page [spatialite-android-tutorial] by sandro 2012-11-26 12:32:02.
0000: 44 20 32 30 31 32 2d 31 31 2d 32 36 54 31 32 3a  D 2012-11-26T12:
0010: 33 32 3a 30 32 2e 33 35 38 0a 4c 20 73 70 61 74  32:02.358.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 55 20 73 61 6e 64 72 6f  utorial.U sandro
0040: 0a 57 20 31 34 38 35 30 0a 3c 74 61 62 6c 65 20  .W 14850.<table 
0050: 63 65 6c 6c 73 70 61 63 69 6e 67 3d 22 31 30 22  cellspacing="10"
0060: 20 63 65 6c 6c 70 61 64 64 69 6e 67 3d 22 33 30   cellpadding="30
0070: 22 3e 3c 74 72 3e 0d 0a 3c 74 64 20 77 69 64 74  "><tr>..<td widt
0080: 68 3d 22 31 30 30 25 22 3e 0d 0a 0d 0a 3c 68 31  h="100%">....<h1
0090: 3e 53 70 61 74 69 61 6c 69 74 65 20 6f 6e 20 41  >Spatialite on A
00a0: 6e 64 72 6f 69 64 3a 20 61 20 71 75 69 63 6b 20  ndroid: a quick 
00b0: 74 75 74 6f 72 69 61 6c 3c 2f 68 31 3e 0d 0a 42  tutorial</h1>..B
00c0: 61 63 6b 20 74 6f 20 3c 61 20 68 72 65 66 3d 22  ack to <a href="
00d0: 68 74 74 70 73 3a 2f 2f 77 77 77 2e 67 61 69 61  https://www.gaia
00e0: 2d 67 69 73 2e 69 74 2f 66 6f 73 73 69 6c 2f 6c  -gis.it/fossil/l
00f0: 69 62 73 70 61 74 69 61 6c 69 74 65 2f 77 69 6b  ibspatialite/wik
0100: 69 3f 6e 61 6d 65 3d 73 70 6c 69 74 65 2d 61 6e  i?name=splite-an
0110: 64 72 6f 69 64 22 3e 53 70 61 74 69 61 4c 69 74  droid">SpatiaLit
0120: 65 2d 41 6e 64 72 6f 69 64 3c 2f 61 3e 20 57 69  e-Android</a> Wi
0130: 6b 69 20 70 61 67 65 3c 62 72 3e 3c 62 72 3e 0d  ki page<br><br>.
0140: 0a 3c 74 61 62 6c 65 20 62 67 63 6f 6c 6f 72 3d  .<table bgcolor=
0150: 22 66 66 66 66 64 30 22 20 63 65 6c 6c 70 61 64  "ffffd0" cellpad
0160: 64 69 6e 64 3d 22 38 22 20 63 65 6c 6c 73 70 61  dind="8" cellspa
0170: 63 69 6e 67 3d 22 38 22 3e 0d 0a 3c 74 72 3e 3c  cing="8">..<tr><
0180: 74 64 3e 0d 0a 3c 62 3e 43 72 65 64 69 74 73 3c  td>..<b>Credits<
0190: 2f 62 3e 3c 62 72 3e 3c 62 72 3e 0d 0a 54 68 69  /b><br><br>..Thi
01a0: 73 20 57 69 6b 69 20 70 61 67 65 20 68 61 73 20  s Wiki page has 
01b0: 62 65 65 6e 20 6b 69 6e 64 6c 79 20 63 6f 6e 74  been kindly cont
01c0: 72 69 62 75 74 65 64 20 62 79 20 3c 61 20 68 72  ributed by <a hr
01d0: 65 66 3d 22 6d 61 69 6c 74 6f 3a 61 6e 64 72 65  ef="mailto:andre
01e0: 61 2e 61 6e 74 6f 6e 65 6c 6c 6f 40 67 6d 61 69  a.antonello@gmai
01f0: 6c 2e 63 6f 6d 22 3e 41 6e 64 72 65 61 20 41 6e  l.com">Andrea An
0200: 74 6f 6e 65 6c 6c 6f 20 3c 2f 61 3e 2c 20 61 20  tonello </a>, a 
0210: 73 6b 69 6c 6c 65 64 20 4a 61 76 61 20 64 65 76  skilled Java dev
0220: 6f 6c 6f 70 65 72 20 77 69 74 68 20 61 20 73 6f  oloper with a so
0230: 75 6e 64 20 73 70 65 63 69 66 69 63 20 65 78 70  und specific exp
0240: 65 72 69 65 6e 63 65 20 6f 6e 20 41 64 72 6f 69  erience on Adroi
0250: 64 2c 20 61 6e 64 20 61 63 74 69 76 65 6c 79 20  d, and actively 
0260: 69 6e 76 6f 6c 76 65 64 20 69 6e 20 73 65 76 65  involved in seve
0270: 72 61 6c 20 47 46 4f 53 53 20 70 72 6f 6a 65 63  ral GFOSS projec
0280: 74 73 20 28 50 53 43 20 6d 65 6d 62 65 72 20 6f  ts (PSC member o
0290: 66 20 3c 61 20 68 72 65 66 3d 22 68 74 74 70 3a  f <a href="http:
02a0: 2f 2f 75 64 69 67 2e 72 65 66 72 61 63 74 69 6f  //udig.refractio
02b0: 6e 73 2e 6e 65 74 2f 22 3e 75 44 69 67 3c 2f 61  ns.net/">uDig</a
02c0: 3e 20 61 6e 64 20 6d 61 69 6e 74 61 69 6e 65 72  > and maintainer
02d0: 20 6f 66 20 3c 61 20 68 72 65 66 3d 22 68 74 74   of <a href="htt
02e0: 70 3a 2f 2f 63 6f 64 65 2e 67 6f 6f 67 6c 65 2e  p://code.google.
02f0: 63 6f 6d 2f 70 2f 67 65 6f 70 61 70 61 72 61 7a  com/p/geopaparaz
0300: 7a 69 2f 22 3e 47 65 6f 50 61 70 61 72 61 7a 7a  zi/">GeoPaparazz
0310: 69 3c 2f 61 3e 29 2e 3c 62 72 3e 0d 0a 4d 61 6e  i</a>).<br>..Man
0320: 79 20 74 68 61 6e 6b 73 20 74 6f 20 41 6e 64 72  y thanks to Andr
0330: 65 61 20 66 6f 72 20 68 69 73 20 74 68 6f 72 6f  ea for his thoro
0340: 75 67 68 20 64 6f 63 75 6d 65 6e 74 61 74 69 6f  ugh documentatio
0350: 6e 20 65 66 66 6f 72 74 20 21 21 21 0d 0a 3c 2f  n effort !!!..</
0360: 74 64 3e 3c 2f 74 72 3e 0d 0a 3c 2f 74 61 62 6c  td></tr>..</tabl
0370: 65 3e 0d 0a 0d 0a 3c 68 32 3e 49 6e 74 72 6f 64  e>....<h2>Introd
0380: 75 63 74 69 6f 6e 3c 2f 68 32 3e 0d 0a 0d 0a 3c  uction</h2>....<
0390: 70 3e 54 68 65 20 41 6e 64 72 6f 69 64 20 6f 70  p>The Android op
03a0: 65 72 61 74 69 6e 67 20 73 79 73 74 65 6d 20 66  erating system f
03b0: 6f 72 20 6d 6f 62 69 6c 65 20 64 65 76 69 63 65  or mobile device
03c0: 73 20 75 73 65 73 20 61 73 20 69 74 73 20 64 65  s uses as its de
03d0: 66 61 75 6c 74 20 72 65 6c 61 74 69 6f 6e 61 6c  fault relational
03e0: 20 64 61 74 61 62 61 73 65 20 53 51 4c 69 74 65   database SQLite
03f0: 2e 20 45 76 65 6e 20 69 66 20 73 69 6e 63 65 20  . Even if since 
0400: 74 68 65 20 61 70 70 65 61 72 65 6e 63 65 20 6f  the appearence o
0410: 66 20 53 70 61 74 69 61 4c 69 74 65 20 69 6e 20  f SpatiaLite in 
0420: 74 68 65 20 67 65 6f 73 70 61 74 69 61 6c 20 77  the geospatial w
0430: 6f 72 6c 64 20 69 74 20 6c 6f 6f 6b 65 64 20 6c  orld it looked l
0440: 69 6b 65 20 61 20 70 65 72 66 65 63 74 20 6d 61  ike a perfect ma
0450: 74 63 68 20 74 6f 20 68 61 76 65 20 69 74 20 61  tch to have it a
0460: 76 61 69 6c 61 62 6c 65 20 62 79 20 64 65 66 61  vailable by defa
0470: 75 6c 74 20 66 6f 72 20 74 68 65 20 73 79 73 74  ult for the syst
0480: 65 6d 2c 20 64 65 76 65 6c 6f 70 65 72 73 20 68  em, developers h
0490: 61 64 20 74 6f 20 77 61 69 74 20 66 6f 72 20 61  ad to wait for a
04a0: 20 77 68 69 6c 65 20 74 6f 20 75 73 65 20 73 70   while to use sp
04b0: 61 74 69 61 6c 69 74 65 20 6f 6e 20 41 6e 64 72  atialite on Andr
04c0: 6f 69 64 2e 0d 0a 41 6e 64 20 65 76 65 6e 20 6e  oid...And even n
04d0: 6f 77 2c 20 74 68 61 74 20 69 74 20 69 73 20 61  ow, that it is a
04e0: 76 61 69 6c 61 62 6c 65 2c 20 69 74 20 69 73 20  vailable, it is 
04f0: 6e 6f 74 20 69 6e 74 65 67 72 61 74 65 64 20 69  not integrated i
0500: 6e 20 74 68 65 20 6f 70 65 72 61 74 69 6e 67 20  n the operating 
0510: 73 79 73 74 65 6d 20 61 6e 64 20 69 74 20 69 73  system and it is
0520: 20 6e 6f 74 20 61 63 63 65 73 73 69 62 6c 65 20   not accessible 
0530: 74 68 72 6f 75 67 68 20 74 68 65 20 73 74 61 6e  through the stan
0540: 64 61 72 64 20 41 6e 64 72 6f 69 64 20 70 65 72  dard Android per
0550: 73 69 73 74 65 6e 63 65 20 41 50 49 73 2e 0d 0a  sistence APIs...
0560: 0d 0a 3c 70 3e 54 68 61 74 20 73 68 6f 75 6c 64  ..<p>That should
0570: 20 6e 6f 74 20 73 63 61 72 65 20 61 77 61 79 20   not scare away 
0580: 61 6e 79 20 64 65 76 65 6c 6f 70 65 72 20 65 61  any developer ea
0590: 67 65 72 20 74 6f 20 70 6c 61 79 20 72 65 61 6c  ger to play real
05a0: 20 67 65 6f 73 70 61 74 69 61 6c 20 6f 6e 20 41   geospatial on A
05b0: 6e 64 72 6f 69 64 20 64 65 76 69 63 65 73 2e 20  ndroid devices. 
05c0: 54 68 65 20 3c 61 20 68 72 65 66 3d 22 68 74 74  The <a href="htt
05d0: 70 3a 2f 2f 63 6f 64 65 2e 67 6f 6f 67 6c 65 2e  p://code.google.
05e0: 63 6f 6d 2f 70 2f 73 70 61 74 69 61 6c 69 74 65  com/p/spatialite
05f0: 2d 61 6e 64 72 6f 69 64 2f 22 3e 53 70 61 74 69  -android/">Spati
0600: 61 6c 69 74 65 2d 41 6e 64 72 6f 69 64 3c 2f 61  alite-Android</a
0610: 3e 20 70 72 6f 6a 65 63 74 20 69 73 20 73 69 6d  > project is sim
0620: 70 6c 65 20 74 6f 20 75 73 65 20 61 6e 64 20 73  ple to use and s
0630: 74 61 62 6c 65 2e 20 0d 0a 0d 0a 3c 70 3e 49 6e  table. ....<p>In
0640: 20 74 68 69 73 20 64 6f 63 75 6d 65 6e 74 20 77   this document w
0650: 65 20 77 69 6c 6c 20 68 65 6c 70 20 6e 65 77 20  e will help new 
0660: 64 65 76 65 6c 6f 70 65 72 73 20 74 6f 20 67 65  developers to ge
0670: 74 20 73 74 61 72 74 65 64 20 77 69 74 68 20 74  t started with t
0680: 68 65 69 72 20 66 69 72 73 74 20 53 70 61 74 69  heir first Spati
0690: 61 6c 69 74 65 20 65 6e 61 62 6c 65 64 20 61 70  alite enabled ap
06a0: 70 6c 69 63 61 74 69 6f 6e 2e 20 49 74 20 69 73  plication. It is
06b0: 20 6d 65 61 6e 74 20 66 6f 72 20 64 65 76 65 6c   meant for devel
06c0: 6f 70 65 72 73 20 74 68 61 74 20 68 61 76 65 20  opers that have 
06d0: 61 74 20 6c 65 61 73 74 20 61 20 6d 69 6e 69 6d  at least a minim
06e0: 61 6c 20 6b 6e 6f 77 6c 65 64 67 65 20 61 62 6f  al knowledge abo
06f0: 75 74 20 41 6e 64 72 6f 69 64 20 61 70 70 6c 69  ut Android appli
0700: 63 61 74 69 6f 6e 20 64 65 76 65 6c 6f 70 6d 65  cation developme
0710: 6e 74 20 28 68 61 76 69 6e 67 20 62 75 69 6c 74  nt (having built
0720: 20 61 6e 64 20 72 75 6e 20 74 68 65 20 68 65 6c   and run the hel
0730: 6c 6f 20 77 6f 72 6c 64 20 61 70 70 20 73 68 6f  lo world app sho
0740: 75 6c 20 62 65 20 65 6e 6f 75 67 68 29 2e 0d 0a  ul be enough)...
0750: 0d 0a 3c 68 32 3e 41 75 74 68 6f 72 73 20 61 6e  ..<h2>Authors an
0760: 64 20 4c 69 63 65 6e 73 65 3c 2f 68 32 3e 0d 0a  d License</h2>..
0770: 0d 0a 3c 70 3e 54 68 65 20 53 70 61 74 69 61 6c  ..<p>The Spatial
0780: 69 74 65 2d 41 6e 64 72 6f 69 64 20 70 72 6f 6a  ite-Android proj
0790: 65 63 74 20 68 61 73 20 62 65 65 6e 20 72 65 6c  ect has been rel
07a0: 65 61 73 65 64 20 62 79 20 74 68 65 20 3c 61 20  eased by the <a 
07b0: 68 72 65 66 3d 22 68 74 74 70 3a 2f 2f 77 77 77  href="http://www
07c0: 2e 61 67 63 2e 61 72 6d 79 2e 6d 69 6c 22 3e 55  .agc.army.mil">U
07d0: 2e 53 2e 20 41 72 6d 79 20 47 65 6f 73 70 61 74  .S. Army Geospat
07e0: 69 61 6c 20 43 65 6e 74 65 72 3c 2f 61 3e 2e 0d  ial Center</a>..
07f0: 0a 3c 70 3e 54 68 65 20 70 72 6f 6a 65 63 74 20  .<p>The project 
0800: 69 73 20 72 65 6c 65 61 73 65 64 20 3c 61 20 68  is released <a h
0810: 72 65 66 3d 22 68 74 74 70 3a 2f 2f 77 77 77 2e  ref="http://www.
0820: 67 61 69 61 2d 67 69 73 2e 69 74 2f 67 61 69 61  gaia-gis.it/gaia
0830: 2d 73 69 6e 73 2f 73 70 61 74 69 61 6c 69 74 65  -sins/spatialite
0840: 2d 61 6e 64 72 6f 69 64 2f 73 70 61 74 69 61 6c  -android/spatial
0850: 69 74 65 2d 61 6e 64 72 6f 69 64 2d 6c 69 63 65  ite-android-lice
0860: 6e 73 65 2e 74 78 74 22 3e 75 6e 64 65 72 20 4c  nse.txt">under L
0870: 47 50 4c 76 33 20 6c 69 63 65 6e 73 65 3c 2f 61  GPLv3 license</a
0880: 3e 2e 0d 0a 0d 0a 3c 68 32 3e 47 65 74 74 69 6e  >.....<h2>Gettin
0890: 67 20 73 74 61 72 74 65 64 3c 2f 68 32 3e 0d 0a  g started</h2>..
08a0: 0d 0a 3c 70 3e 54 6f 20 67 65 74 20 73 74 61 72  ..<p>To get star
08b0: 74 65 64 20 77 65 20 6a 75 73 74 20 6e 65 65 64  ted we just need
08c0: 20 74 6f 20 67 65 74 20 74 68 65 20 53 70 61 74   to get the Spat
08d0: 69 61 6c 69 74 65 20 6c 69 62 72 61 72 69 65 73  ialite libraries
08e0: 20 61 6e 64 20 61 64 64 20 74 68 65 6d 20 74 6f   and add them to
08f0: 20 6f 75 72 20 6e 65 77 20 41 6e 64 72 6f 69 64   our new Android
0900: 20 61 70 70 6c 69 63 61 74 69 6f 6e 20 70 72 6f   application pro
0910: 6a 65 63 74 2e 0d 0a 3c 70 3e 4f 6e 63 65 20 74  ject...<p>Once t
0920: 68 61 74 20 69 73 20 64 6f 6e 65 2c 20 74 68 65  hat is done, the
0930: 72 65 20 61 72 65 20 66 65 77 20 73 74 65 70 73  re are few steps
0940: 20 74 6f 20 70 65 72 66 6f 72 6d 20 74 6f 20 67   to perform to g
0950: 65 74 20 74 68 69 6e 67 73 20 77 6f 72 6b 69 6e  et things workin
0960: 67 2e 20 54 68 65 20 41 50 49 20 69 73 20 76 65  g. The API is ve
0970: 72 79 20 73 6d 61 6c 6c 20 61 6e 64 20 73 69 6d  ry small and sim
0980: 70 6c 65 20 61 6e 64 20 62 61 73 69 63 61 6c 6c  ple and basicall
0990: 79 20 62 61 73 65 73 20 6f 6e 20 61 20 6d 61 6e  y bases on a man
09a0: 75 61 6c 20 62 75 69 6c 64 69 6e 67 20 6f 66 20  ual building of 
09b0: 74 68 65 20 71 75 65 72 69 65 73 20 74 6f 20 73  the queries to s
09c0: 65 6e 64 20 74 6f 20 74 68 65 20 64 61 74 61 62  end to the datab
09d0: 61 73 65 2e 0d 0a 3c 70 3e 4e 6f 74 65 20 74 68  ase...<p>Note th
09e0: 61 74 20 69 74 20 77 6f 75 6c 64 20 62 65 20 70  at it would be p
09f0: 6f 73 73 69 62 6c 65 20 74 6f 20 63 72 65 61 74  ossible to creat
0a00: 65 20 61 6e 20 41 6e 64 72 6f 69 64 20 6c 69 62  e an Android lib
0a10: 72 61 72 79 20 74 6f 20 72 65 66 65 72 65 6e 63  rary to referenc
0a20: 65 20 66 72 6f 6d 20 74 68 65 20 70 72 6f 6a 65  e from the proje
0a30: 63 74 2c 20 62 75 74 20 74 6f 20 6b 65 65 70 20  ct, but to keep 
0a40: 74 68 69 73 20 74 75 74 6f 72 69 61 6c 20 73 68  this tutorial sh
0a50: 6f 72 74 2c 20 77 65 20 77 69 6c 6c 20 6a 75 73  ort, we will jus
0a60: 74 20 73 68 6f 77 20 68 6f 77 20 74 6f 20 69 6e  t show how to in
0a70: 74 65 67 72 61 74 65 20 74 68 65 20 6c 69 62 72  tegrate the libr
0a80: 61 72 79 20 64 69 72 65 63 74 6c 79 20 69 6e 74  ary directly int
0a90: 6f 20 6f 75 72 20 6e 65 77 20 70 72 6f 6a 65 63  o our new projec
0aa0: 74 2e 0d 0a 0d 0a 3c 68 33 3e 44 6f 77 6e 6c 6f  t.....<h3>Downlo
0ab0: 61 64 69 6e 67 20 74 68 65 20 6c 69 62 72 61 72  ading the librar
0ac0: 69 65 73 3c 2f 68 33 3e 0d 0a 0d 0a 3c 70 3e 54  ies</h3>....<p>T
0ad0: 68 65 20 63 61 6e 20 62 65 20 64 6f 77 6e 6c 6f  he can be downlo
0ae0: 61 64 65 64 20 3c 61 20 68 72 65 66 3d 22 68 74  aded <a href="ht
0af0: 74 70 3a 2f 2f 77 77 77 2e 67 61 69 61 2d 67 69  tp://www.gaia-gi
0b00: 73 2e 69 74 2f 67 61 69 61 2d 73 69 6e 73 2f 73  s.it/gaia-sins/s
0b10: 70 61 74 69 61 6c 69 74 65 2d 61 6e 64 72 6f 69  patialite-androi
0b20: 64 2f 73 70 61 74 69 61 6c 69 74 65 2d 66 6f 72  d/spatialite-for
0b30: 2d 61 6e 64 72 6f 69 64 2d 33 2e 30 2e 31 2e 7a  -android-3.0.1.z
0b40: 69 70 22 3e 61 74 20 74 68 69 73 20 6c 69 6e 6b  ip">at this link
0b50: 3c 2f 61 3e 2e 0d 0a 3c 70 3e 54 68 65 20 64 6f  </a>...<p>The do
0b60: 77 6e 6c 6f 61 64 65 64 20 61 72 63 68 69 76 65  wnloaded archive
0b70: 20 63 6f 6e 74 61 69 6e 73 20 32 20 62 61 73 69   contains 2 basi
0b80: 63 20 63 6f 6d 70 6f 6e 65 6e 74 73 20 6e 65 63  c components nec
0b90: 65 73 73 61 72 79 20 74 6f 20 65 6e 61 62 6c 65  essary to enable
0ba0: 20 79 6f 75 72 20 70 72 6f 6a 65 63 74 20 74 6f   your project to
0bb0: 20 75 73 65 20 53 70 61 74 69 61 6c 69 74 65 3a   use Spatialite:
0bc0: 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 3c 62 3e 74  ..<ul>..<li><b>t
0bd0: 68 65 20 6e 61 74 69 76 65 20 73 70 61 74 69 61  he native spatia
0be0: 6c 69 74 65 20 6c 69 62 72 61 72 69 65 73 3c 2f  lite libraries</
0bf0: 62 3e 3a 20 74 68 65 79 20 61 72 65 20 70 6c 61  b>: they are pla
0c00: 63 65 73 20 69 6e 20 61 20 66 6f 6c 64 65 72 20  ces in a folder 
0c10: 6e 61 6d 65 64 20 3c 62 3e 6c 69 62 73 3c 2f 62  named <b>libs</b
0c20: 3e 3c 2f 6c 69 3e 20 61 6e 64 20 63 6f 6e 74 61  ></li> and conta
0c30: 69 6e 73 20 73 65 76 65 72 61 6c 20 66 6f 6c 64  ins several fold
0c40: 65 72 73 20 66 6f 72 20 64 69 66 66 65 72 65 6e  ers for differen
0c50: 74 20 70 6c 61 74 66 6f 72 6d 73 20 74 68 61 74  t platforms that
0c60: 20 68 6f 6c 64 20 74 68 65 20 6d 61 69 6e 20 6c   hold the main l
0c70: 69 62 72 61 72 79 2c 20 63 61 6c 6c 65 64 20 3c  ibrary, called <
0c80: 62 3e 6c 69 62 73 70 61 74 69 61 6c 69 74 65 2e  b>libspatialite.
0c90: 73 6f 3c 2f 62 3e 0d 0a 3c 6c 69 3e 74 68 65 20  so</b>..<li>the 
0ca0: 3c 62 3e 62 61 73 69 63 20 41 50 49 20 63 6c 61  <b>basic API cla
0cb0: 73 73 65 73 3c 2f 62 3e 2c 20 63 6f 6e 74 61 69  sses</b>, contai
0cc0: 6e 65 64 20 69 6e 20 74 68 65 20 3c 62 3e 6a 73  ned in the <b>js
0cd0: 71 6c 69 74 65 3c 2f 62 3e 20 70 61 63 6b 61 67  qlite</b> packag
0ce0: 65 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 0d 0a 0d  e</li>..</ul>...
0cf0: 0a 3c 68 33 3e 59 6f 75 72 20 66 69 72 73 74 20  .<h3>Your first 
0d00: 53 70 61 74 69 61 6c 69 74 65 20 65 6e 61 62 6c  Spatialite enabl
0d10: 65 64 20 70 72 6f 6a 65 63 74 3c 2f 68 33 3e 0d  ed project</h3>.
0d20: 0a 0d 0a 3c 68 34 3e 50 72 65 70 61 72 65 20 61  ...<h4>Prepare a
0d30: 20 64 61 74 61 73 65 74 3c 2f 68 34 3e 0d 0a 0d   dataset</h4>...
0d40: 0a 46 6f 6c 6c 6f 77 20 3c 61 20 68 72 65 66 3d  .Follow <a href=
0d50: 22 68 74 74 70 3a 2f 2f 77 77 77 2e 67 61 69 61  "http://www.gaia
0d60: 2d 67 69 73 2e 69 74 2f 67 61 69 61 2d 73 69 6e  -gis.it/gaia-sin
0d70: 73 2f 73 70 61 74 69 61 6c 69 74 65 2d 63 6f 6f  s/spatialite-coo
0d80: 6b 62 6f 6f 6b 2f 68 74 6d 6c 2f 66 69 72 73 74  kbook/html/first
0d90: 2d 64 62 2e 68 74 6d 6c 22 3e 74 68 69 73 20 74  -db.html">this t
0da0: 75 74 6f 72 69 61 6c 3c 2f 61 3e 20 74 6f 20 63  utorial</a> to c
0db0: 72 65 61 74 65 20 61 20 73 70 61 74 69 61 6c 69  reate a spatiali
0dc0: 74 65 20 64 61 74 61 62 61 73 65 20 74 68 61 74  te database that
0dd0: 20 63 6f 6e 74 61 69 6e 73 20 74 68 65 20 63 6f   contains the co
0de0: 6d 75 6e 69 5f 32 30 31 31 2e 73 68 70 20 28 66  muni_2011.shp (f
0df0: 69 6e 64 20 72 65 66 65 72 65 6e 63 65 73 20 74  ind references t
0e00: 6f 20 77 68 65 72 65 20 74 6f 20 67 65 74 20 69  o where to get i
0e10: 74 20 3c 61 20 68 72 65 66 3d 22 68 74 74 70 3a  t <a href="http:
0e20: 2f 2f 77 77 77 2e 67 61 69 61 2d 67 69 73 2e 69  //www.gaia-gis.i
0e30: 74 2f 67 61 69 61 2d 73 69 6e 73 2f 73 70 61 74  t/gaia-sins/spat
0e40: 69 61 6c 69 74 65 2d 63 6f 6f 6b 62 6f 6f 6b 2f  ialite-cookbook/
0e50: 68 74 6d 6c 2f 73 74 61 72 74 2e 68 74 6d 6c 22  html/start.html"
0e60: 3e 68 65 72 65 3c 2f 61 3e 29 20 64 61 74 61 2e  >here</a>) data.
0e70: 20 43 6f 70 79 20 74 68 65 20 63 72 65 61 74 65   Copy the create
0e80: 64 20 64 61 74 61 62 61 73 65 20 6f 6e 20 74 68  d database on th
0e90: 65 20 6d 6f 62 69 6c 65 20 64 65 76 69 63 65 27  e mobile device'
0ea0: 73 20 65 78 74 65 72 6e 61 6c 20 73 74 6f 72 61  s external stora
0eb0: 67 65 20 63 61 72 64 2e 0d 0a 0d 0a 3c 68 34 3e  ge card.....<h4>
0ec0: 43 72 65 61 74 65 20 74 68 65 20 62 61 73 69 63  Create the basic
0ed0: 20 68 65 6c 6c 6f 20 77 6f 72 6c 64 20 70 72 6f   hello world pro
0ee0: 6a 65 63 74 3c 2f 68 34 3e 0d 0a 0d 0a 3c 70 3e  ject</h4>....<p>
0ef0: 55 73 65 20 74 68 65 20 41 6e 64 72 6f 69 64 20  Use the Android 
0f00: 65 63 6c 69 70 73 65 20 6e 65 77 20 70 72 6f 6a  eclipse new proj
0f10: 65 63 74 20 77 69 7a 61 72 64 20 74 6f 20 63 72  ect wizard to cr
0f20: 65 61 74 65 20 61 20 62 61 73 69 63 20 68 65 6c  eate a basic hel
0f30: 6c 6f 20 77 6f 72 6c 64 20 65 78 61 6d 70 6c 65  lo world example
0f40: 20 66 6f 72 20 41 6e 64 72 6f 69 64 2e 20 49 74   for Android. It
0f50: 20 77 69 6c 6c 20 67 65 6e 65 72 61 74 65 20 79   will generate y
0f60: 6f 75 20 61 20 72 65 61 64 79 20 74 6f 20 75 73  ou a ready to us
0f70: 65 20 41 6e 64 72 6f 69 64 20 61 70 70 6c 69 63  e Android applic
0f80: 61 74 69 6f 6e 20 74 68 61 74 20 73 68 6f 77 73  ation that shows
0f90: 20 61 20 6e 69 63 65 20 56 69 65 77 20 77 69 74   a nice View wit
0fa0: 68 20 3c 69 3e 48 65 6c 6c 6f 20 57 6f 72 6c 64  h <i>Hello World
0fb0: 3c 2f 69 3e 20 6f 6e 20 69 74 2e 0d 0a 0d 0a 3c  </i> on it.....<
0fc0: 70 3e 4f 6e 63 65 20 74 68 65 20 68 65 6c 6c 6f  p>Once the hello
0fd0: 20 77 6f 72 6c 64 20 70 72 6f 6a 65 63 74 20 63   world project c
0fe0: 61 6e 20 62 65 20 72 75 6e 2c 20 77 65 20 63 61  an be run, we ca
0ff0: 6e 20 73 74 61 72 74 20 74 6f 20 61 64 64 20 74  n start to add t
1000: 68 65 20 73 70 61 74 69 61 6c 69 74 65 20 70 61  he spatialite pa
1010: 72 74 2e 0d 0a 0d 0a 3c 70 3e 54 68 65 20 66 69  rt.....<p>The fi
1020: 72 73 74 20 73 74 65 70 20 69 73 20 74 6f 20 63  rst step is to c
1030: 6f 70 79 20 74 68 65 20 6d 61 69 6e 20 63 6f 6d  opy the main com
1040: 70 6f 6e 65 6e 74 73 20 6f 66 20 74 68 65 20 53  ponents of the S
1050: 70 61 74 69 61 6c 69 74 65 2d 41 6e 64 72 6f 69  patialite-Androi
1060: 64 20 70 72 6f 6a 65 63 74 20 61 73 20 6d 65 6e  d project as men
1070: 74 69 6f 6e 65 64 20 62 65 66 6f 72 65 2e 0d 0a  tioned before...
1080: 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 63 6f 70 79  ..<ul>..<li>copy
1090: 20 74 68 65 20 6e 61 74 69 76 65 20 6c 69 62 73   the native libs
10a0: 20 69 6e 74 6f 20 74 68 65 20 72 6f 6f 74 20 6f   into the root o
10b0: 66 20 74 68 65 20 6e 65 77 6c 79 20 63 72 65 61  f the newly crea
10c0: 74 65 64 20 41 6e 64 72 6f 69 64 20 70 72 6f 6a  ted Android proj
10d0: 65 63 74 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 63 6f  ect</li>..<li>co
10e0: 70 79 20 74 68 65 20 6a 61 76 61 20 70 61 63 6b  py the java pack
10f0: 61 67 65 20 6f 66 20 74 68 65 20 62 61 73 65 20  age of the base 
1100: 41 50 49 20 69 6e 74 6f 20 79 6f 75 20 6e 65 77  API into you new
1110: 20 70 72 6f 6a 65 63 74 27 73 20 73 6f 75 72 63   project's sourc
1120: 65 20 66 6f 6c 64 65 72 3c 2f 6c 69 3e 0d 0a 3c  e folder</li>..<
1130: 2f 75 6c 3e 0d 0a 0d 0a 3c 70 3e 41 6e 64 20 74  /ul>....<p>And t
1140: 68 61 74 20 69 73 20 69 74 2e 20 59 6f 75 72 20  hat is it. Your 
1150: 70 72 6f 6a 65 63 74 20 69 73 20 61 6c 72 65 61  project is alrea
1160: 64 79 20 53 70 61 74 69 61 6c 69 74 65 20 65 6e  dy Spatialite en
1170: 61 62 6c 65 64 2e 0d 0a 4c 65 74 27 73 20 64 6f  abled...Let's do
1180: 20 73 6f 6d 65 20 62 61 73 69 63 20 73 74 75 66   some basic stuf
1190: 66 20 77 69 74 68 20 69 74 20 69 6e 20 74 68 65  f with it in the
11a0: 20 6e 65 78 74 20 63 68 61 70 74 65 72 73 2e 0d   next chapters..
11b0: 0a 0d 0a 3c 68 34 3e 4f 70 65 6e 20 61 6e 20 64  ...<h4>Open an d
11c0: 61 74 61 62 61 73 65 3c 2f 68 34 3e 0d 0a 0d 0a  atabase</h4>....
11d0: 3c 70 3e 54 68 65 20 66 6f 6c 6c 6f 77 69 6e 67  <p>The following
11e0: 20 77 69 6c 6c 20 6f 70 65 6e 20 74 68 65 20 64   will open the d
11f0: 61 74 61 62 61 73 65 20 6e 61 6d 65 64 20 3c 69  atabase named <i
1200: 3e 69 74 61 6c 79 2e 73 71 6c 69 74 65 3c 2f 69  >italy.sqlite</i
1210: 3e 20 74 68 61 74 20 69 73 20 70 6c 61 63 65 64  > that is placed
1220: 20 69 6e 20 79 6f 75 72 20 73 64 63 61 72 64 2e   in your sdcard.
1230: 20 49 66 20 74 68 65 20 64 61 74 61 62 61 73 65   If the database
1240: 20 64 6f 65 73 6e 27 74 20 65 78 69 73 74 2c 20   doesn't exist, 
1250: 69 74 20 77 69 6c 6c 20 62 65 20 63 72 65 61 74  it will be creat
1260: 65 64 20 65 6d 70 74 79 20 28 64 75 65 20 74 6f  ed empty (due to
1270: 20 74 68 65 20 53 51 4c 49 54 45 5f 4f 50 45 4e   the SQLITE_OPEN
1280: 5f 43 52 45 41 54 45 20 66 6c 61 67 29 2e 0d 0a  _CREATE flag)...
1290: 0d 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 20 20  ..<verbatim>..  
12a0: 20 20 20 20 20 20 74 72 79 20 7b 0d 0a 20 20 20        try {..   
12b0: 20 20 20 20 20 20 20 20 20 46 69 6c 65 20 73 64           File sd
12c0: 63 61 72 64 44 69 72 20 3d 20 22 22 3b 20 2f 2f  cardDir = ""; //
12d0: 20 79 6f 75 72 20 73 64 63 61 72 64 20 70 61 74   your sdcard pat
12e0: 68 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 46  h..            F
12f0: 69 6c 65 20 73 70 61 74 69 61 6c 44 62 46 69 6c  ile spatialDbFil
1300: 65 20 3d 20 6e 65 77 20 46 69 6c 65 28 73 64 63  e = new File(sdc
1310: 61 72 64 44 69 72 2c 20 22 69 74 61 6c 79 2e 73  ardDir, "italy.s
1320: 71 6c 69 74 65 22 29 3b 0d 0a 0d 0a 20 20 20 20  qlite");....    
1330: 20 20 20 20 20 20 20 20 64 62 20 3d 20 6e 65 77          db = new
1340: 20 6a 73 71 6c 69 74 65 2e 44 61 74 61 62 61 73   jsqlite.Databas
1350: 65 28 29 3b 0d 0a 20 20 20 20 20 20 20 20 20 20  e();..          
1360: 20 20 64 62 2e 6f 70 65 6e 28 73 70 61 74 69 61    db.open(spatia
1370: 6c 44 62 46 69 6c 65 2e 67 65 74 41 62 73 6f 6c  lDbFile.getAbsol
1380: 75 74 65 50 61 74 68 28 29 2c 20 6a 73 71 6c 69  utePath(), jsqli
1390: 74 65 2e 43 6f 6e 73 74 61 6e 74 73 2e 53 51 4c  te.Constants.SQL
13a0: 49 54 45 5f 4f 50 45 4e 5f 52 45 41 44 57 52 49  ITE_OPEN_READWRI
13b0: 54 45 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20  TE..            
13c0: 20 20 20 20 20 20 20 20 7c 20 6a 73 71 6c 69 74          | jsqlit
13d0: 65 2e 43 6f 6e 73 74 61 6e 74 73 2e 53 51 4c 49  e.Constants.SQLI
13e0: 54 45 5f 4f 50 45 4e 5f 43 52 45 41 54 45 29 3b  TE_OPEN_CREATE);
13f0: 0d 0a 20 20 20 20 20 20 20 20 7d 20 63 61 74 63  ..        } catc
1400: 68 20 28 45 78 63 65 70 74 69 6f 6e 20 65 29 20  h (Exception e) 
1410: 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 65  {..            e
1420: 2e 70 72 69 6e 74 53 74 61 63 6b 54 72 61 63 65  .printStackTrace
1430: 28 29 3b 0d 0a 20 20 20 20 20 20 20 20 7d 0d 0a  ();..        }..
1440: 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 0d 0a 4f  </verbatim>....O
1450: 6e 63 65 20 79 6f 75 20 68 61 76 65 20 6f 70 65  nce you have ope
1460: 6e 65 64 20 74 68 65 20 64 61 74 61 62 61 73 65  ned the database
1470: 2c 20 79 6f 75 20 61 72 65 20 72 65 61 64 79 20  , you are ready 
1480: 74 6f 20 64 6f 20 73 6f 6d 65 20 73 70 61 74 69  to do some spati
1490: 61 6c 20 6d 61 67 69 63 2e 0d 0a 0d 0a 3c 68 34  al magic.....<h4
14a0: 3e 47 65 74 20 76 65 72 73 69 6f 6e 73 20 6f 66  >Get versions of
14b0: 20 74 68 65 20 73 6f 66 74 77 61 72 65 3c 2f 68   the software</h
14c0: 34 3e 0d 0a 0d 0a 54 6f 20 67 65 74 20 74 68 65  4>....To get the
14d0: 20 76 65 72 73 69 6f 6e 73 20 6f 66 20 73 70 61   versions of spa
14e0: 74 69 61 6c 69 74 65 2c 20 67 65 6f 73 20 61 6e  tialite, geos an
14f0: 64 20 70 72 6f 6a 20 74 68 61 74 20 61 72 65 20  d proj that are 
1500: 69 6e 20 75 73 65 2c 20 79 6f 75 20 63 61 6e 20  in use, you can 
1510: 75 73 65 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e  use the followin
1520: 67 20 6d 65 74 68 6f 64 3a 0d 0a 0d 0a 3c 76 65  g method:....<ve
1530: 72 62 61 74 69 6d 3e 0d 0a 20 20 20 20 70 75 62  rbatim>..    pub
1540: 6c 69 63 20 53 74 72 69 6e 67 20 71 75 65 72 79  lic String query
1550: 56 65 72 73 69 6f 6e 73 28 29 20 74 68 72 6f 77  Versions() throw
1560: 73 20 45 78 63 65 70 74 69 6f 6e 20 7b 0d 0a 20  s Exception {.. 
1570: 20 20 20 20 20 20 20 53 74 72 69 6e 67 42 75 69         StringBui
1580: 6c 64 65 72 20 73 62 20 3d 20 6e 65 77 20 53 74  lder sb = new St
1590: 72 69 6e 67 42 75 69 6c 64 65 72 28 29 3b 0d 0a  ringBuilder();..
15a0: 20 20 20 20 20 20 20 20 73 62 2e 61 70 70 65 6e          sb.appen
15b0: 64 28 22 43 68 65 63 6b 20 76 65 72 73 69 6f 6e  d("Check version
15c0: 73 2e 2e 2e 5c 6e 22 29 3b 0d 0a 0d 0a 20 20 20  s...\n");....   
15d0: 20 20 20 20 20 53 74 6d 74 20 73 74 6d 74 30 31       Stmt stmt01
15e0: 20 3d 20 64 62 2e 70 72 65 70 61 72 65 28 22 53   = db.prepare("S
15f0: 45 4c 45 43 54 20 73 70 61 74 69 61 6c 69 74 65  ELECT spatialite
1600: 5f 76 65 72 73 69 6f 6e 28 29 3b 22 29 3b 0d 0a  _version();");..
1610: 20 20 20 20 20 20 20 20 69 66 20 28 73 74 6d 74          if (stmt
1620: 30 31 2e 73 74 65 70 28 29 29 20 7b 0d 0a 20 20  01.step()) {..  
1630: 20 20 20 20 20 20 20 20 20 20 73 62 2e 61 70 70            sb.app
1640: 65 6e 64 28 22 5c 74 22 29 2e 61 70 70 65 6e 64  end("\t").append
1650: 28 22 53 50 41 54 49 41 4c 49 54 45 5f 56 45 52  ("SPATIALITE_VER
1660: 53 49 4f 4e 3a 20 22 20 2b 20 73 74 6d 74 30 31  SION: " + stmt01
1670: 2e 63 6f 6c 75 6d 6e 5f 73 74 72 69 6e 67 28 30  .column_string(0
1680: 29 29 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 20  ));..           
1690: 20 73 62 2e 61 70 70 65 6e 64 28 22 5c 6e 22 29   sb.append("\n")
16a0: 3b 0d 0a 20 20 20 20 20 20 20 20 7d 0d 0a 0d 0a  ;..        }....
16b0: 20 20 20 20 20 20 20 20 73 74 6d 74 30 31 20 3d          stmt01 =
16c0: 20 64 62 2e 70 72 65 70 61 72 65 28 22 53 45 4c   db.prepare("SEL
16d0: 45 43 54 20 70 72 6f 6a 34 5f 76 65 72 73 69 6f  ECT proj4_versio
16e0: 6e 28 29 3b 22 29 3b 0d 0a 20 20 20 20 20 20 20  n();");..       
16f0: 20 69 66 20 28 73 74 6d 74 30 31 2e 73 74 65 70   if (stmt01.step
1700: 28 29 29 20 7b 0d 0a 20 20 20 20 20 20 20 20 20  ()) {..         
1710: 20 20 20 73 62 2e 61 70 70 65 6e 64 28 22 5c 74     sb.append("\t
1720: 22 29 2e 61 70 70 65 6e 64 28 22 50 52 4f 4a 34  ").append("PROJ4
1730: 5f 56 45 52 53 49 4f 4e 3a 20 22 20 2b 20 73 74  _VERSION: " + st
1740: 6d 74 30 31 2e 63 6f 6c 75 6d 6e 5f 73 74 72 69  mt01.column_stri
1750: 6e 67 28 30 29 29 3b 0d 0a 20 20 20 20 20 20 20  ng(0));..       
1760: 20 20 20 20 20 73 62 2e 61 70 70 65 6e 64 28 22       sb.append("
1770: 5c 6e 22 29 3b 0d 0a 20 20 20 20 20 20 20 20 7d  \n");..        }
1780: 0d 0a 0d 0a 20 20 20 20 20 20 20 20 73 74 6d 74  ....        stmt
1790: 30 31 20 3d 20 64 62 2e 70 72 65 70 61 72 65 28  01 = db.prepare(
17a0: 22 53 45 4c 45 43 54 20 67 65 6f 73 5f 76 65 72  "SELECT geos_ver
17b0: 73 69 6f 6e 28 29 3b 22 29 3b 0d 0a 20 20 20 20  sion();");..    
17c0: 20 20 20 20 69 66 20 28 73 74 6d 74 30 31 2e 73      if (stmt01.s
17d0: 74 65 70 28 29 29 20 7b 0d 0a 20 20 20 20 20 20  tep()) {..      
17e0: 20 20 20 20 20 20 73 62 2e 61 70 70 65 6e 64 28        sb.append(
17f0: 22 5c 74 22 29 2e 61 70 70 65 6e 64 28 22 47 45  "\t").append("GE
1800: 4f 53 5f 56 45 52 53 49 4f 4e 3a 20 22 20 2b 20  OS_VERSION: " + 
1810: 73 74 6d 74 30 31 2e 63 6f 6c 75 6d 6e 5f 73 74  stmt01.column_st
1820: 72 69 6e 67 28 30 29 29 3b 0d 0a 20 20 20 20 20  ring(0));..     
1830: 20 20 20 20 20 20 20 73 62 2e 61 70 70 65 6e 64         sb.append
1840: 28 22 5c 6e 22 29 3b 0d 0a 20 20 20 20 20 20 20  ("\n");..       
1850: 20 7d 0d 0a 20 20 20 20 20 20 20 20 73 74 6d 74   }..        stmt
1860: 30 31 2e 63 6c 6f 73 65 28 29 3b 0d 0a 0d 0a 20  01.close();.... 
1870: 20 20 20 20 20 20 20 73 62 2e 61 70 70 65 6e 64         sb.append
1880: 28 22 44 6f 6e 65 2e 2e 2e 5c 6e 22 29 3b 0d 0a  ("Done...\n");..
1890: 20 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 73          return s
18a0: 62 2e 74 6f 53 74 72 69 6e 67 28 29 3b 0d 0a 20  b.toString();.. 
18b0: 20 20 20 7d 0d 0a 3c 2f 76 65 72 62 61 74 69 6d     }..</verbatim
18c0: 3e 0d 0a 0d 0a 0d 0a 3c 68 34 3e 43 68 65 63 6b  >......<h4>Check
18d0: 20 70 6c 61 69 6e 20 73 71 6c 69 74 65 20 71 75   plain sqlite qu
18e0: 65 72 69 65 73 3c 2f 68 34 3e 0d 0a 0d 0a 54 6f  eries</h4>....To
18f0: 20 73 65 65 20 69 66 20 69 74 20 61 6c 6c 20 77   see if it all w
1900: 6f 72 6b 73 2c 20 77 65 20 63 61 6e 20 64 6f 20  orks, we can do 
1910: 61 20 70 6c 61 69 6e 20 73 71 6c 69 74 65 20 71  a plain sqlite q
1920: 75 65 72 79 20 61 6e 64 20 73 65 65 20 69 66 20  uery and see if 
1930: 77 65 20 68 61 76 65 20 74 68 65 20 64 61 74 61  we have the data
1940: 62 61 73 65 20 73 65 74 75 70 20 77 69 74 68 20  base setup with 
1950: 74 68 65 20 64 61 74 61 2e 0d 0a 41 73 73 75 6d  the data...Assum
1960: 69 6e 67 20 79 6f 75 20 69 6d 70 6f 72 74 65 64  ing you imported
1970: 20 74 68 65 20 73 68 61 70 66 69 6c 65 20 43 6f   the shapfile Co
1980: 6d 75 6e 69 5f 32 30 31 31 20 69 6e 74 6f 20 61  muni_2011 into a
1990: 20 74 61 62 6c 65 20 6e 61 6d 65 64 20 43 6f 6d   table named Com
19a0: 75 6e 69 5f 31 31 2c 20 77 68 69 63 68 20 68 61  uni_11, which ha
19b0: 73 20 61 20 66 69 65 6c 64 20 63 61 6c 6c 65 64  s a field called
19c0: 20 4e 4f 4d 45 2c 20 74 68 65 20 66 6f 6c 6c 6f   NOME, the follo
19d0: 77 69 6e 67 20 67 69 76 65 73 20 79 6f 75 20 74  wing gives you t
19e0: 68 65 20 66 69 72 73 74 20 35 20 65 6e 74 72 69  he first 5 entri
19f0: 65 73 3a 0d 0a 0d 0a 3c 76 65 72 62 61 74 69 6d  es:....<verbatim
1a00: 3e 0d 0a 20 20 20 20 70 75 62 6c 69 63 20 53 74  >..    public St
1a10: 72 69 6e 67 20 71 75 65 72 79 43 6f 6d 75 6e 69  ring queryComuni
1a20: 28 29 20 7b 0d 0a 20 20 20 20 20 20 20 20 73 62  () {..        sb
1a30: 2e 61 70 70 65 6e 64 28 22 51 75 65 72 79 20 43  .append("Query C
1a40: 6f 6d 75 6e 69 2e 2e 2e 5c 6e 22 29 3b 0d 0a 0d  omuni...\n");...
1a50: 0a 20 20 20 20 20 20 20 20 53 74 72 69 6e 67 20  .        String 
1a60: 71 75 65 72 79 20 3d 20 22 53 45 4c 45 43 54 20  query = "SELECT 
1a70: 4e 4f 4d 45 22 20 2b 20 2f 2f 0d 0a 20 20 20 20  NOME" + //..    
1a80: 20 20 20 20 20 20 20 20 20 20 20 20 22 20 66 72              " fr
1a90: 6f 6d 20 43 6f 6d 75 6e 69 5f 31 31 22 20 2b 20  om Comuni_11" + 
1aa0: 2f 2f 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20  //..            
1ab0: 20 20 20 20 22 20 6f 72 64 65 72 20 62 79 20 4e      " order by N
1ac0: 4f 4d 45 3b 22 3b 0d 0a 20 20 20 20 20 20 20 20  OME;";..        
1ad0: 73 62 2e 61 70 70 65 6e 64 28 22 45 78 65 63 75  sb.append("Execu
1ae0: 74 65 20 71 75 65 72 79 3a 20 22 29 2e 61 70 70  te query: ").app
1af0: 65 6e 64 28 71 75 65 72 79 29 2e 61 70 70 65 6e  end(query).appen
1b00: 64 28 22 5c 6e 22 29 3b 0d 0a 20 20 20 20 20 20  d("\n");..      
1b10: 20 20 74 72 79 20 7b 0d 0a 20 20 20 20 20 20 20    try {..       
1b20: 20 20 20 20 20 53 74 6d 74 20 73 74 6d 74 20 3d       Stmt stmt =
1b30: 20 64 62 2e 70 72 65 70 61 72 65 28 71 75 65 72   db.prepare(quer
1b40: 79 29 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 20  y);..           
1b50: 20 69 6e 74 20 69 6e 64 65 78 20 3d 20 30 3b 0d   int index = 0;.
1b60: 0a 20 20 20 20 20 20 20 20 20 20 20 20 77 68 69  .            whi
1b70: 6c 65 28 20 73 74 6d 74 2e 73 74 65 70 28 29 20  le( stmt.step() 
1b80: 29 20 7b 0d 0a 20 20 20 20 20 20 20 20 20 20 20  ) {..           
1b90: 20 20 20 20 20 53 74 72 69 6e 67 20 6e 6f 6d 65       String nome
1ba0: 53 74 72 20 3d 20 73 74 6d 74 2e 63 6f 6c 75 6d  Str = stmt.colum
1bb0: 6e 5f 73 74 72 69 6e 67 28 30 29 3b 0d 0a 20 20  n_string(0);..  
1bc0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 73 62                sb
1bd0: 2e 61 70 70 65 6e 64 28 22 5c 74 22 29 2e 61 70  .append("\t").ap
1be0: 70 65 6e 64 28 6e 6f 6d 65 53 74 72 29 2e 61 70  pend(nomeStr).ap
1bf0: 70 65 6e 64 28 22 5c 6e 22 29 3b 0d 0a 20 20 20  pend("\n");..   
1c00: 20 20 20 20 20 20 20 20 20 20 20 20 20 69 66 20               if 
1c10: 28 69 6e 64 65 78 2b 2b 20 3e 20 35 29 20 7b 0d  (index++ > 5) {.
1c20: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20  .               
1c30: 20 20 20 20 20 62 72 65 61 6b 3b 0d 0a 20 20 20       break;..   
1c40: 20 20 20 20 20 20 20 20 20 20 20 20 20 7d 0d 0a               }..
1c50: 20 20 20 20 20 20 20 20 20 20 20 20 7d 0d 0a 20              }.. 
1c60: 20 20 20 20 20 20 20 20 20 20 20 73 62 2e 61 70             sb.ap
1c70: 70 65 6e 64 28 22 5c 74 2e 2e 2e 22 29 3b 0d 0a  pend("\t...");..
1c80: 20 20 20 20 20 20 20 20 20 20 20 20 73 74 6d 74              stmt
1c90: 2e 63 6c 6f 73 65 28 29 3b 0d 0a 20 20 20 20 20  .close();..     
1ca0: 20 20 20 7d 20 63 61 74 63 68 20 28 45 78 63 65     } catch (Exce
1cb0: 70 74 69 6f 6e 20 65 29 20 7b 0d 0a 20 20 20 20  ption e) {..    
1cc0: 20 20 20 20 20 20 20 20 65 72 72 6f 72 28 65 29          error(e)
1cd0: 3b 0d 0a 20 20 20 20 20 20 20 20 7d 0d 0a 0d 0a  ;..        }....
1ce0: 20 20 20 20 20 20 20 20 73 62 2e 61 70 70 65 6e          sb.appen
1cf0: 64 28 22 44 6f 6e 65 2e 2e 2e 5c 6e 22 29 3b 0d  d("Done...\n");.
1d00: 0a 0d 0a 20 20 20 20 20 20 20 20 72 65 74 75 72  ...        retur
1d10: 6e 20 73 62 2e 74 6f 53 74 72 69 6e 67 28 29 3b  n sb.toString();
1d20: 0d 0a 20 20 20 20 7d 0d 0a 3c 2f 76 65 72 62 61  ..    }..</verba
1d30: 74 69 6d 3e 0d 0a 0d 0a 3c 68 34 3e 59 6f 75 72  tim>....<h4>Your
1d40: 20 66 69 72 73 74 20 73 70 61 74 69 61 6c 20 71   first spatial q
1d50: 75 65 72 79 3c 2f 68 34 3e 0d 0a 0d 0a 4c 65 74  uery</h4>....Let
1d60: 27 73 20 66 69 6e 61 6c 6c 79 20 71 75 65 72 79  's finally query
1d70: 20 66 6f 72 20 74 68 65 20 67 65 6f 6d 65 74 72   for the geometr
1d80: 69 65 73 2c 20 69 66 20 74 68 65 72 65 20 61 72  ies, if there ar
1d90: 65 20 61 6e 79 2e 20 54 68 65 20 72 65 73 75 6c  e any. The resul
1da0: 74 69 6e 67 20 57 4b 54 20 66 6f 72 6d 61 74 20  ting WKT format 
1db0: 6f 66 20 74 68 65 20 67 65 6f 6d 65 74 72 69 65  of the geometrie
1dc0: 73 20 69 73 20 73 68 6f 72 74 65 6e 65 64 20 69  s is shortened i
1dd0: 6e 20 6f 72 64 65 72 20 74 6f 20 62 65 20 70 72  n order to be pr
1de0: 69 6e 74 65 64 3a 0d 0a 0d 0a 3c 76 65 72 62 61  inted:....<verba
1df0: 74 69 6d 3e 0d 0a 20 20 20 20 70 75 62 6c 69 63  tim>..    public
1e00: 20 53 74 72 69 6e 67 20 71 75 65 72 79 43 6f 6d   String queryCom
1e10: 75 6e 69 57 69 74 68 47 65 6f 6d 28 29 20 7b 0d  uniWithGeom() {.
1e20: 0a 20 20 20 20 20 20 20 20 73 62 2e 61 70 70 65  .        sb.appe
1e30: 6e 64 28 53 45 50 29 3b 0d 0a 20 20 20 20 20 20  nd(SEP);..      
1e40: 20 20 73 62 2e 61 70 70 65 6e 64 28 22 51 75 65    sb.append("Que
1e50: 72 79 20 43 6f 6d 75 6e 69 20 77 69 74 68 20 41  ry Comuni with A
1e60: 73 54 65 78 74 28 47 65 6f 6d 65 74 72 79 29 2e  sText(Geometry).
1e70: 2e 2e 5c 6e 22 29 3b 0d 0a 0d 0a 20 20 20 20 20  ..\n");....     
1e80: 20 20 20 53 74 72 69 6e 67 20 71 75 65 72 79 20     String query 
1e90: 3d 20 22 53 45 4c 45 43 54 20 4e 4f 4d 45 22 20  = "SELECT NOME" 
1ea0: 2b 20 2f 2f 0d 0a 20 20 20 20 20 20 20 20 20 20  + //..          
1eb0: 20 20 20 20 20 20 22 20 2c 20 41 73 54 65 78 74        " , AsText
1ec0: 28 47 65 6f 6d 65 74 72 79 29 22 20 2b 20 2f 2f  (Geometry)" + //
1ed0: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20  ..              
1ee0: 20 20 22 20 61 73 20 67 65 6f 6d 20 66 72 6f 6d    " as geom from
1ef0: 20 43 6f 6d 75 6e 69 5f 31 31 22 20 2b 20 20 2f   Comuni_11" +  /
1f00: 2f 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20  /..             
1f10: 20 20 20 22 20 77 68 65 72 65 20 67 65 6f 6d 20     " where geom 
1f20: 6e 6f 74 20 6e 75 6c 6c 3b 22 3b 0d 0a 20 20 20  not null;";..   
1f30: 20 20 20 20 20 73 62 2e 61 70 70 65 6e 64 28 22       sb.append("
1f40: 45 78 65 63 75 74 65 20 71 75 65 72 79 3a 20 22  Execute query: "
1f50: 29 2e 61 70 70 65 6e 64 28 71 75 65 72 79 29 2e  ).append(query).
1f60: 61 70 70 65 6e 64 28 22 5c 6e 22 29 3b 0d 0a 20  append("\n");.. 
1f70: 20 20 20 20 20 20 20 74 72 79 20 7b 0d 0a 20 20         try {..  
1f80: 20 20 20 20 20 20 20 20 20 20 53 74 6d 74 20 73            Stmt s
1f90: 74 6d 74 20 3d 20 64 62 2e 70 72 65 70 61 72 65  tmt = db.prepare
1fa0: 28 71 75 65 72 79 29 3b 0d 0a 20 20 20 20 20 20  (query);..      
1fb0: 20 20 20 20 20 20 77 68 69 6c 65 28 20 73 74 6d        while( stm
1fc0: 74 2e 73 74 65 70 28 29 20 29 20 7b 0d 0a 20 20  t.step() ) {..  
1fd0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 53 74                St
1fe0: 72 69 6e 67 20 6e 6f 6d 65 53 74 72 20 3d 20 73  ring nomeStr = s
1ff0: 74 6d 74 2e 63 6f 6c 75 6d 6e 5f 73 74 72 69 6e  tmt.column_strin
2000: 67 28 30 29 3b 0d 0a 20 20 20 20 20 20 20 20 20  g(0);..         
2010: 20 20 20 20 20 20 20 53 74 72 69 6e 67 20 67 65         String ge
2020: 6f 6d 53 74 72 20 3d 20 73 74 6d 74 2e 63 6f 6c  omStr = stmt.col
2030: 75 6d 6e 5f 73 74 72 69 6e 67 28 31 29 3b 0d 0a  umn_string(1);..
2040: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
2050: 53 74 72 69 6e 67 20 73 75 62 73 74 72 69 6e 67  String substring
2060: 20 3d 20 67 65 6f 6d 53 74 72 3b 0d 0a 20 20 20   = geomStr;..   
2070: 20 20 20 20 20 20 20 20 20 20 20 20 20 69 66 20               if 
2080: 28 73 75 62 73 74 72 69 6e 67 2e 6c 65 6e 67 74  (substring.lengt
2090: 68 28 29 20 3e 20 34 30 29 0d 0a 20 20 20 20 20  h() > 40)..     
20a0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 73                 s
20b0: 75 62 73 74 72 69 6e 67 20 3d 20 67 65 6f 6d 53  ubstring = geomS
20c0: 74 72 2e 73 75 62 73 74 72 69 6e 67 28 30 2c 20  tr.substring(0, 
20d0: 34 30 29 3b 0d 0a 20 20 20 20 20 20 20 20 20 20  40);..          
20e0: 20 20 20 20 20 20 73 62 2e 61 70 70 65 6e 64 28        sb.append(
20f0: 22 5c 74 22 29 2e 61 70 70 65 6e 64 28 6e 6f 6d  "\t").append(nom
2100: 65 53 74 72 29 2e 61 70 70 65 6e 64 28 22 20 2d  eStr).append(" -
2110: 20 22 29 2e 61 70 70 65 6e 64 28 73 75 62 73 74   ").append(subst
2120: 72 69 6e 67 29 2e 61 70 70 65 6e 64 28 22 2e 2e  ring).append("..
2130: 2e 5c 6e 22 29 3b 0d 0a 20 20 20 20 20 20 20 20  .\n");..        
2140: 20 20 20 20 20 20 20 20 62 72 65 61 6b 3b 0d 0a          break;..
2150: 20 20 20 20 20 20 20 20 20 20 20 20 7d 0d 0a 20              }.. 
2160: 20 20 20 20 20 20 20 20 20 20 20 73 74 6d 74 2e             stmt.
2170: 63 6c 6f 73 65 28 29 3b 0d 0a 20 20 20 20 20 20  close();..      
2180: 20 20 7d 20 63 61 74 63 68 20 28 45 78 63 65 70    } catch (Excep
2190: 74 69 6f 6e 20 65 29 20 7b 0d 0a 20 20 20 20 20  tion e) {..     
21a0: 20 20 20 20 20 20 20 65 2e 70 72 69 6e 74 53 74         e.printSt
21b0: 61 63 6b 54 72 61 63 65 28 29 3b 0d 0a 20 20 20  ackTrace();..   
21c0: 20 20 20 20 20 20 20 20 20 73 62 2e 61 70 70 65           sb.appe
21d0: 6e 64 28 45 52 52 4f 52 29 2e 61 70 70 65 6e 64  nd(ERROR).append
21e0: 28 65 2e 67 65 74 4c 6f 63 61 6c 69 7a 65 64 4d  (e.getLocalizedM
21f0: 65 73 73 61 67 65 28 29 29 2e 61 70 70 65 6e 64  essage()).append
2200: 28 22 5c 6e 22 29 3b 0d 0a 20 20 20 20 20 20 20  ("\n");..       
2210: 20 7d 0d 0a 20 20 20 20 20 20 20 20 73 62 2e 61   }..        sb.a
2220: 70 70 65 6e 64 28 22 44 6f 6e 65 2e 2e 2e 5c 6e  ppend("Done...\n
2230: 22 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 20 20 72  ");....        r
2240: 65 74 75 72 6e 20 73 62 2e 74 6f 53 74 72 69 6e  eturn sb.toStrin
2250: 67 28 29 3b 0d 0a 20 20 20 20 7d 0d 0a 3c 2f 76  g();..    }..</v
2260: 65 72 62 61 74 69 6d 3e 0d 0a 0d 0a 3c 68 34 3e  erbatim>....<h4>
2270: 47 65 74 20 74 68 65 20 61 72 65 61 20 6f 66 20  Get the area of 
2280: 61 20 70 6f 6c 79 67 6f 6e 3c 2f 68 34 3e 0d 0a  a polygon</h4>..
2290: 0d 0a 54 68 65 20 3c 69 3e 53 54 5f 41 72 65 61  ..The <i>ST_Area
22a0: 3c 2f 69 3e 20 66 75 6e 63 74 69 6f 6e 20 69 73  </i> function is
22b0: 20 61 76 61 69 6c 61 62 6c 65 20 74 6f 20 67 65   available to ge
22c0: 74 20 74 68 65 20 61 72 65 61 20 66 72 6f 6d 20  t the area from 
22d0: 61 20 67 65 6f 6d 65 74 72 79 3a 0d 0a 0d 0a 3c  a geometry:....<
22e0: 76 65 72 62 61 74 69 6d 3e 0d 0a 20 20 20 20 70  verbatim>..    p
22f0: 75 62 6c 69 63 20 53 74 72 69 6e 67 20 71 75 65  ublic String que
2300: 72 79 43 6f 6d 75 6e 69 41 72 65 61 28 29 20 7b  ryComuniArea() {
2310: 0d 0a 20 20 20 20 20 20 20 20 73 62 2e 61 70 70  ..        sb.app
2320: 65 6e 64 28 53 45 50 29 3b 0d 0a 20 20 20 20 20  end(SEP);..     
2330: 20 20 20 73 62 2e 61 70 70 65 6e 64 28 22 51 75     sb.append("Qu
2340: 65 72 79 20 43 6f 6d 75 6e 69 20 61 72 65 61 20  ery Comuni area 
2350: 73 75 6d 2e 2e 2e 5c 6e 22 29 3b 0d 0a 0d 0a 20  sum...\n");.... 
2360: 20 20 20 20 20 20 20 53 74 72 69 6e 67 20 71 75         String qu
2370: 65 72 79 20 3d 20 22 53 45 4c 45 43 54 20 53 54  ery = "SELECT ST
2380: 5f 41 72 65 61 28 47 65 6f 6d 65 74 72 79 29 20  _Area(Geometry) 
2390: 2f 20 31 30 30 30 30 30 30 2e 30 20 66 72 6f 6d  / 1000000.0 from
23a0: 20 43 6f 6d 75 6e 69 5f 31 31 22 20 2b 20 20 2f   Comuni_11" +  /
23b0: 2f 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20  /..             
23c0: 20 20 20 22 3b 22 3b 0d 0a 20 20 20 20 20 20 20     ";";..       
23d0: 20 73 62 2e 61 70 70 65 6e 64 28 22 45 78 65 63   sb.append("Exec
23e0: 75 74 65 20 71 75 65 72 79 3a 20 22 29 2e 61 70  ute query: ").ap
23f0: 70 65 6e 64 28 71 75 65 72 79 29 2e 61 70 70 65  pend(query).appe
2400: 6e 64 28 22 5c 6e 22 29 3b 0d 0a 20 20 20 20 20  nd("\n");..     
2410: 20 20 20 74 72 79 20 7b 0d 0a 20 20 20 20 20 20     try {..      
2420: 20 20 20 20 20 20 53 74 6d 74 20 73 74 6d 74 20        Stmt stmt 
2430: 3d 20 64 62 2e 70 72 65 70 61 72 65 28 71 75 65  = db.prepare(que
2440: 72 79 29 3b 0d 0a 20 20 20 20 20 20 20 20 20 20  ry);..          
2450: 20 20 64 6f 75 62 6c 65 20 74 6f 74 61 6c 41 72    double totalAr
2460: 65 61 20 3d 20 30 3b 0d 0a 20 20 20 20 20 20 20  ea = 0;..       
2470: 20 20 20 20 20 77 68 69 6c 65 28 20 73 74 6d 74       while( stmt
2480: 2e 73 74 65 70 28 29 20 29 20 7b 0d 0a 20 20 20  .step() ) {..   
2490: 20 20 20 20 20 20 20 20 20 20 20 20 20 64 6f 75               dou
24a0: 62 6c 65 20 61 72 65 61 20 3d 20 73 74 6d 74 2e  ble area = stmt.
24b0: 63 6f 6c 75 6d 6e 5f 64 6f 75 62 6c 65 28 30 29  column_double(0)
24c0: 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20  ;..             
24d0: 20 20 20 74 6f 74 61 6c 41 72 65 61 20 3d 20 74     totalArea = t
24e0: 6f 74 61 6c 41 72 65 61 20 2b 20 61 72 65 61 3b  otalArea + area;
24f0: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 7d 0d  ..            }.
2500: 0a 20 20 20 20 20 20 20 20 20 20 20 20 73 62 2e  .            sb.
2510: 61 70 70 65 6e 64 28 22 5c 74 54 6f 74 61 6c 20  append("\tTotal 
2520: 61 72 65 61 20 62 79 20 73 75 6d 6d 69 6e 67 20  area by summing 
2530: 65 61 63 68 20 61 72 65 61 3a 20 22 29 2e 61 70  each area: ").ap
2540: 70 65 6e 64 28 74 6f 74 61 6c 41 72 65 61 29 2e  pend(totalArea).
2550: 61 70 70 65 6e 64 28 22 4b 6d 32 5c 6e 22 29 3b  append("Km2\n");
2560: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 73 74  ..            st
2570: 6d 74 2e 63 6c 6f 73 65 28 29 3b 0d 0a 20 20 20  mt.close();..   
2580: 20 20 20 20 20 7d 20 63 61 74 63 68 20 28 45 78       } catch (Ex
2590: 63 65 70 74 69 6f 6e 20 65 29 20 7b 0d 0a 20 20  ception e) {..  
25a0: 20 20 20 20 20 20 20 20 20 20 65 2e 70 72 69 6e            e.prin
25b0: 74 53 74 61 63 6b 54 72 61 63 65 28 29 3b 0d 0a  tStackTrace();..
25c0: 20 20 20 20 20 20 20 20 20 20 20 20 73 62 2e 61              sb.a
25d0: 70 70 65 6e 64 28 45 52 52 4f 52 29 2e 61 70 70  ppend(ERROR).app
25e0: 65 6e 64 28 65 2e 67 65 74 4c 6f 63 61 6c 69 7a  end(e.getLocaliz
25f0: 65 64 4d 65 73 73 61 67 65 28 29 29 2e 61 70 70  edMessage()).app
2600: 65 6e 64 28 22 5c 6e 22 29 3b 0d 0a 20 20 20 20  end("\n");..    
2610: 20 20 20 20 7d 0d 0a 20 20 20 20 20 20 20 20 73      }..        s
2620: 62 2e 61 70 70 65 6e 64 28 22 44 6f 6e 65 2e 2e  b.append("Done..
2630: 2e 5c 6e 22 29 3b 0d 0a 0d 0a 20 20 20 20 20 20  .\n");....      
2640: 20 20 72 65 74 75 72 6e 20 73 62 2e 74 6f 53 74    return sb.toSt
2650: 72 69 6e 67 28 29 3b 0d 0a 20 20 20 20 7d 0d 0a  ring();..    }..
2660: 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 0d 0a 4f  </verbatim>....O
2670: 62 76 69 6f 75 73 6c 79 20 79 6f 75 20 63 6f 75  bviously you cou
2680: 6c 64 20 61 6c 73 6f 20 64 6f 20 74 68 65 20 73  ld also do the s
2690: 75 6d 20 64 69 72 65 63 74 6c 79 20 69 6e 73 69  um directly insi
26a0: 64 65 20 74 68 65 20 71 75 65 72 79 2e 0d 0a 0d  de the query....
26b0: 0a 3c 68 34 3e 53 69 6d 70 6c 65 20 63 6f 6f 72  .<h4>Simple coor
26c0: 64 69 6e 61 74 65 20 74 72 61 6e 73 66 6f 72 6d  dinate transform
26d0: 61 74 69 6f 6e 3c 2f 68 34 3e 0d 0a 0d 0a 59 6f  ation</h4>....Yo
26e0: 75 20 63 61 6e 20 61 6c 73 6f 20 64 6f 20 73 6f  u can also do so
26f0: 6d 65 20 63 6f 6f 72 64 69 6e 61 74 65 20 74 72  me coordinate tr
2700: 61 6e 73 66 6f 72 6d 61 74 69 6f 6e 2e 20 54 72  ansformation. Tr
2710: 79 20 77 69 74 68 3a 0d 0a 0d 0a 3c 76 65 72 62  y with:....<verb
2720: 61 74 69 6d 3e 0d 0a 20 20 20 20 70 75 62 6c 69  atim>..    publi
2730: 63 20 53 74 72 69 6e 67 20 64 6f 53 69 6d 70 6c  c String doSimpl
2740: 65 54 72 61 6e 73 66 6f 72 6d 28 29 20 7b 0d 0a  eTransform() {..
2750: 0d 0a 0d 0a 20 20 20 20 20 20 20 20 73 62 2e 61  ....        sb.a
2760: 70 70 65 6e 64 28 22 43 6f 6f 72 64 69 6e 61 74  ppend("Coordinat
2770: 65 20 74 72 61 6e 73 66 6f 72 6d 61 74 69 6f 6e  e transformation
2780: 2e 2e 2e 5c 6e 22 29 3b 0d 0a 0d 0a 20 20 20 20  ...\n");....    
2790: 20 20 20 20 53 74 72 69 6e 67 20 71 75 65 72 79      String query
27a0: 20 3d 20 22 53 45 4c 45 43 54 20 41 73 54 65 78   = "SELECT AsTex
27b0: 74 28 54 72 61 6e 73 66 6f 72 6d 28 4d 61 6b 65  t(Transform(Make
27c0: 50 6f 69 6e 74 28 22 20 2b 20 54 45 53 54 5f 4c  Point(" + TEST_L
27d0: 4f 4e 20 2b 20 22 2c 20 22 20 2b 20 54 45 53 54  ON + ", " + TEST
27e0: 5f 4c 41 54 20 2b 20 22 2c 20 34 33 32 36 29 2c  _LAT + ", 4326),
27f0: 20 33 32 36 33 32 29 29 3b 22 3b 0d 0a 20 20 20   32632));";..   
2800: 20 20 20 20 20 73 62 2e 61 70 70 65 6e 64 28 22       sb.append("
2810: 45 78 65 63 75 74 65 20 71 75 65 72 79 3a 20 22  Execute query: "
2820: 29 2e 61 70 70 65 6e 64 28 71 75 65 72 79 29 2e  ).append(query).
2830: 61 70 70 65 6e 64 28 22 5c 6e 22 29 3b 0d 0a 20  append("\n");.. 
2840: 20 20 20 20 20 20 20 74 72 79 20 7b 0d 0a 20 20         try {..  
2850: 20 20 20 20 20 20 20 20 20 20 53 74 6d 74 20 73            Stmt s
2860: 74 6d 74 20 3d 20 64 62 2e 70 72 65 70 61 72 65  tmt = db.prepare
2870: 28 71 75 65 72 79 29 3b 0d 0a 20 20 20 20 20 20  (query);..      
2880: 20 20 20 20 20 20 69 66 20 28 73 74 6d 74 2e 73        if (stmt.s
2890: 74 65 70 28 29 29 20 7b 0d 0a 20 20 20 20 20 20  tep()) {..      
28a0: 20 20 20 20 20 20 20 20 20 20 53 74 72 69 6e 67            String
28b0: 20 70 6f 69 6e 74 53 74 72 20 3d 20 73 74 6d 74   pointStr = stmt
28c0: 2e 63 6f 6c 75 6d 6e 5f 73 74 72 69 6e 67 28 30  .column_string(0
28d0: 29 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20  );..            
28e0: 20 20 20 20 73 62 2e 61 70 70 65 6e 64 28 22 5c      sb.append("\
28f0: 74 22 29 2e 61 70 70 65 6e 64 28 54 45 53 54 5f  t").append(TEST_
2900: 4c 4f 4e 20 2b 20 22 2f 22 20 2b 20 54 45 53 54  LON + "/" + TEST
2910: 5f 4c 41 54 20 2b 20 22 2f 45 50 53 47 3a 34 33  _LAT + "/EPSG:43
2920: 32 36 22 29 2e 61 70 70 65 6e 64 28 22 20 3d 20  26").append(" = 
2930: 22 29 2f 2f 0d 0a 20 20 20 20 20 20 20 20 20 20  ")//..          
2940: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2e 61                .a
2950: 70 70 65 6e 64 28 70 6f 69 6e 74 53 74 72 20 2b  ppend(pointStr +
2960: 20 22 2f 45 50 53 47 3a 33 32 36 33 32 22 29 2e   "/EPSG:32632").
2970: 61 70 70 65 6e 64 28 22 2e 2e 2e 5c 6e 22 29 3b  append("...\n");
2980: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 7d 0d  ..            }.
2990: 0a 20 20 20 20 20 20 20 20 20 20 20 20 73 74 6d  .            stm
29a0: 74 2e 63 6c 6f 73 65 28 29 3b 0d 0a 20 20 20 20  t.close();..    
29b0: 20 20 20 20 7d 20 63 61 74 63 68 20 28 45 78 63      } catch (Exc
29c0: 65 70 74 69 6f 6e 20 65 29 20 7b 0d 0a 20 20 20  eption e) {..   
29d0: 20 20 20 20 20 20 20 20 20 65 2e 70 72 69 6e 74           e.print
29e0: 53 74 61 63 6b 54 72 61 63 65 28 29 3b 0d 0a 20  StackTrace();.. 
29f0: 20 20 20 20 20 20 20 20 20 20 20 73 62 2e 61 70             sb.ap
2a00: 70 65 6e 64 28 45 52 52 4f 52 29 2e 61 70 70 65  pend(ERROR).appe
2a10: 6e 64 28 65 2e 67 65 74 4c 6f 63 61 6c 69 7a 65  nd(e.getLocalize
2a20: 64 4d 65 73 73 61 67 65 28 29 29 2e 61 70 70 65  dMessage()).appe
2a30: 6e 64 28 22 5c 6e 22 29 3b 0d 0a 20 20 20 20 20  nd("\n");..     
2a40: 20 20 20 7d 0d 0a 20 20 20 20 20 20 20 20 73 62     }..        sb
2a50: 2e 61 70 70 65 6e 64 28 22 44 6f 6e 65 2e 2e 2e  .append("Done...
2a60: 5c 6e 22 29 3b 0d 0a 0d 0a 20 20 20 20 20 20 20  \n");....       
2a70: 20 72 65 74 75 72 6e 20 73 62 2e 74 6f 53 74 72   return sb.toStr
2a80: 69 6e 67 28 29 3b 0d 0a 0d 0a 20 20 20 20 7d 0d  ing();....    }.
2a90: 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 0d 0a  .</verbatim>....
2aa0: 73 65 74 74 69 6e 67 20 54 45 53 54 5f 4c 4f 4e  setting TEST_LON
2ab0: 20 20 61 6e 64 20 54 45 53 54 5f 4c 41 54 20 74    and TEST_LAT t
2ac0: 6f 20 74 68 65 20 63 6f 6f 72 64 69 6e 61 74 65  o the coordinate
2ad0: 73 20 74 6f 20 74 72 61 6e 73 66 6f 72 6d 2c 20  s to transform, 
2ae0: 69 6e 20 74 68 65 20 61 62 6f 76 65 20 63 61 73  in the above cas
2af0: 65 20 66 72 6f 6d 20 53 52 49 44 20 34 33 32 36  e from SRID 4326
2b00: 20 74 6f 20 33 32 36 33 32 2e 0d 0a 0d 0a 3c 68   to 32632.....<h
2b10: 34 3e 41 20 6d 6f 72 65 20 63 6f 6d 70 6c 65 78  4>A more complex
2b20: 20 71 75 65 72 79 3c 2f 68 34 3e 0d 0a 0d 0a 3c   query</h4>....<
2b30: 76 65 72 62 61 74 69 6d 3e 0d 0a 20 20 20 20 70  verbatim>..    p
2b40: 75 62 6c 69 63 20 53 74 72 69 6e 67 20 71 75 65  ublic String que
2b50: 72 79 43 6f 6d 75 6e 69 4e 65 61 72 62 79 28 29  ryComuniNearby()
2b60: 20 7b 0d 0a 20 20 20 20 20 20 20 20 73 62 2e 61   {..        sb.a
2b70: 70 70 65 6e 64 28 53 45 50 29 3b 0d 0a 20 20 20  ppend(SEP);..   
2b80: 20 20 20 20 20 73 62 2e 61 70 70 65 6e 64 28 22       sb.append("
2b90: 51 75 65 72 79 20 43 6f 6d 75 6e 69 20 6e 65 61  Query Comuni nea
2ba0: 72 62 79 2e 2e 2e 5c 6e 22 29 3b 0d 0a 0d 0a 20  rby...\n");.... 
2bb0: 20 20 20 20 20 20 20 53 74 72 69 6e 67 20 71 75         String qu
2bc0: 65 72 79 20 3d 20 22 53 45 4c 45 43 54 20 48 65  ery = "SELECT He
2bd0: 78 28 53 54 5f 41 73 42 69 6e 61 72 79 28 53 54  x(ST_AsBinary(ST
2be0: 5f 42 75 66 66 65 72 28 47 65 6f 6d 65 74 72 79  _Buffer(Geometry
2bf0: 2c 20 31 2e 30 29 29 29 2c 20 53 54 5f 53 72 69  , 1.0))), ST_Sri
2c00: 64 28 47 65 6f 6d 65 74 72 79 29 2c 20 53 54 5f  d(Geometry), ST_
2c10: 47 65 6f 6d 65 74 72 79 54 79 70 65 28 47 65 6f  GeometryType(Geo
2c20: 6d 65 74 72 79 29 20 66 72 6f 6d 20 43 6f 6d 75  metry) from Comu
2c30: 6e 69 5f 31 31 22 20 2b 0d 0a 20 20 20 20 20 20  ni_11" +..      
2c40: 20 20 20 20 20 20 20 20 20 20 22 20 77 68 65 72            " wher
2c50: 65 20 4e 4f 4d 45 20 3d 20 27 42 6f 6c 7a 61 6e  e NOME = 'Bolzan
2c60: 6f 27 3b 22 3b 0d 0a 20 20 20 20 20 20 20 20 73  o';";..        s
2c70: 62 2e 61 70 70 65 6e 64 28 22 45 78 65 63 75 74  b.append("Execut
2c80: 65 20 71 75 65 72 79 3a 20 22 29 2e 61 70 70 65  e query: ").appe
2c90: 6e 64 28 71 75 65 72 79 29 2e 61 70 70 65 6e 64  nd(query).append
2ca0: 28 22 5c 6e 22 29 3b 0d 0a 20 20 20 20 20 20 20  ("\n");..       
2cb0: 20 53 74 72 69 6e 67 20 62 75 66 66 65 72 47 65   String bufferGe
2cc0: 6f 6d 20 3d 20 22 22 3b 0d 0a 20 20 20 20 20 20  om = "";..      
2cd0: 20 20 53 74 72 69 6e 67 20 62 75 66 66 65 72 47    String bufferG
2ce0: 65 6f 6d 53 68 6f 72 74 20 3d 20 22 22 3b 0d 0a  eomShort = "";..
2cf0: 20 20 20 20 20 20 20 20 74 72 79 20 7b 0d 0a 20          try {.. 
2d00: 20 20 20 20 20 20 20 20 20 20 20 53 74 6d 74 20             Stmt 
2d10: 73 74 6d 74 20 3d 20 64 62 2e 70 72 65 70 61 72  stmt = db.prepar
2d20: 65 28 71 75 65 72 79 29 3b 0d 0a 20 20 20 20 20  e(query);..     
2d30: 20 20 20 20 20 20 20 69 66 20 28 73 74 6d 74 2e         if (stmt.
2d40: 73 74 65 70 28 29 29 20 7b 0d 0a 20 20 20 20 20  step()) {..     
2d50: 20 20 20 20 20 20 20 20 20 20 20 62 75 66 66 65             buffe
2d60: 72 47 65 6f 6d 20 3d 20 73 74 6d 74 2e 63 6f 6c  rGeom = stmt.col
2d70: 75 6d 6e 5f 73 74 72 69 6e 67 28 30 29 3b 0d 0a  umn_string(0);..
2d80: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
2d90: 53 74 72 69 6e 67 20 67 65 6f 6d 53 72 69 64 20  String geomSrid 
2da0: 3d 20 73 74 6d 74 2e 63 6f 6c 75 6d 6e 5f 73 74  = stmt.column_st
2db0: 72 69 6e 67 28 31 29 3b 0d 0a 20 20 20 20 20 20  ring(1);..      
2dc0: 20 20 20 20 20 20 20 20 20 20 53 74 72 69 6e 67            String
2dd0: 20 67 65 6f 6d 54 79 70 65 20 3d 20 73 74 6d 74   geomType = stmt
2de0: 2e 63 6f 6c 75 6d 6e 5f 73 74 72 69 6e 67 28 32  .column_string(2
2df0: 29 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20  );..            
2e00: 20 20 20 20 73 62 2e 61 70 70 65 6e 64 28 22 5c      sb.append("\
2e10: 74 54 68 65 20 73 65 6c 65 63 74 65 64 20 67 65  tThe selected ge
2e20: 6f 6d 65 74 72 79 20 69 73 20 6f 66 20 74 79 70  ometry is of typ
2e30: 65 3a 20 22 29 2e 61 70 70 65 6e 64 28 67 65 6f  e: ").append(geo
2e40: 6d 54 79 70 65 29 2e 61 70 70 65 6e 64 28 22 20  mType).append(" 
2e50: 61 6e 64 20 6f 66 20 53 52 49 44 3a 20 22 29 2e  and of SRID: ").
2e60: 61 70 70 65 6e 64 28 67 65 6f 6d 53 72 69 64 29  append(geomSrid)
2e70: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20  ..              
2e80: 20 20 20 20 20 20 20 20 20 20 2e 61 70 70 65 6e            .appen
2e90: 64 28 22 5c 6e 22 29 3b 0d 0a 20 20 20 20 20 20  d("\n");..      
2ea0: 20 20 20 20 20 20 7d 0d 0a 20 20 20 20 20 20 20        }..       
2eb0: 20 20 20 20 20 62 75 66 66 65 72 47 65 6f 6d 53       bufferGeomS
2ec0: 68 6f 72 74 20 3d 20 62 75 66 66 65 72 47 65 6f  hort = bufferGeo
2ed0: 6d 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20  m;..            
2ee0: 69 66 20 28 62 75 66 66 65 72 47 65 6f 6d 2e 6c  if (bufferGeom.l
2ef0: 65 6e 67 74 68 28 29 20 3e 20 31 30 29 0d 0a 20  ength() > 10).. 
2f00: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 62                 b
2f10: 75 66 66 65 72 47 65 6f 6d 53 68 6f 72 74 20 3d  ufferGeomShort =
2f20: 20 62 75 66 66 65 72 47 65 6f 6d 2e 73 75 62 73   bufferGeom.subs
2f30: 74 72 69 6e 67 28 30 2c 20 31 30 29 20 2b 20 22  tring(0, 10) + "
2f40: 2e 2e 2e 22 3b 0d 0a 20 20 20 20 20 20 20 20 20  ...";..         
2f50: 20 20 20 73 62 2e 61 70 70 65 6e 64 28 22 5c 74     sb.append("\t
2f60: 42 6f 6c 7a 61 6e 6f 20 70 6f 6c 79 67 6f 6e 20  Bolzano polygon 
2f70: 62 75 66 66 65 72 20 67 65 6f 6d 65 74 72 79 20  buffer geometry 
2f80: 69 6e 20 48 45 58 3a 20 22 29 2e 61 70 70 65 6e  in HEX: ").appen
2f90: 64 28 62 75 66 66 65 72 47 65 6f 6d 53 68 6f 72  d(bufferGeomShor
2fa0: 74 29 2e 61 70 70 65 6e 64 28 22 5c 6e 22 29 3b  t).append("\n");
2fb0: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 73 74  ..            st
2fc0: 6d 74 2e 63 6c 6f 73 65 28 29 3b 0d 0a 20 20 20  mt.close();..   
2fd0: 20 20 20 20 20 7d 20 63 61 74 63 68 20 28 45 78       } catch (Ex
2fe0: 63 65 70 74 69 6f 6e 20 65 29 20 7b 0d 0a 20 20  ception e) {..  
2ff0: 20 20 20 20 20 20 20 20 20 20 65 2e 70 72 69 6e            e.prin
3000: 74 53 74 61 63 6b 54 72 61 63 65 28 29 3b 0d 0a  tStackTrace();..
3010: 20 20 20 20 20 20 20 20 20 20 20 20 73 62 2e 61              sb.a
3020: 70 70 65 6e 64 28 45 52 52 4f 52 29 2e 61 70 70  ppend(ERROR).app
3030: 65 6e 64 28 65 2e 67 65 74 4c 6f 63 61 6c 69 7a  end(e.getLocaliz
3040: 65 64 4d 65 73 73 61 67 65 28 29 29 2e 61 70 70  edMessage()).app
3050: 65 6e 64 28 22 5c 6e 22 29 3b 0d 0a 20 20 20 20  end("\n");..    
3060: 20 20 20 20 7d 0d 0a 0d 0a 20 20 20 20 20 20 20      }....       
3070: 20 71 75 65 72 79 20 3d 20 22 53 45 4c 45 43 54   query = "SELECT
3080: 20 22 20 2b 20 4e 4f 4d 45 20 2b 20 22 2c 20 41   " + NOME + ", A
3090: 73 54 65 78 74 28 53 54 5f 63 65 6e 74 72 6f 69  sText(ST_centroi
30a0: 64 28 47 65 6f 6d 65 74 72 79 29 29 20 66 72 6f  d(Geometry)) fro
30b0: 6d 20 22 20 2b 20 43 4f 4d 55 4e 49 54 41 42 4c  m " + COMUNITABL
30c0: 45 20 2b 20 2f 2f 0d 0a 20 20 20 20 20 20 20 20  E + //..        
30d0: 20 20 20 20 20 20 20 20 22 20 77 68 65 72 65 20          " where 
30e0: 53 54 5f 49 6e 74 65 72 73 65 63 74 73 28 20 53  ST_Intersects( S
30f0: 54 5f 47 65 6f 6d 46 72 6f 6d 57 4b 42 28 78 27  T_GeomFromWKB(x'
3100: 22 20 2b 20 62 75 66 66 65 72 47 65 6f 6d 20 2b  " + bufferGeom +
3110: 20 22 27 29 20 2c 20 47 65 6f 6d 65 74 72 79 20   "') , Geometry 
3120: 29 3b 22 3b 0d 0a 20 20 20 20 20 20 20 20 2f 2f  );";..        //
3130: 20 6a 75 73 74 20 66 6f 72 20 70 72 69 6e 74 0d   just for print.
3140: 0a 20 20 20 20 20 20 20 20 53 74 72 69 6e 67 20  .        String 
3150: 74 6d 70 51 75 65 72 79 20 3d 20 22 53 45 4c 45  tmpQuery = "SELE
3160: 43 54 20 22 20 2b 20 4e 4f 4d 45 20 2b 20 22 20  CT " + NOME + " 
3170: 66 72 6f 6d 20 22 20 2b 20 43 4f 4d 55 4e 49 54  from " + COMUNIT
3180: 41 42 4c 45 20 2b 20 2f 2f 0d 0a 20 20 20 20 20  ABLE + //..     
3190: 20 20 20 20 20 20 20 20 20 20 20 22 20 77 68 65             " whe
31a0: 72 65 20 53 54 5f 49 6e 74 65 72 73 65 63 74 73  re ST_Intersects
31b0: 28 20 53 54 5f 47 65 6f 6d 46 72 6f 6d 57 4b 42  ( ST_GeomFromWKB
31c0: 28 78 27 22 20 2b 20 62 75 66 66 65 72 47 65 6f  (x'" + bufferGeo
31d0: 6d 53 68 6f 72 74 20 2b 20 22 27 29 20 2c 20 47  mShort + "') , G
31e0: 65 6f 6d 65 74 72 79 20 29 3b 22 3b 0d 0a 20 20  eometry );";..  
31f0: 20 20 20 20 20 20 73 62 2e 61 70 70 65 6e 64 28        sb.append(
3200: 22 45 78 65 63 75 74 65 20 71 75 65 72 79 3a 20  "Execute query: 
3210: 22 29 2e 61 70 70 65 6e 64 28 74 6d 70 51 75 65  ").append(tmpQue
3220: 72 79 29 2e 61 70 70 65 6e 64 28 22 5c 6e 22 29  ry).append("\n")
3230: 3b 0d 0a 20 20 20 20 20 20 20 20 74 72 79 20 7b  ;..        try {
3240: 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20 73 62  ..            sb
3250: 2e 61 70 70 65 6e 64 28 22 5c 74 43 6f 6d 75 6e  .append("\tComun
3260: 69 20 6e 65 61 72 62 79 20 42 6f 6c 7a 61 6e 6f  i nearby Bolzano
3270: 3a 20 5c 6e 22 29 3b 0d 0a 20 20 20 20 20 20 20  : \n");..       
3280: 20 20 20 20 20 53 74 6d 74 20 73 74 6d 74 20 3d       Stmt stmt =
3290: 20 64 62 2e 70 72 65 70 61 72 65 28 71 75 65 72   db.prepare(quer
32a0: 79 29 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 20  y);..           
32b0: 20 77 68 69 6c 65 28 20 73 74 6d 74 2e 73 74 65   while( stmt.ste
32c0: 70 28 29 20 29 20 7b 0d 0a 20 20 20 20 20 20 20  p() ) {..       
32d0: 20 20 20 20 20 20 20 20 20 53 74 72 69 6e 67 20           String 
32e0: 6e 61 6d 65 20 3d 20 73 74 6d 74 2e 63 6f 6c 75  name = stmt.colu
32f0: 6d 6e 5f 73 74 72 69 6e 67 28 30 29 3b 0d 0a 20  mn_string(0);.. 
3300: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 53                 S
3310: 74 72 69 6e 67 20 77 6b 74 20 3d 20 73 74 6d 74  tring wkt = stmt
3320: 2e 63 6f 6c 75 6d 6e 5f 73 74 72 69 6e 67 28 31  .column_string(1
3330: 29 3b 0d 0a 20 20 20 20 20 20 20 20 20 20 20 20  );..            
3340: 20 20 20 20 73 62 2e 61 70 70 65 6e 64 28 22 5c      sb.append("\
3350: 74 5c 74 22 29 2e 61 70 70 65 6e 64 28 6e 61 6d  t\t").append(nam
3360: 65 29 2e 61 70 70 65 6e 64 28 22 20 2d 20 77 69  e).append(" - wi
3370: 74 68 20 63 65 6e 74 72 6f 69 64 20 69 6e 20 22  th centroid in "
3380: 29 2e 61 70 70 65 6e 64 28 77 6b 74 29 2e 61 70  ).append(wkt).ap
3390: 70 65 6e 64 28 22 5c 6e 22 29 3b 0d 0a 20 20 20  pend("\n");..   
33a0: 20 20 20 20 20 20 20 20 20 7d 0d 0a 20 20 20 20           }..    
33b0: 20 20 20 20 20 20 20 20 73 74 6d 74 2e 63 6c 6f          stmt.clo
33c0: 73 65 28 29 3b 0d 0a 20 20 20 20 20 20 20 20 7d  se();..        }
33d0: 20 63 61 74 63 68 20 28 45 78 63 65 70 74 69 6f   catch (Exceptio
33e0: 6e 20 65 29 20 7b 0d 0a 20 20 20 20 20 20 20 20  n e) {..        
33f0: 20 20 20 20 65 2e 70 72 69 6e 74 53 74 61 63 6b      e.printStack
3400: 54 72 61 63 65 28 29 3b 0d 0a 20 20 20 20 20 20  Trace();..      
3410: 20 20 20 20 20 20 73 62 2e 61 70 70 65 6e 64 28        sb.append(
3420: 45 52 52 4f 52 29 2e 61 70 70 65 6e 64 28 65 2e  ERROR).append(e.
3430: 67 65 74 4c 6f 63 61 6c 69 7a 65 64 4d 65 73 73  getLocalizedMess
3440: 61 67 65 28 29 29 2e 61 70 70 65 6e 64 28 22 5c  age()).append("\
3450: 6e 22 29 3b 0d 0a 20 20 20 20 20 20 20 20 7d 0d  n");..        }.
3460: 0a 20 20 20 20 20 20 20 20 73 62 2e 61 70 70 65  .        sb.appe
3470: 6e 64 28 22 44 6f 6e 65 2e 2e 2e 5c 6e 22 29 3b  nd("Done...\n");
3480: 0d 0a 0d 0a 20 20 20 20 20 20 20 20 72 65 74 75  ....        retu
3490: 72 6e 20 73 62 2e 74 6f 53 74 72 69 6e 67 28 29  rn sb.toString()
34a0: 3b 0d 0a 20 20 20 20 7d 0d 0a 3c 2f 76 65 72 62  ;..    }..</verb
34b0: 61 74 69 6d 3e 0d 0a 0d 0a 54 68 65 20 61 62 6f  atim>....The abo
34c0: 76 65 20 77 69 6c 6c 20 65 78 74 72 61 63 74 20  ve will extract 
34d0: 74 68 65 20 70 6f 6c 79 67 6f 6e 20 6f 66 20 74  the polygon of t
34e0: 68 65 20 72 65 67 69 6f 6e 20 42 6f 6c 7a 61 6e  he region Bolzan
34f0: 6f 2c 20 62 75 66 66 65 72 20 69 74 20 61 6e 64  o, buffer it and
3500: 20 74 68 65 6e 20 66 69 6e 64 20 61 6c 6c 20 67   then find all g
3510: 65 6f 6d 65 74 72 69 65 73 20 74 68 61 74 20 69  eometries that i
3520: 6e 74 65 72 73 65 63 74 20 77 69 74 68 20 74 68  ntersect with th
3530: 61 74 20 62 75 66 66 65 72 2e 20 49 74 20 69 73  at buffer. It is
3540: 20 61 20 73 69 6d 70 6c 65 20 77 61 79 20 74 6f   a simple way to
3550: 20 66 69 6e 64 20 74 68 65 20 72 65 67 69 6f 6e   find the region
3560: 73 20 73 75 72 72 6f 75 6e 64 69 6e 67 20 42 6f  s surrounding Bo
3570: 6c 7a 61 6e 6f 2e 20 0d 0a 0d 0a 3c 68 34 3e 43  lzano. ....<h4>C
3580: 6c 6f 73 65 20 74 68 65 20 64 61 74 61 62 61 73  lose the databas
3590: 65 3c 2f 68 34 3e 0d 0a 0d 0a 4f 6e 63 65 20 79  e</h4>....Once y
35a0: 6f 75 20 64 6f 20 6e 6f 74 20 6e 65 65 64 20 74  ou do not need t
35b0: 68 65 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 74 6f  he connection to
35c0: 20 74 68 65 20 64 61 74 61 62 61 73 65 20 61 6e   the database an
35d0: 79 20 6c 6f 6e 67 65 72 2c 20 72 65 6d 65 6d 62  y longer, rememb
35e0: 65 72 20 74 6f 20 72 65 6c 65 61 73 65 20 74 68  er to release th
35f0: 65 20 72 65 73 6f 75 72 63 65 20 62 79 20 63 6c  e resource by cl
3600: 6f 73 69 6e 67 20 74 68 65 20 63 6f 6e 6e 65 63  osing the connec
3610: 74 69 6f 6e 3a 0d 0a 0d 0a 3c 76 65 72 62 61 74  tion:....<verbat
3620: 69 6d 3e 0d 0a 64 62 2e 63 6c 6f 73 65 28 29 3b  im>..db.close();
3630: 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 0d  ..</verbatim>...
3640: 0a 3c 68 33 3e 50 75 74 74 69 6e 67 20 69 74 20  .<h3>Putting it 
3650: 61 6c 6c 20 74 6f 67 65 74 68 65 72 3c 2f 68 33  all together</h3
3660: 3e 0d 0a 0d 0a 3c 70 3e 57 65 20 68 61 76 65 20  >....<p>We have 
3670: 63 72 65 61 74 65 64 20 61 20 73 69 6d 70 6c 65  created a simple
3680: 20 41 6e 64 72 6f 69 64 20 70 72 6f 6a 65 63 74   Android project
3690: 2c 20 77 68 69 63 68 20 69 6d 70 6c 65 6d 65 6e  , which implemen
36a0: 74 73 20 74 68 65 20 73 69 6d 70 6c 65 20 71 75  ts the simple qu
36b0: 65 72 69 65 73 20 73 65 65 6e 20 69 6e 20 74 68  eries seen in th
36c0: 65 20 61 62 6f 76 65 20 63 68 61 70 74 65 72 73  e above chapters
36d0: 2e 0d 0a 49 74 20 77 69 6c 6c 20 68 61 76 65 20  ...It will have 
36e0: 61 20 76 69 65 77 20 77 69 74 68 20 61 20 62 75  a view with a bu
36f0: 74 74 6f 6e 2c 20 77 68 69 63 68 2c 20 6f 6e 63  tton, which, onc
3700: 65 20 70 72 65 73 73 65 64 2c 20 77 69 6c 6c 20  e pressed, will 
3710: 65 78 65 63 75 74 65 20 69 6e 20 61 20 72 6f 77  execute in a row
3720: 20 61 6c 6c 20 74 68 65 20 71 75 65 72 69 65 73   all the queries
3730: 20 61 6e 64 20 73 68 6f 77 20 74 68 65 20 72 65   and show the re
3740: 73 75 6c 74 73 2e 0d 0a 0d 0a 3c 68 32 3e 50 72  sults.....<h2>Pr
3750: 6f 6a 65 63 74 73 20 69 6d 70 6c 65 6d 65 6e 74  ojects implement
3760: 69 6e 67 20 69 74 3c 2f 68 32 3e 0d 0a 0d 0a 3c  ing it</h2>....<
3770: 68 33 3e 47 65 6f 50 61 70 61 72 61 7a 7a 69 3c  h3>GeoPaparazzi<
3780: 2f 68 33 3e 0d 0a 0d 0a 3c 70 3e 54 68 65 20 3c  /h3>....<p>The <
3790: 61 20 68 72 65 66 3d 22 68 74 74 70 3a 2f 2f 77  a href="http://w
37a0: 77 77 2e 67 65 6f 70 61 70 61 72 61 7a 7a 69 2e  ww.geopaparazzi.
37b0: 65 75 22 3e 47 65 6f 50 61 70 61 72 61 7a 7a 69  eu">GeoPaparazzi
37c0: 3c 2f 61 3e 20 70 72 6f 6a 65 63 74 20 73 75 70  </a> project sup
37d0: 70 6f 72 74 73 20 74 68 65 20 53 70 61 74 69 61  ports the Spatia
37e0: 6c 69 74 65 2d 41 6e 64 72 6f 69 64 20 69 6e 20  lite-Android in 
37f0: 61 20 6d 6f 72 65 20 63 6f 6d 70 6c 65 78 20 77  a more complex w
3800: 61 79 20 74 68 61 6e 20 64 65 73 63 72 69 62 65  ay than describe
3810: 64 20 69 6e 20 74 68 69 73 20 73 68 6f 72 74 20  d in this short 
3820: 74 75 74 6f 72 69 61 6c 2e 0d 0a 0d 0a 3c 70 3e  tutorial.....<p>
3830: 47 65 6f 50 61 70 61 72 61 7a 7a 69 20 65 6e 61  GeoPaparazzi ena
3840: 62 6c 65 73 20 74 68 65 20 75 73 65 20 6f 66 20  bles the use of 
3850: 73 70 61 74 69 61 6c 69 74 65 20 64 61 74 61 62  spatialite datab
3860: 61 73 65 73 20 61 73 20 64 61 74 61 20 73 6f 75  ases as data sou
3870: 72 63 65 73 20 61 6e 64 20 76 69 73 75 61 6c 69  rces and visuali
3880: 7a 65 73 20 74 68 65 6d 20 6f 6e 20 74 68 65 20  zes them on the 
3890: 6d 61 70 20 76 69 65 77 2e 20 42 65 69 6e 67 20  map view. Being 
38a0: 74 68 65 20 6d 61 70 76 69 65 77 20 66 6f 72 63  the mapview forc
38b0: 65 64 20 6f 6e 20 61 20 4d 65 72 63 61 74 6f 72  ed on a Mercator
38c0: 20 70 72 6f 6a 65 63 74 69 6f 6e 2c 20 74 68 65   projection, the
38d0: 20 64 61 74 61 73 65 74 73 20 61 72 65 20 65 78   datasets are ex
38e0: 74 72 61 63 74 65 64 20 61 6e 64 20 72 65 70 72  tracted and repr
38f0: 6f 6a 65 63 74 65 64 20 64 69 72 65 63 74 6c 79  ojected directly
3900: 20 69 6e 20 73 70 61 74 69 61 6c 69 74 65 2e 20   in spatialite. 
3910: 49 74 20 69 73 20 61 6c 73 6f 20 70 6f 73 73 69  It is also possi
3920: 62 6c 65 20 74 6f 20 71 75 65 72 79 20 6c 61 79  ble to query lay
3930: 65 72 73 20 62 79 20 74 61 70 70 69 6e 67 20 6f  ers by tapping o
3940: 6e 20 74 68 65 20 6d 61 70 2e 20 0d 0a 0d 0a 3c  n the map. ....<
3950: 70 3e 49 66 20 79 6f 75 20 61 72 65 20 69 6e 74  p>If you are int
3960: 65 72 65 73 74 65 64 20 69 6e 20 74 68 65 20 71  erested in the q
3970: 75 65 72 69 65 73 20 75 73 65 64 2c 20 68 61 76  ueries used, hav
3980: 65 20 61 20 6c 6f 6f 6b 20 69 6e 74 6f 20 69 74  e a look into it
3990: 73 20 63 6f 64 65 20 6f 6e 20 74 68 65 20 68 6f  s code on the ho
39a0: 6d 65 70 61 67 65 2c 20 74 68 65 20 70 72 6f 6a  mepage, the proj
39b0: 65 63 74 20 69 73 20 6f 70 65 6e 20 73 6f 75 72  ect is open sour
39c0: 63 65 2e 0d 0a 0d 0a 3c 62 72 3e 3c 68 72 3e 0d  ce.....<br><hr>.
39d0: 0a 42 61 63 6b 20 74 6f 20 3c 61 20 68 72 65 66  .Back to <a href
39e0: 3d 22 68 74 74 70 73 3a 2f 2f 77 77 77 2e 67 61  ="https://www.ga
39f0: 69 61 2d 67 69 73 2e 69 74 2f 66 6f 73 73 69 6c  ia-gis.it/fossil
3a00: 2f 6c 69 62 73 70 61 74 69 61 6c 69 74 65 2f 77  /libspatialite/w
3a10: 69 6b 69 3f 6e 61 6d 65 3d 73 70 6c 69 74 65 2d  iki?name=splite-
3a20: 61 6e 64 72 6f 69 64 22 3e 53 70 61 74 69 61 4c  android">SpatiaL
3a30: 69 74 65 2d 41 6e 64 72 6f 69 64 3c 2f 61 3e 20  ite-Android</a> 
3a40: 57 69 6b 69 20 70 61 67 65 0d 0a 0a 5a 20 65 30  Wiki page...Z e0
3a50: 62 65 62 36 62 37 35 34 39 63 33 38 65 39 62 33  beb6b7549c38e9b3
3a60: 64 37 34 31 33 39 39 36 36 34 32 38 62 63 0a     d74139966428bc.