Hex Artifact Content
Not logged in

Artifact ac4d14b19870c304878d030920ae94afca7917fa:

Wiki page [benchmark-4.0] by sandro 2012-11-10 02:50:22.
0000: 44 20 32 30 31 32 2d 31 31 2d 31 30 54 30 32 3a  D 2012-11-10T02:
0010: 35 30 3a 32 32 2e 34 39 30 0a 4c 20 62 65 6e 63  50:22.490.L benc
0020: 68 6d 61 72 6b 2d 34 2e 30 0a 55 20 73 61 6e 64  hmark-4.0.U sand
0030: 72 6f 0a 57 20 39 34 37 30 0a 3c 68 32 3e 42 65  ro.W 9470.<h2>Be
0040: 6e 63 68 6d 61 63 6b 20 28 61 6b 61 20 22 63 6f  nchmack (aka "co
0050: 6d 70 61 72 69 6e 67 20 61 70 70 6c 65 73 20 61  mparing apples a
0060: 6e 64 20 6f 72 61 6e 67 65 73 22 29 3c 2f 68 32  nd oranges")</h2
0070: 3e 0d 0a 42 61 63 6b 20 74 6f 20 3c 61 20 68 72  >..Back to <a hr
0080: 65 66 3d 22 68 74 74 70 73 3a 2f 2f 77 77 77 2e  ef="https://www.
0090: 67 61 69 61 2d 67 69 73 2e 69 74 2f 66 6f 73 73  gaia-gis.it/foss
00a0: 69 6c 2f 6c 69 62 73 70 61 74 69 61 6c 69 74 65  il/libspatialite
00b0: 2f 77 69 6b 69 3f 6e 61 6d 65 3d 73 77 69 74 63  /wiki?name=switc
00c0: 68 69 6e 67 2d 74 6f 2d 34 2e 30 23 76 69 72 74  hing-to-4.0#virt
00d0: 75 61 6c 6f 67 72 22 3e 6d 61 69 6e 20 70 61 67  ualogr">main pag
00e0: 65 3c 2f 61 3e 0d 0a 3c 68 32 3e 49 6e 74 72 6f  e</a>..<h2>Intro
00f0: 64 75 63 74 69 6f 6e 3c 2f 68 32 3e 0d 0a 54 6f  duction</h2>..To
0100: 64 61 79 20 49 27 76 65 20 63 61 73 75 61 6c 6c  day I've casuall
0110: 79 20 72 65 61 64 20 74 68 69 73 20 3c 61 20 68  y read this <a h
0120: 72 65 66 3d 22 68 74 74 70 3a 2f 2f 67 66 6f 73  ref="http://gfos
0130: 73 2e 62 6c 6f 67 73 70 6f 74 2e 69 74 2f 32 30  s.blogspot.it/20
0140: 31 32 2f 31 31 2f 61 72 63 67 69 73 2d 76 73 2d  12/11/arcgis-vs-
0150: 71 67 69 73 2d 65 74 63 2d 63 6c 69 70 70 69 6e  qgis-etc-clippin
0160: 67 2d 63 6f 6e 74 65 73 74 2e 68 74 6d 6c 22 3e  g-contest.html">
0170: 62 6c 6f 67 20 70 61 67 65 3c 2f 61 3e 3b 20 6d  blog page</a>; m
0180: 61 6e 79 20 74 68 61 6e 6b 73 20 74 6f 20 6d 79  any thanks to my
0190: 20 64 65 61 72 20 66 72 69 65 6e 64 20 4d 61 72   dear friend Mar
01a0: 6b 75 73 20 4e 65 74 65 6c 65 72 20 28 74 68 65  kus Neteler (the
01b0: 20 6d 61 69 6e 74 61 69 6e 65 72 20 6f 66 20 47   maintainer of G
01c0: 52 41 53 53 20 47 49 53 29 20 66 6f 72 20 70 6f  RASS GIS) for po
01d0: 69 6e 74 69 6e 67 20 6d 79 20 61 74 74 65 6e 74  inting my attent
01e0: 69 6f 6e 20 6f 6e 20 74 68 69 73 20 74 6f 70 69  ion on this topi
01f0: 63 2e 3c 62 72 3e 0d 0a 54 68 65 20 6f 72 69 67  c.<br>..The orig
0200: 69 6e 61 6c 20 3c 62 3e 43 6c 69 70 70 69 6e 67  inal <b>Clipping
0210: 20 43 6f 6e 74 65 78 74 3c 2f 62 3e 20 73 69 6d   Context</b> sim
0220: 70 6c 79 20 63 6f 6d 70 61 72 65 64 20 73 65 76  ply compared sev
0230: 65 72 61 6c 20 70 6f 70 75 6c 61 72 20 44 65 73  eral popular Des
0240: 74 6b 6f 70 20 47 49 53 20 28 41 72 63 47 69 73  tkop GIS (ArcGis
0250: 2c 20 51 47 49 53 2c 20 67 76 53 49 47 2c 20 47  , QGIS, gvSIG, G
0260: 52 41 53 53 20 61 6e 64 20 6f 74 68 65 72 73 29  RASS and others)
0270: 2c 20 62 75 74 20 74 68 65 72 65 20 77 61 73 20  , but there was 
0280: 61 6e 20 6f 62 76 69 6f 75 73 20 6f 6d 69 73 73  an obvious omiss
0290: 69 6f 6e 2e 3c 62 72 3e 0d 0a 4e 6f 20 53 70 61  ion.<br>..No Spa
02a0: 74 69 61 6c 20 44 42 4d 53 20 77 61 73 20 63 6f  tial DBMS was co
02b0: 6e 73 69 64 65 72 65 64 20 61 74 20 61 6c 6c 2e  nsidered at all.
02c0: 20 28 3c 69 3e 74 6f 6f 20 62 61 64 3b 20 61 20   (<i>too bad; a 
02d0: 72 65 61 6c 6c 79 20 65 6d 62 61 72 61 73 73 69  really embarassi
02e0: 6e 67 20 6f 6d 69 73 73 69 6f 6e 3c 2f 69 3e 29  ng omission</i>)
02f0: 3c 62 72 3e 3c 62 72 3e 0d 0a 41 66 74 65 72 20  <br><br>..After 
0300: 61 6c 6c 20 61 20 3c 62 3e 43 6c 69 70 70 69 6e  all a <b>Clippin
0310: 67 20 43 6f 6e 74 65 78 74 3c 2f 62 3e 20 73 6f  g Context</b> so
0320: 75 6e 64 73 20 6d 6f 72 65 20 6c 69 6b 65 20 61  unds more like a
0330: 20 70 75 72 65 20 64 61 74 61 2d 70 72 6f 63 65   pure data-proce
0340: 73 73 69 6e 67 20 70 72 6f 62 6c 65 6d 20 74 68  ssing problem th
0350: 61 6e 20 6c 69 6b 65 20 61 20 74 79 70 69 63 61  an like a typica
0360: 6c 20 47 49 53 2f 47 55 49 20 70 72 6f 62 6c 65  l GIS/GUI proble
0370: 6d 2c 20 73 6f 20 69 74 27 73 20 70 72 6f 62 61  m, so it's proba
0380: 62 6c 79 20 75 73 65 66 75 6c 20 69 6e 74 72 6f  bly useful intro
0390: 64 75 63 69 6e 67 20 73 6f 6d 65 20 53 70 61 74  ducing some Spat
03a0: 69 61 6c 20 44 42 4d 53 20 69 6e 20 74 68 65 20  ial DBMS in the 
03b0: 42 65 6e 63 68 6d 61 72 6b 2e 0d 0a 54 68 69 73  Benchmark...This
03c0: 20 77 61 73 20 6d 79 20 66 69 72 73 74 20 74 68   was my first th
03d0: 6f 75 67 68 74 20 77 68 69 6c 65 20 72 65 61 64  ought while read
03e0: 69 6e 67 20 74 68 65 20 62 65 6e 63 68 6d 61 72  ing the benchmar
03f0: 6b 20 72 65 70 6f 72 74 2c 20 73 6f 20 49 20 64  k report, so I d
0400: 75 6c 79 20 73 74 61 72 74 65 64 20 70 72 65 70  uly started prep
0410: 61 72 69 6e 67 20 6d 79 20 6f 77 6e 20 74 65 73  aring my own tes
0420: 74 62 65 64 20 62 61 73 65 64 20 6f 6e 20 53 70  tbed based on Sp
0430: 61 74 69 61 4c 69 74 65 2e 0d 0a 3c 68 32 3e 54  atiaLite...<h2>T
0440: 65 73 74 20 63 6f 6e 66 69 67 75 72 61 74 69 6f  est configuratio
0450: 6e 3c 2f 68 32 3e 0d 0a 3c 75 6c 3e 0d 0a 3c 6c  n</h2>..<ul>..<l
0460: 69 3e 49 6e 74 65 6c 20 43 6f 72 65 20 69 35 20  i>Intel Core i5 
0470: 33 2e 34 36 20 47 48 7a 3c 2f 6c 69 3e 0d 0a 3c  3.46 GHz</li>..<
0480: 6c 69 3e 34 20 47 42 20 52 41 4d 3c 2f 6c 69 3e  li>4 GB RAM</li>
0490: 0d 0a 3c 6c 69 3e 57 69 6e 64 6f 77 73 20 37 20  ..<li>Windows 7 
04a0: 36 34 20 62 69 74 20 28 70 68 79 73 69 63 61 6c  64 bit (physical
04b0: 29 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 44 65 62 69  )</li>..<li>Debi
04c0: 61 6e 20 53 71 75 65 65 7a 65 20 33 32 20 62 69  an Squeeze 32 bi
04d0: 74 20 28 76 69 72 74 75 61 6c 20 6d 61 63 68 69  t (virtual machi
04e0: 6e 65 29 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 3c  ne)</li>..</ul><
04f0: 62 72 3e 0d 0a 49 20 74 65 73 74 65 64 20 62 6f  br>..I tested bo
0500: 74 68 20 57 69 6e 64 6f 77 73 20 61 6e 64 20 44  th Windows and D
0510: 65 62 69 61 6e 20 6f 6e 20 74 68 65 20 73 61 6d  ebian on the sam
0520: 65 20 68 61 72 64 77 61 72 65 2e 3c 62 72 3e 0d  e hardware.<br>.
0530: 0a 54 68 65 20 6d 65 61 73 75 72 65 64 20 74 69  .The measured ti
0540: 6d 69 6e 67 73 20 61 72 65 20 72 61 74 68 65 72  mings are rather
0550: 20 73 69 6d 69 6c 61 72 3b 20 61 6e 79 77 61 79   similar; anyway
0560: 20 4c 69 6e 75 78 20 70 65 72 66 6f 72 6d 65 64   Linux performed
0570: 20 73 74 6c 69 67 68 74 6c 79 20 62 65 74 74 65   stlightly bette
0580: 72 20 74 68 61 6e 20 74 68 65 20 6e 61 74 69 76  r than the nativ
0590: 65 20 57 69 6e 64 6f 77 73 20 73 79 73 74 65 6d  e Windows system
05a0: 20 28 6d 6f 72 65 20 6f 72 20 6c 65 73 73 2c 20   (more or less, 
05b0: 62 79 20 61 20 31 30 25 20 2d 20 31 35 25 20 66  by a 10% - 15% f
05c0: 61 63 74 6f 72 29 2e 3c 62 72 3e 0d 0a 54 68 69  actor).<br>..Thi
05d0: 73 20 69 73 20 6e 6f 74 20 61 74 20 61 6c 6c 20  s is not at all 
05e0: 73 75 72 70 72 69 73 69 6e 67 20 66 6f 72 20 6d  surprising for m
05f0: 65 2c 20 62 65 63 61 75 73 65 20 74 68 69 73 20  e, because this 
0600: 74 72 65 6e 64 20 73 65 65 6d 73 20 74 6f 20 62  trend seems to b
0610: 65 20 63 6f 6e 73 74 61 6e 74 6c 79 20 76 65 72  e constantly ver
0620: 69 66 69 65 64 20 65 61 63 68 20 74 69 6d 65 20  ified each time 
0630: 49 20 6d 61 6e 61 67 65 20 73 6f 6d 65 20 63 6f  I manage some co
0640: 6d 70 61 72 61 74 69 76 65 20 62 65 6e 63 68 6d  mparative benchm
0650: 61 72 6b 2e 3c 62 72 3e 0d 0a 56 65 72 79 20 6f  ark.<br>..Very o
0660: 66 74 65 6e 20 4c 69 6e 75 78 20 69 73 20 61 20  ften Linux is a 
0670: 62 65 73 74 20 70 65 72 66 6f 72 6d 65 72 20 74  best performer t
0680: 68 61 6e 20 57 69 6e 64 6f 77 73 2c 20 65 76 65  han Windows, eve
0690: 6e 20 77 68 65 6e 20 72 75 6e 6e 69 6e 67 20 61  n when running a
06a0: 73 20 61 20 56 69 72 74 75 61 6c 20 4d 61 63 68  s a Virtual Mach
06b0: 69 6e 65 20 6f 6e 20 74 68 65 20 74 6f 70 20 6f  ine on the top o
06c0: 66 20 61 20 70 68 79 73 69 63 61 6c 20 57 69 6e  f a physical Win
06d0: 64 6f 77 73 20 73 79 73 74 65 6d 2e 3c 62 72 3e  dows system.<br>
06e0: 0d 0a 51 75 69 74 65 20 70 61 72 61 64 6f 78 69  ..Quite paradoxi
06f0: 63 61 6c 2c 20 62 75 74 20 69 6e 64 69 73 70 75  cal, but indispu
0700: 74 61 62 6c 79 20 74 72 75 65 20 61 6e 64 20 6f  tably true and o
0710: 62 6a 65 63 74 69 76 65 6c 79 20 76 65 72 69 66  bjectively verif
0720: 69 65 64 2e 0d 0a 3c 68 32 3e 54 68 65 20 73 61  ied...<h2>The sa
0730: 6d 70 6c 65 20 64 61 74 61 73 65 74 3c 2f 68 32  mple dataset</h2
0740: 3e 0d 0a 49 27 76 65 20 73 69 6d 70 6c 79 20 64  >..I've simply d
0750: 6f 77 6e 6c 6f 61 64 65 64 20 74 68 65 20 73 61  ownloaded the sa
0760: 6d 65 20 69 64 65 6e 74 69 63 61 6c 20 3c 61 20  me identical <a 
0770: 68 72 65 66 3d 22 68 74 74 70 3a 2f 2f 77 77 77  href="http://www
0780: 2e 64 6f 6e 6d 65 6c 74 7a 2e 63 6f 6d 2f 5f 66  .donmeltz.com/_f
0790: 69 6c 65 73 2f 43 6f 6e 74 6f 75 72 43 6c 69 70  iles/ContourClip
07a0: 54 65 73 74 2e 7a 69 70 22 3e 73 61 6d 70 6c 65  Test.zip">sample
07b0: 20 64 61 74 61 73 65 74 3c 2f 61 3e 20 61 6c 72   dataset</a> alr
07c0: 65 61 64 79 20 75 73 65 64 20 66 6f 72 20 61 6c  eady used for al
07d0: 6c 20 6f 74 68 65 72 20 74 65 73 74 73 20 72 65  l other tests re
07e0: 70 6f 72 74 65 64 20 69 6e 20 74 68 65 20 43 6c  ported in the Cl
07f0: 69 70 70 69 6e 67 20 43 6f 6e 74 65 78 74 2e 3c  ipping Context.<
0800: 62 72 3e 0d 0a 56 65 72 79 20 73 68 6f 72 74 6c  br>..Very shortl
0810: 79 20 73 61 69 64 3a 20 69 74 27 73 20 61 20 72  y said: it's a r
0820: 65 61 6c 6c 79 20 68 75 67 65 20 73 65 74 20 6f  eally huge set o
0830: 66 20 3c 62 3e 43 6f 6e 74 6f 75 72 20 4c 69 6e  f <b>Contour Lin
0840: 65 73 3c 2f 62 3e 20 28 74 68 65 20 75 6e 63 6f  es</b> (the unco
0850: 6d 70 72 65 73 73 65 64 20 53 68 61 70 65 66 69  mpressed Shapefi
0860: 6c 65 20 69 73 20 61 62 6f 75 74 20 3c 62 3e 31  le is about <b>1
0870: 2c 33 20 47 42 3c 2f 62 3e 29 3c 62 72 3e 3c 62  ,3 GB</b>)<br><b
0880: 72 3e 0d 0a 3c 74 61 62 6c 65 20 63 65 6c 6c 73  r>..<table cells
0890: 70 61 63 69 6e 67 3d 22 36 22 20 63 65 6c 6c 70  pacing="6" cellp
08a0: 61 64 64 69 6e 67 3d 22 36 22 3e 0d 0a 3c 74 72  adding="6">..<tr
08b0: 3e 3c 74 64 3e 3c 68 33 3e 46 69 67 2e 20 31 3c  ><td><h3>Fig. 1<
08c0: 2f 68 33 3e 0d 0a 54 68 69 73 20 6f 6e 65 20 69  /h3>..This one i
08d0: 73 20 74 68 65 20 6f 72 67 69 6e 61 6c 20 73 65  s the orginal se
08e0: 74 20 6f 66 20 43 6f 6e 74 6f 75 72 20 4c 69 6e  t of Contour Lin
08f0: 65 73 20 74 6f 20 62 65 20 63 6c 69 70 70 65 64  es to be clipped
0900: 2e 3c 2f 74 64 3e 0d 0a 3c 74 64 3e 3c 69 6d 67  .</td>..<td><img
0910: 20 62 6f 72 64 65 72 3d 22 31 22 20 73 72 63 3d   border="1" src=
0920: 22 68 74 74 70 3a 2f 2f 77 77 77 2e 67 61 69 61  "http://www.gaia
0930: 2d 67 69 73 2e 69 74 2f 67 61 69 61 2d 73 69 6e  -gis.it/gaia-sin
0940: 73 2f 76 69 72 74 75 61 6c 6f 67 72 2f 63 6c 69  s/virtualogr/cli
0950: 70 2d 30 2e 70 6e 67 22 20 61 6c 74 3d 22 6f 72  p-0.png" alt="or
0960: 69 67 69 6e 61 6c 20 64 61 74 61 73 65 74 22 3e  iginal dataset">
0970: 3c 2f 74 64 3e 3c 2f 74 72 3e 0d 0a 3c 74 72 3e  </td></tr>..<tr>
0980: 3c 74 64 3e 3c 68 33 3e 46 69 67 2e 20 32 3c 2f  <td><h3>Fig. 2</
0990: 68 33 3e 0d 0a 54 68 69 73 20 69 73 20 74 68 65  h3>..This is the
09a0: 20 66 69 6e 61 6c 20 72 65 73 75 6c 74 20 6f 66   final result of
09b0: 20 74 68 65 20 63 6c 69 70 70 69 6e 67 20 6f 70   the clipping op
09c0: 65 72 61 74 69 6f 6e 2e 3c 75 6c 3e 0d 0a 3c 6c  eration.<ul>..<l
09d0: 69 3e 74 68 65 20 53 74 75 64 79 20 41 72 65 61  i>the Study Area
09e0: 20 62 6f 75 6e 64 61 72 79 20 28 70 6f 6c 79 67   boundary (polyg
09f0: 6f 6e 29 20 69 73 20 72 65 70 72 65 73 65 6e 74  on) is represent
0a00: 65 64 20 69 6e 20 72 65 64 2e 3c 2f 6c 69 3e 0d  ed in red.</li>.
0a10: 0a 3c 6c 69 3e 74 68 65 20 43 6f 6e 74 6f 75 72  .<li>the Contour
0a20: 20 4c 69 6e 65 73 20 61 72 65 20 72 65 70 72 65   Lines are repre
0a30: 73 65 6e 74 65 64 20 69 6e 20 64 61 72 6b 20 62  sented in dark b
0a40: 6c 75 65 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 74  lue.</li>..<li>t
0a50: 68 65 20 61 7a 75 72 65 20 72 65 63 74 61 6e 67  he azure rectang
0a60: 6c 65 20 73 69 6d 70 6c 79 20 6d 61 72 6b 73 20  le simply marks 
0a70: 74 68 65 20 64 65 74 61 69 6c 20 61 72 65 61 20  the detail area 
0a80: 73 68 6f 77 6e 20 69 6e 20 74 68 65 20 6e 65 78  shown in the nex
0a90: 74 20 66 69 67 75 72 65 2e 3c 2f 6c 69 3e 20 0d  t figure.</li> .
0aa0: 0a 3c 2f 75 6c 3e 3c 2f 74 64 3e 0d 0a 3c 74 64  .</ul></td>..<td
0ab0: 3e 3c 69 6d 67 20 62 6f 72 64 65 72 3d 22 31 22  ><img border="1"
0ac0: 20 73 72 63 3d 22 68 74 74 70 3a 2f 2f 77 77 77   src="http://www
0ad0: 2e 67 61 69 61 2d 67 69 73 2e 69 74 2f 67 61 69  .gaia-gis.it/gai
0ae0: 61 2d 73 69 6e 73 2f 76 69 72 74 75 61 6c 6f 67  a-sins/virtualog
0af0: 72 2f 63 6c 69 70 2d 31 2e 70 6e 67 22 20 61 6c  r/clip-1.png" al
0b00: 74 3d 22 63 6c 69 70 70 65 64 22 3e 3c 2f 74 64  t="clipped"></td
0b10: 3e 3c 2f 74 72 3e 0d 0a 3c 74 72 3e 3c 74 64 3e  ></tr>..<tr><td>
0b20: 3c 68 33 3e 46 69 67 2e 20 33 3c 2f 68 33 3e 54  <h3>Fig. 3</h3>T
0b30: 68 69 73 20 69 73 20 61 20 6d 61 67 6e 69 66 69  his is a magnifi
0b40: 65 64 20 64 65 74 61 69 6c 20 6f 66 20 74 68 65  ed detail of the
0b50: 20 53 74 75 64 79 20 41 72 65 61 2e 3c 62 72 3e   Study Area.<br>
0b60: 0d 0a 41 73 20 79 6f 75 20 63 61 6e 20 65 61 73  ..As you can eas
0b70: 69 6c 79 20 6e 6f 74 69 63 65 20 74 68 65 72 65  ily notice there
0b80: 20 61 72 65 20 6c 6f 74 73 20 6f 66 20 43 6f 6e   are lots of Con
0b90: 74 72 6f 75 72 20 4c 69 6e 65 73 3b 20 61 6e 64  trour Lines; and
0ba0: 20 65 61 63 68 20 4c 69 6e 65 20 68 61 73 20 6d   each Line has m
0bb0: 61 6e 79 20 76 65 72 74 69 63 65 73 2e 3c 62 72  any vertices.<br
0bc0: 3e 3c 62 72 3e 0d 0a 54 68 69 73 20 6f 6e 65 20  ><br>..This one 
0bd0: 73 75 72 65 6c 79 20 69 73 20 61 20 72 61 74 68  surely is a rath
0be0: 65 72 20 63 6f 6d 70 6c 65 78 20 70 72 6f 62 6c  er complex probl
0bf0: 65 6d 20 74 6f 20 62 65 20 72 65 73 6f 6c 76 65  em to be resolve
0c00: 64 2c 20 61 6e 64 20 69 74 20 72 65 70 72 65 73  d, and it repres
0c10: 65 6e 74 73 20 61 20 74 68 6f 72 6f 75 67 68 20  ents a thorough 
0c20: 61 6e 64 20 64 65 6d 61 6e 64 69 6e 67 20 74 65  and demanding te
0c30: 73 74 2e 3c 2f 74 64 3e 0d 0a 3c 74 64 3e 3c 69  st.</td>..<td><i
0c40: 6d 67 20 62 6f 72 64 65 72 3d 22 31 22 20 73 72  mg border="1" sr
0c50: 63 3d 22 68 74 74 70 3a 2f 2f 77 77 77 2e 67 61  c="http://www.ga
0c60: 69 61 2d 67 69 73 2e 69 74 2f 67 61 69 61 2d 73  ia-gis.it/gaia-s
0c70: 69 6e 73 2f 76 69 72 74 75 61 6c 6f 67 72 2f 63  ins/virtualogr/c
0c80: 6c 69 70 2d 32 2e 70 6e 67 22 20 61 6c 74 3d 22  lip-2.png" alt="
0c90: 6c 6f 61 64 5f 65 78 74 65 6e 73 69 6f 6e 22 3e  load_extension">
0ca0: 3c 2f 74 64 3e 3c 2f 74 72 3e 0d 0a 3c 2f 74 61  </td></tr>..</ta
0cb0: 62 6c 65 3e 0d 0a 3c 68 32 3e 54 68 65 20 53 70  ble>..<h2>The Sp
0cc0: 61 74 69 61 6c 20 53 51 4c 20 61 70 70 72 6f 61  atial SQL approa
0cd0: 63 68 3c 2f 68 32 3e 0d 0a 54 68 69 73 20 69 73  ch</h2>..This is
0ce0: 20 61 20 70 75 72 65 20 64 61 74 61 2d 70 72 6f   a pure data-pro
0cf0: 63 65 73 73 69 6e 67 20 61 70 70 72 6f 61 63 68  cessing approach
0d00: 3b 20 77 65 27 6c 6c 20 75 73 65 20 74 68 65 20  ; we'll use the 
0d10: 6d 6f 73 74 20 63 6c 61 73 73 69 63 61 6c 20 3c  most classical <
0d20: 62 3e 3c 69 3e 53 70 61 74 69 61 6c 20 49 73 20  b><i>Spatial Is 
0d30: 4e 6f 74 20 53 70 65 63 69 61 6c 3c 2f 69 3e 3c  Not Special</i><
0d40: 2f 62 3e 20 6d 65 74 68 6f 64 6f 6c 6f 67 79 2c  /b> methodology,
0d50: 20 69 2e 65 2e 20 77 65 27 6c 6c 20 67 6f 20 70   i.e. we'll go p
0d60: 65 72 66 6f 72 6d 69 6e 67 20 74 68 65 20 3c 62  erforming the <b
0d70: 3e 43 6c 69 70 70 69 6e 67 20 43 6f 6e 74 65 78  >Clipping Contex
0d80: 74 3c 2f 62 3e 20 65 78 61 63 74 6c 79 20 61 73  t</b> exactly as
0d90: 20 69 66 20 69 74 20 77 61 73 20 61 20 74 72 69   if it was a tri
0da0: 76 69 61 6c 20 6f 72 64 69 6e 61 72 79 20 53 51  vial ordinary SQ
0db0: 4c 20 71 75 65 72 79 20 70 65 72 66 6f 72 6d 65  L query performe
0dc0: 64 20 6f 6e 20 62 65 68 61 6c 66 20 6f 66 20 70  d on behalf of p
0dd0: 6c 61 69 6e 20 67 65 6e 65 72 69 63 20 64 61 74  lain generic dat
0de0: 61 2e 3c 62 72 3e 0d 0a 57 65 27 6c 6c 20 6e 6f  a.<br>..We'll no
0df0: 74 20 75 73 65 20 61 74 20 61 6c 6c 20 61 6e 79  t use at all any
0e00: 20 47 49 53 2d 73 70 65 63 69 66 69 63 20 66 72   GIS-specific fr
0e10: 69 6c 6c 2c 20 61 6e 64 20 77 65 27 6c 6c 20 73  ill, and we'll s
0e20: 69 6d 70 6c 79 20 75 73 65 20 61 20 63 6f 75 70  imply use a coup
0e30: 6c 65 20 6f 66 20 53 70 61 74 69 61 6c 20 53 51  le of Spatial SQ
0e40: 4c 20 66 75 6e 63 74 69 6f 6e 73 20 77 68 65 72  L functions wher
0e50: 65 20 73 74 72 69 63 74 6c 79 20 72 65 71 75 69  e strictly requi
0e60: 72 65 64 2e 3c 62 72 3e 0d 0a 4c 65 74 27 73 20  red.<br>..Let's 
0e70: 67 6f 20 2e 2e 2e 0d 0a 3c 68 34 3e 50 72 65 70  go .....<h4>Prep
0e80: 61 72 69 6e 67 20 74 68 65 20 53 51 4c 20 73 63  aring the SQL sc
0e90: 72 69 70 74 3c 2f 68 34 3e 0d 0a 3c 76 65 72 62  ript</h4>..<verb
0ea0: 61 74 69 6d 3e 0d 0a 2d 2d 0d 0a 2d 2d 20 53 51  atim>..--..-- SQ
0eb0: 4c 20 73 63 72 69 70 74 20 70 65 72 66 6f 72 6d  L script perform
0ec0: 69 6e 67 20 74 68 65 20 43 6c 69 70 70 69 6e 67  ing the Clipping
0ed0: 20 43 6f 6e 74 65 78 74 0d 0a 2d 2d 20 54 61 72   Context..-- Tar
0ee0: 67 65 74 20 44 42 4d 53 3a 20 53 51 4c 69 74 65  get DBMS: SQLite
0ef0: 20 77 69 74 68 20 53 70 61 74 69 61 4c 69 74 65   with SpatiaLite
0f00: 20 65 78 74 65 6e 73 69 6f 6e 0d 0a 2d 2d 0d 0a   extension..--..
0f10: 0d 0a 53 45 4c 45 43 54 20 44 61 74 65 54 69 6d  ..SELECT DateTim
0f20: 65 28 27 6e 6f 77 27 29 2c 20 27 4c 6f 61 64 69  e('now'), 'Loadi
0f30: 6e 67 20 74 68 65 20 53 74 75 64 79 41 72 65 61  ng the StudyArea
0f40: 20 53 48 50 27 3b 0d 0a 2d 2d 0d 0a 2d 2d 20 6c   SHP';..--..-- l
0f50: 6f 61 64 69 6e 67 20 74 68 65 20 53 74 75 64 79  oading the Study
0f60: 41 72 65 61 20 53 68 61 70 65 66 69 6c 65 20 69  Area Shapefile i
0f70: 6e 74 6f 20 74 68 65 20 44 42 0d 0a 2d 2d 0d 0a  nto the DB..--..
0f80: 2e 6c 6f 61 64 73 68 70 20 53 74 75 64 79 41 72  .loadshp StudyAr
0f90: 65 61 31 4d 69 6c 65 42 75 66 66 65 72 20 53 74  ea1MileBuffer St
0fa0: 75 64 79 41 72 65 61 31 4d 69 6c 65 42 75 66 66  udyArea1MileBuff
0fb0: 65 72 20 43 50 31 32 35 32 20 32 32 36 30 20 47  er CP1252 2260 G
0fc0: 65 6f 6d 65 74 72 79 20 49 64 20 50 4f 4c 59 47  eometry Id POLYG
0fd0: 4f 4e 20 32 64 20 6e 6f 20 6e 6f 5f 73 70 61 74  ON 2d no no_spat
0fe0: 69 61 6c 5f 69 6e 64 65 78 0d 0a 0d 0a 53 45 4c  ial_index....SEL
0ff0: 45 43 54 20 44 61 74 65 54 69 6d 65 28 27 6e 6f  ECT DateTime('no
1000: 77 27 29 2c 20 27 4c 6f 61 64 69 6e 67 20 74 68  w'), 'Loading th
1010: 65 20 43 6f 6e 74 6f 75 72 73 20 53 48 50 27 3b  e Contours SHP';
1020: 0d 0a 2d 2d 0d 0a 2d 2d 20 6c 6f 61 64 69 6e 67  ..--..-- loading
1030: 20 74 68 65 20 43 6f 6e 74 6f 75 72 20 53 68 61   the Contour Sha
1040: 70 65 66 69 6c 65 20 69 6e 74 6f 20 74 68 65 20  pefile into the 
1050: 44 42 0d 0a 2d 2d 0d 0a 2e 6c 6f 61 64 73 68 70  DB..--...loadshp
1060: 20 43 6f 6e 74 6f 75 72 73 32 30 46 74 20 43 6f   Contours20Ft Co
1070: 6e 74 6f 75 72 73 32 30 46 74 20 43 50 31 32 35  ntours20Ft CP125
1080: 32 20 32 32 36 30 20 47 65 6f 6d 65 74 72 79 20  2 2260 Geometry 
1090: 49 64 20 4c 49 4e 45 53 54 52 49 4e 47 20 32 64  Id LINESTRING 2d
10a0: 20 6e 6f 20 77 69 74 68 5f 73 70 61 74 69 61 6c   no with_spatial
10b0: 5f 69 6e 64 65 78 0d 0a 0d 0a 53 45 4c 45 43 54  _index....SELECT
10c0: 20 44 61 74 65 54 69 6d 65 28 27 6e 6f 77 27 29   DateTime('now')
10d0: 2c 20 27 43 6c 69 70 70 69 6e 67 20 2e 2e 2e 20  , 'Clipping ... 
10e0: 70 6c 65 61 73 65 20 77 61 69 74 27 3b 0d 0a 2d  please wait';..-
10f0: 2d 0d 0a 2d 2d 20 63 72 65 61 74 69 6e 67 20 61  -..-- creating a
1100: 20 6e 65 77 20 74 61 62 6c 65 20 63 6f 6e 74 61   new table conta
1110: 69 6e 69 6e 67 20 74 68 65 20 43 6c 69 70 70 65  ining the Clippe
1120: 64 20 43 6f 6e 74 6f 75 72 73 0d 0a 2d 2d 0d 0a  d Contours..--..
1130: 43 52 45 41 54 45 20 54 41 42 4c 45 20 43 6f 6e  CREATE TABLE Con
1140: 74 6f 75 72 73 32 30 46 74 43 6c 69 70 70 65 64  tours20FtClipped
1150: 20 41 53 0d 0a 53 45 4c 45 43 54 20 63 2e 49 64   AS..SELECT c.Id
1160: 20 41 53 20 49 64 2c 20 63 2e 4f 42 4a 45 43 54   AS Id, c.OBJECT
1170: 49 44 20 41 53 20 4f 42 4a 45 43 54 49 44 2c 20  ID AS OBJECTID, 
1180: 0d 0a 20 20 63 2e 43 6f 6e 74 6f 75 72 20 41 53  ..  c.Contour AS
1190: 20 43 6f 6e 74 6f 75 72 2c 20 63 2e 53 68 61 70   Contour, c.Shap
11a0: 65 5f 4c 65 6e 67 20 41 53 20 53 68 61 70 65 5f  e_Leng AS Shape_
11b0: 4c 65 6e 67 2c 0d 0a 20 20 43 61 73 74 54 6f 4d  Leng,..  CastToM
11c0: 75 6c 74 69 4c 69 6e 65 73 74 72 69 6e 67 28 53  ultiLinestring(S
11d0: 54 5f 49 6e 74 65 72 73 65 63 74 69 6f 6e 28 0d  T_Intersection(.
11e0: 0a 20 20 20 20 20 20 63 2e 47 65 6f 6d 65 74 72  .      c.Geometr
11f0: 79 2c 20 61 2e 47 65 6f 6d 65 74 72 79 29 29 20  y, a.Geometry)) 
1200: 41 53 20 47 65 6f 6d 65 74 72 79 0d 0a 46 52 4f  AS Geometry..FRO
1210: 4d 20 43 6f 6e 74 6f 75 72 73 32 30 46 74 20 41  M Contours20Ft A
1220: 53 20 63 2c 20 53 74 75 64 79 41 72 65 61 31 4d  S c, StudyArea1M
1230: 69 6c 65 42 75 66 66 65 72 20 41 53 20 61 0d 0a  ileBuffer AS a..
1240: 57 48 45 52 45 20 63 2e 52 4f 57 49 44 20 49 4e  WHERE c.ROWID IN
1250: 20 28 0d 0a 20 20 20 20 53 45 4c 45 43 54 20 52   (..    SELECT R
1260: 4f 57 49 44 20 0d 0a 20 20 20 20 46 52 4f 4d 20  OWID ..    FROM 
1270: 53 70 61 74 69 61 6c 49 6e 64 65 78 0d 0a 20 20  SpatialIndex..  
1280: 20 20 57 48 45 52 45 20 66 5f 74 61 62 6c 65 5f    WHERE f_table_
1290: 6e 61 6d 65 20 3d 20 27 43 6f 6e 74 6f 75 72 73  name = 'Contours
12a0: 32 30 46 74 27 20 0d 0a 20 20 20 20 20 20 20 20  20Ft' ..        
12b0: 41 4e 44 20 73 65 61 72 63 68 5f 66 72 61 6d 65  AND search_frame
12c0: 20 3d 20 61 2e 47 65 6f 6d 65 74 72 79 0d 0a 29   = a.Geometry..)
12d0: 3b 0d 0a 0d 0a 53 45 4c 45 43 54 20 44 61 74 65  ;....SELECT Date
12e0: 54 69 6d 65 28 27 6e 6f 77 27 29 2c 20 27 64 65  Time('now'), 'de
12f0: 6c 65 74 69 6e 67 20 4e 55 4c 4c 20 47 65 6f 6d  leting NULL Geom
1300: 65 74 72 69 65 73 27 3b 0d 0a 2d 2d 0d 0a 2d 2d  etries';..--..--
1310: 20 63 6c 65 61 6e 20 75 70 0d 0a 2d 2d 20 64 65   clean up..-- de
1320: 6c 65 74 69 6e 67 20 61 6e 79 20 4e 55 4c 4c 20  leting any NULL 
1330: 47 65 6f 6d 65 74 72 79 20 66 72 6f 6d 20 43 6c  Geometry from Cl
1340: 69 70 70 65 64 20 43 6f 6e 74 6f 75 72 73 0d 0a  ipped Contours..
1350: 2d 2d 0d 0a 44 45 4c 45 54 45 20 46 52 4f 4d 20  --..DELETE FROM 
1360: 43 6f 6e 74 6f 75 72 73 32 30 46 74 43 6c 69 70  Contours20FtClip
1370: 70 65 64 20 0d 0a 57 48 45 52 45 20 47 65 6f 6d  ped ..WHERE Geom
1380: 65 74 72 79 20 49 53 20 4e 55 4c 4c 3b 0d 0a 0d  etry IS NULL;...
1390: 0a 53 45 4c 45 43 54 20 44 61 74 65 54 69 6d 65  .SELECT DateTime
13a0: 28 27 6e 6f 77 27 29 2c 20 27 72 65 63 6f 76 65  ('now'), 'recove
13b0: 72 69 6e 67 20 61 20 67 65 6e 75 69 6e 65 20 47  ring a genuine G
13c0: 65 6f 6d 65 74 72 79 20 63 6f 6c 75 6d 6e 27 3b  eometry column';
13d0: 0d 0a 2d 2d 0d 0a 2d 2d 20 72 65 63 6f 76 65 72  ..--..-- recover
13e0: 69 6e 67 20 61 20 67 65 6e 75 69 6e 65 20 47 65  ing a genuine Ge
13f0: 6f 6d 65 74 72 79 20 43 6f 6c 75 6d 6e 20 28 43  ometry Column (C
1400: 6c 69 70 70 65 64 20 43 6f 6e 74 6f 75 72 73 29  lipped Contours)
1410: 0d 0a 2d 2d 2d 0d 0a 53 45 4c 45 43 54 20 52 65  ..---..SELECT Re
1420: 63 6f 76 65 72 47 65 6f 6d 65 74 72 79 43 6f 6c  coverGeometryCol
1430: 75 6d 6e 28 27 43 6f 6e 74 6f 75 72 73 32 30 46  umn('Contours20F
1440: 74 43 6c 69 70 70 65 64 27 2c 20 27 47 65 6f 6d  tClipped', 'Geom
1450: 65 74 72 79 27 2c 20 32 32 36 30 2c 20 27 4d 55  etry', 2260, 'MU
1460: 4c 54 49 4c 49 4e 45 53 54 52 49 4e 47 27 2c 20  LTILINESTRING', 
1470: 32 29 3b 0d 0a 0d 0a 53 45 4c 45 43 54 20 44 61  2);....SELECT Da
1480: 74 65 54 69 6d 65 28 27 6e 6f 77 27 29 2c 20 27  teTime('now'), '
1490: 63 72 65 61 74 69 6e 67 20 74 68 65 20 53 70 61  creating the Spa
14a0: 74 69 61 6c 20 49 6e 64 65 78 27 3b 0d 0a 2d 2d  tial Index';..--
14b0: 0d 0a 2d 2d 20 63 72 65 61 74 69 6e 67 20 61 20  ..-- creating a 
14c0: 53 70 61 74 69 61 6c 20 28 49 6e 64 65 78 20 73  Spatial (Index s
14d0: 75 70 70 6f 72 74 69 6e 67 20 43 6c 69 70 70 65  upporting Clippe
14e0: 64 20 43 6f 6e 74 6f 75 72 73 29 0d 0a 2d 2d 0d  d Contours)..--.
14f0: 0a 53 45 4c 45 43 54 20 43 72 65 61 74 65 53 70  .SELECT CreateSp
1500: 61 74 69 61 6c 49 6e 64 65 78 28 27 43 6f 6e 74  atialIndex('Cont
1510: 6f 75 72 73 32 30 46 74 43 6c 69 70 70 65 64 27  ours20FtClipped'
1520: 2c 20 27 47 65 6f 6d 65 74 72 79 27 29 3b 0d 0a  , 'Geometry');..
1530: 0d 0a 0d 0a 53 45 4c 45 43 54 20 44 61 74 65 54  ....SELECT DateT
1540: 69 6d 65 28 27 6e 6f 77 27 29 2c 20 27 61 6c 6c  ime('now'), 'all
1550: 20 64 6f 6e 65 20 2e 2e 2e 20 71 75 69 74 74 69   done ... quitti
1560: 6e 67 27 3b 0d 0a 2d 2d 0d 0a 2d 2d 20 65 6e 64  ng';..--..-- end
1570: 20 6a 6f 62 0d 0a 2d 2d 0d 0a 3c 2f 76 65 72 62   job..--..</verb
1580: 61 74 69 6d 3e 0d 0a 44 6f 6e 27 74 20 62 65 20  atim>..Don't be 
1590: 66 6f 75 6c 65 64 3b 20 63 6f 6d 70 6c 65 78 69  fouled; complexi
15a0: 74 79 20 69 73 20 6d 6f 72 65 20 61 70 70 61 72  ty is more appar
15b0: 65 6e 74 20 74 68 61 6e 20 72 65 61 6c 2e 0d 0a  ent than real...
15c0: 3c 74 61 62 6c 65 20 63 65 6c 6c 73 70 61 63 69  <table cellspaci
15d0: 6e 67 3d 22 36 22 20 63 65 6c 6c 70 61 64 64 69  ng="6" cellpaddi
15e0: 6e 67 3d 22 36 22 3e 0d 0a 3c 74 72 3e 3c 74 64  ng="6">..<tr><td
15f0: 20 62 67 63 6f 6c 6f 72 3d 22 23 66 34 66 34 66   bgcolor="#f4f4f
1600: 34 22 3e 3c 62 3e 2e 6c 6f 61 64 73 68 70 3c 2f  4"><b>.loadshp</
1610: 62 3e 20 3c 69 3e 70 61 72 61 6d 65 74 65 72 73  b> <i>parameters
1620: 3c 2f 69 3e 3c 2f 74 64 3e 0d 0a 3c 74 64 3e 3c  </i></td>..<td><
1630: 68 33 3e 53 74 65 70 20 23 31 3c 2f 68 33 3e 0d  h3>Step #1</h3>.
1640: 0a 73 69 6d 70 6c 79 20 61 20 3c 62 3e 64 6f 74  .simply a <b>dot
1650: 20 6d 61 63 72 6f 20 63 6f 6d 6d 61 6e 64 3c 2f   macro command</
1660: 62 3e 20 75 6e 64 65 72 73 74 6f 6f 64 20 62 79  b> understood by
1670: 20 74 68 65 20 53 70 61 74 69 61 4c 69 74 65 20   the SpatiaLite 
1680: 66 72 6f 6e 74 65 6e 64 20 74 6f 6f 6c 2c 20 61  frontend tool, a
1690: 6c 6c 6f 77 69 6e 67 20 74 6f 20 64 69 72 65 63  llowing to direc
16a0: 74 6c 79 20 69 6d 70 6f 72 74 20 61 6e 20 65 78  tly import an ex
16b0: 74 65 72 6e 61 6c 20 53 68 61 70 65 66 69 6c 65  ternal Shapefile
16c0: 20 69 6e 74 6f 20 61 20 63 6f 72 72 65 73 70 6f   into a correspo
16d0: 6e 64 69 6e 67 20 53 70 61 74 69 61 6c 20 54 61  nding Spatial Ta
16e0: 62 6c 65 20 77 69 74 68 69 6e 20 74 68 65 20 44  ble within the D
16f0: 42 2e 3c 2f 74 64 3e 3c 2f 74 72 3e 0d 0a 3c 74  B.</td></tr>..<t
1700: 72 3e 3c 74 64 3e 3c 76 65 72 62 61 74 69 6d 3e  r><td><verbatim>
1710: 0d 0a 43 52 45 41 54 45 20 54 41 42 4c 45 20 43  ..CREATE TABLE C
1720: 6f 6e 74 6f 75 72 73 32 30 46 74 43 6c 69 70 70  ontours20FtClipp
1730: 65 64 20 41 53 0d 0a 53 45 4c 45 43 54 20 63 2e  ed AS..SELECT c.
1740: 49 64 20 41 53 20 49 64 2c 20 63 2e 4f 42 4a 45  Id AS Id, c.OBJE
1750: 43 54 49 44 20 41 53 20 4f 42 4a 45 43 54 49 44  CTID AS OBJECTID
1760: 2c 20 0d 0a 20 20 63 2e 43 6f 6e 74 6f 75 72 20  , ..  c.Contour 
1770: 41 53 20 43 6f 6e 74 6f 75 72 2c 20 63 2e 53 68  AS Contour, c.Sh
1780: 61 70 65 5f 4c 65 6e 67 20 41 53 20 53 68 61 70  ape_Leng AS Shap
1790: 65 5f 4c 65 6e 67 2c 0d 0a 20 20 43 61 73 74 54  e_Leng,..  CastT
17a0: 6f 4d 75 6c 74 69 4c 69 6e 65 73 74 72 69 6e 67  oMultiLinestring
17b0: 28 53 54 5f 49 6e 74 65 72 73 65 63 74 69 6f 6e  (ST_Intersection
17c0: 28 0d 0a 20 20 20 20 20 20 63 2e 47 65 6f 6d 65  (..      c.Geome
17d0: 74 72 79 2c 20 61 2e 47 65 6f 6d 65 74 72 79 29  try, a.Geometry)
17e0: 29 20 41 53 20 47 65 6f 6d 65 74 72 79 0d 0a 46  ) AS Geometry..F
17f0: 52 4f 4d 20 43 6f 6e 74 6f 75 72 73 32 30 46 74  ROM Contours20Ft
1800: 20 41 53 20 63 2c 20 53 74 75 64 79 41 72 65 61   AS c, StudyArea
1810: 31 4d 69 6c 65 42 75 66 66 65 72 20 41 53 20 61  1MileBuffer AS a
1820: 0d 0a 57 48 45 52 45 20 63 2e 52 4f 57 49 44 20  ..WHERE c.ROWID 
1830: 49 4e 20 28 0d 0a 20 20 20 20 53 45 4c 45 43 54  IN (..    SELECT
1840: 20 52 4f 57 49 44 20 0d 0a 20 20 20 20 46 52 4f   ROWID ..    FRO
1850: 4d 20 53 70 61 74 69 61 6c 49 6e 64 65 78 0d 0a  M SpatialIndex..
1860: 20 20 20 20 57 48 45 52 45 20 66 5f 74 61 62 6c      WHERE f_tabl
1870: 65 5f 6e 61 6d 65 20 3d 20 27 43 6f 6e 74 6f 75  e_name = 'Contou
1880: 72 73 32 30 46 74 27 20 0d 0a 20 20 20 20 20 20  rs20Ft' ..      
1890: 20 20 41 4e 44 20 73 65 61 72 63 68 5f 66 72 61    AND search_fra
18a0: 6d 65 20 3d 20 61 2e 47 65 6f 6d 65 74 72 79 0d  me = a.Geometry.
18b0: 0a 29 3b 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e  .);..</verbatim>
18c0: 3c 2f 74 64 3e 0d 0a 3c 74 64 3e 3c 68 33 3e 53  </td>..<td><h3>S
18d0: 74 65 70 20 23 32 3c 2f 68 33 3e 0d 0a 74 68 69  tep #2</h3>..thi
18e0: 73 20 73 69 6e 67 6c 65 20 53 51 4c 20 71 75 65  s single SQL que
18f0: 72 79 20 70 65 72 66 6f 72 6d 73 20 61 6c 6c 20  ry performs all 
1900: 74 68 65 20 61 63 74 75 61 6c 20 43 6c 69 70 70  the actual Clipp
1910: 69 6e 67 20 74 61 73 6b 2e 3c 62 72 3e 0d 0a 3c  ing task.<br>..<
1920: 62 3e 53 54 5f 49 6e 74 65 72 73 65 63 74 69 6f  b>ST_Intersectio
1930: 6e 28 29 3c 2f 62 3e 20 69 73 20 61 20 53 70 61  n()</b> is a Spa
1940: 74 69 61 6c 20 53 51 4c 20 66 75 6e 63 74 69 6f  tial SQL functio
1950: 6e 20 63 6f 6d 70 75 74 69 6e 67 20 74 68 65 20  n computing the 
1960: 69 6e 74 65 72 73 65 63 74 69 6f 6e 20 62 65 74  intersection bet
1970: 77 65 65 6e 20 74 68 65 20 3c 62 3e 53 74 75 64  ween the <b>Stud
1980: 79 20 41 72 65 61 3c 2f 62 3e 20 28 3c 69 3e 70  y Area</b> (<i>p
1990: 6f 6c 79 67 6f 6e 3c 2f 69 3e 29 20 61 6e 64 20  olygon</i>) and 
19a0: 65 61 63 68 20 3c 62 3e 43 6f 6e 74 6f 75 72 20  each <b>Contour 
19b0: 4c 69 6e 65 3c 2f 62 3e 20 28 3c 69 3e 6c 69 6e  Line</b> (<i>lin
19c0: 65 73 74 72 69 6e 67 3c 2f 69 3e 29 2e 20 54 68  estring</i>). Th
19d0: 69 73 20 63 6f 75 6c 64 20 62 65 3a 3c 75 6c 3e  is could be:<ul>
19e0: 0d 0a 3c 6c 69 3e 61 20 4c 69 6e 65 73 74 72 69  ..<li>a Linestri
19f0: 6e 67 20 6f 72 20 61 20 4d 75 6c 74 69 4c 69 6e  ng or a MultiLin
1a00: 65 73 74 72 69 6e 67 20 28 64 65 70 65 6e 64 69  estring (dependi
1a10: 6e 67 20 6f 6e 20 74 68 65 20 73 70 65 63 69 66  ng on the specif
1a20: 69 63 20 73 68 61 70 65 20 6f 66 20 62 6f 74 68  ic shape of both
1a30: 20 67 65 6f 6d 65 74 72 69 65 73 29 3c 2f 6c 69   geometries)</li
1a40: 3e 0d 0a 3c 6c 69 3e 61 20 4e 55 4c 4c 20 28 69  >..<li>a NULL (i
1a50: 2e 65 2e 20 3c 2f 69 3e 61 62 73 6f 6c 75 74 65  .e. </i>absolute
1a60: 6c 79 20 6e 6f 74 68 69 6e 67 3c 2f 69 3e 29 20  ly nothing</i>) 
1a70: 69 66 20 74 68 65 20 43 6f 6e 74 6f 75 72 20 4c  if the Contour L
1a80: 69 6e 65 20 61 6e 64 20 74 68 65 20 53 74 75 64  ine and the Stud
1a90: 79 20 41 72 65 61 20 64 6f 20 6e 6f 74 20 69 6e  y Area do not in
1aa0: 74 65 72 73 65 63 74 20 61 74 20 61 6c 6c 2e 3c  tersect at all.<
1ab0: 2f 6c 69 3e 0d 0a 3c 6c 69 3e 3c 62 3e 43 61 73  /li>..<li><b>Cas
1ac0: 74 54 6f 4d 75 6c 74 69 4c 69 6e 65 73 74 72 69  tToMultiLinestri
1ad0: 6e 67 28 29 3c 2f 62 3e 20 73 69 6d 70 6c 79 20  ng()</b> simply 
1ae0: 69 73 20 61 20 3c 75 3e 3c 69 3e 63 61 73 74 20  is a <u><i>cast 
1af0: 6f 70 65 72 61 74 6f 72 3c 2f 69 3e 3c 2f 75 3e  operator</i></u>
1b00: 20 65 6e 73 75 72 69 6e 67 20 74 68 61 74 20 61   ensuring that a
1b10: 6c 6c 20 72 65 74 75 72 6e 65 64 20 67 65 6f 6d  ll returned geom
1b20: 65 74 72 69 65 73 20 77 69 6c 6c 20 62 65 20 6f  etries will be o
1b30: 66 20 74 68 65 20 73 61 6d 65 20 74 79 70 65 2e  f the same type.
1b40: 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 74 68 65 20 69  </li>..<li>the i
1b50: 6e 6e 65 72 20 73 75 62 2d 71 75 65 72 79 20 3c  nner sub-query <
1b60: 62 3e 53 45 4c 45 43 54 20 52 4f 57 49 44 20 46  b>SELECT ROWID F
1b70: 52 4f 4d 20 53 70 61 74 69 61 6c 49 6e 64 65 78  ROM SpatialIndex
1b80: 20 2e 2e 2e 3c 2f 62 3e 20 69 73 20 73 69 6d 70   ...</b> is simp
1b90: 6c 79 20 69 6e 74 65 6e 64 65 64 20 74 6f 20 61  ly intended to a
1ba0: 63 63 65 73 73 20 74 68 65 20 53 70 61 74 69 61  ccess the Spatia
1bb0: 6c 20 49 6e 64 65 78 20 73 75 70 70 6f 72 74 69  l Index supporti
1bc0: 6e 67 20 74 68 65 20 43 6f 6e 74 6f 75 72 20 4c  ng the Contour L
1bd0: 69 6e 65 73 2c 20 73 6f 20 74 6f 20 73 70 65 65  ines, so to spee
1be0: 64 20 75 70 20 74 68 65 20 77 68 6f 6c 65 20 71  d up the whole q
1bf0: 75 65 72 79 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e  uery.</li>..<li>
1c00: 3c 62 3e 43 52 45 41 54 45 20 54 41 42 4c 45 20  <b>CREATE TABLE 
1c10: 43 6f 6e 74 6f 75 72 73 32 30 46 74 43 6c 69 70  Contours20FtClip
1c20: 70 65 64 20 41 53 3c 2f 62 3e 20 73 69 6d 70 6c  ped AS</b> simpl
1c30: 79 20 69 6e 74 65 6e 64 73 20 74 68 61 74 20 74  y intends that t
1c40: 68 65 20 72 65 73 75 6c 74 73 65 74 20 72 65 74  he resultset ret
1c50: 75 72 6e 65 64 20 62 79 20 74 68 69 73 20 53 51  urned by this SQ
1c60: 4c 20 71 75 65 72 79 20 68 61 73 20 74 6f 20 62  L query has to b
1c70: 65 20 70 65 6d 61 6e 65 6e 74 6c 79 20 73 61 76  e pemanently sav
1c80: 65 64 20 69 6e 74 6f 20 61 6e 6f 74 68 65 72 20  ed into another 
1c90: 74 61 62 6c 65 20 74 6f 20 62 65 20 63 72 65 61  table to be crea
1ca0: 74 65 64 20 6f 6e 20 74 68 65 20 66 6c 79 2e 3c  ted on the fly.<
1cb0: 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 3c 62 72 3e 0d  /li>..</ul><br>.
1cc0: 0a 3c 2f 74 64 3e 3c 2f 74 72 3e 0d 0a 3c 74 72  .</td></tr>..<tr
1cd0: 3e 3c 74 64 3e 3c 76 65 72 62 61 74 69 6d 3e 0d  ><td><verbatim>.
1ce0: 0a 44 45 4c 45 54 45 20 46 52 4f 4d 20 43 6f 6e  .DELETE FROM Con
1cf0: 74 6f 75 72 73 32 30 46 74 43 6c 69 70 70 65 64  tours20FtClipped
1d00: 20 0d 0a 57 48 45 52 45 20 47 65 6f 6d 65 74 72   ..WHERE Geometr
1d10: 79 20 49 53 20 4e 55 4c 4c 3b 0d 0a 3c 2f 76 65  y IS NULL;..</ve
1d20: 72 62 61 74 69 6d 3e 3c 2f 74 64 3e 0d 0a 3c 74  rbatim></td>..<t
1d30: 64 3e 3c 68 33 3e 53 74 65 70 20 23 33 3c 2f 68  d><h3>Step #3</h
1d40: 33 3e 0d 0a 6a 75 73 74 20 61 20 73 74 75 70 69  3>..just a stupi
1d50: 64 20 70 6f 73 74 2d 70 72 6f 63 65 73 73 69 6e  d post-processin
1d60: 67 20 73 74 65 70 3b 20 74 68 65 20 70 72 65 76  g step; the prev
1d70: 69 6f 75 73 20 71 75 65 72 79 20 68 61 73 20 73  ious query has s
1d80: 75 72 65 6c 79 20 67 65 6e 65 72 61 74 65 64 20  urely generated 
1d90: 6d 61 6e 79 20 4e 55 4c 4c 20 67 65 6f 6d 65 74  many NULL geomet
1da0: 72 69 65 73 2c 20 61 6e 64 20 77 65 27 6c 6c 20  ries, and we'll 
1db0: 6e 6f 77 20 64 65 6c 65 74 65 20 61 6c 6c 20 74  now delete all t
1dc0: 68 65 6d 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e  hem.</li>..</ul>
1dd0: 3c 62 72 3e 0d 0a 3c 2f 74 64 3e 3c 2f 74 72 3e  <br>..</td></tr>
1de0: 0d 0a 3c 74 72 3e 3c 74 64 3e 3c 76 65 72 62 61  ..<tr><td><verba
1df0: 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 52 65 63  tim>..SELECT Rec
1e00: 6f 76 65 72 47 65 6f 6d 65 74 72 79 43 6f 6c 75  overGeometryColu
1e10: 6d 6e 28 27 43 6f 6e 74 6f 75 72 73 32 30 46 74  mn('Contours20Ft
1e20: 43 6c 69 70 70 65 64 27 2c 20 27 47 65 6f 6d 65  Clipped', 'Geome
1e30: 74 72 79 27 2c 20 0d 0a 20 20 20 20 32 32 36 30  try', ..    2260
1e40: 2c 20 27 4d 55 4c 54 49 4c 49 4e 45 53 54 52 49  , 'MULTILINESTRI
1e50: 4e 47 27 2c 20 32 29 3b 0d 0a 53 45 4c 45 43 54  NG', 2);..SELECT
1e60: 20 43 72 65 61 74 65 53 70 61 74 69 61 6c 49 6e   CreateSpatialIn
1e70: 64 65 78 28 27 43 6f 6e 74 6f 75 72 73 32 30 46  dex('Contours20F
1e80: 74 43 6c 69 70 70 65 64 27 2c 20 27 47 65 6f 6d  tClipped', 'Geom
1e90: 65 74 72 79 27 29 3b 0d 0a 3c 2f 76 65 72 62 61  etry');..</verba
1ea0: 74 69 6d 3e 3c 2f 74 64 3e 0d 0a 3c 74 64 3e 3c  tim></td>..<td><
1eb0: 68 33 3e 53 74 65 70 20 23 34 3c 2f 68 33 3e 0d  h3>Step #4</h3>.
1ec0: 0a 74 68 65 20 76 65 72 79 20 66 69 6e 61 6c 20  .the very final 
1ed0: 70 6f 73 74 2d 70 72 6f 63 65 73 73 69 6e 67 20  post-processing 
1ee0: 73 74 65 70 3a 20 74 72 61 6e 73 66 6f 72 6d 69  step: transformi
1ef0: 6e 67 20 74 68 65 20 74 61 62 6c 65 20 63 6f 6e  ng the table con
1f00: 74 61 69 6e 69 6e 67 20 61 6c 6c 20 43 6c 69 70  taining all Clip
1f10: 70 65 64 20 43 6f 6e 74 6f 75 72 20 4c 69 6e 65  ped Contour Line
1f20: 73 20 69 6e 74 6f 20 61 20 67 65 6e 75 69 6e 65  s into a genuine
1f30: 20 53 70 61 74 69 61 6c 20 54 61 62 6c 65 20 73   Spatial Table s
1f40: 75 70 70 6f 72 74 65 64 20 62 79 20 69 74 73 20  upported by its 
1f50: 6f 77 6e 20 53 70 61 74 69 61 6c 20 49 6e 64 65  own Spatial Inde
1f60: 78 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 3c 62  x.</li>..</ul><b
1f70: 72 3e 0d 0a 3c 2f 74 64 3e 3c 2f 74 72 3e 0d 0a  r>..</td></tr>..
1f80: 3c 74 72 3e 3c 74 64 3e 3c 76 65 72 62 61 74 69  <tr><td><verbati
1f90: 6d 3e 0d 0a 53 45 4c 45 43 54 20 44 61 74 65 54  m>..SELECT DateT
1fa0: 69 6d 65 28 27 6e 6f 77 27 29 2c 20 27 73 6f 6d  ime('now'), 'som
1fb0: 65 20 6d 65 73 73 61 67 65 27 3b 0d 0a 3c 2f 76  e message';..</v
1fc0: 65 72 62 61 74 69 6d 3e 3c 2f 74 64 3e 0d 0a 3c  erbatim></td>..<
1fd0: 74 64 3e 74 68 69 73 20 73 69 6d 70 6c 79 20 69  td>this simply i
1fe0: 73 20 61 20 77 65 69 72 64 20 62 75 74 20 69 6e  s a weird but in
1ff0: 20 74 68 69 73 20 73 70 65 63 69 66 63 20 63 61   this specifc ca
2000: 73 65 20 72 65 61 6c 6c 79 20 75 73 65 66 75 6c  se really useful
2010: 20 53 51 4c 20 74 72 69 63 6b 3b 20 77 65 27 6c   SQL trick; we'l
2020: 6c 20 71 75 65 72 79 20 74 68 65 20 73 79 73 74  l query the syst
2030: 65 6d 20 63 6c 6f 63 6b 20 69 6d 6d 65 64 69 61  em clock immedia
2040: 74 65 6c 79 20 62 65 66 6f 72 65 20 61 6e 64 20  tely before and 
2050: 61 66 74 65 72 20 70 65 72 66 6f 72 6d 69 6e 67  after performing
2060: 20 65 61 63 68 20 73 74 65 70 2c 20 73 6f 20 74   each step, so t
2070: 6f 20 67 65 74 20 66 75 6c 6c 20 74 72 61 63 65  o get full trace
2080: 20 6f 66 20 74 68 65 20 63 6f 72 72 65 73 70 6f   of the correspo
2090: 6e 64 69 6e 67 20 74 69 6d 69 6e 67 73 2e 3c 2f  nding timings.</
20a0: 6c 69 3e 0d 0a 3c 2f 75 6c 3e 3c 62 72 3e 0d 0a  li>..</ul><br>..
20b0: 3c 2f 74 64 3e 3c 2f 74 72 3e 0d 0a 3c 2f 74 61  </td></tr>..</ta
20c0: 62 6c 65 3e 0d 0a 3c 68 34 3e 42 72 69 6e 67 69  ble>..<h4>Bringi
20d0: 6e 67 20 74 68 69 6e 67 73 20 74 6f 20 61 20 68  ng things to a h
20e0: 65 61 64 3c 2f 68 34 3e 0d 0a 3c 76 65 72 62 61  ead</h4>..<verba
20f0: 74 69 6d 3e 0d 0a 23 20 73 70 61 74 69 61 6c 69  tim>..# spatiali
2100: 74 65 20 6d 79 5f 74 65 73 74 2e 73 71 6c 69 74  te my_test.sqlit
2110: 65 20 3c 20 74 65 73 74 2e 73 71 6c 0d 0a 0d 0a  e < test.sql....
2120: 53 70 61 74 69 61 4c 69 74 65 20 76 65 72 73 69  SpatiaLite versi
2130: 6f 6e 20 2e 2e 3a 20 34 2e 30 2e 30 2d 52 43 32  on ..: 4.0.0-RC2
2140: 09 53 75 70 70 6f 72 74 65 64 20 45 78 74 65 6e  .Supported Exten
2150: 73 69 6f 6e 73 3a 0d 0a 09 2d 20 27 56 69 72 74  sions:...- 'Virt
2160: 75 61 6c 53 68 61 70 65 27 09 5b 64 69 72 65 63  ualShape'.[direc
2170: 74 20 53 68 61 70 65 66 69 6c 65 20 61 63 63 65  t Shapefile acce
2180: 73 73 5d 0d 0a 09 2d 20 27 56 69 72 74 75 61 6c  ss]...- 'Virtual
2190: 44 62 66 27 09 09 5b 64 69 72 65 63 74 20 44 42  Dbf'..[direct DB
21a0: 46 20 61 63 63 65 73 73 5d 0d 0a 09 2d 20 27 56  F access]...- 'V
21b0: 69 72 74 75 61 6c 58 4c 27 09 09 5b 64 69 72 65  irtualXL'..[dire
21c0: 63 74 20 58 4c 53 20 61 63 63 65 73 73 5d 0d 0a  ct XLS access]..
21d0: 09 2d 20 27 56 69 72 74 75 61 6c 54 65 78 74 27  .- 'VirtualText'
21e0: 09 09 5b 64 69 72 65 63 74 20 43 53 56 2f 54 58  ..[direct CSV/TX
21f0: 54 20 61 63 63 65 73 73 5d 0d 0a 09 2d 20 27 56  T access]...- 'V
2200: 69 72 74 75 61 6c 4e 65 74 77 6f 72 6b 27 09 5b  irtualNetwork'.[
2210: 44 69 6a 6b 73 74 72 61 20 73 68 6f 72 74 65 73  Dijkstra shortes
2220: 74 20 70 61 74 68 5d 0d 0a 09 2d 20 27 52 54 72  t path]...- 'RTr
2230: 65 65 27 09 09 5b 53 70 61 74 69 61 6c 20 49 6e  ee'..[Spatial In
2240: 64 65 78 20 2d 20 52 2a 54 72 65 65 5d 0d 0a 09  dex - R*Tree]...
2250: 2d 20 27 4d 62 72 43 61 63 68 65 27 09 09 5b 53  - 'MbrCache'..[S
2260: 70 61 74 69 61 6c 20 49 6e 64 65 78 20 2d 20 4d  patial Index - M
2270: 42 52 20 63 61 63 68 65 5d 0d 0a 09 2d 20 27 56  BR cache]...- 'V
2280: 69 72 74 75 61 6c 53 70 61 74 69 61 6c 49 6e 64  irtualSpatialInd
2290: 65 78 27 09 5b 52 2a 54 72 65 65 20 6d 65 74 61  ex'.[R*Tree meta
22a0: 68 61 6e 64 6c 65 72 5d 0d 0a 09 2d 20 27 56 69  handler]...- 'Vi
22b0: 72 74 75 61 6c 46 44 4f 27 09 09 5b 46 44 4f 2d  rtualFDO'..[FDO-
22c0: 4f 47 52 20 69 6e 74 65 72 6f 70 65 72 61 62 69  OGR interoperabi
22d0: 6c 69 74 79 5d 0d 0a 09 2d 20 27 53 70 61 74 69  lity]...- 'Spati
22e0: 61 4c 69 74 65 27 09 09 5b 53 70 61 74 69 61 6c  aLite'..[Spatial
22f0: 20 53 51 4c 20 2d 20 4f 47 43 5d 0d 0a 50 52 4f   SQL - OGC]..PRO
2300: 4a 2e 34 20 76 65 72 73 69 6f 6e 20 2e 2e 2e 2e  J.4 version ....
2310: 2e 2e 3a 20 52 65 6c 2e 20 34 2e 37 2e 31 2c 20  ..: Rel. 4.7.1, 
2320: 32 33 20 53 65 70 74 65 6d 62 65 72 20 32 30 30  23 September 200
2330: 39 0d 0a 47 45 4f 53 20 76 65 72 73 69 6f 6e 20  9..GEOS version 
2340: 2e 2e 2e 2e 2e 2e 2e 2e 3a 20 33 2e 32 2e 30 2d  ........: 3.2.0-
2350: 43 41 50 49 2d 31 2e 36 2e 30 0d 0a 0d 0a 32 30  CAPI-1.6.0....20
2360: 31 32 2d 31 31 2d 31 30 20 30 30 3a 30 33 3a 35  12-11-10 00:03:5
2370: 32 7c 4c 6f 61 64 69 6e 67 20 74 68 65 20 53 74  2|Loading the St
2380: 75 64 79 41 72 65 61 20 53 48 50 0d 0a 32 30 31  udyArea SHP..201
2390: 32 2d 31 31 2d 31 30 20 30 30 3a 30 33 3a 35 32  2-11-10 00:03:52
23a0: 7c 4c 6f 61 64 69 6e 67 20 74 68 65 20 43 6f 6e  |Loading the Con
23b0: 74 6f 75 72 73 20 53 48 50 0d 0a 32 30 31 32 2d  tours SHP..2012-
23c0: 31 31 2d 31 30 20 30 30 3a 30 34 3a 35 34 7c 43  11-10 00:04:54|C
23d0: 6c 69 70 70 69 6e 67 20 2e 2e 2e 20 70 6c 65 61  lipping ... plea
23e0: 73 65 20 77 61 69 74 0d 0a 32 30 31 32 2d 31 31  se wait..2012-11
23f0: 2d 31 30 20 30 30 3a 30 37 3a 33 31 7c 64 65 6c  -10 00:07:31|del
2400: 65 74 69 6e 67 20 4e 55 4c 4c 20 47 65 6f 6d 65  eting NULL Geome
2410: 74 72 69 65 73 0d 0a 32 30 31 32 2d 31 31 2d 31  tries..2012-11-1
2420: 30 20 30 30 3a 30 37 3a 33 33 7c 72 65 63 6f 76  0 00:07:33|recov
2430: 65 72 69 6e 67 20 61 20 67 65 6e 75 69 6e 65 20  ering a genuine 
2440: 47 65 6f 6d 65 74 72 79 20 63 6f 6c 75 6d 6e 0d  Geometry column.
2450: 0a 32 30 31 32 2d 31 31 2d 31 30 20 30 30 3a 30  .2012-11-10 00:0
2460: 37 3a 33 34 7c 63 72 65 61 74 69 6e 67 20 74 68  7:34|creating th
2470: 65 20 53 70 61 74 69 61 6c 20 49 6e 64 65 78 0d  e Spatial Index.
2480: 0a 32 30 31 32 2d 31 31 2d 31 30 20 30 30 3a 30  .2012-11-10 00:0
2490: 37 3a 33 36 7c 61 6c 6c 20 64 6f 6e 65 20 2e 2e  7:36|all done ..
24a0: 2e 20 71 75 69 74 74 69 6e 67 0d 0a 23 0d 0a 3c  . quitting..#..<
24b0: 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 3c 62 72 3e  /verbatim>..<br>
24c0: 3c 68 72 3e 0d 0a 42 61 63 6b 20 74 6f 20 3c 61  <hr>..Back to <a
24d0: 20 68 72 65 66 3d 22 68 74 74 70 73 3a 2f 2f 77   href="https://w
24e0: 77 77 2e 67 61 69 61 2d 67 69 73 2e 69 74 2f 66  ww.gaia-gis.it/f
24f0: 6f 73 73 69 6c 2f 6c 69 62 73 70 61 74 69 61 6c  ossil/libspatial
2500: 69 74 65 2f 77 69 6b 69 3f 6e 61 6d 65 3d 73 77  ite/wiki?name=sw
2510: 69 74 63 68 69 6e 67 2d 74 6f 2d 34 2e 30 23 76  itching-to-4.0#v
2520: 69 72 74 75 61 6c 6f 67 72 22 3e 6d 61 69 6e 20  irtualogr">main 
2530: 70 61 67 65 3c 2f 61 3e 0a 5a 20 63 66 36 30 63  page</a>.Z cf60c
2540: 64 62 30 37 35 62 62 39 35 38 38 33 36 64 30 36  db075bb958836d06
2550: 65 64 66 63 30 38 38 34 33 34 33 0a              edfc0884343.