Wiki page
[about DE-9IM] by
anonymous
2022-04-05 14:47:07.
0000: 44 20 32 30 32 32 2d 30 34 2d 30 35 54 31 34 3a D 2022-04-05T14:
0010: 34 37 3a 30 37 2e 36 31 39 0a 4c 20 61 62 6f 75 47:07.619.L abou
0020: 74 5c 73 44 45 2d 39 49 4d 0a 50 20 31 31 31 65 t\sDE-9IM.P 111e
0030: 32 37 39 62 63 65 64 37 34 64 66 62 66 38 36 36 279bced74dfbf866
0040: 37 32 36 65 65 38 34 37 61 32 35 33 34 63 61 36 726ee847a2534ca6
0050: 64 30 66 63 0a 55 20 61 6e 6f 6e 79 6d 6f 75 73 d0fc.U anonymous
0060: 0a 57 20 39 31 38 38 0a 3c 68 32 3e 43 6f 72 72 .W 9188.<h2>Corr
0070: 65 73 70 6f 6e 64 65 6e 63 65 73 20 62 65 74 77 espondences betw
0080: 65 65 6e 20 53 51 4c 20 46 75 6e 63 74 69 6f 6e een SQL Function
0090: 73 20 61 6e 64 20 44 45 2d 39 49 4d 20 49 6e 74 s and DE-9IM Int
00a0: 65 72 73 65 63 74 69 6f 6e 20 4d 61 74 72 69 63 ersection Matric
00b0: 65 73 3c 2f 68 32 3e 0d 0a 51 75 69 63 6b 20 72 es</h2>..Quick r
00c0: 65 63 61 6c 6c 3a 0d 0a 3c 6f 6c 3e 0d 0a 3c 6c ecall:..<ol>..<l
00d0: 69 3e 54 68 65 20 73 74 61 6e 64 61 72 64 20 53 i>The standard S
00e0: 70 61 74 69 61 6c 20 53 51 4c 20 6d 6f 64 65 6c patial SQL model
00f0: 20 64 65 66 69 6e 65 73 20 73 65 76 65 72 61 6c defines several
0100: 20 66 75 6e 63 74 69 6f 6e 73 20 28 61 73 20 65 functions (as e
0110: 2e 67 2e 20 3c 62 3e 53 54 5f 45 71 75 61 6c 73 .g. <b>ST_Equals
0120: 28 29 3c 2f 62 3e 2c 20 3c 62 3e 53 54 5f 49 6e ()</b>, <b>ST_In
0130: 74 65 72 73 65 63 74 73 28 29 3c 2f 62 3e 2c 20 tersects()</b>,
0140: 3c 62 3e 53 54 5f 54 6f 75 63 68 65 73 28 29 3c <b>ST_Touches()<
0150: 2f 62 3e 20 61 6e 64 20 61 6c 69 6b 65 29 20 69 /b> and alike) i
0160: 6e 74 65 6e 64 65 64 20 74 6f 20 74 65 73 74 20 ntended to test
0170: 69 66 20 61 20 67 69 76 65 6e 20 73 70 61 74 69 if a given spati
0180: 61 6c 20 72 65 6c 61 74 69 6f 6e 73 68 69 70 20 al relationship
0190: 65 78 69 73 74 73 20 62 65 74 77 65 65 6e 20 61 exists between a
01a0: 20 70 61 69 72 20 6f 66 20 47 65 6f 6d 65 74 72 pair of Geometr
01b0: 69 65 73 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 41 ies.</li>..<li>A
01c0: 6c 6c 20 73 75 63 68 20 53 51 4c 20 66 75 6e 63 ll such SQL func
01d0: 74 69 6f 6e 73 20 61 72 65 20 73 69 6d 70 6c 79 tions are simply
01e0: 20 63 6f 6e 76 65 6e 69 65 6e 63 65 20 77 72 61 convenience wra
01f0: 70 70 65 72 73 20 62 61 73 65 64 20 6f 6e 20 74 ppers based on t
0200: 68 65 20 6d 6f 73 74 20 67 65 6e 65 72 61 6c 20 he most general
0210: 44 45 2d 39 49 4d 20 6d 6f 64 65 6c 2e 3c 2f 6c DE-9IM model.</l
0220: 69 3e 0d 0a 3c 6c 69 3e 41 6e 20 61 6c 74 65 72 i>..<li>An alter
0230: 6e 61 74 69 76 65 20 28 6d 6f 72 65 20 66 6c 65 native (more fle
0240: 78 69 62 6c 65 2c 20 6d 6f 72 65 20 67 65 6e 65 xible, more gene
0250: 72 69 63 20 61 6e 64 20 6d 6f 72 65 20 65 66 66 ric and more eff
0260: 69 63 69 65 6e 74 29 20 61 70 70 72 6f 61 63 68 icient) approach
0270: 20 66 6f 72 20 65 76 61 6c 75 61 74 69 6e 67 20 for evaluating
0280: 73 70 61 74 69 61 6c 20 72 65 6c 61 74 69 6f 6e spatial relation
0290: 73 68 69 70 73 20 63 6f 75 6c 64 20 62 65 20 62 ships could be b
02a0: 61 73 65 64 20 6f 6e 20 74 68 65 20 66 6f 6c 6c ased on the foll
02b0: 6f 77 69 6e 67 20 74 77 6f 20 3c 62 3e 3c 69 3e owing two <b><i>
02c0: 61 64 76 61 6e 63 65 64 3c 2f 69 3e 3c 2f 62 3e advanced</i></b>
02d0: 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e 73 3a 0d SQL functions:.
02e0: 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 3c 62 3e 53 54 .<ul>..<li><b>ST
02f0: 5f 52 65 6c 61 74 65 20 28 3c 2f 62 3e 20 3c 69 _Relate (</b> <i
0300: 3e 67 31 3c 2f 69 3e 20 47 65 6f 6d 65 74 72 79 >g1</i> Geometry
0310: 20 2c 20 3c 69 3e 67 32 3c 2f 69 3e 20 47 65 6f , <i>g2</i> Geo
0320: 6d 65 74 72 79 20 3c 62 3e 29 20 3a 3c 2f 62 3e metry <b>) :</b>
0330: 20 3c 69 3e 69 6e 74 65 72 73 65 63 74 69 6f 6e <i>intersection
0340: 5f 6d 61 74 72 69 78 3c 2f 69 3e 20 54 65 78 74 _matrix</i> Text
0350: 3c 62 72 3e 0d 0a 54 68 69 73 20 66 69 72 73 74 <br>..This first
0360: 20 66 75 6e 63 74 69 6f 6e 20 77 69 6c 6c 20 65 function will e
0370: 76 61 6c 75 61 74 65 20 62 6f 74 68 20 47 65 6f valuate both Geo
0380: 6d 65 74 72 69 65 73 2c 20 74 68 65 6e 20 72 65 metries, then re
0390: 74 75 72 6e 69 6e 67 20 61 20 54 65 78 74 20 73 turning a Text s
03a0: 74 72 69 6e 67 20 63 6f 72 72 65 73 70 6f 6e 64 tring correspond
03b0: 69 6e 67 20 74 6f 20 61 20 6e 69 6e 65 09 64 69 ing to a nine.di
03c0: 67 69 74 73 20 73 65 72 69 61 6c 69 7a 65 64 20 gits serialized
03d0: 44 45 2d 39 49 4d 20 3c 62 3e 69 6e 74 65 72 73 DE-9IM <b>inters
03e0: 65 63 74 69 6f 6e 5f 6d 61 74 72 69 78 3c 2f 62 ection_matrix</b
03f0: 3e 20 61 73 20 65 2e 67 2e 20 3c 62 3e 27 30 46 > as e.g. <b>'0F
0400: 31 46 46 30 46 46 32 27 3c 2f 62 3e 20 6f 72 20 1FF0FF2'</b> or
0410: 3c 62 3e 27 32 31 32 31 30 31 32 31 32 27 3c 2f <b>'212101212'</
0420: 62 3e 20 77 69 74 68 20 74 68 65 20 66 6f 6c 6c b> with the foll
0430: 6f 77 69 6e 67 20 69 6e 74 65 72 70 72 65 74 61 owing interpreta
0440: 74 69 6f 6e 3a 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 tion:..<ul>..<li
0450: 3e 3c 62 3e 46 3c 2f 62 3e 3a 20 74 68 69 73 20 ><b>F</b>: this
0460: 73 74 61 6e 64 73 20 66 6f 72 20 3c 62 3e 46 41 stands for <b>FA
0470: 4c 53 45 3c 2f 62 3e 2c 20 69 2e 65 2e 20 74 68 LSE</b>, i.e. th
0480: 65 20 63 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 e corresponding
0490: 69 6e 74 65 72 73 65 63 74 69 6f 6e 20 64 6f 65 intersection doe
04a0: 73 6e 27 74 20 6f 63 63 75 72 73 2e 3c 2f 6c 69 sn't occurs.</li
04b0: 3e 0d 0a 3c 6c 69 3e 3c 62 3e 30 3c 2f 62 3e 3a >..<li><b>0</b>:
04c0: 20 74 68 65 20 63 6f 72 72 65 73 70 6f 6e 64 69 the correspondi
04d0: 6e 67 20 69 6e 74 65 72 73 65 63 74 69 6f 6e 20 ng intersection
04e0: 69 73 20 61 20 50 6f 69 6e 74 2c 20 69 2e 65 2e is a Point, i.e.
04f0: 20 61 20 7a 65 72 6f 2d 64 69 6d 65 6e 73 69 6f a zero-dimensio
0500: 6e 73 20 47 65 6f 6d 65 74 72 79 2e 3c 2f 6c 69 ns Geometry.</li
0510: 3e 0d 0a 3c 6c 69 3e 3c 62 3e 31 3c 2f 62 3e 3a >..<li><b>1</b>:
0520: 20 74 68 65 20 63 6f 72 72 65 73 70 6f 6e 64 69 the correspondi
0530: 6e 67 20 69 6e 74 65 72 73 65 63 74 69 6f 6e 20 ng intersection
0540: 69 73 20 61 20 4c 69 6e 65 73 74 72 69 6e 67 2c is a Linestring,
0550: 20 69 2e 65 2e 20 61 20 20 6f 6e 65 2d 64 69 6d i.e. a one-dim
0560: 65 6e 73 69 6f 6e 20 47 65 6f 6d 65 74 72 79 2e ension Geometry.
0570: 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 3c 62 3e 32 3c </li>..<li><b>2<
0580: 2f 62 3e 3a 20 74 68 65 20 63 6f 72 72 65 73 70 /b>: the corresp
0590: 6f 6e 64 69 6e 67 20 69 6e 74 65 72 73 65 63 74 onding intersect
05a0: 69 6f 6e 20 69 73 20 61 20 50 6f 6c 79 67 6f 6e ion is a Polygon
05b0: 2c 20 69 2e 65 2e 20 61 20 74 77 6f 2d 64 69 6d , i.e. a two-dim
05c0: 65 6e 73 69 6f 6e 73 20 47 65 6f 6d 65 74 72 79 ensions Geometry
05d0: 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 3c 2f 6c .</li>..</ul></l
05e0: 69 3e 0d 0a 3c 6c 69 3e 3c 62 3e 53 54 5f 52 65 i>..<li><b>ST_Re
05f0: 6c 61 74 65 4d 61 74 63 68 20 28 3c 2f 62 3e 20 lateMatch (</b>
0600: 3c 69 3e 69 6e 74 65 72 73 65 63 74 69 6f 6e 5f <i>intersection_
0610: 6d 61 74 72 69 78 3c 2f 69 3e 20 54 65 78 74 20 matrix</i> Text
0620: 2c 20 3c 69 3e 72 65 66 65 72 65 6e 63 65 5f 70 , <i>reference_p
0630: 61 74 74 65 72 6e 3c 2f 69 3e 20 54 65 78 74 20 attern</i> Text
0640: 3c 62 3e 29 20 3a 3c 2f 62 3e 20 3c 69 3e 74 72 <b>) :</b> <i>tr
0650: 75 65 5f 6f 72 5f 66 61 6c 73 65 3c 2f 69 3e 20 ue_or_false</i>
0660: 42 6f 6f 6c 65 61 6e 3c 62 72 3e 0d 0a 54 68 69 Boolean<br>..Thi
0670: 73 20 73 65 63 6f 6e 64 20 66 75 6e 63 74 69 6f s second functio
0680: 6e 20 69 73 20 69 6e 74 65 6e 64 65 64 20 74 6f n is intended to
0690: 20 65 76 61 6c 75 61 74 65 20 61 6e 20 3c 62 3e evaluate an <b>
06a0: 69 6e 74 65 72 73 65 63 74 69 6f 6e 20 6d 61 74 intersection mat
06b0: 72 69 78 3c 2f 62 3e 20 72 65 74 75 72 6e 65 64 rix</b> returned
06c0: 20 62 79 20 61 20 70 72 65 76 69 6f 75 73 20 63 by a previous c
06d0: 61 6c 6c 20 74 6f 20 3c 62 3e 53 54 5f 52 65 6c all to <b>ST_Rel
06e0: 61 74 65 28 29 3c 2f 62 3e 20 61 67 61 69 6e 73 ate()</b> agains
06f0: 74 20 61 20 67 69 76 65 6e 20 3c 62 3e 72 65 66 t a given <b>ref
0700: 65 72 65 6e 63 65 5f 70 61 74 74 65 72 6e 3c 2f erence_pattern</
0710: 62 3e 2c 20 74 68 65 6e 20 72 65 74 75 72 6e 69 b>, then returni
0720: 6e 67 20 3c 62 3e 54 52 55 45 3c 2f 62 3e 20 6f ng <b>TRUE</b> o
0730: 72 20 3c 62 3e 46 41 4c 53 45 3c 2f 62 3e 2e 3c r <b>FALSE</b>.<
0740: 62 72 3e 0d 0a 41 20 3c 62 3e 72 65 66 65 72 65 br>..A <b>refere
0750: 6e 63 65 5f 70 61 74 74 65 72 6e 3c 2f 62 3e 20 nce_pattern</b>
0760: 61 73 20 65 2e 67 2e 20 3c 62 3e 27 54 2a 46 2a as e.g. <b>'T*F*
0770: 2a 46 46 46 2a 27 3c 2f 62 3e 20 6f 72 20 3c 62 *FFF*'</b> or <b
0780: 3e 27 30 2a 2a 2a 2a 2a 2a 2a 2a 27 3c 2f 62 3e >'0********'</b>
0790: 20 20 73 69 6d 70 6c 79 20 69 73 20 79 65 74 20 simply is yet
07a0: 61 6e 6f 74 68 65 72 20 6e 69 6e 65 20 64 69 67 another nine dig
07b0: 69 74 73 20 73 65 72 69 61 6c 69 7a 65 64 20 44 its serialized D
07c0: 45 2d 39 49 4d 20 6d 61 74 72 69 78 20 61 64 6f E-9IM matrix ado
07d0: 70 74 69 6e 67 20 61 20 73 6c 69 67 68 74 6c 79 pting a slightly
07e0: 20 63 68 61 6e 67 65 64 20 73 79 6e 74 61 78 3a changed syntax:
07f0: 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 3c 62 3e 46 ..<ul>..<li><b>F
0800: 3c 2f 62 3e 2c 20 3c 62 3e 30 3c 2f 62 3e 2c 20 </b>, <b>0</b>,
0810: 3c 62 3e 31 3c 2f 62 3e 20 61 6e 64 20 3c 62 3e <b>1</b> and <b>
0820: 32 3c 2f 62 3e 3a 20 73 61 6d 65 20 69 6e 74 65 2</b>: same inte
0830: 72 70 72 65 74 61 74 69 6f 6e 20 61 73 20 62 65 rpretation as be
0840: 66 6f 72 65 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e fore.</li>..<li>
0850: 3c 62 3e 54 3c 2f 62 3e 3a 20 74 68 69 73 20 73 <b>T</b>: this s
0860: 74 61 6e 64 73 20 66 6f 72 20 3c 62 3e 54 52 55 tands for <b>TRU
0870: 45 3c 2f 62 3e 2c 20 69 2e 65 2e 20 74 68 65 20 E</b>, i.e. the
0880: 63 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 69 6e corresponding in
0890: 74 65 72 73 65 63 74 69 6f 6e 20 69 73 20 65 78 tersection is ex
08a0: 70 65 63 74 65 64 20 74 6f 20 6f 63 63 75 72 2c pected to occur,
08b0: 20 62 75 74 20 69 74 73 20 73 70 65 63 69 66 69 but its specifi
08c0: 63 20 6e 61 74 75 72 65 20 64 6f 65 73 6e 27 74 c nature doesn't
08d0: 20 6d 61 74 74 65 72 73 2e 3c 2f 6c 69 3e 0d 0a matters.</li>..
08e0: 3c 6c 69 3e 3c 62 3e 2a 3c 2f 62 3e 3a 20 61 6e <li><b>*</b>: an
08f0: 20 61 73 74 65 72 69 73 6b 20 69 73 20 61 20 3c asterisk is a <
0900: 62 3e 6d 61 73 6b 20 73 69 67 6e 3c 2f 62 3e 20 b>mask sign</b>
0910: 61 6e 64 20 61 6c 77 61 79 73 20 6d 65 61 6e 73 and always means
0920: 20 3c 62 3e 3c 69 3e 69 67 6e 6f 72 65 20 2f 20 <b><i>ignore /
0930: 64 6f 6e 27 74 20 63 61 72 65 20 2f 20 73 6b 69 don't care / ski
0940: 70 3c 2f 69 3e 3c 2f 62 3e 20 74 68 69 73 20 6d p</i></b> this m
0950: 61 74 72 69 78 20 63 65 6c 6c 2e 3c 2f 6c 69 3e atrix cell.</li>
0960: 0d 0a 3c 2f 75 6c 3e 3c 2f 6c 69 3e 0d 0a 3c 6c ..</ul></li>..<l
0970: 69 3e 3c 75 3e 4e 6f 74 65 3c 2f 75 3e 3a 20 3c i><u>Note</u>: <
0980: 62 3e 53 54 5f 52 65 6c 61 74 65 28 29 3c 2f 62 b>ST_Relate()</b
0990: 3e 20 69 73 20 61 20 63 6f 6d 70 75 74 61 74 69 > is a computati
09a0: 6f 6e 61 6c 6c 79 20 68 65 61 76 79 20 66 75 6e onally heavy fun
09b0: 63 74 69 6f 6e 20 28 65 78 61 63 74 6c 79 20 20 ction (exactly
09c0: 61 73 20 3c 62 3e 53 54 5f 45 71 75 61 6c 73 28 as <b>ST_Equals(
09d0: 29 3c 2f 62 3e 2c 20 3c 62 3e 53 54 5f 43 72 6f )</b>, <b>ST_Cro
09e0: 73 73 65 73 28 29 3c 2f 62 3e 20 61 6e 64 20 61 sses()</b> and a
09f0: 6c 69 6b 65 20 61 72 65 29 3b 20 09 09 09 6f 6e like are); ...on
0a00: 20 74 68 65 20 6f 74 68 65 72 20 68 61 6e 64 20 the other hand
0a10: 3c 62 3e 53 54 5f 52 65 6c 61 74 65 4d 61 74 63 <b>ST_RelateMatc
0a20: 68 28 29 3c 2f 62 3e 20 69 73 20 61 20 76 65 72 h()</b> is a ver
0a30: 79 20 6c 69 67 68 74 20 61 6e 64 20 71 75 69 63 y light and quic
0a40: 6b 20 66 75 6e 63 74 69 6f 6e 2e 3c 62 72 3e 0d k function.<br>.
0a50: 0a 53 6f 20 77 68 65 6e 20 79 6f 75 20 68 61 76 .So when you hav
0a60: 65 20 74 6f 20 63 68 65 63 6b 20 66 6f 72 20 6d e to check for m
0a70: 6f 72 65 20 74 68 61 6e 20 61 20 73 69 6e 67 6c ore than a singl
0a80: 65 20 72 65 6c 61 74 69 6f 6e 73 68 69 70 20 61 e relationship a
0a90: 74 20 74 68 65 20 73 61 6d 65 20 74 69 6d 65 2c t the same time,
0aa0: 20 63 61 6c 6c 69 6e 67 20 3c 62 3e 53 54 5f 52 calling <b>ST_R
0ab0: 65 6c 61 74 65 28 29 3c 2f 62 3e 20 6a 75 73 74 elate()</b> just
0ac0: 20 6f 6e 63 65 20 61 6e 64 20 74 68 65 6e 20 65 once and then e
0ad0: 76 61 6c 75 61 74 69 6e 67 20 65 61 63 68 20 73 valuating each s
0ae0: 70 61 74 69 61 6c 20 72 65 6c 61 74 69 6f 6e 73 patial relations
0af0: 68 69 70 20 62 79 20 63 61 6c 6c 69 6e 67 20 3c hip by calling <
0b00: 62 3e 53 54 5f 52 65 6c 61 74 65 4d 61 74 63 68 b>ST_RelateMatch
0b10: 28 29 3c 2f 62 3e 20 6d 75 6c 74 69 70 6c 65 20 ()</b> multiple
0b20: 74 69 6d 65 73 20 77 69 6c 6c 20 61 6c 77 61 79 times will alway
0b30: 73 20 65 6e 73 75 72 65 20 6e 6f 74 69 63 65 61 s ensure noticea
0b40: 62 6c 79 20 66 61 73 74 65 72 20 70 65 72 66 6f bly faster perfo
0b50: 72 6d 61 6e 63 65 73 2e 3c 2f 6c 69 3e 0d 0a 3c rmances.</li>..<
0b60: 6c 69 3e 3c 75 3e 43 6f 6e 63 6c 75 73 69 6f 6e li><u>Conclusion
0b70: 3c 2f 75 3e 3a 20 75 73 69 6e 67 20 74 68 65 20 </u>: using the
0b80: 71 75 69 72 6b 79 20 61 6e 64 20 61 77 6b 77 61 quirky and awkwa
0b90: 72 64 20 44 45 2d 39 49 4d 20 6d 6f 64 65 6c 20 rd DE-9IM model
0ba0: 73 75 72 65 6c 79 20 69 73 20 6e 65 69 74 68 65 surely is neithe
0bb0: 72 20 65 61 73 79 20 6f 72 20 69 6e 74 75 69 74 r easy or intuit
0bc0: 69 76 65 2e 3c 62 72 3e 0d 0a 54 68 65 20 66 6f ive.<br>..The fo
0bd0: 6c 6c 6f 77 69 6e 67 20 74 61 62 6c 65 20 69 73 llowing table is
0be0: 20 73 70 65 63 69 66 69 63 61 6c 6c 79 20 69 6e specifically in
0bf0: 74 65 6e 64 65 64 20 74 6f 20 6d 61 6b 65 20 74 tended to make t
0c00: 68 65 20 75 73 61 67 65 20 6f 66 20 62 6f 74 68 he usage of both
0c10: 20 3c 62 3e 53 54 5f 52 65 6c 61 74 65 28 29 3c <b>ST_Relate()<
0c20: 2f 62 3e 20 61 6e 64 20 3c 62 3e 53 54 5f 52 65 /b> and <b>ST_Re
0c30: 6c 61 74 65 4d 61 74 63 68 28 29 3c 2f 62 3e 20 lateMatch()</b>
0c40: 65 61 73 69 65 72 2c 20 69 6e 20 61 20 72 65 61 easier, in a rea
0c50: 73 6f 6e 61 62 6c 79 20 70 61 69 6e 6c 65 73 73 sonably painless
0c60: 20 77 61 79 2e 0d 0a 3c 2f 75 6c 3e 3c 2f 6c 69 way...</ul></li
0c70: 3e 0d 0a 3c 2f 6f 6c 3e 0d 0a 3c 74 61 62 6c 65 >..</ol>..<table
0c80: 20 63 65 6c 6c 73 70 61 63 69 6e 67 3d 22 34 22 cellspacing="4"
0c90: 20 63 65 6c 6c 70 61 64 64 69 6e 67 3d 22 36 22 cellpadding="6"
0ca0: 20 62 6f 72 64 65 72 3d 22 31 22 20 62 67 63 6f border="1" bgco
0cb0: 6c 6f 72 3d 22 23 66 30 66 66 66 30 22 3e 0d 0a lor="#f0fff0">..
0cc0: 3c 74 72 3e 3c 74 68 20 62 67 63 6f 6c 6f 72 3d <tr><th bgcolor=
0cd0: 22 23 66 66 63 30 30 30 22 3e 53 51 4c 20 66 75 "#ffc000">SQL fu
0ce0: 6e 63 74 69 6f 6e 3c 2f 74 68 3e 3c 74 68 20 62 nction</th><th b
0cf0: 67 63 6f 6c 6f 72 3d 22 23 66 66 63 30 30 30 22 gcolor="#ffc000"
0d00: 3e 52 65 66 65 72 65 6e 63 65 20 50 61 74 74 65 >Reference Patte
0d10: 72 6e 3c 2f 74 68 3e 3c 2f 74 72 3e 0d 0a 3c 74 rn</th></tr>..<t
0d20: 72 3e 3c 74 64 3e 3c 62 3e 53 54 5f 45 71 75 61 r><td><b>ST_Equa
0d30: 6c 73 28 20 3c 2f 62 3e 3c 69 3e 67 31 3c 2f 69 ls( </b><i>g1</i
0d40: 3e 2c 20 3c 69 3e 67 32 3c 2f 69 3e 20 3c 62 3e >, <i>g2</i> <b>
0d50: 29 3c 2f 62 3e 3c 2f 74 64 3e 3c 74 64 20 61 6c )</b></td><td al
0d60: 69 67 6e 3d 22 63 65 6e 74 65 72 22 3e 3c 62 3e ign="center"><b>
0d70: 54 2a 46 2a 2a 46 46 46 2a 3c 2f 62 3e 3c 2f 74 T*F**FFF*</b></t
0d80: 64 3e 3c 2f 74 72 3e 0d 0a 3c 74 72 3e 3c 74 64 d></tr>..<tr><td
0d90: 3e 3c 62 3e 53 54 5f 44 69 73 6a 6f 69 6e 74 28 ><b>ST_Disjoint(
0da0: 20 3c 2f 62 3e 3c 69 3e 67 31 3c 2f 69 3e 2c 20 </b><i>g1</i>,
0db0: 3c 69 3e 67 32 3c 2f 69 3e 20 3c 62 3e 29 3c 2f <i>g2</i> <b>)</
0dc0: 62 3e 3c 2f 74 64 3e 3c 74 64 20 61 6c 69 67 6e b></td><td align
0dd0: 3d 22 63 65 6e 74 65 72 22 3e 3c 62 3e 46 46 2a ="center"><b>FF*
0de0: 46 46 2a 2a 2a 2a 3c 2f 62 3e 3c 2f 74 64 3e 3c FF****</b></td><
0df0: 2f 74 72 3e 0d 0a 3c 74 72 3e 3c 74 64 20 72 6f /tr>..<tr><td ro
0e00: 77 73 70 61 6e 3d 22 33 22 3e 3c 62 3e 53 54 5f wspan="3"><b>ST_
0e10: 54 6f 75 63 68 65 73 28 20 3c 2f 62 3e 3c 69 3e Touches( </b><i>
0e20: 67 31 3c 2f 69 3e 2c 20 3c 69 3e 67 32 3c 2f 69 g1</i>, <i>g2</i
0e30: 3e 20 3c 62 3e 29 3c 2f 62 3e 3c 2f 74 64 3e 3c > <b>)</b></td><
0e40: 74 64 20 61 6c 69 67 6e 3d 22 63 65 6e 74 65 72 td align="center
0e50: 22 3e 3c 62 3e 46 54 2a 2a 2a 2a 2a 2a 2a 3c 2f "><b>FT*******</
0e60: 62 3e 3c 2f 74 64 3e 3c 2f 74 72 3e 0d 0a 3c 74 b></td></tr>..<t
0e70: 72 3e 3c 74 64 20 61 6c 69 67 6e 3d 22 63 65 6e r><td align="cen
0e80: 74 65 72 22 3e 3c 62 3e 46 2a 2a 54 2a 2a 2a 2a ter"><b>F**T****
0e90: 2a 3c 2f 62 3e 3c 2f 74 64 3e 3c 2f 74 72 3e 0d *</b></td></tr>.
0ea0: 0a 3c 74 72 3e 3c 74 64 20 61 6c 69 67 6e 3d 22 .<tr><td align="
0eb0: 63 65 6e 74 65 72 22 3e 3c 62 3e 46 2a 2a 2a 54 center"><b>F***T
0ec0: 2a 2a 2a 2a 3c 2f 62 3e 3c 2f 74 64 3e 3c 2f 74 ****</b></td></t
0ed0: 72 3e 0d 0a 3c 74 72 3e 3c 74 64 3e 3c 62 3e 53 r>..<tr><td><b>S
0ee0: 54 5f 57 69 74 68 69 6e 28 20 3c 2f 62 3e 3c 69 T_Within( </b><i
0ef0: 3e 67 31 3c 2f 69 3e 2c 20 3c 69 3e 67 32 3c 2f >g1</i>, <i>g2</
0f00: 69 3e 20 3c 62 3e 29 3c 2f 62 3e 3c 2f 74 64 3e i> <b>)</b></td>
0f10: 3c 74 64 20 61 6c 69 67 6e 3d 22 63 65 6e 74 65 <td align="cente
0f20: 72 22 3e 3c 62 3e 54 2a 46 2a 2a 46 2a 2a 2a 3c r"><b>T*F**F***<
0f30: 2f 62 3e 3c 2f 74 64 3e 3c 2f 74 72 3e 0d 0a 3c /b></td></tr>..<
0f40: 74 72 3e 3c 74 64 20 72 6f 77 73 70 61 6e 3d 22 tr><td rowspan="
0f50: 32 22 3e 3c 62 3e 53 54 5f 4f 76 65 72 6c 61 70 2"><b>ST_Overlap
0f60: 73 28 20 3c 2f 62 3e 3c 69 3e 67 31 3c 2f 69 3e s( </b><i>g1</i>
0f70: 2c 20 3c 69 3e 67 32 3c 2f 69 3e 20 3c 62 3e 29 , <i>g2</i> <b>)
0f80: 3c 2f 62 3e 3c 2f 74 64 3e 3c 74 64 20 61 6c 69 </b></td><td ali
0f90: 67 6e 3d 22 63 65 6e 74 65 72 22 3e 3c 62 3e 54 gn="center"><b>T
0fa0: 2a 54 2a 2a 2a 54 2a 2a 3c 2f 62 3e 3c 2f 74 64 *T***T**</b></td
0fb0: 3e 3c 2f 74 72 3e 0d 0a 3c 74 72 3e 3c 74 64 20 ></tr>..<tr><td
0fc0: 61 6c 69 67 6e 3d 22 63 65 6e 74 65 72 22 3e 3c align="center"><
0fd0: 62 3e 31 2a 54 2a 2a 2a 54 2a 2a 3c 2f 62 3e 3c b>1*T***T**</b><
0fe0: 2f 74 64 3e 3c 2f 74 72 3e 0d 0a 3c 74 72 3e 3c /td></tr>..<tr><
0ff0: 74 64 20 72 6f 77 73 70 61 6e 3d 22 33 22 3e 3c td rowspan="3"><
1000: 62 3e 53 54 5f 43 72 6f 73 73 65 73 28 20 3c 2f b>ST_Crosses( </
1010: 62 3e 3c 69 3e 67 31 3c 2f 69 3e 2c 20 3c 69 3e b><i>g1</i>, <i>
1020: 67 32 3c 2f 69 3e 20 3c 62 3e 29 3c 2f 62 3e 3c g2</i> <b>)</b><
1030: 2f 74 64 3e 3c 74 64 20 61 6c 69 67 6e 3d 22 63 /td><td align="c
1040: 65 6e 74 65 72 22 3e 3c 62 3e 54 2a 54 2a 2a 2a enter"><b>T*T***
1050: 2a 2a 2a 3c 2f 62 3e 3c 2f 74 64 3e 3c 2f 74 72 ***</b></td></tr
1060: 3e 0d 0a 3c 74 72 3e 3c 74 64 20 61 6c 69 67 6e >..<tr><td align
1070: 3d 22 63 65 6e 74 65 72 22 3e 3c 62 3e 54 2a 2a ="center"><b>T**
1080: 2a 2a 2a 54 2a 2a 3c 2f 62 3e 3c 2f 74 64 3e 3c ***T**</b></td><
1090: 2f 74 72 3e 0d 0a 3c 74 72 3e 3c 74 64 20 61 6c /tr>..<tr><td al
10a0: 69 67 6e 3d 22 63 65 6e 74 65 72 22 3e 3c 62 3e ign="center"><b>
10b0: 30 2a 2a 2a 2a 2a 2a 2a 2a 3c 2f 62 3e 3c 2f 74 0********</b></t
10c0: 64 3e 3c 2f 74 72 3e 0d 0a 3c 74 72 3e 3c 74 64 d></tr>..<tr><td
10d0: 20 72 6f 77 73 70 61 6e 3d 22 34 22 3e 3c 62 3e rowspan="4"><b>
10e0: 53 54 5f 49 6e 74 65 72 73 65 63 74 73 28 20 3c ST_Intersects( <
10f0: 2f 62 3e 3c 69 3e 67 31 3c 2f 69 3e 2c 20 3c 69 /b><i>g1</i>, <i
1100: 3e 67 32 3c 2f 69 3e 20 3c 62 3e 29 3c 2f 62 3e >g2</i> <b>)</b>
1110: 3c 2f 74 64 3e 3c 74 64 20 61 6c 69 67 6e 3d 22 </td><td align="
1120: 63 65 6e 74 65 72 22 3e 3c 62 3e 54 2a 2a 2a 2a center"><b>T****
1130: 2a 2a 2a 2a 3c 2f 62 3e 3c 2f 74 64 3e 3c 2f 74 ****</b></td></t
1140: 72 3e 0d 0a 3c 74 72 3e 3c 74 64 20 61 6c 69 67 r>..<tr><td alig
1150: 6e 3d 22 63 65 6e 74 65 72 22 3e 3c 62 3e 2a 54 n="center"><b>*T
1160: 2a 2a 2a 2a 2a 2a 2a 3c 2f 62 3e 3c 2f 74 64 3e *******</b></td>
1170: 3c 2f 74 72 3e 0d 0a 3c 74 72 3e 3c 74 64 20 61 </tr>..<tr><td a
1180: 6c 69 67 6e 3d 22 63 65 6e 74 65 72 22 3e 3c 62 lign="center"><b
1190: 3e 2a 2a 2a 54 2a 2a 2a 2a 2a 3c 2f 62 3e 3c 2f >***T*****</b></
11a0: 74 64 3e 3c 2f 74 72 3e 0d 0a 3c 74 72 3e 3c 74 td></tr>..<tr><t
11b0: 64 20 61 6c 69 67 6e 3d 22 63 65 6e 74 65 72 22 d align="center"
11c0: 3e 3c 62 3e 2a 2a 2a 2a 54 2a 2a 2a 2a 3c 2f 62 ><b>****T****</b
11d0: 3e 3c 2f 74 64 3e 3c 2f 74 72 3e 0d 0a 3c 74 72 ></td></tr>..<tr
11e0: 3e 3c 74 64 3e 3c 62 3e 53 54 5f 43 6f 6e 74 61 ><td><b>ST_Conta
11f0: 69 6e 73 28 20 3c 2f 62 3e 3c 69 3e 67 31 3c 2f ins( </b><i>g1</
1200: 69 3e 2c 20 3c 69 3e 67 32 3c 2f 69 3e 20 3c 62 i>, <i>g2</i> <b
1210: 3e 29 3c 2f 62 3e 3c 2f 74 64 3e 3c 74 64 20 61 >)</b></td><td a
1220: 6c 69 67 6e 3d 22 63 65 6e 74 65 72 22 3e 3c 62 lign="center"><b
1230: 3e 54 2a 2a 2a 2a 2a 46 46 2a 3c 2f 62 3e 3c 2f >T*****FF*</b></
1240: 74 64 3e 3c 2f 74 72 3e 0d 0a 3c 74 72 3e 3c 74 td></tr>..<tr><t
1250: 64 20 72 6f 77 73 70 61 6e 3d 22 34 22 3e 3c 62 d rowspan="4"><b
1260: 3e 53 54 5f 43 6f 76 65 72 73 28 20 3c 2f 62 3e >ST_Covers( </b>
1270: 3c 69 3e 67 31 3c 2f 69 3e 2c 20 3c 69 3e 67 32 <i>g1</i>, <i>g2
1280: 3c 2f 69 3e 20 3c 62 3e 29 3c 2f 62 3e 3c 2f 74 </i> <b>)</b></t
1290: 64 3e 3c 74 64 20 61 6c 69 67 6e 3d 22 63 65 6e d><td align="cen
12a0: 74 65 72 22 3e 3c 62 3e 54 2a 2a 2a 2a 2a 46 46 ter"><b>T*****FF
12b0: 2a 3c 2f 62 3e 3c 2f 74 64 3e 3c 2f 74 72 3e 0d *</b></td></tr>.
12c0: 0a 3c 74 72 3e 3c 74 64 20 61 6c 69 67 6e 3d 22 .<tr><td align="
12d0: 63 65 6e 74 65 72 22 3e 3c 62 3e 2a 54 2a 2a 2a center"><b>*T***
12e0: 2a 46 46 2a 3c 2f 62 3e 3c 2f 74 64 3e 3c 2f 74 *FF*</b></td></t
12f0: 72 3e 0d 0a 3c 74 72 3e 3c 74 64 20 61 6c 69 67 r>..<tr><td alig
1300: 6e 3d 22 63 65 6e 74 65 72 22 3e 3c 62 3e 2a 2a n="center"><b>**
1310: 2a 54 2a 2a 46 46 2a 3c 2f 62 3e 3c 2f 74 64 3e *T**FF*</b></td>
1320: 3c 2f 74 72 3e 0d 0a 3c 74 72 3e 3c 74 64 20 61 </tr>..<tr><td a
1330: 6c 69 67 6e 3d 22 63 65 6e 74 65 72 22 3e 3c 62 lign="center"><b
1340: 3e 2a 2a 2a 2a 54 2a 46 46 2a 3c 2f 62 3e 3c 2f >****T*FF*</b></
1350: 74 64 3e 3c 2f 74 72 3e 0d 0a 3c 74 72 3e 3c 74 td></tr>..<tr><t
1360: 64 20 72 6f 77 73 70 61 6e 3d 22 34 22 3e 3c 62 d rowspan="4"><b
1370: 3e 53 54 5f 43 6f 76 65 72 65 64 42 79 28 20 3c >ST_CoveredBy( <
1380: 2f 62 3e 3c 69 3e 67 31 3c 2f 69 3e 2c 20 3c 69 /b><i>g1</i>, <i
1390: 3e 67 32 3c 2f 69 3e 20 3c 62 3e 29 3c 2f 62 3e >g2</i> <b>)</b>
13a0: 3c 2f 74 64 3e 3c 74 64 20 61 6c 69 67 6e 3d 22 </td><td align="
13b0: 63 65 6e 74 65 72 22 3e 3c 62 3e 54 2a 46 2a 2a center"><b>T*F**
13c0: 46 2a 2a 2a 3c 2f 62 3e 3c 2f 74 64 3e 3c 2f 74 F***</b></td></t
13d0: 72 3e 0d 0a 3c 74 72 3e 3c 74 64 20 61 6c 69 67 r>..<tr><td alig
13e0: 6e 3d 22 63 65 6e 74 65 72 22 3e 3c 62 3e 2a 54 n="center"><b>*T
13f0: 46 2a 2a 46 2a 2a 2a 3c 2f 62 3e 3c 2f 74 64 3e F**F***</b></td>
1400: 3c 2f 74 72 3e 0d 0a 3c 74 72 3e 3c 74 64 20 61 </tr>..<tr><td a
1410: 6c 69 67 6e 3d 22 63 65 6e 74 65 72 22 3e 3c 62 lign="center"><b
1420: 3e 2a 2a 46 54 2a 46 2a 2a 2a 3c 2f 62 3e 3c 2f >**FT*F***</b></
1430: 74 64 3e 3c 2f 74 72 3e 0d 0a 3c 74 72 3e 3c 74 td></tr>..<tr><t
1440: 64 20 61 6c 69 67 6e 3d 22 63 65 6e 74 65 72 22 d align="center"
1450: 3e 3c 62 3e 2a 2a 46 2a 54 46 2a 2a 2a 3c 2f 62 ><b>**F*TF***</b
1460: 3e 3c 2f 74 64 3e 3c 2f 74 72 3e 0d 0a 3c 2f 74 ></td></tr>..</t
1470: 61 62 6c 65 3e 3c 62 72 3e 0d 0a 46 75 72 74 68 able><br>..Furth
1480: 65 72 20 75 73 65 66 75 6c 20 72 65 61 64 69 6e er useful readin
1490: 67 73 3a 0d 0a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 61 gs:..<ul>..<li>a
14a0: 20 67 65 6e 65 72 61 6c 20 69 6e 74 72 6f 64 75 general introdu
14b0: 63 74 69 6f 6e 20 74 6f 20 3c 61 20 68 72 65 66 ction to <a href
14c0: 3d 22 68 74 74 70 73 3a 2f 2f 65 6e 2e 77 69 6b ="https://en.wik
14d0: 69 70 65 64 69 61 2e 6f 72 67 2f 77 69 6b 69 2f ipedia.org/wiki/
14e0: 44 45 2d 39 49 4d 22 3e 44 45 2d 39 49 4d 3c 2f DE-9IM">DE-9IM</
14f0: 61 3e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 61 20 77 a></li>..<li>a w
1500: 65 6c 6c 2d 77 72 69 74 74 65 6e 20 64 6f 63 75 ell-written docu
1510: 6d 65 6e 74 61 74 69 6f 6e 20 66 72 6f 6d 20 61 mentation from a
1520: 20 3c 61 20 68 72 65 66 3d 22 68 74 74 70 3a 2f <a href="http:/
1530: 2f 65 64 6e 64 6f 63 2e 65 73 72 69 2e 63 6f 6d /edndoc.esri.com
1540: 2f 61 72 63 73 64 65 2f 39 2e 30 2f 67 65 6e 65 /arcsde/9.0/gene
1550: 72 61 6c 5f 74 6f 70 69 63 73 2f 75 6e 64 65 72 ral_topics/under
1560: 73 74 61 6e 64 5f 73 70 61 74 69 61 6c 5f 72 65 stand_spatial_re
1570: 6c 61 74 69 6f 6e 73 2e 68 74 6d 22 3e 50 72 6f lations.htm">Pro
1580: 70 72 69 65 74 61 72 79 20 53 57 20 56 65 6e 64 prietary SW Vend
1590: 6f 72 3c 2f 61 3e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 or</a></li>..</u
15a0: 6c 3e 3c 62 72 3e 0d 0a 3c 68 72 3e 0d 0a 3c 68 l><br>..<hr>..<h
15b0: 33 3e 41 20 70 72 61 63 74 69 63 61 6c 20 65 78 3>A practical ex
15c0: 61 6d 70 6c 65 20 28 61 6e 64 20 72 65 6c 61 74 ample (and relat
15d0: 65 64 20 6f 62 6a 65 63 74 69 76 65 20 74 69 6d ed objective tim
15e0: 69 6e 67 73 29 3c 2f 68 33 3e 0d 0a 3c 76 65 72 ings)</h3>..<ver
15f0: 62 61 74 69 6d 3e 0d 0a 53 45 4c 45 43 54 20 6d batim>..SELECT m
1600: 2e 6e 61 6d 65 20 41 53 20 6d 75 6e 69 63 69 70 .name AS municip
1610: 61 6c 69 74 79 2c 20 70 2e 6e 61 6d 65 20 41 53 ality, p.name AS
1620: 20 70 72 6f 76 69 6e 63 65 2c 0d 0a 20 20 20 20 province,..
1630: 53 54 5f 44 69 73 6a 6f 69 6e 74 28 6d 2e 67 65 ST_Disjoint(m.ge
1640: 6f 6d 2c 20 70 2e 67 65 6f 6d 29 20 41 53 20 64 om, p.geom) AS d
1650: 69 73 6a 6f 69 6e 74 2c 0d 0a 20 20 20 20 53 54 isjoint,.. ST
1660: 5f 54 6f 75 63 68 65 73 28 6d 2e 67 65 6f 6d 2c _Touches(m.geom,
1670: 20 70 2e 67 65 6f 6d 29 20 41 53 20 74 6f 75 63 p.geom) AS touc
1680: 68 65 73 2c 0d 0a 20 20 20 20 53 54 5f 57 69 74 hes,.. ST_Wit
1690: 68 69 6e 28 6d 2e 67 65 6f 6d 2c 20 70 2e 67 65 hin(m.geom, p.ge
16a0: 6f 6d 29 20 41 53 20 77 69 74 68 69 6e 2c 0d 0a om) AS within,..
16b0: 20 20 20 20 53 54 5f 49 6e 74 65 72 73 65 63 74 ST_Intersect
16c0: 73 28 6d 2e 67 65 6f 6d 2c 20 70 2e 67 65 6f 6d s(m.geom, p.geom
16d0: 29 20 41 53 20 69 6e 74 65 72 73 65 63 74 73 2c ) AS intersects,
16e0: 0d 0a 20 20 20 20 53 54 5f 4f 76 65 72 6c 61 70 .. ST_Overlap
16f0: 73 28 6d 2e 67 65 6f 6d 2c 20 70 2e 67 65 6f 6d s(m.geom, p.geom
1700: 29 20 41 53 20 6f 76 65 72 6c 61 70 73 2c 0d 0a ) AS overlaps,..
1710: 20 20 20 20 53 54 5f 43 6f 76 65 72 65 64 42 79 ST_CoveredBy
1720: 28 6d 2e 67 65 6f 6d 2c 20 70 2e 67 65 6f 6d 29 (m.geom, p.geom)
1730: 20 41 53 20 63 6f 76 65 72 65 64 5f 62 79 0d 0a AS covered_by..
1740: 46 52 4f 4d 20 6d 75 6e 69 63 69 70 61 6c 69 74 FROM municipalit
1750: 69 65 73 20 41 53 20 6d 2c 20 70 72 6f 76 69 6e ies AS m, provin
1760: 63 65 73 20 41 53 20 70 3b 0d 0a 3c 2f 76 65 72 ces AS p;..</ver
1770: 62 61 74 69 6d 3e 0d 0a 49 6e 20 74 68 69 73 20 batim>..In this
1780: 66 69 72 73 74 20 74 65 73 74 20 49 27 76 65 20 first test I've
1790: 66 6f 6c 6c 6f 77 65 64 20 74 68 65 20 6d 6f 73 followed the mos
17a0: 74 20 3c 62 3e 63 6c 61 73 73 69 63 61 6c 20 61 t <b>classical a
17b0: 70 70 72 6f 61 63 68 3c 2f 62 3e 20 74 6f 20 64 pproach</b> to d
17c0: 65 74 65 72 6d 69 6e 65 20 73 65 76 65 72 61 6c etermine several
17d0: 20 73 70 61 74 69 61 6c 20 72 65 6c 61 74 69 6f spatial relatio
17e0: 6e 73 68 69 70 73 20 69 6e 74 65 72 63 75 72 72 nships intercurr
17f0: 69 6e 67 20 62 65 74 77 65 65 6e 3a 0d 0a 3c 75 ing between:..<u
1800: 6c 3e 0d 0a 3c 6c 69 3e 74 68 65 20 3c 62 3e 6d l>..<li>the <b>m
1810: 75 6e 69 63 69 70 61 6c 69 74 69 65 73 3c 2f 62 unicipalities</b
1820: 3e 20 74 61 62 6c 65 20 28 4d 75 6c 74 69 50 6f > table (MultiPo
1830: 6c 79 67 6f 6e 73 29 2c 20 63 6f 6e 74 61 69 6e lygons), contain
1840: 69 6e 67 20 74 68 65 20 3c 62 3e 32 37 36 3c 2f ing the <b>276</
1850: 62 3e 20 4d 75 6e 69 63 69 70 61 6c 69 74 65 73 b> Municipalites
1860: 20 6f 66 20 54 75 73 63 61 6e 79 2e 3c 2f 6c 69 of Tuscany.</li
1870: 3e 0d 0a 3c 6c 69 3e 61 6e 64 20 74 68 65 20 3c >..<li>and the <
1880: 62 3e 70 72 6f 76 69 6e 63 65 73 3c 2f 62 3e 20 b>provinces</b>
1890: 74 61 62 6c 65 20 28 4d 75 6c 74 69 50 6f 6c 79 table (MultiPoly
18a0: 67 6f 6e 73 29 2c 20 63 6f 6e 74 61 69 6e 69 6e gons), containin
18b0: 67 20 74 68 65 20 3c 62 3e 31 30 3c 2f 62 3e 20 g the <b>10</b>
18c0: 50 72 6f 76 69 6e 63 65 73 20 6f 66 20 54 75 73 Provinces of Tus
18d0: 63 61 6e 79 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e cany.</li>..<li>
18e0: 74 68 69 73 20 69 73 20 61 6e 20 75 6e 73 6f 70 this is an unsop
18f0: 68 69 73 74 69 63 61 74 65 64 20 71 75 65 72 79 histicated query
1900: 2c 20 61 6e 64 20 74 68 65 20 72 65 73 75 6c 74 , and the result
1910: 69 6e 67 20 3c 62 3e 63 61 72 74 65 73 69 61 6e ing <b>cartesian
1920: 20 70 72 6f 64 75 63 74 3c 2f 62 3e 20 6f 66 20 product</b> of
1930: 62 6f 74 68 20 74 61 62 6c 65 73 20 63 6f 6e 74 both tables cont
1940: 61 69 6e 73 20 3c 62 3e 32 2e 37 36 30 3c 2f 62 ains <b>2.760</b
1950: 3e 20 72 6f 77 73 2e 3c 2f 6c 69 3e 0d 0a 3c 2f > rows.</li>..</
1960: 75 6c 3e 0d 0a 3c 75 3e 4d 65 61 73 75 72 65 64 ul>..<u>Measured
1970: 20 74 69 6d 69 6e 67 3c 2f 75 3e 3a 20 3c 62 3e timing</u>: <b>
1980: 36 37 20 73 65 63 73 3c 2f 62 3e 0d 0a 3c 62 72 67 secs</b>..<br
1990: 3e 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 76 65 72 62 ><br><br>..<verb
19a0: 61 74 69 6d 3e 0d 0a 43 52 45 41 54 45 20 54 45 atim>..CREATE TE
19b0: 4d 50 4f 52 41 52 59 20 54 41 42 4c 45 20 74 6d MPORARY TABLE tm
19c0: 70 5f 72 65 6c 61 74 65 20 41 53 0d 0a 53 45 4c p_relate AS..SEL
19d0: 45 43 54 20 6d 2e 6e 61 6d 65 20 41 53 20 6d 75 ECT m.name AS mu
19e0: 6e 69 63 69 70 61 6c 69 74 79 2c 20 70 2e 6e 61 nicipality, p.na
19f0: 6d 65 20 41 53 20 70 72 6f 76 69 6e 63 65 2c 20 me AS province,
1a00: 53 54 5f 52 65 6c 61 74 65 28 6d 2e 67 65 6f 6d ST_Relate(m.geom
1a10: 2c 20 70 2e 67 65 6f 6d 29 20 41 53 20 6d 61 74 , p.geom) AS mat
1a20: 72 69 78 0d 0a 46 52 4f 4d 20 6d 75 6e 69 63 69 rix..FROM munici
1a30: 70 61 6c 69 74 69 65 73 20 41 53 20 6d 2c 20 70 palities AS m, p
1a40: 72 6f 76 69 6e 63 65 73 20 41 53 20 70 3b 0d 0a rovinces AS p;..
1a50: 0d 0a 53 45 4c 45 43 54 20 6d 75 6e 69 63 69 70 ..SELECT municip
1a60: 61 6c 69 74 79 2c 20 70 72 6f 76 69 6e 63 65 2c ality, province,
1a70: 20 6d 61 74 72 69 78 2c 0d 0a 20 20 20 20 53 54 matrix,.. ST
1a80: 5f 52 65 6c 61 74 65 4d 61 74 63 68 28 6d 61 74 _RelateMatch(mat
1a90: 72 69 78 2c 20 27 46 46 2a 46 46 2a 2a 2a 2a 27 rix, 'FF*FF****'
1aa0: 29 20 41 53 20 64 69 73 6a 6f 69 6e 74 2c 0d 0a ) AS disjoint,..
1ab0: 20 20 20 20 53 54 5f 52 65 6c 61 74 65 4d 61 74 ST_RelateMat
1ac0: 63 68 28 6d 61 74 72 69 78 2c 20 27 46 54 2a 2a ch(matrix, 'FT**
1ad0: 2a 2a 2a 2a 2a 27 29 20 4f 52 0d 0a 20 20 20 20 *****') OR..
1ae0: 53 54 5f 52 65 6c 61 74 65 4d 61 74 63 68 28 6d ST_RelateMatch(m
1af0: 61 74 72 69 78 2c 20 27 46 2a 2a 54 2a 2a 2a 2a atrix, 'F**T****
1b00: 2a 27 29 20 4f 52 0d 0a 20 20 20 20 53 54 5f 52 *') OR.. ST_R
1b10: 65 6c 61 74 65 4d 61 74 63 68 28 6d 61 74 72 69 elateMatch(matri
1b20: 78 2c 20 27 46 2a 2a 2a 54 2a 2a 2a 2a 27 29 20 x, 'F***T****')
1b30: 41 53 20 74 6f 75 63 68 65 73 2c 0d 0a 20 20 20 AS touches,..
1b40: 20 53 54 5f 52 65 6c 61 74 65 4d 61 74 63 68 28 ST_RelateMatch(
1b50: 6d 61 74 72 69 78 2c 20 27 54 2a 46 2a 2a 46 2a matrix, 'T*F**F*
1b60: 2a 2a 27 29 20 41 53 20 77 69 74 68 69 6e 2c 0d **') AS within,.
1b70: 0a 20 20 20 20 53 54 5f 52 65 6c 61 74 65 4d 61 . ST_RelateMa
1b80: 74 63 68 28 6d 61 74 72 69 78 2c 20 27 54 2a 2a tch(matrix, 'T**
1b90: 2a 2a 2a 2a 2a 2a 27 29 20 4f 52 0d 0a 20 20 20 ******') OR..
1ba0: 20 53 54 5f 52 65 6c 61 74 65 4d 61 74 63 68 28 ST_RelateMatch(
1bb0: 6d 61 74 72 69 78 2c 20 27 2a 54 2a 2a 2a 2a 2a matrix, '*T*****
1bc0: 2a 2a 27 29 20 4f 52 0d 0a 20 20 20 20 53 54 5f **') OR.. ST_
1bd0: 52 65 6c 61 74 65 4d 61 74 63 68 28 6d 61 74 72 RelateMatch(matr
1be0: 69 78 2c 20 27 2a 2a 2a 54 2a 2a 2a 2a 2a 27 29 ix, '***T*****')
1bf0: 20 4f 52 0d 0a 20 20 20 20 53 54 5f 52 65 6c 61 OR.. ST_Rela
1c00: 74 65 4d 61 74 63 68 28 6d 61 74 72 69 78 2c 20 teMatch(matrix,
1c10: 27 2a 2a 2a 2a 54 2a 2a 2a 2a 27 29 20 41 53 20 '****T****') AS
1c20: 69 6e 74 65 72 73 65 63 74 73 2c 0d 0a 20 20 20 intersects,..
1c30: 20 53 54 5f 52 65 6c 61 74 65 4d 61 74 63 68 28 ST_RelateMatch(
1c40: 6d 61 74 72 69 78 2c 20 27 54 2a 54 2a 2a 2a 54 matrix, 'T*T***T
1c50: 2a 2a 27 29 20 41 53 20 6f 76 65 72 6c 61 70 73 **') AS overlaps
1c60: 2c 0d 0a 20 20 20 20 53 54 5f 52 65 6c 61 74 65 ,.. ST_Relate
1c70: 4d 61 74 63 68 28 6d 61 74 72 69 78 2c 20 27 54 Match(matrix, 'T
1c80: 2a 46 2a 2a 46 2a 2a 2a 27 29 20 4f 52 0d 0a 20 *F**F***') OR..
1c90: 20 20 20 53 54 5f 52 65 6c 61 74 65 4d 61 74 63 ST_RelateMatc
1ca0: 68 28 6d 61 74 72 69 78 2c 20 27 2a 54 46 2a 2a h(matrix, '*TF**
1cb0: 46 2a 2a 2a 27 29 20 4f 52 0d 0a 20 20 20 20 53 F***') OR.. S
1cc0: 54 5f 52 65 6c 61 74 65 4d 61 74 63 68 28 6d 61 T_RelateMatch(ma
1cd0: 74 72 69 78 2c 20 27 2a 2a 46 54 2a 46 2a 2a 2a trix, '**FT*F***
1ce0: 27 29 20 4f 52 0d 0a 20 20 20 20 53 54 5f 52 65 ') OR.. ST_Re
1cf0: 6c 61 74 65 4d 61 74 63 68 28 6d 61 74 72 69 78 lateMatch(matrix
1d00: 2c 20 27 2a 2a 46 2a 54 46 2a 2a 2a 27 29 20 41 , '**F*TF***') A
1d10: 53 20 63 6f 76 65 72 65 64 5f 62 79 0d 0a 46 52 S covered_by..FR
1d20: 4f 4d 20 74 6d 70 5f 72 65 6c 61 74 65 3b 0d 0a OM tmp_relate;..
1d30: 3c 2f 76 65 72 62 61 74 69 6d 3e 0d 0a 55 73 69 </verbatim>..Usi
1d40: 6e 67 20 74 68 65 20 73 61 6d 65 20 74 61 62 6c ng the same tabl
1d50: 65 73 20 61 73 20 62 65 66 6f 72 65 20 69 6e 20 es as before in
1d60: 74 68 69 73 20 73 65 63 6f 6e 64 20 74 65 73 74 this second test
1d70: 2c 20 62 75 74 20 74 68 69 73 20 74 69 6d 65 20 , but this time
1d80: 49 27 76 65 20 61 64 6f 70 74 65 64 20 74 68 65 I've adopted the
1d90: 20 61 6c 74 65 72 6e 61 74 69 76 65 20 61 70 70 alternative app
1da0: 72 6f 61 63 68 20 62 61 73 65 64 20 6f 6e 20 3c roach based on <
1db0: 62 3e 53 54 5f 52 65 6c 61 74 65 28 29 3c 2f 62 b>ST_Relate()</b
1dc0: 3e 20 61 6e 64 20 3c 62 3e 53 54 5f 52 65 6c 61 > and <b>ST_Rela
1dd0: 74 65 4d 61 74 63 68 28 29 3c 2f 62 3e 2e 3c 62 teMatch()</b>.<b
1de0: 72 3e 0d 0a 41 66 74 65 72 20 73 6f 6d 65 20 70 r>..After some p
1df0: 72 65 6c 69 6d 69 6e 61 72 79 20 74 65 73 74 73 reliminary tests
1e00: 2c 20 69 74 20 71 75 69 63 6b 6c 79 20 65 6d 65 , it quickly eme
1e10: 72 67 65 64 20 74 68 61 74 20 74 68 65 20 53 51 rged that the SQ
1e20: 4c 69 74 65 20 6f 70 74 69 6d 69 7a 65 72 20 64 Lite optimizer d
1e30: 6f 65 73 6e 27 74 20 6c 69 6b 65 20 74 68 65 20 oesn't like the
1e40: 6d 69 78 74 75 72 65 20 6f 66 20 61 6e 20 69 6e mixture of an in
1e50: 6e 65 72 20 71 75 65 72 79 20 74 6f 67 65 74 68 ner query togeth
1e60: 65 72 20 77 69 74 68 20 66 75 6e 63 74 69 6f 6e er with function
1e70: 20 63 61 6c 6c 73 20 6f 6e 20 74 68 65 20 73 61 calls on the sa
1e80: 6d 65 20 6f 76 65 72 61 6c 6c 20 71 75 65 72 79 me overall query
1e90: 20 28 72 65 73 75 6c 74 69 6e 67 20 69 6e 20 61 (resulting in a
1ea0: 77 66 75 6c 20 74 69 6d 69 6e 67 73 29 2c 20 73 wful timings), s
1eb0: 6f 20 49 20 64 75 6c 79 20 73 77 69 74 63 68 65 o I duly switche
1ec0: 64 20 74 6f 20 61 6e 20 69 6e 64 69 72 65 63 74 d to an indirect
1ed0: 20 3c 62 3e 74 77 6f 2d 73 74 65 70 73 20 61 70 <b>two-steps ap
1ee0: 70 72 6f 61 63 68 3c 2f 62 3e 3a 0d 0a 3c 75 6c proach</b>:..<ul
1ef0: 3e 0d 0a 3c 6c 69 3e 3c 62 3e 73 74 65 70 20 23 >..<li><b>step #
1f00: 31 3c 2f 62 3e 3a 20 63 6f 6d 70 75 74 69 6e 67 1</b>: computing
1f10: 20 3c 62 3e 53 54 5f 52 65 6c 61 74 65 64 28 29 <b>ST_Related()
1f20: 3c 2f 62 3e 20 61 6e 64 20 73 61 76 69 6e 67 20 </b> and saving
1f30: 74 68 65 20 77 68 6f 6c 65 20 72 65 73 75 6c 74 the whole result
1f40: 73 65 74 20 69 6e 74 6f 20 61 20 3c 62 3e 74 65 set into a <b>te
1f50: 6d 70 6f 72 61 72 79 20 74 61 62 6c 65 3c 2f 62 mporary table</b
1f60: 3e 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 3c 62 3e >.</li>..<li><b>
1f70: 73 74 65 70 20 23 32 3c 2f 62 3e 3a 20 63 6f 6d step #2</b>: com
1f80: 70 6c 65 74 69 6e 67 20 74 68 65 20 74 61 73 6b pleting the task
1f90: 20 62 79 20 63 61 6c 6c 69 6e 67 20 3c 62 3e 53 by calling <b>S
1fa0: 54 5f 52 65 6c 61 74 65 4d 61 74 63 68 3c 2f 62 T_RelateMatch</b
1fb0: 3e 20 6f 6e 20 74 68 65 20 61 62 6f 76 65 20 74 > on the above t
1fc0: 65 6d 70 6f 72 61 72 79 20 74 61 62 6c 65 2e 3c emporary table.<
1fd0: 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 0d 0a 3c 75 3e /li>..</ul>..<u>
1fe0: 4d 65 61 73 75 72 65 64 20 74 69 6d 69 6e 67 3c Measured timing<
1ff0: 2f 75 3e 3a 20 3c 62 3e 32 32 20 73 65 63 73 3c /u>: <b>22 secs<
2000: 2f 62 3e 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 75 3e /b><br><br>..<u>
2010: 4e 6f 74 65 3c 2f 75 3e 3a 20 74 68 65 20 73 65 Note</u>: the se
2020: 63 6f 6e 64 20 71 75 65 72 79 20 28 53 54 5f 52 cond query (ST_R
2030: 65 6c 61 74 65 4d 61 74 63 68 29 20 6f 6e 6c 79 elateMatch) only
2040: 20 72 65 71 75 69 72 65 64 20 61 20 66 65 77 20 required a few
2050: 6d 69 6c 6c 69 73 65 63 6f 6e 64 73 20 74 6f 20 milliseconds to
2060: 63 6f 6d 70 6c 65 74 65 3b 20 74 68 65 20 72 65 complete; the re
2070: 61 6c 20 63 6f 6d 70 75 74 61 74 69 6f 6e 61 6c al computational
2080: 20 6c 6f 61 64 20 77 61 73 20 65 6e 74 69 72 65 load was entire
2090: 6c 79 20 63 6f 6e 66 69 6e 65 64 20 77 69 74 68 ly confined with
20a0: 69 6e 20 74 68 65 20 66 69 72 73 74 20 71 75 65 in the first que
20b0: 72 79 20 28 53 54 5f 52 65 6c 61 74 65 29 2e 3c ry (ST_Relate).<
20c0: 62 72 3e 3c 62 72 3e 0d 0a 3c 75 3e 46 69 6e 61 br><br>..<u>Fina
20d0: 6c 20 63 6f 6e 63 6c 75 73 69 6f 6e 3c 2f 75 3e l conclusion</u>
20e0: 3a 20 64 69 72 65 63 74 6c 79 20 75 73 69 6e 67 : directly using
20f0: 20 74 68 65 20 61 77 6b 77 61 72 64 20 44 45 2d the awkward DE-
2100: 39 49 4d 20 6d 6f 64 65 6c 20 69 73 20 69 6e 20 9IM model is in
2110: 73 6f 6d 65 77 61 79 73 20 64 69 66 66 69 63 75 someways difficu
2120: 6c 74 2c 20 62 75 74 20 69 74 20 64 6f 65 73 20 lt, but it does
2130: 65 6e 73 75 72 65 20 61 6e 20 61 73 74 6f 6e 69 ensure an astoni
2140: 73 68 69 6e 67 20 70 65 72 66 6f 72 6d 61 6e 63 shing performanc
2150: 65 20 62 6f 6f 73 74 2e 3c 62 72 3e 0d 0a 49 74 e boost.<br>..It
2160: 27 73 20 75 73 61 67 65 20 69 73 20 68 69 67 68 's usage is high
2170: 6c 79 20 72 65 63 6f 6d 6d 65 6e 64 65 64 20 77 ly recommended w
2180: 68 65 6e 20 79 6f 75 20 61 72 65 20 72 65 71 75 hen you are requ
2190: 69 72 65 64 20 74 6f 20 63 68 65 63 6b 20 6d 6f ired to check mo
21a0: 72 65 20 74 68 61 6e 20 61 20 73 69 6e 67 6c 65 re than a single
21b0: 20 73 70 61 74 69 61 6c 20 72 65 6c 61 74 69 6f spatial relatio
21c0: 6e 73 68 69 70 20 62 65 74 77 65 65 6e 20 74 68 nship between th
21d0: 65 20 73 61 6d 65 20 70 61 69 72 20 6f 66 20 47 e same pair of G
21e0: 65 6f 6d 65 74 72 69 65 73 2e 0d 0a 3c 62 72 3e eometries...<br>
21f0: 3c 62 72 3e 0a 0a 3c 68 72 20 2f 3e 3c 64 69 76 <br>..<hr /><div
2200: 20 69 64 3d 22 31 35 30 39 65 36 61 32 31 35 37 id="1509e6a2157
2210: 39 38 30 36 39 22 3e 3c 69 3e 4f 6e 20 32 30 32 98069"><i>On 202
2220: 32 2d 30 34 2d 30 35 20 31 34 3a 34 37 3a 30 37 2-04-05 14:47:07
2230: 20 55 54 43 20 61 6e 6f 6e 79 6d 6f 75 73 20 61 UTC anonymous a
2240: 64 64 65 64 3a 3c 2f 69 3e 3c 62 72 20 2f 3e 0a dded:</i><br />.
2250: 46 6f 72 20 74 68 65 20 70 65 72 66 6f 72 6d 61 For the performa
2260: 6e 63 65 20 69 73 73 75 65 20 77 68 65 6e 20 75 nce issue when u
2270: 73 69 6e 67 20 6d 75 6c 74 69 70 6c 65 20 53 54 sing multiple ST
2280: 5f 52 65 6c 61 74 65 4d 61 74 63 68 28 29 20 63 _RelateMatch() c
2290: 61 6c 6c 73 2c 20 68 74 65 72 65 20 73 65 65 6d alls, htere seem
22a0: 73 20 74 6f 20 62 65 20 61 6e 20 61 6c 74 65 72 s to be an alter
22b0: 6e 61 74 69 76 65 20 74 6f 20 70 75 74 74 69 6e native to puttin
22c0: 67 20 74 68 65 20 64 61 74 61 20 69 6e 20 61 20 g the data in a
22d0: 74 65 6d 70 20 74 61 62 6c 65 20 66 69 72 73 74 temp table first
22e0: 2e 20 41 63 63 6f 72 64 69 6e 67 20 74 6f 20 74 . According to t
22f0: 65 73 74 73 20 49 20 64 69 64 20 6f 6e 20 6d 79 ests I did on my
2300: 20 6f 77 6e 20 64 61 74 61 2c 20 69 66 20 79 6f own data, if yo
2310: 75 20 75 73 65 20 61 20 73 75 62 73 65 6c 65 63 u use a subselec
2320: 74 20 61 6e 64 20 70 72 65 76 65 6e 74 20 73 71 t and prevent sq
2330: 6c 69 74 65 20 66 72 6f 6d 20 22 66 6c 61 74 74 lite from "flatt
2340: 65 6e 69 6e 67 22 20 74 68 65 20 73 75 62 73 65 ening" the subse
2350: 63 74 20 62 79 20 61 64 64 69 6e 67 20 61 20 4c ct by adding a L
2360: 49 4d 49 54 20 61 6e 64 20 4f 46 46 53 45 54 20 IMIT and OFFSET
2370: 63 6c 61 75 73 65 20 6c 69 6b 65 20 74 68 69 73 clause like this
2380: 2c 20 70 65 72 66 6f 72 6d 61 6e 63 65 20 69 73 , performance is
2390: 20 67 6f 6f 64 20 61 73 20 77 65 6c 6c 3a 0d 0a good as well:..
23a0: 0d 0a 3c 62 6c 6f 63 6b 71 75 6f 74 65 3e 3c 70 ..<blockquote><p
23b0: 72 65 3e 0d 0a 20 20 53 45 4c 45 43 54 20 2e 2e re>.. SELECT ..
23c0: 2e 0d 0a 20 20 20 20 46 52 4f 4d 20 28 0d 0a 20 ... FROM (..
23d0: 20 20 20 20 20 53 45 4c 45 43 54 20 2e 2e 2e 0d SELECT ....
23e0: 0a 20 20 20 20 20 20 20 20 46 52 4f 4d 20 2e 2e . FROM ..
23f0: 2e 0d 0a 20 20 20 20 20 20 20 4c 49 4d 49 54 20 ... LIMIT
2400: 2d 31 20 4f 46 46 53 45 54 20 30 29 20 0d 0a 20 -1 OFFSET 0) ..
2410: 20 20 57 48 45 52 45 20 2e 2e 2e 0d 0a 3c 2f 70 WHERE .....</p
2420: 72 65 3e 3c 2f 62 6c 6f 63 6b 71 75 6f 74 65 3e re></blockquote>
2430: 3c 2f 64 69 76 20 69 64 3d 22 31 35 30 39 65 36 </div id="1509e6
2440: 61 32 31 35 37 39 38 30 36 39 22 3e 0a 5a 20 34 a215798069">.Z 4
2450: 31 62 35 34 64 37 33 34 35 33 66 33 37 30 61 31 1b54d73453f370a1
2460: 65 35 39 65 37 62 61 31 34 64 32 32 30 31 66 0a e59e7ba14d2201f.