Changes between Version 2 and Version 3 of NewDistCalcSubGeom


Ignore:
Timestamp:
11/08/09 08:52:19 (15 years ago)
Author:
nicklas
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • NewDistCalcSubGeom

    v2 v3  
    33Calculating distances is quite a costly process. Because of that it is often worth the effort to sort the geometries depending on how the bounding boxes are related to each other. This example is a little extreme in the amount of subgeometries and vertexes but then the gain will really show. The example is a distance-calculation between Texas and Alaska.
    44
    5 [[Image(illustration1.png, 300)]]
     5[[Image(illustration1.png, 300, border=1)]]
    66
    77In postgis 1.4 this would cause 178137 * 12167 = 2 167 392 879 iterations.
    88With the faster algorithm described in [wiki:NewDistCalcGeom2Geom How the distance calculations is done] the iterations will be very much reduced and then takes about 7 seconds. But even now there is a lot of unnecessary work done when calculating the exact distance to each and every of the sub geometries. This is how we now instead uses bounding boxes to only calculate a selection of geometries.
    99
    10 [[Image(illustration2.png, 300)]]
     10[[Image(illustration2.png, 300, border=1)]]
    1111
    1212Here is the bounding boxes of the two states. The first thing we do is to iterate through all combinations of bounding boxes to find the “smallest max distance” between the boxes. What we know from this value is that the distance we get here is longer or the same (if two inputed points) than the min distance we are looking  for
    1313The result is the distance along a line like this:
    1414
    15 [[Image(illustration3.png, 300)]]
     15[[Image(illustration3.png, 300, border=1)]]
    1616
    1717Now we iterate through all the combinations again and store all combinations with smaller min distance than the earlier found in a list. We also order the list so we get the smallest min distance first.
     
    2121The result is then the distance along a line like this returned in about 600ms.
    2222
    23 [[Image(illustration4.png, 300)]]
     23[[Image(illustration4.png, 300, border=1)]]