@Test public void testPathSimplify() { PointList pointList = new PointList(); pointList.parse2DJSON(points1); assertEquals(32, pointList.getSize()); new DouglasPeucker().setMaxDistance(.5).simplify(pointList); // Arrays.asList(2, 4, 6, 7, 8, 9, 12, 14, 15, 17, 18, 19, 20, 22, 24, 27, 28, 29, 31, 33), assertEquals(20, pointList.getSize()); }
/** * Simplifies a part of the <code>points</code>. The <code>fromIndex</code> and <code>lastIndex</code> * are guaranteed to be kept. * * @param points The PointList to simplify * @param fromIndex Start index to simplify, should be >= <code>lastIndex</code> * @param lastIndex Simplify up to this index * @return The number of removed points */ public int simplify(PointList points, int fromIndex, int lastIndex) { int removed = 0; int size = lastIndex - fromIndex; if (approx) { int delta = 500; int segments = size / delta + 1; int start = fromIndex; for (int i = 0; i < segments; i++) { // start of next is end of last segment, except for the last removed += subSimplify(points, start, Math.min(lastIndex, start + delta)); start += delta; } } else { removed = subSimplify(points, fromIndex, lastIndex); } if (removed > 0) compressNew(points, removed); return removed; }
public DouglasPeucker() { setApproximation(true); // 1m setMaxDistance(1); }
double wayPointMaxDistance = hints.getDouble(Routing.WAY_POINT_MAX_DISTANCE, 1d); DouglasPeucker peucker = new DouglasPeucker().setMaxDistance(wayPointMaxDistance); PathMerger pathMerger = new PathMerger(). setCalcPoints(tmpCalcPoints).
/** * Simplifies the <code>points</code>, from index 0 to size-1. * <p> * It is a wrapper method for {@link DouglasPeucker#simplify(PointList, int, int)}. * * @return The number removed points */ public int simplify(PointList points) { return simplify(points, 0, points.size() - 1); }
@Override public OSMReader setWayPointMaxDistance(double maxDist) { doSimplify = maxDist > 0; simplifyAlgo.setMaxDistance(maxDist); return this; }
/** * This method removes points which are close to the line (defined by maxDist). * <p> * * @return removed nodes */ public int simplify(PointList points) { int removed = 0; int size = points.getSize(); if (approx) { int delta = 500; int segments = size / delta + 1; int start = 0; for (int i = 0; i < segments; i++) { // start of next is end of last segment, except for the last removed += simplify(points, start, Math.min(size - 1, start + delta)); start += delta; } } else { removed = simplify(points, 0, size - 1); } compressNew(points, removed); return removed; }
DouglasPeucker douglasPeucker = new DouglasPeucker(); douglasPeucker.setMaxDistance(0); pathWrapper.setPoints(p.calcPoints()); douglasPeucker.setMaxDistance(100000000); ps = new PathSimplification(pathWrapper, douglasPeucker, true); ps.simplify();
public OSMReader setWayPointMaxDistance( double maxDist ) { doSimplify = maxDist > 0; simplifyAlgo.setMaxDistance(maxDist); return this; }
/** * This method removes points which are close to the line (defined by maxDist). * <p> * @return removed nodes */ public int simplify( PointList points ) { int removed = 0; int size = points.getSize(); if (approx) { int delta = 500; int segments = size / delta + 1; int start = 0; for (int i = 0; i < segments; i++) { // start of next is end of last segment, except for the last removed += simplify(points, start, Math.min(size - 1, start + delta)); start += delta; } } else { removed = simplify(points, 0, size - 1); } compressNew(points, removed); return removed; }
@Test public void testSimplifyCheckPointOrder() { PointList pointList = new PointList(); pointList.parse2DJSON(points2); assertEquals(13, pointList.getSize()); new DouglasPeucker().setMaxDistance(.5).simplify(pointList); assertEquals(11, pointList.getSize()); assertFalse(pointList.toString(), pointList.toString().contains("NaN")); assertEquals("(50.203764443183644,9.961074440801317), (50.20318963087774,9.960999562464645), (50.202952888673984,9.96094144793469), (50.20267889356641,9.96223002587773), (50.201853928011374,9.961859918278305), " + "(50.20138565901039,9.961668810881722), (50.20128507617008,9.96216874485095), (50.20088553877664,9.961953795595925), (50.200686794534775,9.961899033827313), (50.20014066696481,9.961716680863127), (50.199798499043254,9.961588158344957)", pointList.toString()); } }
} else { Translation tr = trMap.getWithFallBack(Helper.getLocale(localeStr)); DouglasPeucker peucker = new DouglasPeucker().setMaxDistance(minPathPrecision); PathMerger pathMerger = new PathMerger(). setEnableInstructions(instructions).
simplifyAlgo.simplify(pillarNodes);
public DouglasPeucker() { setApproximation(true); // 1m setMaxDistance(1); }
@Override public OSMReader setWayPointMaxDistance(double maxDist) { doSimplify = maxDist > 0; simplifyAlgo.setMaxDistance(maxDist); return this; }
/** * Simplifies a part of the <code>points</code>. The <code>fromIndex</code> and <code>lastIndex</code> * are guaranteed to be kept. * * @param points The PointList to simplify * @param fromIndex Start index to simplify, should be >= <code>lastIndex</code> * @param lastIndex Simplify up to this index * @return The number of removed points */ public int simplify(PointList points, int fromIndex, int lastIndex) { int removed = 0; int size = lastIndex - fromIndex; if (approx) { int delta = 500; int segments = size / delta + 1; int start = fromIndex; for (int i = 0; i < segments; i++) { // start of next is end of last segment, except for the last removed += subSimplify(points, start, Math.min(lastIndex, start + delta)); start += delta; } } else { removed = subSimplify(points, fromIndex, lastIndex); } if (removed > 0) compressNew(points, removed); return removed; }
@Test public void testSimplifyCheckPointCount() { PointList pointList = new PointList(); pointList.parse2DJSON(points1); DouglasPeucker dp = new DouglasPeucker().setMaxDistance(.5); assertEquals(32, pointList.getSize()); dp.simplify(pointList); assertEquals(20, pointList.getSize()); assertFalse(pointList.toString(), pointList.toString().contains("NaN")); pointList.clear(); pointList.parse2DJSON(points1); dp.simplify(pointList, 0, pointList.size() -1); assertEquals(20, pointList.getSize()); pointList.clear(); pointList.parse2DJSON(points1); int removed1 = dp.simplify(pointList.copy(10, 20)); pointList.clear(); pointList.parse2DJSON(points1); int removed2 = dp.simplify(pointList, 10, 19); assertEquals(removed1, removed2); }
boolean tmpCalcPoints = hints.getBool(Routing.CALC_POINTS, calcPoints); double wayPointMaxDistance = hints.getDouble(Routing.WAY_POINT_MAX_DISTANCE, 1d); DouglasPeucker peucker = new DouglasPeucker().setMaxDistance(wayPointMaxDistance); PathMerger pathMerger = new PathMerger(). setCalcPoints(tmpCalcPoints).
/** * Simplifies the <code>points</code>, from index 0 to size-1. * <p> * It is a wrapper method for {@link DouglasPeucker#simplify(PointList, int, int)}. * * @return The number removed points */ public int simplify(PointList points) { return simplify(points, 0, points.size() - 1); }