Hex Artifact Content
Not logged in

Artifact a8c4338631671dc24d303cce016441f9768529e5:

Wiki page [about GetShapefileExtent()] by sandro 2017-04-20 22:45:55.
0000: 44 20 32 30 31 37 2d 30 34 2d 32 30 54 32 32 3a  D 2017-04-20T22:
0010: 34 35 3a 35 35 2e 39 37 37 0a 4c 20 61 62 6f 75  45:55.977.L abou
0020: 74 5c 73 47 65 74 53 68 61 70 65 66 69 6c 65 45  t\sGetShapefileE
0030: 78 74 65 6e 74 28 29 0a 55 20 73 61 6e 64 72 6f  xtent().U sandro
0040: 0a 57 20 32 32 32 33 0a 3c 68 32 3e 61 62 6f 75  .W 2223.<h2>abou
0050: 74 20 47 65 74 53 68 61 70 65 66 69 6c 65 45 78  t GetShapefileEx
0060: 74 65 6e 74 28 29 3c 2f 68 32 3e 0d 0a 53 74 61  tent()</h2>..Sta
0070: 72 74 69 6e 67 20 73 69 6e 63 65 20 76 65 72 73  rting since vers
0080: 69 6f 6e 20 3c 62 3e 34 2e 35 2e 30 3c 2f 62 3e  ion <b>4.5.0</b>
0090: 20 6c 69 62 73 70 61 74 69 61 6c 69 74 65 20 73   libspatialite s
00a0: 75 70 70 6f 72 74 73 20 61 20 6e 65 77 20 53 51  upports a new SQ
00b0: 4c 20 66 75 6e 63 74 69 6f 6e 20 72 65 6c 61 74  L function relat
00c0: 65 64 20 74 6f 20 3c 62 3e 56 69 72 74 75 61 6c  ed to <b>Virtual
00d0: 53 68 61 70 65 3c 2f 62 3e 20 54 61 62 6c 65 73  Shape</b> Tables
00e0: 20 61 6e 64 20 73 70 65 63 69 66 69 63 61 6c 6c   and specificall
00f0: 79 20 69 6e 74 65 6e 64 65 64 20 74 6f 20 71 75  y intended to qu
0100: 69 63 6b 6c 79 20 72 65 74 72 69 65 76 65 20 74  ickly retrieve t
0110: 68 65 20 3c 62 3e 46 75 6c 6c 20 45 78 74 65 6e  he <b>Full Exten
0120: 74 3c 2f 62 3e 20 6f 66 20 74 68 65 20 75 6e 64  t</b> of the und
0130: 65 72 6c 61 79 69 6e 67 20 53 68 61 70 65 66 69  erlaying Shapefi
0140: 6c 65 2e 3c 62 72 3e 3c 62 72 3e 0d 0a 4a 75 73  le.<br><br>..Jus
0150: 74 20 61 20 73 68 6f 72 74 20 72 65 63 61 6c 6c  t a short recall
0160: 20 61 62 6f 75 74 20 53 68 61 70 65 66 69 6c 65   about Shapefile
0170: 73 3a 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 41 6e  s:..<ul>..<li>An
0180: 79 20 53 68 61 70 65 66 69 6c 65 20 69 73 20 61  y Shapefile is a
0190: 6c 77 61 79 73 20 65 78 70 65 63 74 65 64 20 74  lways expected t
01a0: 6f 20 64 65 63 6c 61 72 65 20 69 74 73 20 6f 77  o declare its ow
01b0: 6e 20 66 75 6c 6c 20 65 78 74 65 6e 74 20 28 61  n full extent (a
01c0: 6b 61 20 6f 76 65 72 61 6c 20 42 42 4f 58 29 20  ka overal BBOX) 
01d0: 77 69 74 68 69 6e 20 69 74 73 20 3c 62 3e 48 65  within its <b>He
01e0: 61 64 65 72 20 42 6c 6f 63 6b 3c 2f 62 3e 2e 0d  ader Block</b>..
01f0: 0a 3c 6c 69 3e 53 6f 20 74 68 65 72 65 20 69 73  .<li>So there is
0200: 20 6e 6f 20 6e 65 65 64 20 74 6f 20 70 65 72 66   no need to perf
0210: 6f 72 6d 20 61 20 28 73 6c 6f 77 29 20 66 75 6c  orm a (slow) ful
0220: 6c 2d 74 61 62 6c 65 2d 73 63 61 6e 20 69 6e 20  l-table-scan in 
0230: 6f 72 64 65 72 20 74 6f 20 63 6f 6d 70 75 74 65  order to compute
0240: 20 74 68 65 20 66 75 6c 6c 20 65 78 74 65 6e 74   the full extent
0250: 2c 20 73 69 6d 70 6c 79 20 62 65 63 61 75 73 65  , simply because
0260: 20 74 68 69 73 20 69 6e 66 6f 72 6d 61 74 69 6f   this informatio
0270: 6e 20 69 73 20 61 6c 72 65 61 64 79 20 73 74 6f  n is already sto
0280: 72 65 64 20 69 6e 74 6f 20 74 68 65 20 68 65 61  red into the hea
0290: 64 65 72 20 64 65 63 6c 61 72 61 74 69 6f 6e 73  der declarations
02a0: 20 61 6e 64 20 69 73 20 69 6d 6d 65 64 69 61 74   and is immediat
02b0: 65 6c 79 20 61 76 61 69 6c 61 62 6c 65 2e 3c 2f  ely available.</
02c0: 6c 69 3e 0d 0a 3c 6c 69 3e 3c 62 3e 56 69 72 74  li>..<li><b>Virt
02d0: 75 61 6c 53 68 61 70 65 73 3c 2f 62 3e 20 61 72  ualShapes</b> ar
02e0: 65 20 61 6c 77 61 79 73 20 63 6f 6e 73 69 64 65  e always conside
02f0: 72 65 64 20 62 79 20 53 70 61 74 69 61 4c 69 74  red by SpatiaLit
0300: 65 20 61 73 20 3c 62 3e 72 65 61 64 2d 6f 6e 6c  e as <b>read-onl
0310: 79 3c 2f 62 3e 20 54 61 62 6c 65 73 2c 20 61 6e  y</b> Tables, an
0320: 64 20 63 6f 6e 73 65 71 75 65 6e 74 6c 79 20 74  d consequently t
0330: 68 65 20 42 42 4f 58 20 64 65 63 6c 61 72 61 74  he BBOX declarat
0340: 69 6f 6e 20 66 6f 75 6e 64 20 69 6e 74 6f 20 74  ion found into t
0350: 68 65 20 68 65 61 64 65 72 20 62 6c 6f 63 6b 20  he header block 
0360: 63 61 6e 20 6e 65 76 65 72 20 63 68 61 6e 67 65  can never change
0370: 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 3c 62 72  .</li>..</ul><br
0380: 3e 0d 0a 54 68 65 20 6e 65 77 20 3c 62 3e 47 65  >..The new <b>Ge
0390: 74 53 68 61 70 65 66 69 6c 65 45 78 74 65 6e 74  tShapefileExtent
03a0: 28 29 3c 2f 62 3e 20 53 51 4c 20 66 75 6e 63 74  ()</b> SQL funct
03b0: 69 6f 6e 20 64 69 72 65 63 74 6c 79 20 71 75 65  ion directly que
03c0: 72 69 65 73 20 74 68 65 20 66 75 6c 6c 20 65 78  ries the full ex
03d0: 74 65 6e 74 20 64 65 63 6c 61 72 65 64 20 69 6e  tent declared in
03e0: 74 6f 20 74 68 65 20 73 68 61 70 65 66 69 6c 65  to the shapefile
03f0: 27 73 20 68 65 61 64 65 72 20 62 6c 6f 63 6b 2c  's header block,
0400: 20 73 6f 20 69 74 27 73 20 65 78 70 65 63 74 65   so it's expecte
0410: 64 20 74 6f 20 62 65 20 76 65 72 79 20 66 61 73  d to be very fas
0420: 74 20 65 76 65 6e 20 77 68 65 6e 20 74 68 65 20  t even when the 
0430: 73 68 61 70 65 66 69 6c 65 20 63 6f 6e 74 61 69  shapefile contai
0440: 6e 73 20 61 6e 20 68 75 67 65 20 6e 75 6d 62 65  ns an huge numbe
0450: 72 20 6f 66 20 46 65 61 74 75 72 65 73 2e 3c 62  r of Features.<b
0460: 72 3e 3c 62 72 3e 0d 0a 3c 68 72 3e 0d 0a 3c 68  r><br>..<hr>..<h
0470: 33 3e 45 78 61 6d 70 6c 65 3c 2f 68 33 3e 0d 0a  3>Example</h3>..
0480: 57 65 27 6c 6c 20 73 74 61 72 74 20 62 79 20 63  We'll start by c
0490: 72 65 61 74 69 6e 67 20 61 20 56 69 72 74 75 61  reating a Virtua
04a0: 6c 53 68 61 70 65 20 54 61 62 6c 65 3a 0d 0a 3c  lShape Table:..<
04b0: 76 65 72 62 61 74 69 6d 3e 0d 0a 43 52 45 41 54  verbatim>..CREAT
04c0: 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20  E VIRTUAL TABLE 
04d0: 74 65 73 74 20 55 53 49 4e 47 20 56 69 72 74 75  test USING Virtu
04e0: 61 6c 53 68 61 70 65 28 27 2e 2f 73 6f 6d 65 73  alShape('./somes
04f0: 68 61 70 65 66 69 6c 65 27 2c 20 27 43 50 31 32  hapefile', 'CP12
0500: 35 32 27 2c 20 34 33 32 36 29 3b 0d 0a 3c 2f 76  52', 4326);..</v
0510: 65 72 62 61 74 69 6d 3e 0d 0a 61 6e 64 20 6e 6f  erbatim>..and no
0520: 77 20 77 65 20 61 72 65 20 72 65 61 64 79 20 74  w we are ready t
0530: 6f 20 63 68 65 63 6b 20 74 68 65 20 56 69 72 75  o check the Viru
0540: 61 6c 53 68 61 70 65 27 73 20 46 75 6c 6c 20 45  alShape's Full E
0550: 78 74 65 6e 74 3a 0d 0a 3c 76 65 72 62 61 74 69  xtent:..<verbati
0560: 6d 3e 0d 0a 53 45 4c 45 43 54 20 41 73 45 57 4b  m>..SELECT AsEWK
0570: 54 28 47 65 74 53 68 61 70 65 66 69 6c 65 45 78  T(GetShapefileEx
0580: 74 65 6e 74 28 27 74 65 73 74 27 29 29 3b 0d 0a  tent('test'));..
0590: 2d 2d 2d 2d 2d 2d 2d 0d 0a 53 52 49 44 3d 34 33  -------..SRID=43
05a0: 32 36 3b 50 4f 4c 59 47 4f 4e 28 28 36 2e 36 32  26;POLYGON((6.62
05b0: 36 36 32 31 33 36 30 30 30 30 30 35 38 20 33 35  6621360000058 35
05c0: 2e 34 39 32 38 35 32 35 39 32 30 30 30 30 37 2c  .49285259200007,
05d0: 31 38 2e 35 32 30 33 38 31 35 35 33 30 30 30 30  18.5203815530000
05e0: 35 20 33 35 2e 34 39 32 38 35 32 35 39 32 30 30  5 35.49285259200
05f0: 30 30 37 2c 31 38 2e 35 32 30 33 38 31 35 35 33  007,18.520381553
0600: 30 30 30 30 35 20 34 37 2e 30 39 31 37 38 33 37  00005 47.0917837
0610: 34 32 30 30 30 30 37 2c 36 2e 36 32 36 36 32 31  4200007,6.626621
0620: 33 36 30 30 30 30 30 35 38 20 34 37 2e 30 39 31  360000058 47.091
0630: 37 38 33 37 34 32 30 30 30 30 37 2c 36 2e 36 32  78374200007,6.62
0640: 36 36 32 31 33 36 30 30 30 30 30 35 38 20 33 35  6621360000058 35
0650: 2e 34 39 32 38 35 32 35 39 32 30 30 30 30 37 29  .49285259200007)
0660: 29 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a  )..</verbatim>..
0670: 3c 75 3e 50 6c 65 61 73 65 20 6e 6f 74 65 3c 2f  <u>Please note</
0680: 75 3e 3a 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 41  u>:..<ul>..<li>A
0690: 20 47 65 6f 6d 65 74 72 79 20 6f 66 20 74 68 65   Geometry of the
06a0: 20 50 6f 6c 79 67 6f 6e 20 74 79 70 65 20 28 6e   Polygon type (n
06b0: 61 6d 65 6c 79 20 61 20 3c 62 3e 72 65 63 74 61  amely a <b>recta
06c0: 6e 67 6c 65 3c 2f 62 3e 29 20 68 61 73 20 62 65  ngle</b>) has be
06d0: 65 6e 20 72 65 74 75 72 6e 65 64 20 61 6e 64 20  en returned and 
06e0: 69 74 20 72 65 70 72 65 73 65 6e 74 73 20 74 68  it represents th
06f0: 65 20 73 68 61 70 65 66 69 6c 65 27 73 20 42 42  e shapefile's BB
0700: 4f 58 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 49 66  OX.</li>..<li>If
0710: 20 61 6e 79 20 65 72 72 6f 72 20 6f 63 63 75 72   any error occur
0720: 73 20 28 61 72 67 75 6d 65 6e 74 20 6f 66 20 74  s (argument of t
0730: 68 65 20 77 72 6f 6e 67 20 74 79 70 65 20 6f 72  he wrong type or
0740: 20 6e 6f 74 20 65 78 69 73 74 69 6e 67 20 56 69   not existing Vi
0750: 72 74 75 61 6c 53 68 61 70 65 29 20 74 68 65 6e  rtualShape) then
0760: 20 61 20 3c 62 3e 4e 55 4c 4c 3c 2f 62 3e 20 77   a <b>NULL</b> w
0770: 69 6c 6c 20 62 65 20 72 65 74 75 72 6e 65 64 2e  ill be returned.
0780: 0d 0a 3c 2f 75 6c 3e 3c 62 72 3e 0d 0a 3c 74 61  ..</ul><br>..<ta
0790: 62 6c 65 20 62 67 63 6f 6c 6f 72 3d 22 23 66 66  ble bgcolor="#ff
07a0: 65 30 30 30 22 20 63 65 6c 6c 70 61 64 64 69 6e  e000" cellpaddin
07b0: 67 3d 22 31 30 22 3e 0d 0a 3c 74 72 3e 3c 74 68  g="10">..<tr><th
07c0: 3e 43 61 76 65 61 74 3c 2f 74 68 3e 3c 2f 74 72  >Caveat</th></tr
07d0: 3e 0d 0a 3c 74 72 3e 3c 74 64 3e 0d 0a 49 66 20  >..<tr><td>..If 
07e0: 74 77 6f 20 28 6f 72 20 6d 6f 72 65 29 20 56 69  two (or more) Vi
07f0: 72 74 75 61 6c 53 68 61 70 65 73 20 65 78 69 73  rtualShapes exis
0800: 74 20 77 69 74 68 69 6e 20 74 68 65 20 73 61 6d  t within the sam
0810: 65 20 44 42 20 63 6f 6e 6e 65 63 74 69 6f 6e 20  e DB connection 
0820: 65 78 61 63 74 6c 79 20 73 68 61 72 69 6e 67 20  exactly sharing 
0830: 61 6e 20 69 64 65 6e 74 69 63 61 6c 20 54 61 62  an identical Tab
0840: 6c 65 2d 6e 61 6d 65 20 28 6f 62 76 69 6f 75 73  le-name (obvious
0850: 6c 79 2c 20 65 61 63 68 20 6f 6e 65 20 62 65 69  ly, each one bei
0860: 6e 67 20 6c 6f 63 61 74 65 64 20 6f 6e 20 61 20  ng located on a 
0870: 64 69 66 66 65 72 65 6e 74 20 3c 62 3e 41 54 54  different <b>ATT
0880: 41 43 48 45 44 2d 44 42 3c 2f 62 3e 29 20 74 68  ACHED-DB</b>) th
0890: 65 20 72 65 73 75 6c 74 20 72 65 74 75 72 6e 65  e result returne
08a0: 64 20 62 79 20 3c 62 3e 47 65 74 53 68 61 70 65  d by <b>GetShape
08b0: 66 69 6c 65 45 78 74 65 6e 74 28 29 3c 2f 62 3e  fileExtent()</b>
08c0: 20 77 69 6c 6c 20 62 65 20 75 6e 70 72 65 64 69   will be unpredi
08d0: 63 74 61 62 6c 65 2e 0d 0a 3c 2f 74 64 3e 3c 2f  ctable...</td></
08e0: 74 72 3e 0d 0a 3c 2f 74 61 62 6c 65 3e 0d 0a 3c  tr>..</table>..<
08f0: 62 72 3e 3c 62 72 3e 0a 5a 20 61 38 34 31 66 62  br><br>.Z a841fb
0900: 36 34 30 38 32 33 34 38 35 34 35 33 32 30 38 33  6408234854532083
0910: 31 65 62 64 38 65 35 65 34 61 0a                 1ebd8e5e4a.