Hex Artifact Content
Not logged in

Artifact c1b93588cadb3995e2ded5bffbf31daacc83c217:

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