Hex Artifact Content
Not logged in

Artifact 5184ac9e3a9d12a6ccecefa6144de04b2b0850a3:

Wiki page [liblwgeom-4.0] by sandro 2012-08-30 17:15:23.
0000: 44 20 32 30 31 32 2d 30 38 2d 33 30 54 31 37 3a  D 2012-08-30T17:
0010: 31 35 3a 32 33 2e 34 34 33 0a 4c 20 6c 69 62 6c  15:23.443.L libl
0020: 77 67 65 6f 6d 2d 34 2e 30 0a 55 20 73 61 6e 64  wgeom-4.0.U sand
0030: 72 6f 0a 57 20 31 31 39 31 33 0a 3c 68 32 3e 53  ro.W 11913.<h2>S
0040: 51 4c 20 66 75 6e 63 74 69 6f 6e 73 20 62 61 73  QL functions bas
0050: 65 64 20 6f 6e 20 6c 69 62 6c 77 67 65 6f 6d 20  ed on liblwgeom 
0060: 73 75 70 70 6f 72 74 20 69 6e 20 76 65 72 73 69  support in versi
0070: 6f 6e 20 34 2e 30 2e 30 3c 2f 68 32 3e 0d 0a 42  on 4.0.0</h2>..B
0080: 61 63 6b 20 74 6f 20 3c 61 20 68 72 65 66 3d 22  ack to <a href="
0090: 68 74 74 70 73 3a 2f 2f 77 77 77 2e 67 61 69 61  https://www.gaia
00a0: 2d 67 69 73 2e 69 74 2f 66 6f 73 73 69 6c 2f 6c  -gis.it/fossil/l
00b0: 69 62 73 70 61 74 69 61 6c 69 74 65 2f 77 69 6b  ibspatialite/wik
00c0: 69 3f 6e 61 6d 65 3d 73 77 69 74 63 68 69 6e 67  i?name=switching
00d0: 2d 74 6f 2d 34 2e 30 23 6c 69 62 6c 77 67 65 6f  -to-4.0#liblwgeo
00e0: 6d 22 3e 6d 61 69 6e 20 70 61 67 65 3c 2f 61 3e  m">main page</a>
00f0: 0d 0a 3c 68 33 3e 4d 61 6b 69 6e 67 20 69 6e 76  ..<h3>Making inv
0100: 61 6c 69 64 20 47 65 6f 6d 65 74 72 69 65 73 20  alid Geometries 
0110: 74 6f 20 62 65 63 6f 6d 65 20 70 65 72 66 65 63  to become perfec
0120: 74 6c 79 20 76 61 6c 69 64 20 6f 6e 65 73 3c 2f  tly valid ones</
0130: 68 33 3e 0d 0a 41 73 20 79 6f 75 20 61 6c 72 65  h3>..As you alre
0140: 61 64 79 20 73 75 72 65 6c 79 20 6b 6e 6f 77 2c  ady surely know,
0150: 20 6e 6f 74 20 61 6c 6c 20 67 65 6f 6d 65 74 72   not all geometr
0160: 69 65 73 20 61 72 65 20 76 61 6c 69 64 20 6f 6e  ies are valid on
0170: 65 73 3a 20 6d 6f 73 74 20 6e 6f 74 61 62 6c 79  es: most notably
0180: 20 69 6e 20 74 68 65 20 73 70 65 63 69 66 69 63   in the specific
0190: 20 63 61 73 65 20 6f 66 20 50 6f 6c 79 67 6f 6e   case of Polygon
01a0: 61 6c 20 67 65 6f 6d 65 74 72 69 65 73 20 74 68  al geometries th
01b0: 65 72 65 20 61 72 65 20 6d 61 6e 79 20 64 65 74  ere are many det
01c0: 61 69 6c 65 64 20 72 75 6c 65 73 20 74 6f 20 62  ailed rules to b
01d0: 65 20 72 65 73 70 65 63 74 65 64 2e 0d 0a 49 6e  e respected...In
01e0: 66 72 69 6e 67 69 6e 67 20 6f 6e 65 20 6f 66 20  fringing one of 
01f0: 73 75 63 68 20 72 75 6c 65 73 20 64 69 72 65 63  such rules direc
0200: 74 6c 79 20 6c 65 61 64 73 20 74 6f 20 73 6f 6d  tly leads to som
0210: 65 20 69 6e 76 61 6c 69 64 20 47 65 6f 6d 65 74  e invalid Geomet
0220: 72 79 3a 20 61 6e 64 20 61 6e 20 69 6e 76 61 6c  ry: and an inval
0230: 69 64 20 47 65 6f 6d 65 74 72 79 20 63 6f 75 6c  id Geometry coul
0240: 64 20 63 61 75 73 65 20 69 6e 76 61 6c 69 64 20  d cause invalid 
0250: 72 65 73 75 6c 74 73 20 74 6f 20 62 65 20 72 65  results to be re
0260: 74 75 72 6e 65 64 2c 20 6f 72 20 63 6f 75 6c 64  turned, or could
0270: 20 65 76 65 6e 74 75 61 6c 6c 79 20 63 61 75 73   eventually caus
0280: 65 20 73 6f 6d 65 20 75 6e 65 78 70 65 63 74 65  e some unexpecte
0290: 64 20 6e 61 73 74 79 20 63 72 61 73 68 20 69 6e  d nasty crash in
02a0: 20 74 68 65 20 77 6f 72 73 74 20 63 61 73 65 2e   the worst case.
02b0: 3c 62 72 3e 3c 62 72 3e 0d 0a 47 45 4f 53 20 28  <br><br>..GEOS (
02c0: 61 6e 64 20 74 68 75 73 20 53 70 61 74 69 61 4c  and thus SpatiaL
02d0: 69 74 65 29 20 61 6c 72 65 61 64 79 20 73 75 70  ite) already sup
02e0: 70 6f 72 74 20 74 68 65 20 3c 62 3e 53 54 5f 49  port the <b>ST_I
02f0: 73 56 61 6c 69 64 28 29 3c 2f 62 3e 20 53 51 4c  sValid()</b> SQL
0300: 20 66 75 6e 63 74 69 6f 6e 3b 20 62 79 20 69 6e   function; by in
0310: 76 6f 6b 69 6e 67 20 74 68 69 73 20 66 75 6e 63  voking this func
0320: 74 69 6f 6e 20 79 6f 75 20 63 61 6e 20 65 61 73  tion you can eas
0330: 69 6c 79 20 69 64 65 6e 74 69 66 79 20 61 6c 6c  ily identify all
0340: 20 6f 66 66 65 6e 64 69 6e 67 20 47 65 6f 6d 65   offending Geome
0350: 74 72 69 65 73 20 65 76 65 6e 74 75 61 6c 6c 79  tries eventually
0360: 20 63 6f 6e 74 61 69 6e 65 64 20 77 69 74 68 69   contained withi
0370: 6e 20 79 6f 75 72 20 74 61 62 6c 65 73 3b 20 61  n your tables; a
0380: 6e 79 77 61 79 20 79 6f 75 20 63 61 6e 6e 6f 74  nyway you cannot
0390: 20 61 74 74 65 6d 70 74 20 74 6f 20 3c 69 3e 73   attempt to <i>s
03a0: 61 6e 69 74 69 7a 65 3c 2f 69 3e 20 74 68 65 6d  anitize</i> them
03b0: 2e 3c 62 72 3e 0d 0a 53 70 61 74 69 61 4c 69 74  .<br>..SpatiaLit
03c0: 65 20 61 6c 72 65 61 64 79 20 73 75 70 70 6f 72  e already suppor
03d0: 74 65 64 20 61 20 3c 62 3e 53 54 5f 53 61 6e 69  ted a <b>ST_Sani
03e0: 74 69 7a 65 47 65 6f 6d 65 74 72 79 28 29 3c 2f  tizeGeometry()</
03f0: 62 3e 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e 3b  b> SQL function;
0400: 20 62 75 74 20 74 68 69 73 20 77 61 73 20 73 69   but this was si
0410: 6d 70 6c 79 20 63 61 70 61 62 6c 65 20 74 6f 20  mply capable to 
0420: 65 66 66 65 63 74 69 76 65 6c 79 20 72 65 73 6f  effectively reso
0430: 6c 76 65 20 6a 75 73 74 20 66 65 77 20 69 6e 76  lve just few inv
0440: 61 6c 69 64 69 74 79 20 63 61 75 73 65 73 2c 20  alidity causes, 
0450: 61 6e 64 20 77 61 73 6e 27 74 20 61 74 20 61 6c  and wasn't at al
0460: 6c 20 61 20 67 65 6e 65 72 61 6c 20 73 6f 6c 75  l a general solu
0470: 74 69 6f 6e 20 66 6f 72 20 74 68 69 73 20 70 72  tion for this pr
0480: 6f 62 6c 65 6d 2e 3c 62 72 3e 3c 62 72 3e 0d 0a  oblem.<br><br>..
0490: 4e 6f 77 2c 20 74 68 61 6e 6b 73 20 74 6f 20 3c  Now, thanks to <
04a0: 69 3e 6c 69 62 6c 77 67 65 6f 6d 3c 2f 69 3e 2c  i>liblwgeom</i>,
04b0: 20 53 70 61 74 69 61 4c 69 74 65 20 63 61 6e 20   SpatiaLite can 
04c0: 73 75 70 70 6f 72 74 20 74 68 65 20 73 61 6d 65  support the same
04d0: 20 69 64 65 6e 74 69 63 61 6c 20 3c 62 3e 53 54   identical <b>ST
04e0: 5f 4d 61 6b 65 56 61 6c 69 64 28 29 3c 2f 62 3e  _MakeValid()</b>
04f0: 20 61 6c 72 65 61 64 79 20 73 75 70 70 6f 72 74   already support
0500: 65 64 20 62 79 20 50 6f 73 74 47 49 53 3b 20 66  ed by PostGIS; f
0510: 65 77 20 73 6d 61 6c 6c 20 69 6d 70 6c 65 6d 65  ew small impleme
0520: 6e 74 61 74 69 6f 6e 20 64 65 74 61 69 6c 73 20  ntation details 
0530: 64 69 66 66 65 72 20 28 64 75 65 20 74 6f 20 74  differ (due to t
0540: 68 65 20 68 75 67 65 20 61 72 63 68 69 74 65 63  he huge architec
0550: 74 75 72 61 6c 20 64 69 66 66 65 72 65 6e 63 65  tural difference
0560: 73 20 64 69 73 74 69 6e 67 75 69 73 68 69 6e 67  s distinguishing
0570: 20 50 6f 73 74 47 49 53 20 61 6e 64 20 53 70 61   PostGIS and Spa
0580: 74 69 61 4c 69 74 65 29 2c 20 62 75 74 20 74 68  tiaLite), but th
0590: 65 20 75 6e 64 65 72 6c 79 69 6e 67 20 63 6f 64  e underlying cod
05a0: 65 20 69 73 20 65 78 61 63 74 65 6c 79 20 6f 6e  e is exactely on
05b0: 65 20 61 6e 64 20 74 68 65 20 73 61 6d 65 20 66  e and the same f
05c0: 6f 72 20 62 6f 74 68 2e 0d 0a 3c 68 34 3e 61 20  or both...<h4>a 
05d0: 66 69 72 73 74 20 62 61 73 69 63 20 65 78 61 6d  first basic exam
05e0: 70 6c 65 3c 2f 68 34 3e 0d 0a 57 65 27 6c 6c 20  ple</h4>..We'll 
05f0: 73 74 61 72 74 20 6c 6f 61 64 69 6e 67 20 74 68  start loading th
0600: 65 20 4c 6f 63 61 6c 20 43 6f 75 6e 63 69 6c 73  e Local Councils
0610: 20 61 64 6d 69 6e 69 73 74 72 61 74 69 76 65 20   administrative 
0620: 62 6f 75 6e 64 61 72 69 65 73 20 73 75 70 70 6c  boundaries suppl
0630: 69 65 64 20 62 79 20 49 53 54 41 54 20 28 74 68  ied by ISTAT (th
0640: 65 20 49 74 61 6c 69 61 6e 20 4e 61 74 69 6f 6e  e Italian Nation
0650: 61 6c 20 53 74 61 74 69 63 73 20 41 67 65 6e 63  al Statics Agenc
0660: 79 29 3a 20 74 68 69 73 20 64 61 74 61 73 61 74  y): this datasat
0670: 20 69 73 20 66 72 65 65 6c 79 20 61 76 61 69 6c   is freely avail
0680: 61 62 6c 65 20 66 6f 72 20 3c 61 20 68 72 65 66  able for <a href
0690: 3d 22 68 74 74 70 3a 2f 2f 77 77 77 2e 69 73 74  ="http://www.ist
06a0: 61 74 2e 69 74 2f 75 70 6c 6f 61 64 73 2f 63 6f  at.it/uploads/co
06b0: 6d 32 30 31 31 2e 7a 69 70 22 3e 64 6f 77 6e 6c  m2011.zip">downl
06c0: 6f 61 64 3c 2f 61 3e 20 75 6e 64 65 72 20 61 20  oad</a> under a 
06d0: 43 43 2d 42 59 20 6c 69 63 65 6e 73 65 2e 0d 0a  CC-BY license...
06e0: 4a 75 73 74 20 61 20 71 75 69 63 6b 20 63 68 65  Just a quick che
06f0: 63 6b 2c 20 61 6e 64 20 77 65 27 6c 6c 20 73 6f  ck, and we'll so
0700: 6f 6e 20 64 69 73 63 6f 76 65 72 20 74 68 61 74  on discover that
0710: 20 74 68 69 73 20 64 61 74 61 73 65 74 20 61 63   this dataset ac
0720: 74 75 61 6c 6c 79 20 63 6f 6e 74 61 69 6e 73 20  tually contains 
0730: 73 65 76 65 72 61 6c 20 6d 61 6c 66 6f 72 6d 65  several malforme
0740: 64 20 50 6f 6c 79 67 6f 6e 73 3a 0d 0a 3c 74 61  d Polygons:..<ta
0750: 62 6c 65 20 62 67 63 6f 6c 6f 72 3d 22 23 65 30  ble bgcolor="#e0
0760: 65 30 65 30 22 20 63 65 6c 6c 73 70 61 63 69 6e  e0e0" cellspacin
0770: 67 3d 22 34 22 20 63 65 6c 6c 70 61 64 64 69 6e  g="4" cellpaddin
0780: 67 3d 22 38 22 3e 0d 0a 3c 74 72 3e 3c 74 64 3e  g="8">..<tr><td>
0790: 0d 0a 3c 62 3e 53 45 4c 45 43 54 20 43 6f 75 6e  ..<b>SELECT Coun
07a0: 74 28 2a 29 3c 62 72 3e 0d 0a 46 52 4f 4d 20 63  t(*)<br>..FROM c
07b0: 6f 6d 32 30 31 31 3c 62 72 3e 0d 0a 57 48 45 52  om2011<br>..WHER
07c0: 45 20 53 54 5f 49 73 56 61 6c 69 64 28 67 65 6f  E ST_IsValid(geo
07d0: 6d 65 74 72 79 29 20 3d 20 30 3b 3c 2f 62 3e 0d  metry) = 0;</b>.
07e0: 0a 3c 68 72 3e 0d 0a 31 39 0d 0a 3c 2f 74 64 3e  .<hr>..19..</td>
07f0: 3c 2f 74 72 3e 0d 0a 3c 2f 74 61 62 6c 65 3e 3c  </tr>..</table><
0800: 62 72 3e 0d 0a 52 65 63 6f 76 65 72 69 6e 67 20  br>..Recovering 
0810: 61 6c 6c 20 6d 61 6c 66 6f 72 6d 65 64 20 47 65  all malformed Ge
0820: 6f 6d 65 74 72 69 65 73 20 69 73 20 6e 6f 77 20  ometries is now 
0830: 61 62 73 6f 6c 75 74 65 6c 79 20 73 69 6d 70 6c  absolutely simpl
0840: 65 20 61 6e 64 20 65 61 73 79 3a 0d 0a 3c 74 61  e and easy:..<ta
0850: 62 6c 65 20 62 67 63 6f 6c 6f 72 3d 22 23 65 30  ble bgcolor="#e0
0860: 65 30 65 30 22 20 63 65 6c 6c 73 70 61 63 69 6e  e0e0" cellspacin
0870: 67 3d 22 34 22 20 63 65 6c 6c 70 61 64 64 69 6e  g="4" cellpaddin
0880: 67 3d 22 38 22 3e 3c 74 72 3e 3c 74 64 3e 0d 0a  g="8"><tr><td>..
0890: 3c 62 3e 55 50 44 41 54 45 20 63 6f 6d 32 30 31  <b>UPDATE com201
08a0: 31 20 53 45 54 20 67 65 6f 6d 65 74 72 79 20 3d  1 SET geometry =
08b0: 20 53 54 5f 4d 61 6b 65 56 61 6c 69 64 28 67 65   ST_MakeValid(ge
08c0: 6f 6d 65 74 72 79 29 3c 62 72 3e 0d 0a 57 48 45  ometry)<br>..WHE
08d0: 52 45 20 53 54 5f 49 73 56 61 6c 69 64 28 67 65  RE ST_IsValid(ge
08e0: 6f 6d 65 74 72 79 29 20 3d 20 30 3b 3c 2f 62 3e  ometry) = 0;</b>
08f0: 0d 0a 3c 2f 74 64 3e 3c 2f 74 72 3e 0d 0a 3c 74  ..</td></tr>..<t
0900: 72 3e 3c 74 64 3e 0d 0a 3c 62 3e 53 45 4c 45 43  r><td>..<b>SELEC
0910: 54 20 43 6f 75 6e 74 28 2a 29 3c 62 72 3e 0d 0a  T Count(*)<br>..
0920: 46 52 4f 4d 20 63 6f 6d 32 30 31 31 3c 62 72 3e  FROM com2011<br>
0930: 0d 0a 57 48 45 52 45 20 53 54 5f 49 73 56 61 6c  ..WHERE ST_IsVal
0940: 69 64 28 67 65 6f 6d 65 74 72 79 29 20 3d 20 30  id(geometry) = 0
0950: 3b 3c 2f 62 3e 0d 0a 3c 68 72 3e 0d 0a 30 0d 0a  ;</b>..<hr>..0..
0960: 3c 2f 74 64 3e 3c 2f 74 72 3e 0d 0a 3c 2f 74 61  </td></tr>..</ta
0970: 62 6c 65 3e 3c 62 72 3e 0d 0a 3c 74 61 62 6c 65  ble><br>..<table
0980: 20 62 6f 72 64 65 72 3d 22 31 22 20 63 65 6c 6c   border="1" cell
0990: 73 70 61 63 69 6e 67 3d 22 34 22 20 63 65 6c 6c  spacing="4" cell
09a0: 70 61 64 64 69 6e 67 3d 22 34 22 3e 0d 0a 3c 74  padding="4">..<t
09b0: 72 3e 3c 74 68 20 63 6f 6c 73 70 61 6e 3d 22 32  r><th colspan="2
09c0: 22 3e 57 68 79 20 74 68 65 20 42 72 6f 6e 74 65  ">Why the Bronte
09d0: 20 4c 6f 63 61 6c 20 43 6f 75 6e 63 69 6c 20 62   Local Council b
09e0: 6f 75 6e 64 61 72 79 20 77 61 73 20 6d 61 6c 66  oundary was malf
09f0: 6f 72 6d 65 64 20 3f 3c 62 72 3e 0d 0a 61 20 71  ormed ?<br>..a q
0a00: 75 69 63 6b 20 61 6e 61 6c 79 73 69 73 3c 2f 74  uick analysis</t
0a10: 68 3e 3c 2f 74 72 3e 0d 0a 3c 74 72 3e 3c 74 68  h></tr>..<tr><th
0a20: 3e 6d 61 6c 66 6f 72 6d 65 64 20 2f 20 69 6e 76  >malformed / inv
0a30: 61 6c 69 64 3c 2f 74 68 3e 3c 74 68 3e 76 61 6c  alid</th><th>val
0a40: 69 64 3c 2f 74 68 3e 3c 2f 74 72 3e 0d 0a 3c 74  id</th></tr>..<t
0a50: 72 3e 3c 74 64 3e 0d 0a 3c 69 6d 67 20 73 72 63  r><td>..<img src
0a60: 3d 22 68 74 74 70 3a 2f 2f 77 77 77 2e 67 61 69  ="http://www.gai
0a70: 61 2d 67 69 73 2e 69 74 2f 67 61 69 61 2d 73 69  a-gis.it/gaia-si
0a80: 6e 73 2f 77 72 69 74 65 2d 76 69 65 77 2d 70 69  ns/write-view-pi
0a90: 63 73 2f 62 72 6f 6e 74 65 2d 69 6e 76 61 6c 69  cs/bronte-invali
0aa0: 64 2e 70 6e 67 22 20 61 6c 74 3d 22 62 72 6f 6e  d.png" alt="bron
0ab0: 74 65 20 69 6e 76 61 6c 69 64 22 3e 0d 0a 3c 2f  te invalid">..</
0ac0: 74 64 3e 3c 74 64 3e 0d 0a 3c 69 6d 67 20 73 72  td><td>..<img sr
0ad0: 63 3d 22 68 74 74 70 3a 2f 2f 77 77 77 2e 67 61  c="http://www.ga
0ae0: 69 61 2d 67 69 73 2e 69 74 2f 67 61 69 61 2d 73  ia-gis.it/gaia-s
0af0: 69 6e 73 2f 77 72 69 74 65 2d 76 69 65 77 2d 70  ins/write-view-p
0b00: 69 63 73 2f 62 72 6f 6e 74 65 2d 76 61 6c 69 64  ics/bronte-valid
0b10: 2e 70 6e 67 22 20 61 6c 74 3d 22 62 72 6f 6e 74  .png" alt="bront
0b20: 65 20 76 61 6c 69 64 22 3e 0d 0a 3c 2f 74 64 3e  e valid">..</td>
0b30: 3c 2f 74 72 3e 0d 0a 3c 74 72 3e 3c 74 64 20 63  </tr>..<tr><td c
0b40: 6f 6c 73 70 61 6e 3d 22 32 22 3e 0d 0a 41 73 20  olspan="2">..As 
0b50: 79 6f 75 20 63 61 6e 20 65 61 73 69 6c 79 20 6e  you can easily n
0b60: 6f 74 69 63 65 2c 20 74 68 65 20 3c 69 3e 69 6e  otice, the <i>in
0b70: 76 61 6c 69 64 3c 2f 69 3e 20 70 6f 6c 79 67 6f  valid</i> polygo
0b80: 6e 20 77 61 73 20 73 69 6d 70 6c 79 20 72 65 70  n was simply rep
0b90: 72 65 73 65 6e 74 20 62 79 20 74 68 65 20 3c 69  resent by the <i
0ba0: 3e 65 78 74 65 72 69 6f 72 20 72 69 6e 67 3c 2f  >exterior ring</
0bb0: 69 3e 3a 20 62 75 74 20 74 68 65 72 65 20 69 73  i>: but there is
0bc0: 20 61 20 68 75 67 65 20 69 6e 74 65 72 6e 61 6c   a huge internal
0bd0: 20 68 6f 6c 65 20 69 6e 20 74 68 69 73 20 50 6f   hole in this Po
0be0: 6c 79 67 6f 6e 2e 0d 0a 54 68 69 73 20 6f 64 64  lygon...This odd
0bf0: 20 63 6f 6e 64 69 74 69 6f 6e 20 69 73 20 72 65   condition is re
0c00: 70 75 74 65 64 20 70 65 72 66 65 63 74 6c 79 20  puted perfectly 
0c10: 76 61 6c 69 64 20 62 79 20 73 6f 6d 65 20 6d 61  valid by some ma
0c20: 69 6e 73 74 72 65 61 6d 20 70 72 6f 70 72 69 65  instream proprie
0c30: 74 61 72 79 20 73 6f 66 74 77 61 72 65 3b 20 61  tary software; a
0c40: 6e 79 77 61 79 2c 20 69 73 20 61 63 74 75 61 6c  nyway, is actual
0c50: 6c 79 20 3c 69 3e 69 6e 76 61 6c 69 64 3c 2f 69  ly <i>invalid</i
0c60: 3e 20 61 63 63 6f 72 64 69 6e 67 6c 79 20 74 6f  > accordingly to
0c70: 20 73 74 61 6e 64 61 72 64 20 72 75 6c 65 73 2e   standard rules.
0c80: 3c 62 72 3e 0d 0a 53 6f 20 74 68 65 20 63 6f 72  <br>..So the cor
0c90: 72 65 63 74 20 72 65 70 72 65 73 65 6e 74 61 74  rect representat
0ca0: 69 6f 6e 20 66 6f 72 20 74 68 69 73 20 50 6f 6c  ion for this Pol
0cb0: 79 67 6f 6e 20 72 65 71 75 69 72 65 73 20 61 6e  ygon requires an
0cc0: 20 3c 69 3e 65 78 74 65 72 69 6f 72 20 72 69 6e   <i>exterior rin
0cd0: 67 3c 2f 69 3e 20 61 6e 64 20 61 20 73 65 70 61  g</i> and a sepa
0ce0: 72 61 74 65 20 3c 69 3e 69 6e 74 65 72 69 6f 72  rate <i>interior
0cf0: 20 72 69 6e 67 3c 2f 69 3e 3b 20 53 54 5f 4d 61   ring</i>; ST_Ma
0d00: 6b 65 56 61 6c 69 64 28 29 20 64 6f 65 73 20 74  keValid() does t
0d10: 68 65 20 6d 61 67 69 63 2c 20 74 68 75 73 20 72  he magic, thus r
0d20: 65 63 6f 76 65 72 69 6e 67 20 61 20 66 75 6c 6c  ecovering a full
0d30: 20 76 61 6c 69 64 20 50 6f 6c 79 67 6f 6e 2e 0d   valid Polygon..
0d40: 0a 3c 2f 74 64 3e 3c 2f 74 72 3e 0d 0a 3c 2f 74  .</td></tr>..</t
0d50: 61 62 6c 65 3e 0d 0a 3c 68 34 3e 61 20 73 65 63  able>..<h4>a sec
0d60: 6f 6e 64 20 6d 6f 72 65 20 65 6c 61 62 6f 72 61  ond more elabora
0d70: 74 65 20 65 78 61 6d 70 6c 65 3c 2f 68 34 3e 0d  te example</h4>.
0d80: 0a 54 68 69 73 20 74 69 6d 65 20 77 65 27 6c 6c  .This time we'll
0d90: 20 70 75 72 70 6f 73 65 6c 79 20 63 72 65 61 74   purposely creat
0da0: 65 20 61 20 73 65 76 65 72 65 6c 79 20 6d 61 6c  e a severely mal
0db0: 66 6f 72 6d 65 64 20 50 6f 6c 79 67 6f 6e 3a 0d  formed Polygon:.
0dc0: 0a 3c 74 61 62 6c 65 20 62 67 63 6f 6c 6f 72 3d  .<table bgcolor=
0dd0: 22 23 65 30 65 30 65 30 22 20 63 65 6c 6c 73 70  "#e0e0e0" cellsp
0de0: 61 63 69 6e 67 3d 22 34 22 20 63 65 6c 6c 70 61  acing="4" cellpa
0df0: 64 64 69 6e 67 3d 22 38 22 3e 0d 0a 3c 74 72 3e  dding="8">..<tr>
0e00: 3c 74 64 3e 0d 0a 3c 62 3e 53 45 4c 45 43 54 20  <td>..<b>SELECT 
0e10: 67 2c 20 53 54 5f 4d 61 6b 65 56 61 6c 69 64 28  g, ST_MakeValid(
0e20: 67 29 2c 20 53 54 5f 4d 61 6b 65 56 61 6c 69 64  g), ST_MakeValid
0e30: 44 69 73 63 61 72 64 65 64 28 67 29 3c 62 72 3e  Discarded(g)<br>
0e40: 0d 0a 46 52 4f 4d 20 28 3c 62 72 3e 0d 0a 53 45  ..FROM (<br>..SE
0e50: 4c 45 43 54 20 53 54 5f 47 65 6f 6d 46 72 6f 6d  LECT ST_GeomFrom
0e60: 54 65 78 74 28 27 50 4f 4c 59 47 4f 4e 28 28 30  Text('POLYGON((0
0e70: 20 30 2c 20 30 20 31 30 2c 20 31 31 20 31 30 2c   0, 0 10, 11 10,
0e80: 20 31 30 20 31 30 2c 20 31 30 20 31 2c 20 35 20   10 10, 10 1, 5 
0e90: 31 2c 20 35 20 39 2c 20 35 20 31 2c 20 30 20 31  1, 5 9, 5 1, 0 1
0ea0: 2c 20 30 20 30 29 29 27 29 20 41 53 20 67 3c 62  , 0 0))') AS g<b
0eb0: 72 3e 0d 0a 29 3b 3c 2f 62 3e 0d 0a 3c 2f 74 64  r>..);</b>..</td
0ec0: 3e 3c 2f 74 72 3e 0d 0a 3c 2f 74 61 62 6c 65 3e  ></tr>..</table>
0ed0: 3c 62 72 3e 0d 0a 3c 74 61 62 6c 65 20 63 65 6c  <br>..<table cel
0ee0: 6c 73 70 61 63 69 6e 67 3d 22 34 22 20 63 65 6c  lspacing="4" cel
0ef0: 6c 70 61 64 64 69 6e 67 3d 22 34 22 3e 0d 0a 3c  lpadding="4">..<
0f00: 74 72 3e 3c 74 64 3e 0d 0a 54 68 69 73 20 66 69  tr><td>..This fi
0f10: 67 75 72 65 20 72 65 70 72 65 73 65 6e 74 73 20  gure represents 
0f20: 74 68 65 20 3c 69 3e 69 6e 76 61 6c 69 64 3c 2f  the <i>invalid</
0f30: 69 3e 20 50 6f 6c 79 67 6f 6e 20 72 65 74 75 72  i> Polygon retur
0f40: 6e 65 64 20 62 79 20 3c 62 3e 53 54 5f 47 65 6f  ned by <b>ST_Geo
0f50: 6d 46 72 6f 6d 54 65 78 74 28 29 3c 2f 62 3e 2e  mFromText()</b>.
0f60: 3c 62 72 3e 3c 62 72 3e 0d 0a 54 68 65 72 65 20  <br><br>..There 
0f70: 61 72 65 20 74 68 72 65 65 20 3c 69 3e 73 70 69  are three <i>spi
0f80: 6b 65 73 3c 2f 69 3e 20 69 6e 20 74 68 65 20 3c  kes</i> in the <
0f90: 69 3e 65 78 74 65 72 69 6f 72 20 72 69 6e 67 3c  i>exterior ring<
0fa0: 2f 69 3e 2c 20 61 6e 64 20 74 68 69 73 20 6f 6e  /i>, and this on
0fb0: 65 20 73 75 72 65 6c 79 20 69 73 20 61 20 73 65  e surely is a se
0fc0: 76 65 72 65 20 69 6e 76 61 6c 69 64 69 74 79 20  vere invalidity 
0fd0: 63 61 75 73 65 2e 0d 0a 3c 2f 74 64 3e 3c 74 64  cause...</td><td
0fe0: 3e 0d 0a 3c 69 6d 67 20 73 72 63 3d 22 68 74 74  >..<img src="htt
0ff0: 70 3a 2f 2f 77 77 77 2e 67 61 69 61 2d 67 69 73  p://www.gaia-gis
1000: 2e 69 74 2f 67 61 69 61 2d 73 69 6e 73 2f 77 72  .it/gaia-sins/wr
1010: 69 74 65 2d 76 69 65 77 2d 70 69 63 73 2f 73 70  ite-view-pics/sp
1020: 69 6b 65 2d 69 6e 76 61 6c 69 64 2e 70 6e 67 22  ike-invalid.png"
1030: 20 61 6c 74 3d 22 73 70 69 6b 65 20 69 6e 76 61   alt="spike inva
1040: 6c 69 64 22 3e 0d 0a 3c 2f 74 64 3e 3c 2f 74 72  lid">..</td></tr
1050: 3e 0d 0a 3c 74 72 3e 3c 74 64 3e 0d 0a 54 68 69  >..<tr><td>..Thi
1060: 73 20 66 69 67 75 72 65 20 72 65 70 72 65 73 65  s figure represe
1070: 6e 74 73 20 74 68 65 20 3c 69 3e 76 61 6c 69 64  nts the <i>valid
1080: 3c 2f 69 3e 20 50 6f 6c 79 67 6f 6e 20 72 65 74  </i> Polygon ret
1090: 75 72 6e 65 64 20 62 79 20 3c 62 3e 53 54 5f 4d  urned by <b>ST_M
10a0: 61 6b 65 56 61 6c 69 64 28 29 3c 2f 62 3e 2e 3c  akeValid()</b>.<
10b0: 62 72 3e 3c 62 72 3e 0d 0a 4e 6f 77 20 77 65 20  br><br>..Now we 
10c0: 68 61 76 65 20 61 20 6e 69 63 65 20 72 65 67 75  have a nice regu
10d0: 6c 61 72 20 72 65 63 74 61 6e 67 6c 65 2c 20 61  lar rectangle, a
10e0: 6c 6c 20 3c 69 3e 73 70 69 6b 65 73 3c 2f 69 3e  ll <i>spikes</i>
10f0: 20 68 61 76 65 20 62 65 65 6e 20 72 65 6d 6f 76   have been remov
1100: 65 64 2e 0d 0a 3c 2f 74 64 3e 3c 74 64 3e 0d 0a  ed...</td><td>..
1110: 3c 69 6d 67 20 73 72 63 3d 22 68 74 74 70 3a 2f  <img src="http:/
1120: 2f 77 77 77 2e 67 61 69 61 2d 67 69 73 2e 69 74  /www.gaia-gis.it
1130: 2f 67 61 69 61 2d 73 69 6e 73 2f 77 72 69 74 65  /gaia-sins/write
1140: 2d 76 69 65 77 2d 70 69 63 73 2f 73 70 69 6b 65  -view-pics/spike
1150: 2d 76 61 6c 69 64 2e 70 6e 67 22 20 61 6c 74 3d  -valid.png" alt=
1160: 22 73 70 69 6b 65 20 76 61 6c 69 64 22 3e 0d 0a  "spike valid">..
1170: 3c 2f 74 64 3e 3c 2f 74 72 3e 0d 0a 3c 74 72 3e  </td></tr>..<tr>
1180: 3c 74 64 3e 0d 0a 41 6e 79 77 61 79 20 74 68 65  <td>..Anyway the
1190: 20 72 65 6d 6f 76 65 64 20 3c 69 3e 73 70 69 6b   removed <i>spik
11a0: 65 73 3c 2f 69 3e 20 61 72 65 6e 27 74 20 73 69  es</i> aren't si
11b0: 6d 70 6c 79 20 76 61 6e 69 73 68 65 64 20 69 6e  mply vanished in
11c0: 74 6f 20 6e 6f 74 68 69 6e 67 2e 0d 0a 59 6f 75  to nothing...You
11d0: 20 63 6f 75 6c 64 20 65 76 65 6e 74 75 61 6c 6c   could eventuall
11e0: 79 20 72 65 74 72 69 65 76 65 20 28 61 6e 64 20  y retrieve (and 
11f0: 6d 61 79 20 62 65 2c 20 73 61 76 69 6e 67 20 73  may be, saving s
1200: 6f 6d 65 77 68 65 72 65 29 20 61 6c 6c 20 6f 66  omewhere) all of
1210: 66 65 6e 64 69 6e 67 20 65 6c 65 6d 65 6e 74 73  fending elements
1220: 20 62 65 69 6e 67 20 64 69 73 63 61 72 64 65 64   being discarded
1230: 20 64 75 72 69 6e 67 20 74 68 65 20 76 61 6c 69   during the vali
1240: 64 61 74 69 6f 6e 20 70 72 6f 63 65 73 73 2e 3c  dation process.<
1250: 62 72 3e 3c 62 72 3e 0d 0a 59 6f 75 20 73 69 6d  br><br>..You sim
1260: 70 6c 79 20 68 61 76 65 20 74 6f 20 69 6e 76 6f  ply have to invo
1270: 6b 65 20 3c 62 3e 53 54 5f 4d 61 6b 65 56 61 6c  ke <b>ST_MakeVal
1280: 69 64 44 69 73 63 61 72 64 65 64 28 29 3c 2f 62  idDiscarded()</b
1290: 3e 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 75 3e 50 6c  ><br><br>..<u>Pl
12a0: 65 61 73 65 20 6e 6f 74 65 3c 2f 75 3e 3a 20 74  ease note</u>: t
12b0: 68 69 73 20 69 73 20 73 74 72 6f 6e 67 6c 79 20  his is strongly 
12c0: 64 69 66 66 65 72 65 6e 74 20 66 72 6f 6d 20 74  different from t
12d0: 68 65 20 50 6f 73 74 47 49 53 20 6f 77 6e 20 69  he PostGIS own i
12e0: 6d 70 6c 65 6d 65 6e 74 61 74 69 6f 6e 2e 0d 0a  mplementation...
12f0: 3c 2f 74 64 3e 3c 74 64 3e 0d 0a 3c 69 6d 67 20  </td><td>..<img 
1300: 73 72 63 3d 22 68 74 74 70 3a 2f 2f 77 77 77 2e  src="http://www.
1310: 67 61 69 61 2d 67 69 73 2e 69 74 2f 67 61 69 61  gaia-gis.it/gaia
1320: 2d 73 69 6e 73 2f 77 72 69 74 65 2d 76 69 65 77  -sins/write-view
1330: 2d 70 69 63 73 2f 73 70 69 6b 65 2d 64 69 73 63  -pics/spike-disc
1340: 61 72 64 65 64 2e 70 6e 67 22 20 61 6c 74 3d 22  arded.png" alt="
1350: 73 70 69 6b 65 20 64 69 73 63 61 72 64 65 64 22  spike discarded"
1360: 3e 0d 0a 3c 2f 74 64 3e 3c 2f 74 72 3e 0d 0a 3c  >..</td></tr>..<
1370: 2f 74 61 62 6c 65 3e 0d 0a 3c 62 72 3e 3c 68 72  /table>..<br><hr
1380: 3e 0d 0a 3c 68 33 3e 53 70 6c 69 74 74 69 6e 67  >..<h3>Splitting
1390: 20 67 65 6f 6d 65 74 72 69 65 73 20 69 6e 20 74   geometries in t
13a0: 77 6f 20 68 61 6c 76 65 73 3c 2f 68 33 3e 0d 0a  wo halves</h3>..
13b0: 54 68 65 20 3c 62 3e 53 54 5f 53 70 6c 69 74 28  The <b>ST_Split(
13c0: 29 3c 2f 62 3e 20 53 70 61 74 69 61 6c 20 53 51  )</b> Spatial SQ
13d0: 4c 20 66 75 6e 63 74 69 6f 6e 20 69 73 20 69 6e  L function is in
13e0: 74 65 6e 64 65 64 20 74 6f 20 3c 69 3e 63 75 74  tended to <i>cut
13f0: 3c 2f 69 3e 20 61 20 47 65 6f 6d 65 74 72 79 2e  </i> a Geometry.
1400: 3c 62 72 3e 0d 0a 54 68 69 73 20 66 75 6e 63 74  <br>..This funct
1410: 69 6f 6e 20 61 6c 77 61 79 73 20 72 65 71 75 69  ion always requi
1420: 72 65 73 20 74 6f 20 70 61 73 73 20 74 77 6f 20  res to pass two 
1430: 64 69 66 66 65 72 65 6e 74 20 47 65 6f 6d 65 74  different Geomet
1440: 72 69 65 73 3a 3c 75 6c 3e 0d 0a 3c 6c 69 3e 74  ries:<ul>..<li>t
1450: 68 65 20 66 69 72 73 74 20 47 65 6f 6d 65 74 72  he first Geometr
1460: 79 20 69 73 20 61 73 73 75 6d 65 64 20 74 6f 20  y is assumed to 
1470: 72 65 70 72 65 73 65 6e 74 20 74 68 65 20 3c 62  represent the <b
1480: 3e 69 6e 70 75 74 3c 2f 62 3e 20 61 6b 61 20 3c  >input</b> aka <
1490: 62 3e 74 61 72 67 65 74 3c 2f 62 3e 20 74 6f 20  b>target</b> to 
14a0: 62 65 20 73 70 6c 69 74 2e 3c 2f 6c 69 3e 0d 0a  be split.</li>..
14b0: 3c 6c 69 3e 74 68 65 20 73 65 63 6f 6e 64 20 47  <li>the second G
14c0: 65 6f 6d 65 74 72 79 20 69 73 20 61 73 73 75 6d  eometry is assum
14d0: 65 64 20 74 6f 20 72 65 70 72 65 73 65 6e 74 20  ed to represent 
14e0: 74 68 65 20 3c 62 3e 62 6c 61 64 65 3c 2f 62 3e  the <b>blade</b>
14f0: 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e 0d 0a 4f  .</li>..</ul>..O
1500: 6e 6c 79 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e  nly the followin
1510: 67 20 63 6f 6e 66 69 67 75 72 61 74 69 6f 6e 73  g configurations
1520: 20 61 72 65 20 61 73 73 75 6d 65 64 20 74 6f 20   are assumed to 
1530: 62 65 20 76 61 6c 69 64 3a 3c 75 6c 3e 0d 0a 3c  be valid:<ul>..<
1540: 6c 69 3e 4c 69 6e 65 73 74 72 69 6e 67 20 74 61  li>Linestring ta
1550: 72 67 65 74 20 2f 20 50 6f 69 6e 74 20 62 6c 61  rget / Point bla
1560: 64 65 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 4d 75  de.</li>..<li>Mu
1570: 6c 74 69 4c 69 6e 65 73 74 72 69 6e 67 20 74 61  ltiLinestring ta
1580: 72 67 65 74 20 2f 20 50 6f 69 6e 74 20 62 6c 61  rget / Point bla
1590: 64 65 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 47 65  de.</li>..<li>Ge
15a0: 6f 6d 65 74 72 79 43 6f 6c 6c 65 63 74 69 6f 6e  ometryCollection
15b0: 20 28 63 6f 6e 74 61 69 6e 69 6e 67 20 61 74 20   (containing at 
15c0: 6c 65 61 73 74 20 6f 6e 65 20 4c 69 6e 65 73 74  least one Linest
15d0: 72 69 6e 67 29 20 2f 20 50 6f 69 6e 74 20 62 6c  ring) / Point bl
15e0: 61 64 65 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 4c  ade.</li>..<li>L
15f0: 69 6e 65 73 74 72 69 6e 67 20 74 61 72 67 65 74  inestring target
1600: 20 2f 20 4c 69 6e 65 73 74 72 69 6e 67 20 62 6c   / Linestring bl
1610: 61 64 65 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69 3e 4d  ade.</li>..<li>M
1620: 75 6c 74 69 4c 69 6e 65 73 74 72 69 6e 67 20 74  ultiLinestring t
1630: 61 72 67 65 74 20 2f 20 4c 69 6e 65 73 74 72 69  arget / Linestri
1640: 6e 67 20 62 6c 61 64 65 2e 3c 2f 6c 69 3e 0d 0a  ng blade.</li>..
1650: 3c 6c 69 3e 50 6f 6c 79 67 6f 6e 20 74 61 72 67  <li>Polygon targ
1660: 65 74 20 2f 20 4c 69 6e 65 73 74 72 69 6e 67 20  et / Linestring 
1670: 62 6c 61 64 65 2e 3c 2f 6c 69 3e 0d 0a 3c 6c 69  blade.</li>..<li
1680: 3e 4d 75 6c 74 69 50 6f 6c 79 67 6f 6e 20 74 61  >MultiPolygon ta
1690: 72 67 65 74 20 2f 20 4c 69 6e 65 73 74 72 69 6e  rget / Linestrin
16a0: 67 20 62 6c 61 64 65 2e 3c 2f 6c 69 3e 0d 0a 3c  g blade.</li>..<
16b0: 6c 69 3e 47 65 6f 6d 65 74 72 79 43 6f 6c 6c 65  li>GeometryColle
16c0: 63 74 69 6f 6e 20 2f 20 4c 69 6e 65 73 74 72 69  ction / Linestri
16d0: 6e 67 20 62 6c 61 64 65 2e 3c 2f 6c 69 3e 0d 0a  ng blade.</li>..
16e0: 3c 6c 69 3e 50 6c 65 61 73 65 20 6e 6f 74 69 63  <li>Please notic
16f0: 65 3a 20 74 68 65 20 74 61 72 67 65 74 20 47 65  e: the target Ge
1700: 6f 6d 65 74 72 79 20 73 68 6f 75 6c 64 20 6e 65  ometry should ne
1710: 76 65 72 20 63 6f 6e 74 61 69 6e 20 61 20 50 6f  ver contain a Po
1720: 69 6e 74 2e 3c 2f 6c 69 3e 0d 0a 3c 2f 75 6c 3e  int.</li>..</ul>
1730: 0d 0a 3c 68 34 3e 45 78 61 6d 70 6c 65 20 23 31  ..<h4>Example #1
1740: 20 2d 20 73 70 6c 6c 74 74 69 6e 67 20 61 20 4c   - splltting a L
1750: 69 6e 65 73 74 72 69 6e 67 20 62 79 20 61 20 50  inestring by a P
1760: 6f 69 6e 74 20 62 6c 61 64 65 3c 2f 68 34 3e 0d  oint blade</h4>.
1770: 0a 3c 74 61 62 6c 65 20 62 67 63 6f 6c 6f 72 3d  .<table bgcolor=
1780: 22 23 65 30 65 30 65 30 22 20 63 65 6c 6c 73 70  "#e0e0e0" cellsp
1790: 61 63 69 6e 67 3d 22 34 22 20 63 65 6c 6c 70 61  acing="4" cellpa
17a0: 64 64 69 6e 67 3d 22 38 22 3e 0d 0a 3c 74 72 3e  dding="8">..<tr>
17b0: 3c 74 64 3e 0d 0a 3c 62 3e 53 45 4c 45 43 54 20  <td>..<b>SELECT 
17c0: 53 54 5f 53 70 6c 69 74 28 69 6e 70 75 74 2e 67  ST_Split(input.g
17d0: 2c 20 62 6c 61 64 65 2e 67 29 2c 20 53 54 5f 53  , blade.g), ST_S
17e0: 70 6c 69 74 4c 65 66 74 28 69 6e 70 75 74 2e 67  plitLeft(input.g
17f0: 2c 20 62 6c 61 64 65 2e 67 29 2c 20 53 54 5f 53  , blade.g), ST_S
1800: 70 6c 69 74 52 69 67 68 74 28 69 6e 70 75 74 2e  plitRight(input.
1810: 67 2c 20 62 6c 61 64 65 2e 67 29 3c 62 72 3e 0d  g, blade.g)<br>.
1820: 0a 46 52 4f 4d 3c 62 72 3e 20 0d 0a 28 53 45 4c  .FROM<br> ..(SEL
1830: 45 43 54 20 47 65 6f 6d 46 72 6f 6d 54 65 78 74  ECT GeomFromText
1840: 28 27 4c 49 4e 45 53 54 52 49 4e 47 28 30 20 31  ('LINESTRING(0 1
1850: 30 2c 20 32 20 30 2c 20 34 20 34 2c 20 36 20 30  0, 2 0, 4 4, 6 0
1860: 2c 20 31 30 20 31 30 29 27 29 20 41 53 20 67 29  , 10 10)') AS g)
1870: 20 41 53 20 69 6e 70 75 74 2c 3c 62 72 3e 0d 0a   AS input,<br>..
1880: 28 53 45 4c 45 43 54 20 47 65 6f 6d 46 72 6f 6d  (SELECT GeomFrom
1890: 54 65 78 74 28 27 50 4f 49 4e 54 28 33 20 32 29  Text('POINT(3 2)
18a0: 27 29 20 41 53 20 67 29 20 41 53 20 62 6c 61 64  ') AS g) AS blad
18b0: 65 3b 3c 2f 62 3e 0d 0a 3c 2f 74 64 3e 3c 2f 74  e;</b>..</td></t
18c0: 72 3e 3c 2f 74 61 62 6c 65 3e 0d 0a 3c 74 61 62  r></table>..<tab
18d0: 6c 65 20 63 65 6c 6c 73 70 61 63 69 6e 67 3d 22  le cellspacing="
18e0: 34 22 20 63 65 6c 6c 70 61 64 64 69 6e 67 3d 22  4" cellpadding="
18f0: 34 22 3e 0d 0a 3c 74 72 3e 3c 74 64 3e 0d 0a 54  4">..<tr><td>..T
1900: 68 65 20 3c 62 3e 53 54 5f 53 70 6c 69 74 28 29  he <b>ST_Split()
1910: 3c 2f 62 3e 20 53 51 4c 20 66 75 6e 63 74 69 6f  </b> SQL functio
1920: 6e 20 77 69 6c 6c 20 73 69 6d 70 6c 79 20 72 65  n will simply re
1930: 74 75 72 6e 20 61 20 3c 69 3e 63 6f 6c 6c 65 63  turn a <i>collec
1940: 74 69 6f 6e 3c 2f 69 3e 20 61 67 67 72 65 67 61  tion</i> aggrega
1950: 74 69 6e 67 20 61 6c 6c 20 66 72 61 67 6d 65 6e  ting all fragmen
1960: 74 73 20 64 65 72 69 76 69 6e 67 20 66 72 6f 6d  ts deriving from
1970: 20 74 68 65 20 63 75 74 2e 3c 62 72 3e 0d 0a 54   the cut.<br>..T
1980: 68 69 73 20 69 73 6e 27 74 20 72 65 61 6c 6c 79  his isn't really
1990: 20 75 73 65 66 75 6c 2e 3c 62 72 3e 3c 62 72 3e   useful.<br><br>
19a0: 0d 0a 3c 75 3e 50 6c 65 61 73 65 20 6e 6f 74 65  ..<u>Please note
19b0: 3c 2f 75 3e 3a 20 3c 69 3e 63 6f 6c 6c 65 63 74  </u>: <i>collect
19c0: 69 6f 6e 73 3c 2f 69 3e 20 69 6e 20 53 70 61 74  ions</i> in Spat
19d0: 69 61 4c 69 74 65 20 62 65 68 61 76 65 20 71 75  iaLite behave qu
19e0: 69 74 65 20 64 69 66 66 65 6e 74 6c 79 20 66 72  ite diffently fr
19f0: 6f 6d 20 50 6f 73 74 47 69 73 2e 0d 0a 3c 2f 74  om PostGis...</t
1a00: 64 3e 3c 74 64 3e 0d 0a 3c 69 6d 67 20 73 72 63  d><td>..<img src
1a10: 3d 22 68 74 74 70 3a 2f 2f 77 77 77 2e 67 61 69  ="http://www.gai
1a20: 61 2d 67 69 73 2e 69 74 2f 67 61 69 61 2d 73 69  a-gis.it/gaia-si
1a30: 6e 73 2f 77 72 69 74 65 2d 76 69 65 77 2d 70 69  ns/write-view-pi
1a40: 63 73 2f 73 70 6c 69 74 2d 6c 6e 2e 70 6e 67 22  cs/split-ln.png"
1a50: 20 61 6c 74 3d 22 73 70 6c 69 74 20 6c 69 6e 65   alt="split line
1a60: 22 3e 0d 0a 3c 2f 74 64 3e 3c 2f 74 72 3e 0d 0a  ">..</td></tr>..
1a70: 3c 74 72 3e 3c 74 64 3e 0d 0a 54 68 65 20 3c 62  <tr><td>..The <b
1a80: 3e 53 54 5f 53 70 6c 69 74 4c 65 66 74 28 29 3c  >ST_SplitLeft()<
1a90: 2f 62 3e 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e  /b> SQL function
1aa0: 20 77 69 6c 6c 20 72 65 74 75 72 6e 20 69 6e 73   will return ins
1ab0: 74 65 61 64 20 61 20 3c 69 3e 63 6f 6c 6c 65 63  tead a <i>collec
1ac0: 74 69 6f 6e 3c 2f 69 3e 20 61 67 67 72 65 67 61  tion</i> aggrega
1ad0: 74 69 6e 67 20 61 6c 6c 20 66 72 61 67 6d 65 6e  ting all fragmen
1ae0: 74 73 20 6c 61 79 69 6e 67 20 6f 6e 20 74 68 65  ts laying on the
1af0: 20 3c 69 3e 6c 65 66 74 3c 2f 69 3e 20 73 69 64   <i>left</i> sid
1b00: 65 20 6f 66 20 74 68 65 20 63 75 74 2e 3c 62 72  e of the cut.<br
1b10: 3e 0d 0a 46 6f 72 20 4c 69 6e 65 73 74 72 69 6e  >..For Linestrin
1b20: 67 73 20 79 6f 75 20 63 61 6e 6e 6f 74 20 69 6e  gs you cannot in
1b30: 74 65 6e 64 20 3c 69 3e 6c 65 66 74 3c 2f 69 3e  tend <i>left</i>
1b40: 20 69 6e 20 74 68 65 20 76 65 72 79 20 6c 69 74   in the very lit
1b50: 65 72 61 6c 20 73 65 6e 73 65 3b 20 74 68 69 73  eral sense; this
1b60: 20 72 65 61 6c 6c 79 20 6d 65 61 6e 73 20 3c 69   really means <i
1b70: 3e 74 68 65 20 73 69 64 65 20 77 68 65 72 65 20  >the side where 
1b80: 74 68 65 20 73 74 61 72 74 2d 70 6f 69 6e 74 20  the start-point 
1b90: 6c 61 79 3c 2f 69 3e 2e 3c 62 72 3e 3c 62 72 3e  lay</i>.<br><br>
1ba0: 0d 0a 3c 75 3e 50 6c 65 61 73 65 20 6e 6f 74 65  ..<u>Please note
1bb0: 3c 2f 75 3e 3a 20 69 66 20 74 68 65 20 3c 69 3e  </u>: if the <i>
1bc0: 62 6c 61 64 65 3c 2f 69 3e 20 64 6f 65 73 6e 27  blade</i> doesn'
1bd0: 74 20 69 6e 74 65 72 63 65 70 74 73 20 74 68 65  t intercepts the
1be0: 20 74 61 72 67 65 74 20 61 74 20 61 6c 6c 2c 20   target at all, 
1bf0: 74 68 61 6e 20 6e 6f 20 63 75 74 20 77 6f 75 6c  than no cut woul
1c00: 64 20 62 65 20 6f 62 76 69 6f 75 73 6c 79 20 70  d be obviously p
1c10: 6f 73 73 69 62 6c 65 2e 20 49 6e 20 74 68 69 73  ossible. In this
1c20: 20 73 70 65 63 69 61 6c 20 63 61 73 65 20 74 68   special case th
1c30: 65 20 6f 72 69 67 69 6e 61 6c 20 74 61 72 67 65  e original targe
1c40: 74 20 47 65 6f 6d 65 74 72 79 20 77 69 6c 6c 20  t Geometry will 
1c50: 62 65 20 61 6c 77 61 79 73 20 72 65 74 75 72 6e  be always return
1c60: 65 64 20 28 61 62 73 6f 6c 75 74 65 6c 79 20 75  ed (absolutely u
1c70: 6e 63 68 61 6e 67 65 64 29 20 6f 6e 20 74 68 65  nchanged) on the
1c80: 20 3c 69 3e 6c 65 66 74 3c 2f 69 3e 20 73 69 64   <i>left</i> sid
1c90: 65 20 63 6f 6c 6c 65 63 74 69 6f 6e 2e 0d 0a 3c  e collection...<
1ca0: 2f 74 64 3e 3c 74 64 3e 0d 0a 3c 69 6d 67 20 73  /td><td>..<img s
1cb0: 72 63 3d 22 68 74 74 70 3a 2f 2f 77 77 77 2e 67  rc="http://www.g
1cc0: 61 69 61 2d 67 69 73 2e 69 74 2f 67 61 69 61 2d  aia-gis.it/gaia-
1cd0: 73 69 6e 73 2f 77 72 69 74 65 2d 76 69 65 77 2d  sins/write-view-
1ce0: 70 69 63 73 2f 73 70 6c 69 74 2d 6c 6e 2d 4c 2e  pics/split-ln-L.
1cf0: 70 6e 67 22 20 61 6c 74 3d 22 73 70 6c 69 74 2d  png" alt="split-
1d00: 6c 65 66 74 20 6c 69 6e 65 22 3e 0d 0a 3c 2f 74  left line">..</t
1d10: 64 3e 3c 2f 74 72 3e 0d 0a 3c 74 72 3e 3c 74 64  d></tr>..<tr><td
1d20: 3e 0d 0a 54 68 65 20 3c 62 3e 53 54 5f 53 70 6c  >..The <b>ST_Spl
1d30: 69 74 52 69 67 68 74 28 29 3c 2f 62 3e 20 53 51  itRight()</b> SQ
1d40: 4c 20 66 75 6e 63 74 69 6f 6e 20 77 69 6c 6c 20  L function will 
1d50: 72 65 74 75 72 6e 20 61 20 3c 69 3e 63 6f 6c 6c  return a <i>coll
1d60: 65 63 74 69 6f 6e 3c 2f 69 3e 20 61 67 67 72 65  ection</i> aggre
1d70: 67 61 74 69 6e 67 20 61 6c 6c 20 66 72 61 67 6d  gating all fragm
1d80: 65 6e 74 73 20 6c 61 79 69 6e 67 20 6f 6e 20 74  ents laying on t
1d90: 68 65 20 3c 69 3e 72 69 67 68 74 3c 2f 69 3e 20  he <i>right</i> 
1da0: 73 69 64 65 20 6f 66 20 74 68 65 20 63 75 74 2e  side of the cut.
1db0: 3c 62 72 3e 0d 0a 46 6f 72 20 4c 69 6e 65 73 74  <br>..For Linest
1dc0: 72 69 6e 67 73 20 79 6f 75 20 63 61 6e 6e 6f 74  rings you cannot
1dd0: 20 69 6e 74 65 6e 64 20 3c 69 3e 72 69 67 68 74   intend <i>right
1de0: 3c 2f 69 3e 20 69 6e 20 74 68 65 20 76 65 72 79  </i> in the very
1df0: 20 6c 69 74 65 72 61 6c 20 73 65 6e 73 65 3b 20   literal sense; 
1e00: 74 68 69 73 20 72 65 61 6c 6c 79 20 6d 65 61 6e  this really mean
1e10: 73 20 3c 69 3e 74 68 65 20 73 69 64 65 20 77 68  s <i>the side wh
1e20: 65 72 65 20 74 68 65 20 65 6e 64 2d 70 6f 69 6e  ere the end-poin
1e30: 74 20 6c 61 79 3c 2f 69 3e 2e 3c 62 72 3e 3c 62  t lay</i>.<br><b
1e40: 72 3e 0d 0a 3c 75 3e 50 6c 65 61 73 65 20 6e 6f  r>..<u>Please no
1e50: 74 65 3c 2f 75 3e 3a 20 69 66 20 74 68 65 20 3c  te</u>: if the <
1e60: 69 3e 62 6c 61 64 65 3c 2f 69 3e 20 64 6f 65 73  i>blade</i> does
1e70: 6e 27 74 20 69 6e 74 65 72 63 65 70 74 73 20 74  n't intercepts t
1e80: 68 65 20 74 61 72 67 65 74 20 61 74 20 61 6c 6c  he target at all
1e90: 2c 20 74 68 61 6e 20 6e 6f 20 63 75 74 20 77 6f  , than no cut wo
1ea0: 75 6c 64 20 62 65 20 6f 62 76 69 6f 75 73 6c 79  uld be obviously
1eb0: 20 70 6f 73 73 69 62 6c 65 2e 20 49 6e 20 74 68   possible. In th
1ec0: 69 73 20 73 70 65 63 69 61 6c 20 63 61 73 65 20  is special case 
1ed0: 74 68 65 20 3c 69 3e 72 69 67 68 74 3c 2f 69 3e  the <i>right</i>
1ee0: 20 73 69 64 65 20 63 6f 6c 6c 65 63 74 69 6f 6e   side collection
1ef0: 20 77 69 6c 6c 20 62 65 20 4e 55 4c 4c 2e 0d 0a   will be NULL...
1f00: 3c 2f 74 64 3e 3c 74 64 3e 0d 0a 3c 69 6d 67 20  </td><td>..<img 
1f10: 73 72 63 3d 22 68 74 74 70 3a 2f 2f 77 77 77 2e  src="http://www.
1f20: 67 61 69 61 2d 67 69 73 2e 69 74 2f 67 61 69 61  gaia-gis.it/gaia
1f30: 2d 73 69 6e 73 2f 77 72 69 74 65 2d 76 69 65 77  -sins/write-view
1f40: 2d 70 69 63 73 2f 73 70 6c 69 74 2d 6c 6e 2d 52  -pics/split-ln-R
1f50: 2e 70 6e 67 22 20 61 6c 74 3d 22 73 70 6c 69 74  .png" alt="split
1f60: 2d 72 69 67 68 74 20 6c 69 6e 65 22 3e 0d 0a 3c  -right line">..<
1f70: 2f 74 64 3e 3c 2f 74 72 3e 0d 0a 3c 2f 74 61 62  /td></tr>..</tab
1f80: 6c 65 3e 0d 0a 3c 68 34 3e 45 78 61 6d 70 6c 65  le>..<h4>Example
1f90: 20 23 32 20 2d 20 73 70 6c 6c 74 74 69 6e 67 20   #2 - splltting 
1fa0: 61 20 50 6f 6c 79 67 6f 6e 20 62 79 20 61 20 4c  a Polygon by a L
1fb0: 69 6e 65 73 74 72 69 6e 67 20 62 6c 61 64 65 3c  inestring blade<
1fc0: 2f 68 34 3e 0d 0a 3c 74 61 62 6c 65 20 62 67 63  /h4>..<table bgc
1fd0: 6f 6c 6f 72 3d 22 23 65 30 65 30 65 30 22 20 63  olor="#e0e0e0" c
1fe0: 65 6c 6c 73 70 61 63 69 6e 67 3d 22 34 22 20 63  ellspacing="4" c
1ff0: 65 6c 6c 70 61 64 64 69 6e 67 3d 22 38 22 3e 0d  ellpadding="8">.
2000: 0a 3c 74 72 3e 3c 74 64 3e 0d 0a 3c 62 3e 53 45  .<tr><td>..<b>SE
2010: 4c 45 43 54 20 53 54 5f 53 70 6c 69 74 28 69 6e  LECT ST_Split(in
2020: 70 75 74 2e 67 2c 20 62 6c 61 64 65 2e 67 29 2c  put.g, blade.g),
2030: 20 53 54 5f 53 70 6c 69 74 4c 65 66 74 28 69 6e   ST_SplitLeft(in
2040: 70 75 74 2e 67 2c 20 62 6c 61 64 65 2e 67 29 2c  put.g, blade.g),
2050: 20 53 54 5f 53 70 6c 69 74 52 69 67 68 74 28 69   ST_SplitRight(i
2060: 6e 70 75 74 2e 67 2c 20 62 6c 61 64 65 2e 67 29  nput.g, blade.g)
2070: 3c 62 72 3e 0d 0a 46 52 4f 4d 3c 62 72 3e 20 0d  <br>..FROM<br> .
2080: 0a 28 53 45 4c 45 43 54 20 47 65 6f 6d 46 72 6f  .(SELECT GeomFro
2090: 6d 54 65 78 74 28 27 50 4f 4c 59 47 4f 4e 28 28  mText('POLYGON((
20a0: 30 20 31 2c 20 31 30 20 31 2c 20 31 30 20 39 2c  0 1, 10 1, 10 9,
20b0: 20 30 20 39 2c 20 30 20 31 29 2c 20 28 32 20 32   0 9, 0 1), (2 2
20c0: 2c 20 37 20 32 2c 20 37 20 36 2c 20 32 20 36 2c  , 7 2, 7 6, 2 6,
20d0: 20 32 20 32 29 29 27 29 20 41 53 20 67 29 20 41   2 2))') AS g) A
20e0: 53 20 69 6e 70 75 74 2c 3c 62 72 3e 20 0d 0a 28  S input,<br> ..(
20f0: 53 45 4c 45 43 54 20 47 65 6f 6d 46 72 6f 6d 54  SELECT GeomFromT
2100: 65 78 74 28 27 4c 49 4e 45 53 54 52 49 4e 47 28  ext('LINESTRING(
2110: 32 20 30 2c 20 36 20 31 30 29 27 29 20 41 53 20  2 0, 6 10)') AS 
2120: 67 29 20 41 53 20 62 6c 61 64 65 3b 3c 2f 62 3e  g) AS blade;</b>
2130: 0d 0a 3c 2f 74 64 3e 3c 2f 74 72 3e 0d 0a 3c 2f  ..</td></tr>..</
2140: 74 61 62 6c 65 3e 3c 62 72 3e 0d 0a 3c 74 61 62  table><br>..<tab
2150: 6c 65 20 63 65 6c 6c 73 70 61 63 69 6e 67 3d 22  le cellspacing="
2160: 34 22 20 63 65 6c 6c 70 61 64 64 69 6e 67 3d 22  4" cellpadding="
2170: 34 22 3e 0d 0a 3c 74 72 3e 3c 74 64 3e 0d 0a 54  4">..<tr><td>..T
2180: 68 65 20 3c 62 3e 53 54 5f 53 70 6c 69 74 28 29  he <b>ST_Split()
2190: 3c 2f 62 3e 20 53 51 4c 20 66 75 6e 63 74 69 6f  </b> SQL functio
21a0: 6e 20 77 69 6c 6c 20 73 69 6d 70 6c 79 20 72 65  n will simply re
21b0: 74 75 72 6e 20 61 20 3c 69 3e 63 6f 6c 6c 65 63  turn a <i>collec
21c0: 74 69 6f 6e 3c 2f 69 3e 20 61 67 67 72 65 67 61  tion</i> aggrega
21d0: 74 69 6e 67 20 61 6c 6c 20 66 72 61 67 6d 65 6e  ting all fragmen
21e0: 74 73 20 64 65 72 69 76 69 6e 67 20 66 72 6f 6d  ts deriving from
21f0: 20 74 68 65 20 63 75 74 2e 3c 62 72 3e 0d 0a 45   the cut.<br>..E
2200: 78 65 63 74 6c 79 20 61 73 20 77 65 20 68 61 76  xectly as we hav
2210: 65 20 61 6c 72 65 61 64 79 20 70 72 65 76 69 6f  e already previo
2220: 75 73 6c 79 20 73 65 65 6e 20 6f 6e 20 74 68 65  usly seen on the
2230: 20 4c 69 6e 65 73 74 72 69 6e 67 20 63 61 73 65   Linestring case
2240: 2e 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 2f 74 64 3e  .<br><br>..</td>
2250: 3c 74 64 3e 0d 0a 3c 69 6d 67 20 73 72 63 3d 22  <td>..<img src="
2260: 68 74 74 70 3a 2f 2f 77 77 77 2e 67 61 69 61 2d  http://www.gaia-
2270: 67 69 73 2e 69 74 2f 67 61 69 61 2d 73 69 6e 73  gis.it/gaia-sins
2280: 2f 77 72 69 74 65 2d 76 69 65 77 2d 70 69 63 73  /write-view-pics
2290: 2f 73 70 6c 69 74 2d 70 67 2e 70 6e 67 22 20 61  /split-pg.png" a
22a0: 6c 74 3d 22 73 70 6c 69 74 20 70 6f 6c 79 67 6f  lt="split polygo
22b0: 6e 22 3e 0d 0a 3c 2f 74 64 3e 3c 2f 74 72 3e 0d  n">..</td></tr>.
22c0: 0a 3c 74 72 3e 3c 74 64 3e 0d 0a 54 68 65 20 3c  .<tr><td>..The <
22d0: 62 3e 53 54 5f 53 70 6c 69 74 4c 65 66 74 28 29  b>ST_SplitLeft()
22e0: 3c 2f 62 3e 20 53 51 4c 20 66 75 6e 63 74 69 6f  </b> SQL functio
22f0: 6e 20 77 69 6c 6c 20 72 65 74 75 72 6e 20 69 6e  n will return in
2300: 73 74 65 61 64 20 61 20 3c 69 3e 63 6f 6c 6c 65  stead a <i>colle
2310: 63 74 69 6f 6e 3c 2f 69 3e 20 61 67 67 72 65 67  ction</i> aggreg
2320: 61 74 69 6e 67 20 61 6c 6c 20 66 72 61 67 6d 65  ating all fragme
2330: 6e 74 73 20 6c 61 79 69 6e 67 20 6f 6e 20 74 68  nts laying on th
2340: 65 20 3c 69 3e 6c 65 66 74 3c 2f 69 3e 20 73 69  e <i>left</i> si
2350: 64 65 20 6f 66 20 74 68 65 20 63 75 74 2e 3c 62  de of the cut.<b
2360: 72 3e 0d 0a 46 6f 72 20 50 6f 6c 79 67 6f 6e 73  r>..For Polygons
2370: 20 3c 69 3e 6c 65 66 74 3c 2f 69 3e 20 72 65 61   <i>left</i> rea
2380: 6c 6c 79 20 6d 65 61 6e 73 20 3c 69 3e 6c 65 66  lly means <i>lef
2390: 74 20 73 69 64 65 3c 2f 69 3e 20 28 61 74 20 6c  t side</i> (at l
23a0: 65 61 73 74 2c 20 74 68 69 73 20 69 73 20 74 72  east, this is tr
23b0: 75 65 20 77 68 65 6e 20 74 68 65 20 62 6c 61 64  ue when the blad
23c0: 65 20 69 73 20 61 6c 6d 6f 73 74 20 76 65 72 74  e is almost vert
23d0: 69 63 61 6c 6c 79 20 6f 72 69 65 6e 74 65 64 29  ically oriented)
23e0: 2e 3c 62 72 3e 3c 62 72 3e 0d 0a 3c 75 3e 50 6c  .<br><br>..<u>Pl
23f0: 65 61 73 65 20 6e 6f 74 65 3c 2f 75 3e 3a 20 69  ease note</u>: i
2400: 66 20 74 68 65 20 3c 69 3e 62 6c 61 64 65 3c 2f  f the <i>blade</
2410: 69 3e 20 64 6f 65 73 6e 27 74 20 69 6e 74 65 72  i> doesn't inter
2420: 63 65 70 74 73 20 74 68 65 20 74 61 72 67 65 74  cepts the target
2430: 20 61 74 20 61 6c 6c 2c 20 74 68 61 6e 20 6e 6f   at all, than no
2440: 20 63 75 74 20 77 6f 75 6c 64 20 62 65 20 6f 62   cut would be ob
2450: 76 69 6f 75 73 6c 79 20 70 6f 73 73 69 62 6c 65  viously possible
2460: 2e 20 49 6e 20 74 68 69 73 20 73 70 65 63 69 61  . In this specia
2470: 6c 20 63 61 73 65 20 74 68 65 20 6f 72 69 67 69  l case the origi
2480: 6e 61 6c 20 74 61 72 67 65 74 20 47 65 6f 6d 65  nal target Geome
2490: 74 72 79 20 77 69 6c 6c 20 62 65 20 61 6c 77 61  try will be alwa
24a0: 79 73 20 72 65 74 75 72 6e 65 64 20 28 61 62 73  ys returned (abs
24b0: 6f 6c 75 74 65 6c 79 20 75 6e 63 68 61 6e 67 65  olutely unchange
24c0: 64 29 20 6f 6e 20 74 68 65 20 3c 69 3e 6c 65 66  d) on the <i>lef
24d0: 74 3c 2f 69 3e 20 73 69 64 65 20 63 6f 6c 6c 65  t</i> side colle
24e0: 63 74 69 6f 6e 2e 0d 0a 3c 2f 74 64 3e 3c 74 64  ction...</td><td
24f0: 3e 0d 0a 3c 69 6d 67 20 73 72 63 3d 22 68 74 74  >..<img src="htt
2500: 70 3a 2f 2f 77 77 77 2e 67 61 69 61 2d 67 69 73  p://www.gaia-gis
2510: 2e 69 74 2f 67 61 69 61 2d 73 69 6e 73 2f 77 72  .it/gaia-sins/wr
2520: 69 74 65 2d 76 69 65 77 2d 70 69 63 73 2f 73 70  ite-view-pics/sp
2530: 6c 69 74 2d 70 67 2d 4c 2e 70 6e 67 22 20 61 6c  lit-pg-L.png" al
2540: 74 3d 22 73 70 6c 69 74 2d 6c 65 66 74 20 70 6f  t="split-left po
2550: 6c 79 67 6f 6e 22 3e 0d 0a 3c 2f 74 64 3e 3c 2f  lygon">..</td></
2560: 74 72 3e 0d 0a 3c 74 72 3e 3c 74 64 3e 0d 0a 54  tr>..<tr><td>..T
2570: 68 65 20 3c 62 3e 53 54 5f 53 70 6c 69 74 52 69  he <b>ST_SplitRi
2580: 67 68 74 28 29 3c 2f 62 3e 20 53 51 4c 20 66 75  ght()</b> SQL fu
2590: 6e 63 74 69 6f 6e 20 77 69 6c 6c 20 72 65 74 75  nction will retu
25a0: 72 6e 20 61 20 3c 69 3e 63 6f 6c 6c 65 63 74 69  rn a <i>collecti
25b0: 6f 6e 3c 2f 69 3e 20 61 67 67 72 65 67 61 74 69  on</i> aggregati
25c0: 6e 67 20 61 6c 6c 20 66 72 61 67 6d 65 6e 74 73  ng all fragments
25d0: 20 6c 61 79 69 6e 67 20 6f 6e 20 74 68 65 20 3c   laying on the <
25e0: 69 3e 72 69 67 68 74 3c 2f 69 3e 20 73 69 64 65  i>right</i> side
25f0: 20 6f 66 20 74 68 65 20 63 75 74 2e 3c 62 72 3e   of the cut.<br>
2600: 0d 0a 3c 75 3e 50 6c 65 61 73 65 20 6e 6f 74 65  ..<u>Please note
2610: 3c 2f 75 3e 3a 20 69 66 20 74 68 65 20 3c 69 3e  </u>: if the <i>
2620: 62 6c 61 64 65 3c 2f 69 3e 20 64 6f 65 73 6e 27  blade</i> doesn'
2630: 74 20 69 6e 74 65 72 63 65 70 74 73 20 74 68 65  t intercepts the
2640: 20 74 61 72 67 65 74 20 61 74 20 61 6c 6c 2c 20   target at all, 
2650: 74 68 61 6e 20 6e 6f 20 63 75 74 20 77 6f 75 6c  than no cut woul
2660: 64 20 62 65 20 6f 62 76 69 6f 75 73 6c 79 20 70  d be obviously p
2670: 6f 73 73 69 62 6c 65 2e 20 49 6e 20 74 68 69 73  ossible. In this
2680: 20 73 70 65 63 69 61 6c 20 63 61 73 65 20 74 68   special case th
2690: 65 20 3c 69 3e 72 69 67 68 74 3c 2f 69 3e 20 73  e <i>right</i> s
26a0: 69 64 65 20 63 6f 6c 6c 65 63 74 69 6f 6e 20 77  ide collection w
26b0: 69 6c 6c 20 62 65 20 4e 55 4c 4c 2e 0d 0a 3c 2f  ill be NULL...</
26c0: 74 64 3e 3c 74 64 3e 0d 0a 3c 69 6d 67 20 73 72  td><td>..<img sr
26d0: 63 3d 22 68 74 74 70 3a 2f 2f 77 77 77 2e 67 61  c="http://www.ga
26e0: 69 61 2d 67 69 73 2e 69 74 2f 67 61 69 61 2d 73  ia-gis.it/gaia-s
26f0: 69 6e 73 2f 77 72 69 74 65 2d 76 69 65 77 2d 70  ins/write-view-p
2700: 69 63 73 2f 73 70 6c 69 74 2d 70 67 2d 52 2e 70  ics/split-pg-R.p
2710: 6e 67 22 20 61 6c 74 3d 22 73 70 6c 69 74 2d 72  ng" alt="split-r
2720: 69 67 68 74 20 70 6f 6c 79 67 6f 6e 22 3e 0d 0a  ight polygon">..
2730: 3c 2f 74 64 3e 3c 2f 74 72 3e 0d 0a 3c 2f 74 61  </td></tr>..</ta
2740: 62 6c 65 3e 0d 0a 3c 62 72 3e 3c 68 72 3e 0d 0a  ble>..<br><hr>..
2750: 3c 68 33 3e 53 65 67 6d 65 6e 74 69 7a 61 74 69  <h3>Segmentizati
2760: 6f 6e 3c 2f 68 33 3e 0d 0a 53 6f 6d 65 74 69 6d  on</h3>..Sometim
2770: 65 73 20 69 74 20 63 6f 75 6c 64 20 62 65 20 75  es it could be u
2780: 73 65 66 75 6c 20 3c 69 3e 63 75 74 74 69 6e 67  seful <i>cutting
2790: 3c 2f 69 3e 20 61 20 76 65 72 79 20 6c 6f 6e 67  </i> a very long
27a0: 20 4c 69 6e 65 73 74 72 69 6e 67 20 6f 72 20 50   Linestring or P
27b0: 6f 6c 79 67 6f 6e 27 73 20 52 69 6e 67 20 69 6e  olygon's Ring in
27c0: 74 6f 20 6d 61 6e 79 20 73 6d 61 6c 6c 20 73 65  to many small se
27d0: 67 6d 65 6e 74 73 20 6f 66 20 74 68 65 20 73 61  gments of the sa
27e0: 6d 65 20 69 64 65 6e 74 69 63 61 6c 20 6c 65 6e  me identical len
27f0: 67 74 68 2e 0d 0a 3c 74 61 62 6c 65 20 62 67 63  gth...<table bgc
2800: 6f 6c 6f 72 3d 22 23 65 30 65 30 65 30 22 20 63  olor="#e0e0e0" c
2810: 65 6c 6c 73 70 61 63 69 6e 67 3d 22 34 22 20 63  ellspacing="4" c
2820: 65 6c 6c 70 61 64 64 69 6e 67 3d 22 38 22 3e 0d  ellpadding="8">.
2830: 0a 3c 74 72 3e 3c 74 64 3e 0d 0a 3c 62 3e 53 45  .<tr><td>..<b>SE
2840: 4c 45 43 54 20 67 65 6f 6d 65 74 72 79 2c 20 53  LECT geometry, S
2850: 54 5f 53 65 67 6d 65 6e 74 69 7a 65 28 67 65 6f  T_Segmentize(geo
2860: 6d 65 74 72 79 2c 20 31 30 2e 30 29 3c 62 72 3e  metry, 10.0)<br>
2870: 0d 0a 46 52 4f 4d 20 63 6f 6d 32 30 31 31 3c 62  ..FROM com2011<b
2880: 72 3e 0d 0a 57 48 45 52 45 20 6e 6f 6d 65 5f 63  r>..WHERE nome_c
2890: 6f 6d 20 3d 20 27 42 72 6f 6e 74 65 27 3b 3c 2f  om = 'Bronte';</
28a0: 62 3e 0d 0a 3c 2f 74 64 3e 3c 2f 74 72 3e 3c 2f  b>..</td></tr></
28b0: 74 61 62 6c 65 3e 3c 62 72 3e 0d 0a 3c 74 61 62  table><br>..<tab
28c0: 6c 65 20 62 6f 72 64 65 72 3d 22 31 22 20 63 65  le border="1" ce
28d0: 6c 6c 73 70 61 63 69 6e 67 3d 22 34 22 20 63 65  llspacing="4" ce
28e0: 6c 6c 70 61 64 64 69 6e 67 3d 22 34 22 3e 0d 0a  llpadding="4">..
28f0: 3c 74 72 3e 3c 74 68 3e 6f 72 69 67 69 6e 61 6c  <tr><th>original
2900: 3c 2f 74 68 3e 3c 74 68 3e 73 65 67 6d 65 6e 74  </th><th>segment
2910: 69 7a 65 64 3c 2f 74 68 3e 3c 2f 74 72 3e 0d 0a  ized</th></tr>..
2920: 3c 74 72 3e 3c 74 64 3e 0d 0a 3c 69 6d 67 20 73  <tr><td>..<img s
2930: 72 63 3d 22 68 74 74 70 3a 2f 2f 77 77 77 2e 67  rc="http://www.g
2940: 61 69 61 2d 67 69 73 2e 69 74 2f 67 61 69 61 2d  aia-gis.it/gaia-
2950: 73 69 6e 73 2f 77 72 69 74 65 2d 76 69 65 77 2d  sins/write-view-
2960: 70 69 63 73 2f 62 72 6f 6e 74 65 2d 6f 72 69 67  pics/bronte-orig
2970: 69 6e 61 6c 2e 70 6e 67 22 20 61 6c 74 3d 22 62  inal.png" alt="b
2980: 72 6f 6e 74 65 20 6f 72 69 67 69 6e 61 6c 22 3e  ronte original">
2990: 0d 0a 3c 2f 74 64 3e 3c 74 64 3e 0d 0a 3c 69 6d  ..</td><td>..<im
29a0: 67 20 73 72 63 3d 22 68 74 74 70 3a 2f 2f 77 77  g src="http://ww
29b0: 77 2e 67 61 69 61 2d 67 69 73 2e 69 74 2f 67 61  w.gaia-gis.it/ga
29c0: 69 61 2d 73 69 6e 73 2f 77 72 69 74 65 2d 76 69  ia-sins/write-vi
29d0: 65 77 2d 70 69 63 73 2f 62 72 6f 6e 74 65 2d 73  ew-pics/bronte-s
29e0: 65 67 6d 65 6e 74 69 7a 65 64 2e 70 6e 67 22 20  egmentized.png" 
29f0: 61 6c 74 3d 22 62 72 6f 6e 74 65 20 73 65 67 6d  alt="bronte segm
2a00: 65 6e 74 69 7a 65 64 22 3e 0d 0a 3c 2f 74 64 3e  entized">..</td>
2a10: 3c 2f 74 72 3e 0d 0a 3c 74 72 3e 3c 74 64 20 63  </tr>..<tr><td c
2a20: 6f 6c 73 70 61 6e 3d 22 32 22 3e 0d 0a 41 73 20  olspan="2">..As 
2a30: 79 6f 75 20 63 61 6e 20 65 61 73 69 6c 79 20 6e  you can easily n
2a40: 6f 74 69 63 65 2c 20 74 68 65 72 65 20 61 72 65  otice, there are
2a50: 20 6d 61 6e 79 20 6d 6f 72 65 20 76 65 72 74 69   many more verti
2a60: 63 65 73 20 69 6e 20 74 68 65 20 73 65 67 6d 65  ces in the segme
2a70: 6e 74 69 7a 65 64 20 47 65 6f 6d 65 74 72 79 2e  ntized Geometry.
2a80: 3c 62 72 3e 0d 0a 57 65 20 69 6d 70 6f 73 65 64  <br>..We imposed
2a90: 20 74 68 65 20 63 6f 6e 73 74 72 61 69 6e 74 20   the constraint 
2aa0: 74 68 61 74 20 6e 6f 20 73 65 67 6d 65 6e 74 20  that no segment 
2ab0: 63 6f 75 6c 64 20 62 65 20 6c 6f 6e 67 65 72 20  could be longer 
2ac0: 74 68 61 6e 20 3c 62 3e 31 30 6d 3c 2f 62 3e 2c  than <b>10m</b>,
2ad0: 20 74 68 75 73 20 63 61 75 73 69 6e 67 20 6d 61   thus causing ma
2ae0: 6e 79 20 6d 6f 72 65 20 76 65 72 74 69 63 65 73  ny more vertices
2af0: 20 74 6f 20 62 65 20 69 6e 74 65 72 70 6f 6c 61   to be interpola
2b00: 74 65 64 2e 3c 62 72 3e 0d 0a 54 68 65 20 6f 76  ted.<br>..The ov
2b10: 65 72 61 6c 6c 20 73 68 61 70 65 20 69 73 20 61  erall shape is a
2b20: 62 73 6f 6c 75 74 65 6c 79 20 75 6e 63 68 61 6e  bsolutely unchan
2b30: 67 65 64 2e 0d 0a 3c 2f 74 64 3e 3c 2f 74 72 3e  ged...</td></tr>
2b40: 0d 0a 3c 2f 74 61 62 6c 65 3e 0d 0a 3c 62 72 3e  ..</table>..<br>
2b50: 3c 68 72 3e 0d 0a 3c 68 33 3e 41 7a 69 6d 75 74  <hr>..<h3>Azimut
2b60: 68 3c 2f 68 33 3e 0d 0a 50 72 6f 62 61 62 6c 79  h</h3>..Probably
2b70: 20 6e 6f 74 20 74 68 65 20 6d 6f 73 74 20 69 6e   not the most in
2b80: 74 65 72 65 73 74 69 6e 67 20 66 75 6e 63 74 69  teresting functi
2b90: 6f 6e 20 73 75 70 70 6f 72 74 65 64 20 62 79 20  on supported by 
2ba0: 3c 69 3e 6c 69 62 6c 77 67 65 6f 6d 3c 2f 69 3e  <i>liblwgeom</i>
2bb0: 3b 20 61 6e 79 77 61 79 20 69 74 27 73 20 74 68  ; anyway it's th
2bc0: 65 72 65 2c 20 61 6e 64 20 69 73 20 77 6f 72 74  ere, and is wort
2bd0: 68 20 65 6e 6f 75 67 68 20 74 6f 20 62 65 20 73  h enough to be s
2be0: 75 70 70 6f 72 74 65 64 20 62 79 20 53 70 61 74  upported by Spat
2bf0: 69 61 4c 69 74 65 20 61 73 20 77 65 6c 6c 2e 3c  iaLite as well.<
2c00: 62 72 3e 0d 0a 50 72 6f 62 61 62 6c 79 20 68 69  br>..Probably hi
2c10: 67 68 6c 79 20 61 70 70 72 65 63 69 61 74 65 64  ghly appreciated
2c20: 20 6f 6e 20 3c 62 3e 47 50 53 20 64 65 76 69 63   on <b>GPS devic
2c30: 65 73 3c 2f 62 3e 20 73 6f 20 74 6f 20 64 65 74  es</b> so to det
2c40: 65 72 6d 69 6e 65 20 74 68 65 20 63 75 72 72 65  ermine the curre
2c50: 6e 74 20 62 65 61 72 69 6e 67 2e 0d 0a 3c 74 61  nt bearing...<ta
2c60: 62 6c 65 20 62 67 63 6f 6c 6f 72 3d 22 23 65 30  ble bgcolor="#e0
2c70: 65 30 65 30 22 20 63 65 6c 6c 73 70 61 63 69 6e  e0e0" cellspacin
2c80: 67 3d 22 34 22 20 63 65 6c 6c 70 61 64 64 69 6e  g="4" cellpaddin
2c90: 67 3d 22 38 22 3e 0d 0a 3c 74 72 3e 3c 74 64 3e  g="8">..<tr><td>
2ca0: 0d 0a 3c 62 3e 53 45 4c 45 43 54 20 44 65 67 72  ..<b>SELECT Degr
2cb0: 65 65 73 28 53 54 5f 41 7a 69 6d 75 74 68 28 4d  ees(ST_Azimuth(M
2cc0: 61 6b 65 50 6f 69 6e 74 28 30 2c 20 30 29 2c 20  akePoint(0, 0), 
2cd0: 4d 61 6b 65 50 6f 69 6e 74 28 30 2c 20 31 29 29  MakePoint(0, 1))
2ce0: 29 3b 3c 2f 62 3e 0d 0a 3c 68 72 3e 0d 0a 30 2e  );</b>..<hr>..0.
2cf0: 30 0d 0a 3c 2f 74 64 3e 3c 2f 74 72 3e 0d 0a 3c  0..</td></tr>..<
2d00: 74 72 3e 3c 74 64 3e 0d 0a 3c 62 3e 53 45 4c 45  tr><td>..<b>SELE
2d10: 43 54 20 44 65 67 72 65 65 73 28 53 54 5f 41 7a  CT Degrees(ST_Az
2d20: 69 6d 75 74 68 28 4d 61 6b 65 50 6f 69 6e 74 28  imuth(MakePoint(
2d30: 30 2c 20 30 29 2c 20 4d 61 6b 65 50 6f 69 6e 74  0, 0), MakePoint
2d40: 28 31 2c 20 31 29 29 29 3b 3c 2f 62 3e 0d 0a 3c  (1, 1)));</b>..<
2d50: 68 72 3e 0d 0a 34 35 2e 30 0d 0a 3c 2f 74 64 3e  hr>..45.0..</td>
2d60: 3c 2f 74 72 3e 0d 0a 3c 74 72 3e 3c 74 64 3e 0d  </tr>..<tr><td>.
2d70: 0a 3c 62 3e 53 45 4c 45 43 54 20 44 65 67 72 65  .<b>SELECT Degre
2d80: 65 73 28 53 54 5f 41 7a 69 6d 75 74 68 28 4d 61  es(ST_Azimuth(Ma
2d90: 6b 65 50 6f 69 6e 74 28 30 2c 20 30 29 2c 20 4d  kePoint(0, 0), M
2da0: 61 6b 65 50 6f 69 6e 74 28 31 2c 20 30 29 29 29  akePoint(1, 0)))
2db0: 3b 3c 2f 62 3e 0d 0a 3c 68 72 3e 0d 0a 39 30 2e  ;</b>..<hr>..90.
2dc0: 30 0d 0a 3c 2f 74 64 3e 3c 2f 74 72 3e 0d 0a 3c  0..</td></tr>..<
2dd0: 74 72 3e 3c 74 64 3e 0d 0a 3c 62 3e 53 45 4c 45  tr><td>..<b>SELE
2de0: 43 54 20 44 65 67 72 65 65 73 28 53 54 5f 41 7a  CT Degrees(ST_Az
2df0: 69 6d 75 74 68 28 4d 61 6b 65 50 6f 69 6e 74 28  imuth(MakePoint(
2e00: 30 2c 20 30 29 2c 20 4d 61 6b 65 50 6f 69 6e 74  0, 0), MakePoint
2e10: 28 30 2c 20 2d 31 29 29 29 3b 3c 2f 62 3e 0d 0a  (0, -1)));</b>..
2e20: 3c 68 72 3e 0d 0a 31 38 30 2e 30 0d 0a 3c 2f 74  <hr>..180.0..</t
2e30: 64 3e 3c 2f 74 72 3e 0d 0a 3c 2f 74 61 62 6c 65  d></tr>..</table
2e40: 3e 3c 62 72 3e 0d 0a 3c 62 72 3e 3c 68 72 3e 0d  ><br>..<br><hr>.
2e50: 0a 42 61 63 6b 20 74 6f 20 3c 61 20 68 72 65 66  .Back to <a href
2e60: 3d 22 68 74 74 70 73 3a 2f 2f 77 77 77 2e 67 61  ="https://www.ga
2e70: 69 61 2d 67 69 73 2e 69 74 2f 66 6f 73 73 69 6c  ia-gis.it/fossil
2e80: 2f 6c 69 62 73 70 61 74 69 61 6c 69 74 65 2f 77  /libspatialite/w
2e90: 69 6b 69 3f 6e 61 6d 65 3d 73 77 69 74 63 68 69  iki?name=switchi
2ea0: 6e 67 2d 74 6f 2d 34 2e 30 23 6c 69 62 6c 77 67  ng-to-4.0#liblwg
2eb0: 65 6f 6d 22 3e 6d 61 69 6e 20 70 61 67 65 3c 2f  eom">main page</
2ec0: 61 3e 0d 0a 0a 5a 20 63 36 62 65 65 37 34 37 36  a>...Z c6bee7476
2ed0: 65 33 64 30 30 33 32 64 63 65 64 37 64 34 31 65  e3d0032dced7d41e
2ee0: 66 63 66 35 65 39 38 0a                          fcf5e98.