phpgeo icon indicating copy to clipboard operation
phpgeo copied to clipboard

Multiple Simplifications

Open tobias-r opened this issue 8 years ago • 4 comments

Hi there,

I haven't studied the Douglas-Peucker algorithm in details, but if I execute the simplification algorithm multiple times, the polyline reduces/smoothes more and more, although the algorithm tolerance is still unchanged.

// 1 meter tolerance
$processor = new SimplifyDouglasPeucker(1);

$polyline = $processor->simplify($polyline);
echo sizeof($polyline->getPoints());

echo "<br>";

$polyline = $processor->simplify($polyline);
echo sizeof($polyline->getPoints());

echo "<br>";

$polyline = $processor->simplify($polyline);
echo sizeof($polyline->getPoints());

Shouldn't it be constant?

tobias-r avatar Oct 18 '17 09:10 tobias-r

Hi,

while iterating through all the polyline's points, only the situation around the current point is evaluated. The algorithm doesn't iterate through the polyline in reverse direction, so possible simplifications aren't found in a single run.

To be sure that all simplifications are found and applied, one has to restart the iteration after each changed point.

mjaschen avatar Oct 18 '17 09:10 mjaschen

Look, if I run about 20 simplification iterations with a tolerance of 1 meter on a polyline, that is about 43km long and has roughly 5k points, then I end up having 14 points with a distance of a couple of kilometers each.

Can this really be correct?

tobias-r avatar Oct 18 '17 09:10 tobias-r

That sounds strange, indeed.

I'll take a closer look and create test cases if I find the time.

mjaschen avatar Oct 18 '17 09:10 mjaschen

@mjaschen, thanks for your awesome work btw!

tobias-r avatar Oct 18 '17 15:10 tobias-r