@Test public void zigZag() throws Exception { LineString line = (LineString) reader.read("LINESTRING(0 0, 10 10, 20 0, 30 -10, 40 0)"); LineString sline = smoother.smooth(line, 0.0); Coordinate[] coords = line.getCoordinates(); int i = 0; for (Coordinate scoord : sline.getCoordinates()) { if (scoord.equals2D(coords[i])) { i++ ; } } assertEquals(coords.length, i); assertTrue(line.getEnvelopeInternal().contains(sline.getEnvelopeInternal())); }
public LineString smooth(LineString ls, double alpha) { Coordinate[] coords = ls.getCoordinates(); Coordinate[][] controlPoints = getControlPoints(coords, alpha); final int N = coords.length; List<Coordinate> smoothCoords = new ArrayList<Coordinate>(); double dist; for (int i = 0; i < N - 1; i++) { dist = coords[i].distance(coords[i+1]); if (dist < control.getMinLength()) { smoothCoords.add(new Coordinate(coords[i])); } else { int smoothN = control.getNumVertices(dist); Coordinate[] segment = cubicBezier( coords[i], coords[i+1], controlPoints[i][1], controlPoints[i+1][0], smoothN); int copyN = i < N - 1 ? segment.length - 1 : segment.length; for (int k = 0; k < copyN; k++) { smoothCoords.add(segment[k]); } } } smoothCoords.add(coords[N - 1]); LineString smoothedLine = geomFactory.createLineString(smoothCoords.toArray(new Coordinate[0])); smoothedLine.setUserData(ls.getUserData()); return smoothedLine; }
LineSmoother extends AbstractSmoother { public LineString smooth(LineString ls, double alpha) { Coordinate[] coords = ls.getCoordinates(); Coordinate[][] controlPoints = getControlPoints(coords, alpha); final int N = coords.length; List<Coordinate> smoothCoords = new ArrayList<Coordinate>(); double dist; for (int i = 0; i < N - 1; i++) { dist = coords[i].distance(coords[i+1]); if (dist < control.getMinLength()) { smoothCoords.add(new Coordinate(coords[i])); } else { int smoothN = control.getNumVertices(dist); Coordinate[] segment = cubicBezier( coords[i], coords[i+1], controlPoints[i][1], controlPoints[i+1][0], smoothN); int copyN = i < N - 1 ? segment.length - 1 : segment.length; for (int k = 0; k < copyN; k++) { smoothCoords.add(segment[k]); } } } smoothCoords.add(coords[N - 1]); LineString smoothedLine = geomFactory.createLineString(smoothCoords.toArray(new Coordinate[0])); smoothedLine.setUserData(ls.getUserData()); return smoothedLine; } }
LineSmoother extends AbstractSmoother { public LineString smooth(LineString ls, double alpha) { Coordinate[] coords = ls.getCoordinates(); Coordinate[][] controlPoints = getControlPoints(coords, alpha); final int N = coords.length; List<Coordinate> smoothCoords = new ArrayList<Coordinate>(); double dist; for (int i = 0; i < N - 1; i++) { dist = coords[i].distance(coords[i+1]); if (dist < control.getMinLength()) { smoothCoords.add(new Coordinate(coords[i])); } else { int smoothN = control.getNumVertices(dist); Coordinate[] segment = cubicBezier( coords[i], coords[i+1], controlPoints[i][1], controlPoints[i+1][0], smoothN); int copyN = i < N - 1 ? segment.length - 1 : segment.length; for (int k = 0; k < copyN; k++) { smoothCoords.add(segment[k]); } } } smoothCoords.add(coords[N - 1]); LineString smoothedLine = geomFactory.createLineString(smoothCoords.toArray(new Coordinate[0])); smoothedLine.setUserData(ls.getUserData()); return smoothedLine; } LineSmoother();  LineSmoother(GeometryFactory geomFactory); }
LineSmoother extends AbstractSmoother { public LineString smooth(LineString ls, double alpha) { Coordinate[] coords = ls.getCoordinates(); Coordinate[][] controlPoints = getControlPoints(coords, alpha); final int N = coords.length; List<Coordinate> smoothCoords = new ArrayList<Coordinate>(); double dist; for (int i = 0; i < N - 1; i++) { dist = coords[i].distance(coords[i+1]); if (dist < control.getMinLength()) { smoothCoords.add(new Coordinate(coords[i])); } else { int smoothN = control.getNumVertices(dist); Coordinate[] segment = cubicBezier( coords[i], coords[i+1], controlPoints[i][1], controlPoints[i+1][0], smoothN); int copyN = i < N - 1 ? segment.length - 1 : segment.length; for (int k = 0; k < copyN; k++) { smoothCoords.add(segment[k]); } } } smoothCoords.add(coords[N - 1]); LineString smoothedLine = geomFactory.createLineString(smoothCoords.toArray(new Coordinate[0])); smoothedLine.setUserData(ls.getUserData()); return smoothedLine; } LineSmoother();  LineSmoother(GeometryFactory geomFactory); LineString smooth(LineString ls, double alpha); }
LineSmoother extends AbstractSmoother { public LineString smooth(LineString ls, double alpha) { Coordinate[] coords = ls.getCoordinates(); Coordinate[][] controlPoints = getControlPoints(coords, alpha); final int N = coords.length; List<Coordinate> smoothCoords = new ArrayList<Coordinate>(); double dist; for (int i = 0; i < N - 1; i++) { dist = coords[i].distance(coords[i+1]); if (dist < control.getMinLength()) { smoothCoords.add(new Coordinate(coords[i])); } else { int smoothN = control.getNumVertices(dist); Coordinate[] segment = cubicBezier( coords[i], coords[i+1], controlPoints[i][1], controlPoints[i+1][0], smoothN); int copyN = i < N - 1 ? segment.length - 1 : segment.length; for (int k = 0; k < copyN; k++) { smoothCoords.add(segment[k]); } } } smoothCoords.add(coords[N - 1]); LineString smoothedLine = geomFactory.createLineString(smoothCoords.toArray(new Coordinate[0])); smoothedLine.setUserData(ls.getUserData()); return smoothedLine; } LineSmoother();  LineSmoother(GeometryFactory geomFactory); LineString smooth(LineString ls, double alpha);  }