Artifact
fc842978ba0d7b9506859f68d4e4e2db8628dc3a:
Wiki page
[About ST_Subdivide()] by
sandro
2019-02-15 19:44:20.
0000: 44 20 32 30 31 39 2d 30 32 2d 31 35 54 31 39 3a D 2019-02-15T19:
0010: 34 34 3a 32 30 2e 37 38 35 0a 4c 20 41 62 6f 75 44:20.785.L Abou
0020: 74 5c 73 53 54 5f 53 75 62 64 69 76 69 64 65 28 t\sST_Subdivide(
0030: 29 0a 50 20 64 37 65 31 34 63 64 38 61 32 61 34 ).P d7e14cd8a2a4
0040: 33 65 34 33 61 61 32 64 61 38 62 63 35 33 62 65 3e43aa2da8bc53be
0050: 33 34 36 34 39 36 34 37 35 33 66 37 0a 55 20 73 3464964753f7.U s
0060: 61 6e 64 72 6f 0a 57 20 31 30 38 37 31 0a 3c 74 andro.W 10871.<t
0070: 61 62 6c 65 20 63 65 6c 6c 73 70 61 63 69 6e 67 able cellspacing
0080: 3d 22 31 32 22 20 77 69 64 74 68 3d 22 31 30 30 ="12" width="100
0090: 25 22 3e 0d 0a 3c 74 72 3e 3c 74 64 20 63 6f 6c %">..<tr><td col
00a0: 73 70 61 6e 3d 22 32 22 3e 0d 0a 3c 74 61 62 6c span="2">..<tabl
00b0: 65 20 77 69 64 74 68 3d 22 31 30 30 25 22 20 62 e width="100%" b
00c0: 67 63 6f 6c 6f 72 3d 22 23 66 30 66 30 66 38 22 gcolor="#f0f0f8"
00d0: 3e 0d 0a 3c 74 72 3e 3c 74 64 20 61 6c 69 67 6e >..<tr><td align
00e0: 3d 22 63 65 6e 74 65 72 22 3e 0d 0a 3c 68 31 3e ="center">..<h1>
00f0: 53 54 5f 53 75 62 64 69 76 69 64 65 28 29 3a 20 ST_Subdivide():
0100: 61 20 71 75 69 63 6b 20 69 6e 74 72 6f 3c 2f 68 a quick intro</h
0110: 31 3e 0d 0a 3c 2f 74 64 3e 3c 2f 74 72 3e 3c 2f 1>..</td></tr></
0120: 74 61 62 6c 65 3e 0d 0a 3c 74 61 62 6c 65 20 77 table>..<table w
0130: 69 64 74 68 3d 22 31 30 30 25 22 3e 3c 74 72 3e idth="100%"><tr>
0140: 0d 0a 3c 74 64 20 77 69 64 74 68 3d 22 33 33 25 ..<td width="33%
0150: 22 20 61 6c 69 67 6e 3d 22 6c 65 66 74 22 3e 3c " align="left"><
0160: 2f 74 64 3e 0d 0a 3c 74 64 20 61 6c 69 67 6e 3d /td>..<td align=
0170: 22 63 65 6e 74 65 72 22 3e 3c 61 20 68 72 65 66 "center"><a href
0180: 3d 22 68 74 74 70 73 3a 2f 2f 77 77 77 2e 67 61 ="https://www.ga
0190: 69 61 2d 67 69 73 2e 69 74 2f 66 6f 73 73 69 6c ia-gis.it/fossil
01a0: 2f 6c 69 62 73 70 61 74 69 61 6c 69 74 65 2f 77 /libspatialite/w
01b0: 69 6b 69 3f 6e 61 6d 65 3d 34 2e 33 2e 30 2b 64 iki?name=4.3.0+d
01c0: 6f 63 22 3e 62 61 63 6b 20 74 6f 20 69 6e 64 65 oc">back to inde
01d0: 78 3c 2f 61 3e 3c 2f 74 64 3e 0d 0a 3c 74 64 20 x</a></td>..<td
01e0: 77 69 64 74 68 3d 22 33 33 25 22 20 61 6c 69 67 width="33%" alig
01f0: 6e 3d 22 72 69 67 68 74 22 3e 3c 2f 74 64 3e 0d n="right"></td>.
0200: 0a 3c 2f 74 72 3e 3c 2f 74 61 62 6c 65 3e 3c 62 .</tr></table><b
0210: 72 3e 0d 0a 3c 68 32 3e 41 62 6f 75 74 20 53 54 r>..<h2>About ST
0220: 5f 53 75 62 64 69 76 69 64 65 28 29 3c 2f 68 32 _Subdivide()</h2
0230: 3e 0d 0a 53 69 6e 63 65 20 76 65 72 73 69 6f 6e >..Since version
0240: 20 3c 62 3e 35 2e 30 2e 30 3c 2f 62 3e 20 53 70 <b>5.0.0</b> Sp
0250: 61 74 69 61 4c 69 74 65 20 73 75 70 70 6f 72 74 atiaLite support
0260: 73 20 3c 62 3e 53 54 5f 53 75 62 64 69 76 69 64 s <b>ST_Subdivid
0270: 65 28 29 3c 2f 62 3e 2c 20 61 6e 20 61 64 76 61 e()</b>, an adva
0280: 6e 63 65 64 20 53 51 4c 20 66 75 6e 63 74 69 6f nced SQL functio
0290: 6e 20 61 6c 72 65 61 64 79 20 61 76 61 69 6c 61 n already availa
02a0: 62 6c 65 20 6f 6e 20 3c 61 20 68 72 65 66 3d 22 ble on <a href="
02b0: 68 74 74 70 73 3a 2f 2f 70 6f 73 74 67 69 73 2e https://postgis.
02c0: 6e 65 74 2f 64 6f 63 73 2f 53 54 5f 53 75 62 64 net/docs/ST_Subd
02d0: 69 76 69 64 65 2e 68 74 6d 6c 22 3e 50 6f 73 74 ivide.html">Post
02e0: 47 49 53 3c 2f 61 3e 2e 3c 62 72 3e 0d 0a 54 68 GIS</a>.<br>..Th
02f0: 65 20 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f 6e e implementation
0300: 20 69 73 20 73 74 72 69 63 74 6c 79 20 73 69 6d is strictly sim
0310: 69 6c 61 72 20 69 6e 20 62 6f 74 68 20 53 70 61 ilar in both Spa
0320: 74 69 61 6c 20 44 42 4d 53 65 73 20 62 65 63 61 tial DBMSes beca
0330: 75 73 65 20 6f 6e 20 50 6f 73 74 67 49 53 20 74 use on PostgIS t
0340: 68 65 20 66 75 6e 63 74 69 6f 6e 20 69 73 20 62 he function is b
0350: 75 69 6c 74 20 6f 6e 20 74 68 65 20 74 6f 70 20 uilt on the top
0360: 6f 66 20 74 68 65 20 69 6e 74 65 72 6e 61 6c 20 of the internal
0370: 3c 62 3e 6c 77 67 65 6f 6d 3c 2f 62 3e 20 6c 69 <b>lwgeom</b> li
0380: 62 72 61 72 79 2c 20 61 6e 64 20 6f 6e 20 53 70 brary, and on Sp
0390: 61 74 69 61 4c 69 74 65 20 69 73 20 62 75 69 6c atiaLite is buil
03a0: 74 20 6f 6e 20 74 68 65 20 74 6f 70 20 6f 66 20 t on the top of
03b0: 3c 62 3e 6c 69 62 72 74 74 6f 70 6f 3c 2f 62 3e <b>librttopo</b>
03c0: 20 74 68 61 74 20 73 69 6d 70 6c 79 20 69 73 20 that simply is
03d0: 61 20 6d 6f 72 65 20 75 6e 69 76 65 72 73 61 6c a more universal
03e0: 20 70 6f 72 74 69 6e 67 20 6f 66 20 6c 77 67 65 porting of lwge
03f0: 6f 6d 20 6f 75 74 73 69 64 65 20 50 6f 73 74 47 om outside PostG
0400: 49 53 2e 3c 62 72 3e 3c 62 72 3e 0d 0a 41 20 73 IS.<br><br>..A s
0410: 68 6f 72 74 20 72 61 74 69 6f 6e 61 6c 65 3a 20 hort rationale:
0420: 70 72 6f 63 65 73 73 69 6e 67 20 68 75 67 65 20 processing huge
0430: 67 65 6f 6d 65 74 72 69 65 73 20 68 61 76 69 6e geometries havin
0440: 67 20 61 6e 20 69 6d 70 72 65 73 73 69 76 65 20 g an impressive
0450: 6e 75 6d 62 65 72 20 6f 66 20 56 65 72 74 69 63 number of Vertic
0460: 65 73 20 28 6d 61 6e 79 20 74 68 6f 75 73 61 6e es (many thousan
0470: 64 73 20 6f 72 20 65 76 65 6e 20 6d 6f 72 65 29 ds or even more)
0480: 20 69 73 20 61 6e 20 69 6e 74 72 69 6e 73 69 63 is an intrinsic
0490: 61 6c 6c 79 20 73 6c 6f 77 20 70 72 6f 63 65 73 ally slow proces
04a0: 73 2e 3c 62 72 3e 0d 0a 53 75 62 64 69 76 69 64 s.<br>..Subdivid
04b0: 69 6e 67 20 74 68 65 6d 20 69 6e 74 6f 20 6d 61 ing them into ma
04c0: 6e 79 20 73 6d 61 6c 6c 65 72 20 70 61 72 74 73 ny smaller parts
04d0: 20 28 73 74 69 6c 6c 20 70 72 65 73 65 72 76 69 (still preservi
04e0: 6e 67 20 66 75 6c 6c 20 74 6f 70 6f 6c 6f 67 69 ng full topologi
04f0: 63 61 6c 20 63 6f 6e 73 69 73 74 65 6e 63 79 29 cal consistency)
0500: 20 75 73 75 61 6c 6c 79 20 68 65 6c 70 73 20 74 usually helps t
0510: 6f 20 72 65 73 74 6f 72 65 20 61 20 73 61 74 69 o restore a sati
0520: 73 66 79 69 6e 67 20 70 72 6f 63 65 73 73 69 6e sfying processin
0530: 67 20 73 70 65 65 64 2e 0d 0a 54 68 69 73 20 69 g speed...This i
0540: 73 20 65 78 61 63 74 6c 79 20 74 68 65 20 69 6e s exactly the in
0550: 74 65 6e 64 65 64 20 73 63 6f 70 65 20 6f 66 20 tended scope of
0560: 3c 62 3e 53 54 5f 53 75 62 64 69 76 69 64 65 28 <b>ST_Subdivide(
0570: 29 3c 2f 62 3e 3a 0d 0a 3c 75 6c 3e 0d 0a 3c 6c )</b>:..<ul>..<l
0580: 69 3e 74 68 69 73 20 66 75 6e 63 74 69 6f 6e 20 i>this function
0590: 77 69 6c 6c 20 72 65 63 65 69 76 65 20 61 6e 20 will receive an
05a0: 69 6e 70 75 74 20 67 65 6f 6d 65 74 72 79 20 28 input geometry (
05b0: 6d 61 79 20 77 65 6c 6c 20 62 65 20 61 20 76 65 may well be a ve
05c0: 72 79 20 68 75 67 65 20 6f 6e 65 29 2e 3c 2f 6c ry huge one).</l
05d0: 69 3e 0d 0a 3c 6c 69 3e 65 61 63 68 20 3c 62 3e i>..<li>each <b>
05e0: 4c 69 6e 65 73 74 72 69 6e 67 3c 2f 62 3e 20 6f Linestring</b> o
05f0: 72 20 3c 62 3e 50 6f 6c 79 67 6f 6e 3c 2f 62 3e r <b>Polygon</b>
0600: 20 66 6f 75 6e 64 20 77 69 74 68 69 6e 20 74 68 found within th
0610: 65 20 69 6e 70 75 74 20 67 65 6f 6d 65 74 72 79 e input geometry
0620: 20 77 69 6c 6c 20 62 65 20 74 68 65 6e 20 70 72 will be then pr
0630: 6f 63 65 73 73 65 64 3a 0d 0a 3c 75 6c 3e 0d 0a ocessed:..<ul>..
0640: 3c 6c 69 3e 61 6c 6c 20 4c 69 6e 65 73 74 72 69 <li>all Linestri
0650: 6e 67 73 20 6f 72 20 50 6f 6c 79 67 6f 6e 73 20 ngs or Polygons
0660: 75 73 69 6e 67 20 61 20 6e 75 6d 62 65 72 20 6f using a number o
0670: 66 20 56 65 72 74 69 63 65 73 20 6c 65 73 73 65 f Vertices lesse
0680: 72 20 6f 72 20 65 71 75 61 6c 20 74 68 61 6e 20 r or equal than
0690: 74 68 65 20 67 69 76 65 6e 20 74 68 72 65 73 68 the given thresh
06a0: 6f 6c 64 20 77 69 6c 6c 20 62 65 20 72 65 74 75 old will be retu
06b0: 72 6e 65 64 20 61 73 20 74 68 65 79 20 61 72 65 rned as they are
06c0: 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 62 75 74 20 .</li>..<li>but
06d0: 61 6c 6c 20 4c 69 6e 65 73 74 72 69 6e 67 73 20 all Linestrings
06e0: 6f 72 20 50 6f 6c 79 67 6f 6e 73 20 75 73 69 6e or Polygons usin
06f0: 67 20 61 6e 20 65 78 63 65 65 64 69 6e 67 20 6e g an exceeding n
0700: 75 6d 62 65 72 20 6f 66 20 56 65 72 74 69 63 65 umber of Vertice
0710: 73 20 77 69 6c 6c 20 62 65 20 72 65 63 75 72 73 s will be recurs
0720: 69 76 65 6c 79 20 73 70 6c 69 74 2c 20 75 6e 74 ively split, unt
0730: 69 6c 6c 20 74 68 65 79 27 6c 6c 20 62 65 20 72 ill they'll be r
0740: 65 70 72 65 73 65 6e 74 65 64 20 62 79 20 61 20 epresented by a
0750: 3c 62 3e 63 6f 6c 6c 65 63 74 69 6f 6e 3c 2f 62 <b>collection</b
0760: 3e 20 6f 66 20 65 6c 65 6d 65 6e 74 61 72 79 20 > of elementary
0770: 3c 62 3e 70 61 72 74 73 3c 2f 62 3e 20 75 73 69 <b>parts</b> usi
0780: 6e 67 20 6e 6f 20 6d 6f 72 65 20 74 68 61 6e 20 ng no more than
0790: 74 68 65 20 72 65 71 75 69 72 65 64 20 6e 75 6d the required num
07a0: 62 65 72 20 6f 66 20 76 65 72 74 69 63 65 73 2e ber of vertices.
07b0: 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 3c 2f 6c 69 </li>..</ul></li
07c0: 3e 0d 0a 3c 6c 69 3e 61 74 20 74 68 65 20 65 6e >..<li>at the en
07d0: 64 20 6f 66 20 74 68 65 20 70 72 6f 63 65 73 73 d of the process
07e0: 20 74 68 65 20 66 75 6e 63 74 69 6f 6e 20 77 69 the function wi
07f0: 6c 6c 20 72 65 74 75 72 6e 20 61 20 63 6f 6c 6c ll return a coll
0800: 65 63 74 69 6f 6e 20 63 6f 6e 74 61 69 6e 69 6e ection containin
0810: 67 20 61 6c 6c 20 65 6c 65 6d 65 6e 74 61 72 79 g all elementary
0820: 20 70 61 72 74 73 20 28 61 20 3c 62 3e 4d 75 6c parts (a <b>Mul
0830: 74 69 4c 69 6e 65 73 74 72 69 6e 67 3c 2f 62 3e tiLinestring</b>
0840: 20 6f 72 20 61 20 3c 62 3e 4d 75 6c 74 69 50 6f or a <b>MultiPo
0850: 6c 79 67 6f 6e 3c 2f 62 3e 20 64 65 70 65 6e 64 lygon</b> depend
0860: 69 6e 67 20 6f 6e 20 74 68 65 20 6e 61 74 75 72 ing on the natur
0870: 65 20 6f 66 20 74 68 65 20 69 6e 70 75 74 20 67 e of the input g
0880: 65 6f 6d 65 74 72 79 29 2e 3c 2f 6c 69 3e 0d 0a eometry).</li>..
0890: 3c 2f 75 6c 3e 0d 0a 3c 68 32 3e 42 61 73 69 63 </ul>..<h2>Basic
08a0: 20 45 78 61 6d 70 6c 65 73 3c 2f 68 32 3e 0d 0a Examples</h2>..
08b0: 54 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 65 78 The following ex
08c0: 61 6d 70 6c 65 73 20 61 72 65 20 62 61 73 65 64 amples are based
08d0: 20 6f 6e 20 74 68 65 20 3c 62 3e 61 6d 5f 72 65 on the <b>am_re
08e0: 67 5f 6d 75 6c 74 69 70 61 72 74 3c 2f 62 3e 20 g_multipart</b>
08f0: 53 68 61 70 65 66 69 6c 65 20 66 72 65 65 6c 79 Shapefile freely
0900: 20 61 76 61 69 6c 61 62 6c 65 20 66 6f 72 20 64 available for d
0910: 6f 77 6e 6c 6f 61 64 20 66 72 6f 6d 20 3c 61 20 ownload from <a
0920: 68 72 65 66 3d 22 68 74 74 70 3a 2f 2f 77 77 77 href="http://www
0930: 35 30 32 2e 72 65 67 69 6f 6e 65 2e 74 6f 73 63 502.regione.tosc
0940: 61 6e 61 2e 69 74 2f 67 65 6f 73 63 6f 70 69 6f ana.it/geoscopio
0950: 2f 63 61 72 74 6f 74 65 63 61 2e 68 74 6d 6c 22 /cartoteca.html"
0960: 3e 68 65 72 65 3c 2f 61 3e 20 28 73 65 61 72 63 >here</a> (searc
0970: 68 20 66 6f 72 20 3c 62 3e 41 6d 62 69 74 69 20 h for <b>Ambiti
0980: 41 6d 6d 69 6e 69 73 74 72 61 74 69 76 69 3c 2f Amministrativi</
0990: 62 3e 20 2d 20 3c 69 3e 41 64 6d 69 6e 69 73 74 b> - <i>Administ
09a0: 72 61 74 69 76 65 20 42 6f 75 6e 64 61 72 69 65 rative Boundarie
09b0: 73 3c 2f 69 3e 29 2e 3c 62 72 3e 3c 62 72 3e 0d s</i>).<br><br>.
09c0: 0a 54 68 69 73 20 6f 6e 65 20 73 75 70 70 6f 72 .This one suppor
09d0: 74 73 20 61 20 76 65 72 79 20 61 63 63 75 72 61 ts a very accura
09e0: 74 65 20 61 6e 64 20 70 72 65 63 69 73 65 20 6d te and precise m
09f0: 61 70 20 72 65 70 72 65 73 65 6e 74 61 74 69 6f ap representatio
0a00: 6e 2c 20 61 6e 64 20 74 68 65 20 6d 61 69 6e 20 n, and the main
0a10: 65 78 74 65 72 69 6f 72 20 72 69 6e 67 20 68 61 exterior ring ha
0a20: 73 20 6d 6f 72 65 20 74 68 61 6e 20 31 30 30 2c s more than 100,
0a30: 30 30 30 2b 20 56 65 72 74 69 63 65 73 2e 3c 62 000+ Vertices.<b
0a40: 72 3e 0d 0a 49 74 27 73 20 61 20 76 65 72 79 20 r>..It's a very
0a50: 67 6f 6f 64 20 65 78 61 6d 70 6c 65 20 6f 66 20 good example of
0a60: 61 20 47 65 6f 6d 65 74 72 79 20 73 6f 20 68 75 a Geometry so hu
0a70: 67 65 20 74 6f 20 6d 61 6b 65 20 65 78 74 72 65 ge to make extre
0a80: 6d 65 6c 79 20 73 6c 6f 77 20 63 6f 6d 70 75 74 mely slow comput
0a90: 69 6e 67 20 61 6e 79 20 53 70 61 74 69 61 6c 20 ing any Spatial
0aa0: 6f 70 65 72 61 74 6f 72 20 28 61 73 20 65 2e 67 operator (as e.g
0ab0: 2e 20 53 54 5f 49 6e 74 65 72 73 65 63 74 73 2c . ST_Intersects,
0ac0: 20 53 54 5f 54 6f 75 63 68 65 73 2c 20 53 54 5f ST_Touches, ST_
0ad0: 43 6f 76 65 72 73 20 61 6e 64 20 73 6f 20 6f 6e Covers and so on
0ae0: 29 2e 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 74 61 62 ).<br><br>..<tab
0af0: 6c 65 20 62 67 63 6f 6c 6f 72 3d 22 23 65 30 66 le bgcolor="#e0f
0b00: 66 65 30 22 20 63 65 6c 6c 73 70 61 63 69 6e 67 fe0" cellspacing
0b10: 3d 22 38 22 20 63 65 6c 6c 70 61 64 64 69 6e 67 ="8" cellpadding
0b20: 3d 22 36 22 20 62 6f 72 64 65 72 3d 22 31 22 3e ="6" border="1">
0b30: 0d 0a 3c 74 72 3e 3c 74 68 3e 53 51 4c 20 71 75 ..<tr><th>SQL qu
0b40: 65 72 79 3c 2f 74 68 3e 3c 74 68 3e 56 69 73 75 ery</th><th>Visu
0b50: 61 6c 20 53 61 6d 70 6c 65 3c 2f 74 68 3e 3c 2f al Sample</th></
0b60: 74 72 3e 0d 0a 3c 74 72 3e 0d 0a 3c 74 64 3e 0d tr>..<tr>..<td>.
0b70: 0a 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 53 45 4c .<verbatim>..SEL
0b80: 45 43 54 20 53 54 5f 53 75 62 64 69 76 69 64 65 ECT ST_Subdivide
0b90: 28 67 65 6f 6d 65 74 72 79 29 20 46 52 4f 4d 20 (geometry) FROM
0ba0: 74 75 73 63 61 6e 79 3b 0d 0a 3c 2f 76 65 72 62 tuscany;..</verb
0bb0: 61 74 69 6d 3e 0d 0a 69 6e 20 74 68 69 73 20 66 atim>..in this f
0bc0: 69 72 73 74 20 63 61 6c 6c 20 6e 6f 20 6f 70 74 irst call no opt
0bd0: 69 6f 6e 61 6c 20 61 72 67 75 6d 65 6e 74 20 69 ional argument i
0be0: 73 20 73 70 65 63 69 66 69 65 64 2c 20 61 6e 64 s specified, and
0bf0: 20 74 68 75 73 20 3c 62 3e 53 54 5f 53 75 62 64 thus <b>ST_Subd
0c00: 69 76 69 64 65 28 29 3c 2f 62 3e 20 77 69 6c 6c ivide()</b> will
0c10: 20 69 6d 70 6c 69 63 69 74 6c 79 20 61 73 73 75 implicitly assu
0c20: 6d 65 20 74 68 65 20 73 74 61 6e 64 61 72 64 20 me the standard
0c30: 74 68 72 65 73 68 6f 6c 64 20 6f 66 20 3c 62 3e threshold of <b>
0c40: 6d 61 78 20 31 32 38 3c 2f 62 3e 20 56 65 72 74 max 128</b> Vert
0c50: 69 63 65 73 2e 3c 62 72 3e 3c 62 72 3e 0d 0a 41 ices.<br><br>..A
0c60: 73 20 74 68 65 20 73 69 64 65 20 66 69 67 75 72 s the side figur
0c70: 65 20 73 68 6f 77 73 2c 20 74 68 65 20 72 65 74 e shows, the ret
0c80: 75 72 6e 65 64 20 72 65 73 75 6c 74 20 69 73 20 urned result is
0c90: 61 20 63 6f 6c 6c 65 63 74 69 6f 6e 20 6f 66 20 a collection of
0ca0: 61 62 6f 75 74 20 34 2c 33 30 30 2b 20 65 6c 65 about 4,300+ ele
0cb0: 6d 65 6e 74 61 72 79 20 70 61 72 74 73 2e 0d 0a mentary parts...
0cc0: 3c 2f 74 64 3e 0d 0a 3c 74 64 3e 0d 0a 3c 69 6d </td>..<td>..<im
0cd0: 67 20 73 72 63 3d 22 68 74 74 70 73 3a 2f 2f 77 g src="https://w
0ce0: 77 77 2e 67 61 69 61 2d 67 69 73 2e 69 74 2f 67 ww.gaia-gis.it/g
0cf0: 61 69 61 2d 73 69 6e 73 2f 73 75 62 64 69 76 69 aia-sins/subdivi
0d00: 64 65 2f 73 75 62 31 32 38 2e 70 6e 67 22 20 61 de/sub128.png" a
0d10: 6c 74 3d 22 6d 61 78 3d 31 32 38 22 3e 0d 0a 3c lt="max=128">..<
0d20: 2f 74 64 3e 0d 0a 3c 2f 74 72 3e 0d 0a 3c 74 72 /td>..</tr>..<tr
0d30: 3e 0d 0a 3c 74 64 3e 0d 0a 3c 76 65 72 62 61 74 >..<td>..<verbat
0d40: 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 53 54 5f 53 im>..SELECT ST_S
0d50: 75 62 64 69 76 69 64 65 28 67 65 6f 6d 65 74 72 ubdivide(geometr
0d60: 79 2c 20 35 31 32 29 20 46 52 4f 4d 20 74 75 73 y, 512) FROM tus
0d70: 63 61 6e 79 3b 0d 0a 3c 2f 76 65 72 62 61 74 69 cany;..</verbati
0d80: 6d 3e 0d 0a 69 6e 20 74 68 69 73 20 73 65 63 6f m>..in this seco
0d90: 6e 64 20 63 61 6c 6c 20 74 68 65 20 6f 70 74 69 nd call the opti
0da0: 6f 6e 61 6c 20 61 72 67 75 6d 65 6e 74 20 69 73 onal argument is
0db0: 20 65 78 70 6c 69 63 69 74 6c 79 20 73 65 74 2c explicitly set,
0dc0: 20 61 6e 64 20 3c 62 3e 53 54 5f 53 75 62 64 69 and <b>ST_Subdi
0dd0: 76 69 64 65 28 29 3c 2f 62 3e 20 69 73 20 6e 6f vide()</b> is no
0de0: 77 20 61 73 73 75 6d 69 6e 67 20 61 20 74 68 72 w assuming a thr
0df0: 65 73 68 6f 6c 64 20 6f 66 20 3c 62 3e 6d 61 78 eshold of <b>max
0e00: 20 35 31 32 3c 2f 62 3e 20 56 65 72 74 69 63 65 512</b> Vertice
0e10: 73 2e 3c 62 72 3e 3c 62 72 3e 0d 0a 41 73 20 74 s.<br><br>..As t
0e20: 68 65 20 73 69 64 65 20 66 69 67 75 72 65 20 73 he side figure s
0e30: 68 6f 77 73 2c 20 74 68 65 20 72 65 74 75 72 6e hows, the return
0e40: 65 64 20 72 65 73 75 6c 74 20 69 73 20 61 20 63 ed result is a c
0e50: 6f 6c 6c 65 63 74 69 6f 6e 20 6f 66 20 61 62 6f ollection of abo
0e60: 75 74 20 31 2c 38 30 30 2b 20 65 6c 65 6d 65 6e ut 1,800+ elemen
0e70: 74 61 72 79 20 70 61 72 74 73 2e 0d 0a 3c 2f 74 tary parts...</t
0e80: 64 3e 0d 0a 3c 74 64 3e 0d 0a 3c 69 6d 67 20 73 d>..<td>..<img s
0e90: 72 63 3d 22 68 74 74 70 73 3a 2f 2f 77 77 77 2e rc="https://www.
0ea0: 67 61 69 61 2d 67 69 73 2e 69 74 2f 67 61 69 61 gaia-gis.it/gaia
0eb0: 2d 73 69 6e 73 2f 73 75 62 64 69 76 69 64 65 2f -sins/subdivide/
0ec0: 73 75 62 35 31 32 2e 70 6e 67 22 20 61 6c 74 3d sub512.png" alt=
0ed0: 22 6d 61 78 3d 35 31 32 22 3e 0d 0a 3c 2f 74 64 "max=512">..</td
0ee0: 3e 0d 0a 3c 2f 74 72 3e 0d 0a 3c 74 72 3e 0d 0a >..</tr>..<tr>..
0ef0: 3c 74 64 3e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e <td>..<verbatim>
0f00: 0d 0a 53 45 4c 45 43 54 20 53 54 5f 53 75 62 64 ..SELECT ST_Subd
0f10: 69 76 69 64 65 28 67 65 6f 6d 65 74 72 79 2c 20 ivide(geometry,
0f20: 32 30 34 38 29 20 46 52 4f 4d 20 74 75 73 63 61 2048) FROM tusca
0f30: 6e 79 3b 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e ny;..</verbatim>
0f40: 0d 0a 69 6e 20 74 68 69 73 20 74 68 69 72 64 20 ..in this third
0f50: 61 6e 64 20 66 69 6e 61 6c 20 63 61 6c 6c 20 74 and final call t
0f60: 68 65 20 74 68 72 65 73 68 6f 6c 64 20 69 73 20 he threshold is
0f70: 73 65 74 20 74 6f 20 3c 62 3e 6d 61 78 20 32 2c set to <b>max 2,
0f80: 30 34 38 3c 2f 62 3e 20 56 65 72 74 69 63 65 73 048</b> Vertices
0f90: 2e 3c 62 72 3e 3c 62 72 3e 0d 0a 41 73 20 73 68 .<br><br>..As sh
0fa0: 6f 77 6e 20 62 79 20 74 68 65 20 66 69 67 75 72 own by the figur
0fb0: 65 2c 20 74 68 65 20 72 65 74 75 72 6e 65 64 20 e, the returned
0fc0: 72 65 73 75 6c 74 20 69 73 20 6e 6f 77 20 61 20 result is now a
0fd0: 63 6f 6c 6c 65 63 74 69 6f 6e 20 63 6f 6e 74 61 collection conta
0fe0: 69 6e 69 6e 67 20 6a 75 73 74 20 31 2c 32 30 30 ining just 1,200
0ff0: 2b 20 65 6c 65 6d 65 6e 74 61 72 79 20 70 61 72 + elementary par
1000: 74 73 2e 0d 0a 3c 68 33 3e 53 68 6f 72 74 20 63 ts...<h3>Short c
1010: 6f 6e 63 6c 75 73 69 6f 6e 3c 2f 68 33 3e 0d 0a onclusion</h3>..
1020: 3c 62 3e 53 54 5f 53 75 62 64 69 76 69 64 65 28 <b>ST_Subdivide(
1030: 29 3c 2f 62 3e 20 69 73 20 65 66 66 65 63 74 69 )</b> is effecti
1040: 76 65 6c 79 20 63 61 70 61 62 6c 65 20 74 6f 20 vely capable to
1050: 73 75 62 64 69 76 69 64 65 20 73 6f 6d 65 20 6e subdivide some n
1060: 61 73 74 79 20 68 75 67 65 20 47 65 6f 6d 65 74 asty huge Geomet
1070: 72 79 20 69 6e 74 6f 20 61 20 63 6f 6c 6c 65 63 ry into a collec
1080: 74 69 6f 6e 20 6f 66 20 6d 61 6e 79 20 73 6d 61 tion of many sma
1090: 6c 6c 65 72 20 70 61 72 74 73 20 6d 75 63 68 20 ller parts much
10a0: 6d 6f 72 65 20 72 65 61 73 6f 6e 61 62 6c 65 20 more reasonable
10b0: 74 6f 20 62 65 20 68 61 6e 64 6c 65 64 2e 3c 62 to be handled.<b
10c0: 72 3e 0d 0a 41 6e 64 20 69 74 27 73 20 72 65 61 r>..And it's rea
10d0: 73 6f 6e 61 62 6c 79 20 66 6c 65 78 69 62 6c 65 sonably flexible
10e0: 20 61 6e 64 20 65 61 73 79 20 74 6f 20 62 65 20 and easy to be
10f0: 63 75 73 74 6f 6d 69 7a 65 64 20 61 73 20 72 65 customized as re
1100: 71 75 69 72 65 64 3b 20 79 6f 75 20 6a 75 73 74 quired; you just
1110: 20 68 61 76 65 20 74 6f 20 73 65 74 20 74 68 65 have to set the
1120: 20 6d 6f 73 74 20 61 70 70 72 6f 70 72 69 61 74 most appropriat
1130: 65 20 3c 62 3e 6d 61 78 2e 20 56 65 72 74 69 63 e <b>max. Vertic
1140: 65 73 3c 2f 62 3e 20 74 68 72 65 73 68 6f 6c 64 es</b> threshold
1150: 2e 0d 0a 3c 2f 74 64 3e 0d 0a 3c 74 64 3e 0d 0a ...</td>..<td>..
1160: 3c 69 6d 67 20 73 72 63 3d 22 68 74 74 70 73 3a <img src="https:
1170: 2f 2f 77 77 77 2e 67 61 69 61 2d 67 69 73 2e 69 //www.gaia-gis.i
1180: 74 2f 67 61 69 61 2d 73 69 6e 73 2f 73 75 62 64 t/gaia-sins/subd
1190: 69 76 69 64 65 2f 73 75 62 32 30 34 38 2e 70 6e ivide/sub2048.pn
11a0: 67 22 20 61 6c 74 3d 22 6d 61 78 3d 32 30 34 38 g" alt="max=2048
11b0: 22 3e 0d 0a 3c 2f 74 64 3e 0d 0a 3c 2f 74 72 3e ">..</td>..</tr>
11c0: 0d 0a 3c 2f 74 61 62 6c 65 3e 0d 0a 3c 62 72 3e ..</table>..<br>
11d0: 0d 0a 48 6f 77 65 76 65 72 2c 20 61 20 3c 62 3e ..However, a <b>
11e0: 62 69 67 20 63 61 76 65 61 74 3c 2f 62 3e 20 73 big caveat</b> s
11f0: 68 6f 75 6c 64 20 62 65 20 61 6c 77 61 79 73 20 hould be always
1200: 63 6f 6e 73 69 64 65 72 65 64 20 61 62 6f 75 74 considered about
1210: 20 74 68 65 20 6d 75 6c 74 69 2d 70 61 72 74 20 the multi-part
1220: 63 6f 6c 6c 65 63 74 69 6f 6e 73 20 72 65 74 75 collections retu
1230: 72 6e 65 64 20 62 79 20 3c 62 3e 53 54 5f 53 75 rned by <b>ST_Su
1240: 62 64 69 76 69 64 65 28 29 3c 2f 62 3e 2e 3c 62 bdivide()</b>.<b
1250: 72 3e 0d 0a 41 74 20 6c 65 61 73 74 20 69 6e 20 r>..At least in
1260: 74 68 65 20 63 61 73 65 20 6f 66 20 3c 62 3e 4d the case of <b>M
1270: 75 6c 74 69 50 6f 6c 79 67 6f 6e 73 3c 2f 62 3e ultiPolygons</b>
1280: 20 61 6e 79 20 63 6f 6c 6c 65 63 74 69 6f 6e 20 any collection
1290: 72 65 74 75 72 6e 65 64 20 62 79 20 53 54 5f 53 returned by ST_S
12a0: 75 62 64 69 76 69 64 65 28 29 20 69 73 20 69 6e ubdivide() is in
12b0: 68 65 72 65 6e 74 6c 79 20 69 6e 76 61 6c 69 64 herently invalid
12c0: 2c 20 61 73 20 74 68 65 20 66 6f 6c 6c 6f 77 69 , as the followi
12d0: 6e 67 20 53 51 4c 20 71 75 65 72 79 20 64 65 6d ng SQL query dem
12e0: 6f 6e 73 74 72 61 74 65 73 3a 0d 0a 3c 76 65 72 onstrates:..<ver
12f0: 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 53 batim>..SELECT S
1300: 54 5f 49 73 56 61 6c 69 64 28 53 54 5f 53 75 62 T_IsValid(ST_Sub
1310: 64 69 76 69 64 65 28 67 65 6f 6d 65 74 72 79 29 divide(geometry)
1320: 29 20 46 52 4f 4d 20 74 75 73 63 61 6e 79 3b 0d ) FROM tuscany;.
1330: 0a 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 30 0d 0a 3c .---------..0..<
1340: 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 49 74 27 73 /verbatim>..It's
1350: 20 6e 6f 74 20 61 74 20 61 6c 6c 20 64 69 66 66 not at all diff
1360: 69 63 75 6c 74 20 75 6e 64 65 73 74 61 6e 64 69 icult undestandi
1370: 6e 67 20 77 68 79 20 74 68 69 73 20 68 61 70 70 ng why this happ
1380: 65 6e 73 2e 3c 62 72 3e 0d 0a 41 63 63 6f 72 64 ens.<br>..Accord
1390: 69 6e 67 6c 79 20 74 6f 20 73 74 61 6e 64 61 72 ingly to standar
13a0: 64 20 3c 62 3e 4f 47 43 2f 53 46 53 3c 2f 62 3e d <b>OGC/SFS</b>
13b0: 20 72 75 6c 65 73 20 74 77 6f 20 73 69 6e 67 6c rules two singl
13c0: 65 2d 70 61 72 74 20 50 6f 6c 79 67 6f 6e 73 20 e-part Polygons
13d0: 62 65 6c 6f 6e 67 69 6e 67 20 74 6f 20 74 68 65 belonging to the
13e0: 20 73 61 6d 65 20 4d 75 6c 74 69 50 6f 6c 79 67 same MultiPolyg
13f0: 6f 6e 20 61 72 65 20 61 6c 77 61 79 65 73 20 66 on are alwayes f
1400: 6f 72 62 69 64 64 65 6e 20 74 6f 20 72 65 63 69 orbidden to reci
1410: 70 72 6f 63 61 6c 6c 79 20 74 6f 75 63 68 2e 3c procally touch.<
1420: 62 72 3e 0d 0a 4d 6f 72 65 20 70 72 65 63 69 73 br>..More precis
1430: 65 6c 79 3a 20 74 68 65 79 20 63 61 6e 20 6f 6e ely: they can on
1440: 6c 79 20 74 6f 75 63 68 20 6f 6e 20 73 70 65 63 ly touch on spec
1450: 69 66 69 63 20 70 6f 69 6e 74 28 73 29 2c 20 62 ific point(s), b
1460: 75 74 20 74 68 65 79 20 63 61 6e 20 6e 65 76 65 ut they can neve
1470: 72 20 73 68 61 72 65 20 61 20 63 6f 6d 6d 6f 6e r share a common
1480: 20 62 6f 75 6e 64 61 72 79 2e 3c 62 72 3e 3c 62 boundary.<br><b
1490: 72 3e 0d 0a 3c 74 61 62 6c 65 20 62 67 63 6f 6c r>..<table bgcol
14a0: 6f 72 3d 22 23 66 66 64 30 64 30 22 20 63 65 6c or="#ffd0d0" cel
14b0: 6c 73 70 61 63 69 6e 67 3d 22 38 22 20 63 65 6c lspacing="8" cel
14c0: 6c 70 61 64 64 69 6e 67 3d 22 36 22 3e 0d 0a 3c lpadding="6">..<
14d0: 74 72 3e 3c 74 64 20 61 6c 69 67 6e 3d 22 63 65 tr><td align="ce
14e0: 6e 74 65 72 22 3e 3c 68 33 3e 43 61 76 65 61 74 nter"><h3>Caveat
14f0: 20 21 21 21 3c 2f 68 33 3e 3c 2f 74 64 3e 3c 2f !!!</h3></td></
1500: 74 72 3e 0d 0a 3c 74 72 3e 3c 74 64 3e 3c 62 3e tr>..<tr><td><b>
1510: 4e 65 76 65 72 20 65 76 65 72 3c 2f 62 3e 20 64 Never ever</b> d
1520: 69 72 65 63 74 6c 79 20 70 61 73 73 20 61 20 47 irectly pass a G
1530: 65 6f 6d 65 74 72 79 20 6f 66 20 74 68 69 73 20 eometry of this
1540: 6b 69 6e 64 20 74 6f 20 61 6e 79 20 53 70 61 74 kind to any Spat
1550: 69 61 6c 20 6f 70 65 72 61 74 6f 72 20 73 75 63 ial operator suc
1560: 68 20 61 73 20 53 54 5f 49 6e 74 65 72 73 65 63 h as ST_Intersec
1570: 74 73 2c 20 53 54 5f 54 6f 75 63 68 65 73 2c 20 ts, ST_Touches,
1580: 53 54 5f 43 6f 76 65 72 73 20 61 6e 64 20 61 6c ST_Covers and al
1590: 69 6b 65 2e 3c 62 72 3e 3c 62 72 3e 0d 0a 54 68 ike.<br><br>..Th
15a0: 69 73 20 77 69 6c 6c 20 63 65 72 74 61 69 6e 6c is will certainl
15b0: 79 20 6d 61 6b 65 20 63 72 61 7a 79 20 74 68 65 y make crazy the
15c0: 20 3c 62 3e 47 45 4f 53 3c 2f 62 3e 20 6c 69 62 <b>GEOS</b> lib
15d0: 72 61 72 79 2e 3c 62 72 3e 0d 0a 55 6e 63 6f 72 rary.<br>..Uncor
15e0: 72 65 63 74 20 72 65 73 75 6c 74 73 20 6d 61 79 rect results may
15f0: 20 65 61 73 69 6c 79 20 66 6f 6c 6c 6f 77 2e 3c easily follow.<
1600: 62 72 3e 0d 0a 41 6e 64 20 69 6e 20 74 68 65 20 br>..And in the
1610: 77 6f 72 73 74 20 63 61 73 65 20 73 6f 6d 65 20 worst case some
1620: 75 6e 65 78 70 65 63 74 65 64 20 63 72 61 73 68 unexpected crash
1630: 20 63 6f 75 6c 64 20 65 76 65 6e 74 75 61 6c 6c could eventuall
1640: 79 20 6f 63 63 75 72 2e 0d 0a 3c 68 33 3e 59 6f y occur...<h3>Yo
1650: 75 20 68 61 76 65 20 62 65 65 6e 20 77 61 72 6e u have been warn
1660: 65 64 20 21 21 21 3c 2f 68 33 3e 0d 0a 3c 2f 74 ed !!!</h3>..</t
1670: 64 3e 0d 0a 3c 2f 74 72 3e 0d 0a 3c 2f 74 61 62 d>..</tr>..</tab
1680: 6c 65 3e 0d 0a 3c 62 72 3e 3c 62 72 3e 0d 0a 3c le>..<br><br>..<
1690: 68 72 3e 0d 0a 3c 68 32 3e 41 64 76 61 6e 63 65 hr>..<h2>Advance
16a0: 64 20 45 78 61 6d 70 6c 65 73 3c 2f 68 32 3e 0d d Examples</h2>.
16b0: 0a 4e 6f 77 20 77 65 27 6c 6c 20 67 6f 20 74 6f .Now we'll go to
16c0: 20 65 78 70 6c 6f 72 65 20 74 68 65 20 72 65 61 explore the rea
16d0: 6c 20 65 66 66 65 63 74 69 76 65 6e 65 73 73 20 l effectiveness
16e0: 6f 66 20 3c 62 3e 53 54 5f 53 75 62 64 69 76 69 of <b>ST_Subdivi
16f0: 64 65 28 29 3c 2f 62 3e 20 69 6e 20 6f 6e 65 20 de()</b> in one
1700: 6f 66 20 74 68 65 20 6d 6f 73 74 20 63 6f 6d 6d of the most comm
1710: 6f 6e 20 53 70 61 74 69 61 6c 20 50 72 6f 62 6c on Spatial Probl
1720: 65 6d 73 3a 20 69 64 65 6e 74 69 66 79 69 6e 67 ems: identifying
1730: 20 61 6c 6c 20 69 6e 74 65 72 73 65 63 74 69 6f all intersectio
1740: 6e 73 20 62 65 74 77 65 65 6e 20 61 20 64 61 74 ns between a dat
1750: 61 73 65 74 20 6f 66 20 74 68 65 20 50 4f 49 4e aset of the POIN
1760: 54 20 74 79 70 65 20 61 6e 64 20 61 20 68 75 67 T type and a hug
1770: 65 20 50 6f 6c 79 67 6f 6e 2f 4d 75 6c 74 69 70 e Polygon/Multip
1780: 6f 6c 79 67 6f 6e 2e 3c 62 72 3e 3c 62 72 3e 0d olygon.<br><br>.
1790: 0a 44 75 72 69 6e 67 20 74 68 69 73 20 73 65 63 .During this sec
17a0: 6f 6e 64 20 74 65 73 74 20 77 65 27 6c 6c 20 75 ond test we'll u
17b0: 73 65 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 se the following
17c0: 20 64 61 74 61 73 65 74 73 3a 0d 0a 3c 75 6c 3e datasets:..<ul>
17d0: 0d 0a 3c 6c 69 3e 6f 6e 63 65 20 61 67 61 69 6e ..<li>once again
17e0: 2c 20 74 68 65 20 73 61 6d 65 20 61 64 6d 69 6e , the same admin
17f0: 69 73 74 72 61 74 69 76 65 20 62 6f 75 6e 64 61 istrative bounda
1800: 72 79 20 6f 66 20 54 75 73 63 61 6e 79 20 77 65 ry of Tuscany we
1810: 27 76 65 20 61 6c 72 65 61 64 79 20 75 73 65 64 've already used
1820: 20 62 65 66 6f 72 65 2e 3c 2f 6c 69 3e 0d 0a 3c before.</li>..<
1830: 6c 69 3e 69 6e 20 74 68 65 20 72 6f 6c 65 20 6f li>in the role o
1840: 66 20 74 68 65 20 50 4f 49 4e 54 20 64 61 74 61 f the POINT data
1850: 73 65 74 20 77 65 27 6c 6c 20 75 73 65 20 74 68 set we'll use th
1860: 65 20 3c 62 3e 63 69 76 69 63 69 3c 2f 62 3e 20 e <b>civici</b>
1870: 53 68 61 70 65 66 69 6c 65 20 28 3c 69 3e 48 6f Shapefile (<i>Ho
1880: 75 73 65 20 4e 75 6d 65 72 73 3c 2f 69 3e 29 20 use Numers</i>)
1890: 66 72 65 65 6c 79 20 61 76 61 69 6c 61 62 6c 65 freely available
18a0: 20 66 6f 72 20 64 6f 77 6e 6c 6f 61 64 20 66 72 for download fr
18b0: 6f 6d 20 3c 61 20 68 72 65 66 3d 22 68 74 74 70 om <a href="http
18c0: 3a 2f 2f 77 77 77 35 30 32 2e 72 65 67 69 6f 6e ://www502.region
18d0: 65 2e 74 6f 73 63 61 6e 61 2e 69 74 2f 67 65 6f e.toscana.it/geo
18e0: 73 63 6f 70 69 6f 2f 63 61 72 74 6f 74 65 63 61 scopio/cartoteca
18f0: 2e 68 74 6d 6c 22 3e 68 65 72 65 3c 2f 61 3e 20 .html">here</a>
1900: 28 73 65 61 72 63 68 20 66 6f 72 20 3c 62 3e 47 (search for <b>G
1910: 72 61 66 6f 20 53 74 72 61 64 61 6c 65 3c 2f 62 rafo Stradale</b
1920: 3e 20 2d 20 3c 69 3e 52 6f 61 64 20 4e 65 74 77 > - <i>Road Netw
1930: 6f 72 6b 3c 2f 69 3e 29 2e 3c 62 72 3e 0d 0a 54 ork</i>).<br>..T
1940: 68 69 73 20 74 6f 6f 20 69 73 20 61 20 68 75 67 his too is a hug
1950: 65 20 64 61 74 61 73 65 74 20 63 6f 6e 74 61 69 e dataset contai
1960: 6e 69 6e 67 20 61 62 6f 75 74 20 31 2e 35 20 6d ning about 1.5 m
1970: 69 6c 6c 69 6f 6e 20 70 6f 69 6e 74 73 2e 0d 0a illion points...
1980: 3c 2f 75 6c 3e 0d 0a 3c 68 33 3e 41 20 66 69 72 </ul>..<h3>A fir
1990: 73 74 20 6e 61 69 76 65 20 61 74 74 65 6d 70 3c st naive attemp<
19a0: 2f 68 33 3e 0d 0a 3c 76 65 72 62 61 74 69 6d 3e /h3>..<verbatim>
19b0: 0d 0a 53 45 4c 45 43 54 20 43 6f 75 6e 74 28 2a ..SELECT Count(*
19c0: 29 0d 0a 46 52 4f 4d 20 63 69 76 69 63 69 20 41 )..FROM civici A
19d0: 53 20 63 0d 0a 4c 45 46 54 20 4a 4f 49 4e 20 74 S c..LEFT JOIN t
19e0: 75 73 63 61 6e 79 20 41 53 20 74 20 4f 4e 20 28 uscany AS t ON (
19f0: 53 54 5f 49 6e 74 65 72 73 65 63 74 73 28 63 2e ST_Intersects(c.
1a00: 67 65 6f 6d 65 74 72 79 2c 20 74 2e 67 65 6f 6d geometry, t.geom
1a10: 65 74 72 79 29 20 3d 20 31 29 3b 0d 0a 0d 0a 0d etry) = 1);.....
1a20: 0a 53 45 4c 45 43 54 20 43 6f 75 6e 74 28 2a 29 .SELECT Count(*)
1a30: 0d 0a 46 52 4f 4d 20 63 69 76 69 63 69 20 41 53 ..FROM civici AS
1a40: 20 63 0d 0a 4c 45 46 54 20 4a 4f 49 4e 20 74 75 c..LEFT JOIN tu
1a50: 73 63 61 6e 79 20 41 53 20 74 20 4f 4e 20 28 53 scany AS t ON (S
1a60: 54 5f 49 6e 74 65 72 73 65 63 74 73 28 63 2e 67 T_Intersects(c.g
1a70: 65 6f 6d 65 74 72 79 2c 20 74 2e 67 65 6f 6d 65 eometry, t.geome
1a80: 74 72 79 29 20 3d 20 31 20 0d 0a 20 20 20 20 20 try) = 1 ..
1a90: 41 4e 44 20 63 2e 72 6f 77 69 64 20 49 4e 20 28 AND c.rowid IN (
1aa0: 0d 0a 20 20 20 20 20 20 20 20 20 53 45 4c 45 43 .. SELEC
1ab0: 54 20 72 6f 77 69 64 20 46 52 4f 4d 20 53 70 61 T rowid FROM Spa
1ac0: 74 69 61 6c 49 6e 64 65 78 0d 0a 20 20 20 20 20 tialIndex..
1ad0: 20 20 20 20 57 48 45 52 45 20 66 5f 74 61 62 6c WHERE f_tabl
1ae0: 65 5f 6e 61 6d 65 20 3d 20 27 63 69 76 69 63 69 e_name = 'civici
1af0: 27 20 41 4e 44 20 73 65 61 72 63 68 5f 66 72 61 ' AND search_fra
1b00: 6d 65 20 3d 20 74 2e 67 65 6f 6d 65 74 72 79 29 me = t.geometry)
1b10: 29 3b 0d 0a 3c 2f 76 65 72 62 61 74 69 6d 3e 0d );..</verbatim>.
1b20: 0a 54 68 65 20 6f 6e 6c 79 20 64 69 66 66 65 72 .The only differ
1b30: 65 6e 63 65 20 62 65 74 77 65 65 6e 20 74 68 65 ence between the
1b40: 20 61 62 6f 76 65 20 74 77 6f 20 53 51 4c 20 71 above two SQL q
1b50: 75 65 72 69 65 73 20 69 73 20 69 6e 20 74 68 61 ueries is in tha
1b60: 74 20 74 68 65 20 73 65 63 6f 6e 64 20 6f 6e 65 t the second one
1b70: 20 65 78 70 6c 69 63 69 74 6c 79 20 63 61 6c 6c explicitly call
1b80: 73 20 74 68 65 20 53 70 61 74 69 61 6c 20 49 6e s the Spatial In
1b90: 64 65 78 2e 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 62 dex.<br><br>..<b
1ba0: 3e 41 63 74 75 61 6c 20 66 69 6e 64 69 6e 67 73 >Actual findings
1bb0: 3c 2f 62 3e 3a 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 </b>:..<ul>..<li
1bc0: 3e 49 20 77 61 73 20 66 6f 72 63 65 64 20 74 6f >I was forced to
1bd0: 20 70 72 65 6d 61 74 75 72 65 6c 79 20 61 62 6f prematurely abo
1be0: 72 74 20 74 68 65 20 66 69 72 73 74 20 74 65 73 rt the first tes
1bf0: 74 20 77 68 65 6e 20 49 20 64 69 73 63 6f 76 65 t when I discove
1c00: 72 65 64 20 74 68 61 74 20 64 75 72 69 6e 67 20 red that during
1c10: 74 68 65 20 66 69 72 73 74 20 68 61 6c 66 20 61 the first half a
1c20: 6e 20 68 6f 75 72 20 69 74 20 68 61 76 65 20 6d n hour it have m
1c30: 61 64 65 20 61 20 76 65 72 79 20 6c 69 74 74 6c ade a very littl
1c40: 65 20 70 72 6f 67 72 65 73 73 2e 3c 62 72 3e 0d e progress.<br>.
1c50: 0a 41 63 63 6f 72 64 69 6e 67 6c 79 20 74 6f 20 .Accordingly to
1c60: 6d 79 20 65 78 74 69 6d 61 74 65 64 20 65 73 74 my extimated est
1c70: 72 61 70 6f 6c 61 74 69 6f 6e 2c 20 77 61 69 74 rapolation, wait
1c80: 69 6e 67 20 66 6f 72 20 63 6f 6d 70 6c 65 74 69 ing for completi
1c90: 6f 6e 20 77 69 6c 6c 20 68 61 76 65 20 70 72 65 on will have pre
1ca0: 61 73 75 6d 61 62 6c 79 20 72 65 71 75 69 72 65 asumably require
1cb0: 64 20 62 65 74 77 65 65 6e 20 34 20 61 6e 64 20 d between 4 and
1cc0: 36 20 68 6f 75 72 73 2e 3c 62 72 3e 0d 0a 44 65 6 hours.<br>..De
1cd0: 66 69 6e 69 74 65 6c 79 20 74 68 69 73 20 69 73 finitely this is
1ce0: 6e 27 74 20 61 20 70 72 61 63 74 69 63 61 6c 20 n't a practical
1cf0: 73 6f 6c 75 74 69 6f 6e 20 66 6f 72 20 6f 75 72 solution for our
1d00: 20 70 72 6f 62 6c 65 6d 2e 3c 2f 6c 69 3e 0d 0a problem.</li>..
1d10: 3c 6c 69 3e 74 68 65 20 73 65 63 6f 6e 64 20 74 <li>the second t
1d20: 65 73 74 20 77 61 73 2c 20 69 66 20 70 6f 73 73 est was, if poss
1d30: 69 62 6c 65 2c 20 65 76 65 6e 20 73 6c 6f 77 65 ible, even slowe
1d40: 72 20 74 68 61 6e 20 74 68 65 20 66 69 72 73 74 r than the first
1d50: 20 6f 6e 65 2e 3c 62 72 3e 0d 0a 41 6e 64 20 74 one.<br>..And t
1d60: 68 65 72 65 20 69 73 20 76 65 72 79 20 67 6f 6f here is very goo
1d70: 64 20 72 65 61 73 6f 6e 20 65 78 70 6c 61 69 6e d reason explain
1d80: 69 6e 67 20 66 6f 72 20 74 68 69 73 3b 20 61 6c ing for this; al
1d90: 6c 20 50 6f 69 6e 74 73 20 74 6f 20 62 65 20 63 l Points to be c
1da0: 68 65 63 6b 65 64 20 66 61 6c 6c 20 69 6e 73 69 hecked fall insi
1db0: 64 65 20 74 68 20 42 42 4f 58 20 6f 66 20 54 75 de th BBOX of Tu
1dc0: 73 63 61 6e 79 2e 3c 62 72 3e 0d 0a 53 6f 20 74 scany.<br>..So t
1dd0: 68 65 20 53 70 61 74 69 61 6c 20 49 6e 64 65 78 he Spatial Index
1de0: 20 69 73 6e 27 74 20 6f 66 20 61 6e 79 20 70 6f isn't of any po
1df0: 73 73 69 62 6c 65 20 68 65 6c 70 2e 3c 62 72 3e ssible help.<br>
1e00: 0d 0a 41 6e 64 20 65 76 65 6e 20 77 6f 72 73 74 ..And even worst
1e10: 2c 20 71 75 65 72 79 69 6e 67 20 74 68 65 20 53 , querying the S
1e20: 70 61 74 69 61 6c 20 49 6e 64 65 78 20 69 6d 70 patial Index imp
1e30: 6f 73 65 73 20 61 20 66 75 72 74 68 65 72 20 6f oses a further o
1e40: 76 65 72 68 65 61 64 2c 20 74 68 75 73 20 72 65 verhead, thus re
1e50: 71 75 69 72 69 6e 67 20 61 20 6c 6f 6e 67 65 72 quiring a longer
1e60: 20 74 69 6d 65 20 66 6f 72 20 61 62 73 6f 6c 75 time for absolu
1e70: 74 65 6c 79 20 6e 6f 74 68 69 6e 67 2e 3c 2f 6c tely nothing.</l
1e80: 69 3e 0d 0a 3c 6c 69 3e 3c 62 3e 53 68 6f 72 74 i>..<li><b>Short
1e90: 20 63 6f 6e 63 6c 75 73 69 6f 6e 3c 2f 62 3e 3a conclusion</b>:
1ea0: 20 63 6f 6d 70 75 74 69 6e 67 20 6d 61 6e 79 20 computing many
1eb0: 6d 69 6c 6c 69 6f 6e 20 74 69 6d 65 73 20 74 68 million times th
1ec0: 65 20 69 6e 74 65 72 73 65 63 74 69 6f 6e 73 20 e intersections
1ed0: 62 65 74 77 65 65 6e 20 61 20 50 6f 69 6e 74 20 between a Point
1ee0: 61 6e 64 20 61 20 50 6f 6c 79 67 6f 6e 20 64 65 and a Polygon de
1ef0: 66 69 6e 65 64 20 62 79 20 73 6f 6d 65 20 68 75 fined by some hu
1f00: 6e 64 72 65 64 74 68 20 74 68 6f 75 73 61 6e 64 ndredth thousand
1f10: 73 20 56 65 72 74 69 63 65 73 20 69 73 20 61 20 s Vertices is a
1f20: 64 61 6d 6e 20 68 61 72 64 20 63 6f 6d 70 75 74 damn hard comput
1f30: 61 74 69 6f 6e 61 6c 20 70 72 6f 62 6c 65 6d 2e ational problem.
1f40: 3c 62 72 3e 20 0d 0a 41 6e 64 20 63 6f 6e 73 65 <br> ..And conse
1f50: 71 75 65 6e 74 6c 79 20 69 74 20 72 65 71 75 69 quently it requi
1f60: 72 65 73 20 61 20 76 65 72 79 20 6c 6f 6e 67 20 res a very long
1f70: 74 69 6d 65 2c 20 73 6f 20 6c 6f 6e 67 20 74 6f time, so long to
1f80: 20 62 65 20 61 62 73 6f 6c 75 74 65 6c 79 20 75 be absolutely u
1f90: 6e 70 72 61 63 74 61 6c 2e 3c 2f 6c 69 3e 0d 0a npractal.</li>..
1fa0: 3c 2f 75 6c 3e 0d 0a 3c 68 33 3e 41 20 73 65 63 </ul>..<h3>A sec
1fb0: 6f 6e 64 20 61 74 74 65 6d 70 20 62 61 73 65 64 ond attemp based
1fc0: 20 6f 6e 20 53 54 5f 53 75 62 64 69 76 69 64 65 on ST_Subdivide
1fd0: 28 29 20 61 6e 64 20 56 69 72 74 75 61 6c 45 6c () and VirtualEl
1fe0: 65 6d 65 6e 74 61 72 79 3c 2f 68 33 3e 0d 0a 3c ementary</h3>..<
1ff0: 76 65 72 62 61 74 69 6d 3e 0d 0a 43 52 45 41 54 verbatim>..CREAT
2000: 45 20 54 41 42 4c 45 20 78 78 20 28 69 64 20 49 E TABLE xx (id I
2010: 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b NTEGER PRIMARY K
2020: 45 59 29 3b 0d 0a 53 45 4c 45 43 54 20 41 64 64 EY);..SELECT Add
2030: 47 65 6f 6d 65 74 72 79 43 6f 6c 75 6d 6e 28 27 GeometryColumn('
2040: 78 78 27 2c 20 27 67 65 6f 6d 27 2c 20 33 30 30 xx', 'geom', 300
2050: 33 2c 20 27 4d 55 4c 54 49 50 4f 4c 59 47 4f 4e 3, 'MULTIPOLYGON
2060: 27 2c 20 27 58 59 27 29 3b 0d 0a 49 4e 53 45 52 ', 'XY');..INSER
2070: 54 20 49 4e 54 4f 20 78 78 20 56 41 4c 55 45 53 T INTO xx VALUES
2080: 20 28 31 2c 20 4e 55 4c 4c 29 3b 0d 0a 3c 2f 76 (1, NULL);..</v
2090: 65 72 62 61 74 69 6d 3e 0d 0a 57 65 27 6c 6c 20 erbatim>..We'll
20a0: 73 74 61 72 74 20 66 69 72 73 74 20 62 79 20 63 start first by c
20b0: 72 65 61 74 69 6e 67 20 61 20 63 6f 6e 76 65 6e reating a conven
20c0: 69 65 6e 63 65 20 54 61 62 6c 65 20 69 6e 74 65 ience Table inte
20d0: 6e 64 65 64 20 74 6f 20 74 65 6d 70 6f 72 61 72 nded to temporar
20e0: 69 6c 79 20 73 74 6f 72 65 20 74 68 65 20 72 65 ily store the re
20f0: 73 75 6c 74 20 6f 66 20 53 54 5f 53 75 62 64 69 sult of ST_Subdi
2100: 76 69 64 65 28 29 2e 20 54 68 69 73 20 54 61 62 vide(). This Tab
2110: 6c 65 20 69 73 20 76 65 72 79 20 73 69 6d 70 6c le is very simpl
2120: 65 3a 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 69 74 e:..<ul>..<li>it
2130: 20 68 61 73 20 6a 75 73 74 20 74 77 6f 20 63 6f has just two co
2140: 6c 75 6d 6e 73 2c 20 61 20 50 72 69 6d 61 72 79 lumns, a Primary
2150: 20 4b 65 79 20 61 6e 64 20 61 20 4d 75 6c 74 69 Key and a Multi
2160: 50 6f 6c 79 67 6f 6e 20 47 65 6f 6d 65 74 72 79 Polygon Geometry
2170: 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 61 6e 64 20 .</li>..<li>and
2180: 69 74 27 73 20 69 6e 74 65 6e 64 65 64 20 74 6f it's intended to
2190: 20 73 74 6f 72 65 20 6a 75 73 74 20 61 20 73 69 store just a si
21a0: 6e 67 6c 65 20 72 6f 77 20 69 64 65 6e 74 69 66 ngle row identif
21b0: 69 65 64 20 62 79 20 3c 62 3e 69 64 3d 31 3c 2f ied by <b>id=1</
21c0: 62 3e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 0d 0a b></li>..</ul>..
21d0: 3c 76 65 72 62 61 74 69 6d 3e 0d 0a 55 50 44 41 <verbatim>..UPDA
21e0: 54 45 20 78 78 20 53 45 54 20 67 65 6f 6d 20 3d TE xx SET geom =
21f0: 20 28 53 45 4c 45 43 54 20 53 54 5f 53 75 62 64 (SELECT ST_Subd
2200: 69 76 69 64 65 28 67 65 6f 6d 65 74 72 79 2c 20 ivide(geometry,
2210: 32 30 34 38 29 20 46 52 4f 4d 20 74 75 73 63 61 2048) FROM tusca
2220: 6e 79 29 20 57 48 45 52 45 20 69 64 20 3d 20 31 ny) WHERE id = 1
2230: 3b 0d 0a 53 45 4c 45 43 54 20 43 6f 75 6e 74 28 ;..SELECT Count(
2240: 2a 29 0d 0a 46 52 4f 4d 20 45 6c 65 6d 65 6e 74 *)..FROM Element
2250: 61 72 79 47 65 6f 6d 65 74 72 69 65 73 20 41 53 aryGeometries AS
2260: 20 74 0d 0a 4a 4f 49 4e 20 63 69 76 69 63 69 20 t..JOIN civici
2270: 41 53 20 63 20 4f 4e 20 28 53 54 5f 49 6e 74 65 AS c ON (ST_Inte
2280: 72 73 65 63 74 73 28 63 2e 67 65 6f 6d 65 74 72 rsects(c.geometr
2290: 79 2c 20 74 2e 67 65 6f 6d 65 74 72 79 29 20 3d y, t.geometry) =
22a0: 20 31 0d 0a 20 20 20 20 20 41 4e 44 20 63 2e 72 1.. AND c.r
22b0: 6f 77 69 64 20 49 4e 20 28 0d 0a 20 20 20 20 20 owid IN (..
22c0: 20 20 20 20 53 45 4c 45 43 54 20 72 6f 77 69 64 SELECT rowid
22d0: 20 46 52 4f 4d 20 53 70 61 74 69 61 6c 49 6e 64 FROM SpatialInd
22e0: 65 78 0d 0a 20 20 20 20 20 20 20 20 20 57 48 45 ex.. WHE
22f0: 52 45 20 66 5f 74 61 62 6c 65 5f 6e 61 6d 65 20 RE f_table_name
2300: 3d 20 27 63 69 76 69 63 69 27 20 41 4e 44 20 73 = 'civici' AND s
2310: 65 61 72 63 68 5f 66 72 61 6d 65 20 3d 20 74 2e earch_frame = t.
2320: 67 65 6f 6d 65 74 72 79 29 29 0d 0a 57 48 45 52 geometry))..WHER
2330: 45 20 66 5f 74 61 62 6c 65 5f 6e 61 6d 65 20 3d E f_table_name =
2340: 20 27 78 78 27 20 41 4e 44 20 6f 72 69 67 69 6e 'xx' AND origin
2350: 5f 72 6f 77 69 64 20 3d 20 31 3b 0d 0a 2d 2d 2d _rowid = 1;..---
2360: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a 31 -------------..1
2370: 34 38 30 39 39 31 20 28 69 6e 20 33 38 2e 30 39 480991 (in 38.09
2380: 34 20 73 65 63 6f 6e 64 73 29 0d 0a 0d 0a 0d 0a 4 seconds)......
2390: 55 50 44 41 54 45 20 78 78 20 53 45 54 20 67 65 UPDATE xx SET ge
23a0: 6f 6d 20 3d 20 28 53 45 4c 45 43 54 20 53 54 5f om = (SELECT ST_
23b0: 53 75 62 64 69 76 69 64 65 28 67 65 6f 6d 65 74 Subdivide(geomet
23c0: 72 79 2c 20 35 31 32 29 20 46 52 4f 4d 20 74 75 ry, 512) FROM tu
23d0: 73 63 61 6e 79 29 20 57 48 45 52 45 20 69 64 20 scany) WHERE id
23e0: 3d 20 31 3b 0d 0a 53 45 4c 45 43 54 20 43 6f 75 = 1;..SELECT Cou
23f0: 6e 74 28 2a 29 0d 0a 46 52 4f 4d 20 45 6c 65 6d nt(*)..FROM Elem
2400: 65 6e 74 61 72 79 47 65 6f 6d 65 74 72 69 65 73 entaryGeometries
2410: 20 41 53 20 74 0d 0a 4a 4f 49 4e 20 63 69 76 69 AS t..JOIN civi
2420: 63 69 20 41 53 20 63 20 4f 4e 20 28 53 54 5f 49 ci AS c ON (ST_I
2430: 6e 74 65 72 73 65 63 74 73 28 63 2e 67 65 6f 6d ntersects(c.geom
2440: 65 74 72 79 2c 20 74 2e 67 65 6f 6d 65 74 72 79 etry, t.geometry
2450: 29 20 3d 20 31 0d 0a 20 20 20 20 20 41 4e 44 20 ) = 1.. AND
2460: 63 2e 72 6f 77 69 64 20 49 4e 20 28 0d 0a 20 20 c.rowid IN (..
2470: 20 20 20 20 20 20 20 53 45 4c 45 43 54 20 72 6f SELECT ro
2480: 77 69 64 20 46 52 4f 4d 20 53 70 61 74 69 61 6c wid FROM Spatial
2490: 49 6e 64 65 78 0d 0a 20 20 20 20 20 20 20 20 20 Index..
24a0: 57 48 45 52 45 20 66 5f 74 61 62 6c 65 5f 6e 61 WHERE f_table_na
24b0: 6d 65 20 3d 20 27 63 69 76 69 63 69 27 20 41 4e me = 'civici' AN
24c0: 44 20 73 65 61 72 63 68 5f 66 72 61 6d 65 20 3d D search_frame =
24d0: 20 74 2e 67 65 6f 6d 65 74 72 79 29 29 0d 0a 57 t.geometry))..W
24e0: 48 45 52 45 20 66 5f 74 61 62 6c 65 5f 6e 61 6d HERE f_table_nam
24f0: 65 20 3d 20 27 78 78 27 20 41 4e 44 20 6f 72 69 e = 'xx' AND ori
2500: 67 69 6e 5f 72 6f 77 69 64 20 3d 20 31 3b 0d 0a gin_rowid = 1;..
2510: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
2520: 0d 0a 31 34 38 30 39 39 31 20 28 69 6e 20 31 32 ..1480991 (in 12
2530: 2e 36 31 37 20 73 65 63 6f 6e 64 73 29 0d 0a 0d .617 seconds)...
2540: 0a 0d 0a 55 50 44 41 54 45 20 78 78 20 53 45 54 ...UPDATE xx SET
2550: 20 67 65 6f 6d 20 3d 20 28 53 45 4c 45 43 54 20 geom = (SELECT
2560: 53 54 5f 53 75 62 64 69 76 69 64 65 28 67 65 6f ST_Subdivide(geo
2570: 6d 65 74 72 79 29 20 46 52 4f 4d 20 74 75 73 63 metry) FROM tusc
2580: 61 6e 79 29 20 57 48 45 52 45 20 69 64 20 3d 20 any) WHERE id =
2590: 31 3b 0d 0a 53 45 4c 45 43 54 20 43 6f 75 6e 74 1;..SELECT Count
25a0: 28 2a 29 0d 0a 46 52 4f 4d 20 45 6c 65 6d 65 6e (*)..FROM Elemen
25b0: 74 61 72 79 47 65 6f 6d 65 74 72 69 65 73 20 41 taryGeometries A
25c0: 53 20 74 0d 0a 4a 4f 49 4e 20 63 69 76 69 63 69 S t..JOIN civici
25d0: 20 41 53 20 63 20 4f 4e 20 28 53 54 5f 49 6e 74 AS c ON (ST_Int
25e0: 65 72 73 65 63 74 73 28 63 2e 67 65 6f 6d 65 74 ersects(c.geomet
25f0: 72 79 2c 20 74 2e 67 65 6f 6d 65 74 72 79 29 20 ry, t.geometry)
2600: 3d 20 31 0d 0a 20 20 20 20 20 41 4e 44 20 63 2e = 1.. AND c.
2610: 72 6f 77 69 64 20 49 4e 20 28 0d 0a 20 20 20 20 rowid IN (..
2620: 20 20 20 20 20 53 45 4c 45 43 54 20 72 6f 77 69 SELECT rowi
2630: 64 20 46 52 4f 4d 20 53 70 61 74 69 61 6c 49 6e d FROM SpatialIn
2640: 64 65 78 0d 0a 20 20 20 20 20 20 20 20 20 57 48 dex.. WH
2650: 45 52 45 20 66 5f 74 61 62 6c 65 5f 6e 61 6d 65 ERE f_table_name
2660: 20 3d 20 27 63 69 76 69 63 69 27 20 41 4e 44 20 = 'civici' AND
2670: 73 65 61 72 63 68 5f 66 72 61 6d 65 20 3d 20 74 search_frame = t
2680: 2e 67 65 6f 6d 65 74 72 79 29 29 0d 0a 57 48 45 .geometry))..WHE
2690: 52 45 20 66 5f 74 61 62 6c 65 5f 6e 61 6d 65 20 RE f_table_name
26a0: 3d 20 27 78 78 27 20 41 4e 44 20 6f 72 69 67 69 = 'xx' AND origi
26b0: 6e 5f 72 6f 77 69 64 20 3d 20 31 3b 0d 0a 2d 2d n_rowid = 1;..--
26c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0d 0a --------------..
26d0: 31 34 38 30 39 39 31 20 28 69 6e 20 39 2e 35 33 1480991 (in 9.53
26e0: 34 20 73 65 63 6f 6e 64 73 29 0d 0a 3c 2f 76 65 4 seconds)..</ve
26f0: 72 62 61 74 69 6d 3e 0d 0a 3c 62 3e 51 75 69 63 rbatim>..<b>Quic
2700: 6b 20 65 76 61 6c 75 74 61 74 69 6f 6e 3c 2f 62 k evalutation</b
2710: 3e 3a 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 3c 62 >:..<ul>..<li><b
2720: 3e 53 54 5f 53 75 62 64 69 76 69 64 65 3c 2f 62 >ST_Subdivide</b
2730: 3e 20 64 65 66 69 6e 69 74 65 6c 79 20 69 73 20 > definitely is
2740: 74 68 65 20 74 6f 6f 6c 20 6f 66 20 74 68 65 20 the tool of the
2750: 74 72 61 64 65 20 77 65 20 77 65 72 65 20 73 65 trade we were se
2760: 61 72 63 68 69 6e 67 20 66 6f 72 2e 3c 62 72 3e arching for.<br>
2770: 0d 0a 49 74 20 65 66 66 65 63 74 69 76 65 6c 79 ..It effectively
2780: 20 61 6c 6c 6f 77 73 20 74 6f 20 72 65 73 6f 6c allows to resol
2790: 76 65 20 61 20 63 6f 6d 70 75 74 61 74 69 6f 6e ve a computation
27a0: 61 6c 6c 79 20 68 61 72 64 20 70 72 6f 62 6c 65 ally hard proble
27b0: 6d 20 69 6e 20 61 20 73 75 72 70 72 69 73 69 6e m in a surprisin
27c0: 67 6c 79 20 71 75 69 63 6b 20 74 69 6d 65 2e 3c gly quick time.<
27d0: 62 72 3e 0d 0a 50 61 73 73 69 6e 67 20 66 72 6f br>..Passing fro
27e0: 6d 20 6d 61 6e 79 20 6c 6f 6e 67 20 68 6f 75 72 m many long hour
27f0: 73 20 74 6f 20 6a 75 73 74 20 61 20 68 61 6e 64 s to just a hand
2800: 66 75 6c 6c 20 6f 66 20 73 65 63 6f 6e 64 73 20 full of seconds
2810: 69 73 20 61 20 73 69 6d 70 6c 79 20 61 73 74 6f is a simply asto
2820: 6e 69 73 68 69 6e 67 20 69 6d 70 72 6f 76 65 6d nishing improvem
2830: 65 6e 74 2e 3c 62 72 3e 3c 2f 6c 69 3e 0d 0a 3c ent.<br></li>..<
2840: 6c 69 3e 73 75 62 64 69 76 69 64 69 6e 67 20 74 li>subdividing t
2850: 68 65 20 69 6e 69 74 69 61 6c 20 68 75 67 65 20 he initial huge
2860: 50 6f 6c 79 67 6f 6e 20 69 6e 74 6f 20 6d 61 6e Polygon into man
2870: 79 20 73 69 6d 70 6c 65 72 2f 73 6d 61 6c 6c 65 y simpler/smalle
2880: 72 20 70 61 72 74 73 20 68 61 73 20 73 65 76 65 r parts has seve
2890: 72 61 6c 20 62 65 6e 65 66 69 63 69 61 6c 20 65 ral beneficial e
28a0: 66 66 65 63 74 73 3a 0d 0a 3c 75 6c 3e 0d 0a 3c ffects:..<ul>..<
28b0: 6c 69 3e 74 68 65 20 74 69 6d 65 20 72 65 71 75 li>the time requ
28c0: 69 72 65 64 20 74 6f 20 63 6f 6d 70 75 74 65 20 ired to compute
28d0: 61 20 70 6f 69 6e 74 2d 74 6f 2d 70 6f 6c 79 67 a point-to-polyg
28e0: 6f 6e 20 69 6e 74 65 72 73 65 63 74 69 6f 6e 20 on intersection
28f0: 71 75 69 63 6c 79 20 69 6e 63 72 65 61 73 65 73 quicly increases
2900: 20 77 69 74 68 20 74 68 65 20 6e 75 6d 62 65 72 with the number
2910: 20 6f 66 20 56 65 72 74 69 63 65 73 2e 3c 62 72 of Vertices.<br
2920: 3e 0d 0a 53 6d 61 6c 6c 65 72 20 70 6f 6c 79 67 >..Smaller polyg
2930: 6f 6e 73 20 61 72 65 20 6f 62 76 69 6f 75 73 6c ons are obviousl
2940: 79 20 6d 75 63 68 20 6d 6f 72 65 20 66 61 73 74 y much more fast
2950: 65 72 20 74 6f 20 62 65 20 65 76 61 6c 75 61 74 er to be evaluat
2960: 65 64 20 74 68 61 6e 20 62 69 67 67 65 72 20 6f ed than bigger o
2970: 6e 65 73 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 73 nes.</li>..<li>s
2980: 6d 61 6c 6c 65 72 20 70 6f 6c 79 67 6f 6e 73 20 maller polygons
2990: 64 6f 65 73 6e 27 74 20 73 68 61 64 6f 77 20 74 doesn't shadow t
29a0: 68 65 20 53 70 61 74 69 61 6c 20 49 6e 64 65 78 he Spatial Index
29b0: 2c 20 74 68 61 74 20 63 61 6e 20 62 65 20 65 66 , that can be ef
29c0: 66 69 63 69 65 6e 74 6c 79 20 71 75 65 72 79 69 ficiently queryi
29d0: 65 64 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 3c ed.</li>..</ul><
29e0: 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 0d 0a 0d 0a 0d /li>..</ul>.....
29f0: 0a 0d 0a 0d 0a 3c 62 72 3e 3c 62 72 3e 0d 0a 3c .....<br><br>..<
2a00: 74 61 62 6c 65 20 77 69 64 74 68 3d 22 31 30 30 table width="100
2a10: 25 22 3e 3c 74 72 3e 0d 0a 3c 74 64 20 77 69 64 %"><tr>..<td wid
2a20: 74 68 3d 22 33 33 25 22 20 61 6c 69 67 6e 3d 22 th="33%" align="
2a30: 6c 65 66 74 22 3e 3c 2f 74 64 3e 0d 0a 3c 74 64 left"></td>..<td
2a40: 20 61 6c 69 67 6e 3d 22 63 65 6e 74 65 72 22 3e align="center">
2a50: 3c 61 20 68 72 65 66 3d 22 68 74 74 70 73 3a 2f <a href="https:/
2a60: 2f 77 77 77 2e 67 61 69 61 2d 67 69 73 2e 69 74 /www.gaia-gis.it
2a70: 2f 66 6f 73 73 69 6c 2f 6c 69 62 73 70 61 74 69 /fossil/libspati
2a80: 61 6c 69 74 65 2f 77 69 6b 69 3f 6e 61 6d 65 3d alite/wiki?name=
2a90: 34 2e 33 2e 30 2b 64 6f 63 22 3e 62 61 63 6b 20 4.3.0+doc">back
2aa0: 74 6f 20 69 6e 64 65 78 3c 2f 61 3e 3c 2f 74 64 to index</a></td
2ab0: 3e 0d 0a 3c 74 64 20 77 69 64 74 68 3d 22 33 33 >..<td width="33
2ac0: 25 22 20 61 6c 69 67 6e 3d 22 72 69 67 68 74 22 %" align="right"
2ad0: 3e 3c 2f 74 64 3e 0d 0a 3c 2f 74 72 3e 3c 2f 74 ></td>..</tr></t
2ae0: 61 62 6c 65 3e 0a 5a 20 61 31 36 64 66 38 34 35 able>.Z a16df845
2af0: 62 66 65 61 32 61 30 38 35 65 65 35 65 36 38 32 bfea2a085ee5e682
2b00: 38 37 32 64 31 32 31 65 0a 872d121e.