DistanceAlongShapeLibrary { public PointAndIndex[] getDistancesAlongShape(ShapePoints shapePoints, List<StopTimeEntryImpl> stopTimes) throws DistanceAlongShapeException { PointAndIndex[] stopTimePoints = new PointAndIndex[stopTimes.size()]; UTMProjection projection = UTMLibrary.getProjectionForPoint( shapePoints.getLats()[0], shapePoints.getLons()[0]); List<XYPoint> projectedShapePoints = _shapePointsLibrary.getProjectedShapePoints( shapePoints, projection); double[] shapePointsDistTraveled = shapePoints.getDistTraveled(); List<List<PointAndIndex>> possibleAssignments = computePotentialAssignments( projection, projectedShapePoints, shapePointsDistTraveled, stopTimes); pruneUnnecessaryAssignments(possibleAssignments); assignmentSanityCheck(shapePoints, stopTimes, possibleAssignments); double maxDistanceTraveled = shapePointsDistTraveled[shapePointsDistTraveled.length - 1]; List<PointAndIndex> bestAssignment = computeBestAssignment(shapePoints, stopTimes, possibleAssignments, projection, projectedShapePoints); double last = Double.NEGATIVE_INFINITY; for (int i = 0; i < stopTimePoints.length; i++) { PointAndIndex pindex = bestAssignment.get(i); if (pindex.distanceAlongShape > maxDistanceTraveled) { int index = projectedShapePoints.size() - 1; XYPoint point = projectedShapePoints.get(index); StopEntryImpl stop = stopTimes.get(i).getStop(); XYPoint stopPoint = projection.forward(stop.getStopLocation()); double d = stopPoint.getDistance(point); pindex = new PointAndIndex(point, index, d, maxDistanceTraveled); } if (last > pindex.distanceAlongShape) { constructError(shapePoints, stopTimes, possibleAssignments, projection); } last = pindex.distanceAlongShape; stopTimePoints[i] = pindex; } return stopTimePoints; }  @ConfigurationParameter void setLocalMinimumThreshold(double localMinimumThreshold); @ConfigurationParameter void setMaxDistanceFromStopToShapePoint(
      double maxDistanceFromStopToShapePoint); @ConfigurationParameter void setMaximumNumberOfPotentialAssignment(
      int maximumNumberOfPotentialAssignments); @ConfigurationParameter void setLenientStopShapeAssignment(boolean lenient); PointAndIndex[] getDistancesAlongShape(ShapePoints shapePoints,
      List<StopTimeEntryImpl> stopTimes);  }
@Test public void test01() throws IOException, DistanceAlongShapeException { ShapePoints shapePoints = readShapePoints("shapes-01.txt"); List<StopTimeEntryImpl> stopTimes = readStopTimes("stops-01.txt"); DistanceAlongShapeLibrary library = new DistanceAlongShapeLibrary(); PointAndIndex[] points = library.getDistancesAlongShape(shapePoints, stopTimes); assertEquals(70, points.length); assertEquals(127.6, points[0].distanceAlongShape, 0.1); assertEquals(2, points[0].index); assertEquals(3074.4, points[10].distanceAlongShape, 0.1); assertEquals(95, points[10].index); assertEquals(13759.9, points[50].distanceAlongShape, 0.1); assertEquals(452, points[50].index); assertEquals(18015.3, points[68].distanceAlongShape, 0.1); assertEquals(616, points[68].index); assertEquals(618, points[69].index); }
@Test public void test02() throws IOException, DistanceAlongShapeException { ShapePoints shapePoints = readShapePoints("shapes-02.txt"); List<StopTimeEntryImpl> stopTimes = readStopTimes("stops-02.txt"); DistanceAlongShapeLibrary library = new DistanceAlongShapeLibrary(); PointAndIndex[] points = library.getDistancesAlongShape(shapePoints, stopTimes); assertEquals(4, points.length); assertEquals(155.4, points[0].distanceAlongShape, 0.1); assertEquals(1, points[0].index); assertEquals(816.7, points[1].distanceAlongShape, 0.1); assertEquals(4, points[1].index); assertEquals(819.3, points[2].distanceAlongShape, 0.1); assertEquals(5, points[2].index); assertEquals(1151.1, points[3].distanceAlongShape, 0.1); assertEquals(9, points[3].index); }
@Test public void test03() throws IOException, DistanceAlongShapeException { ShapePoints shapePoints = readShapePoints("shapes-03.txt"); List<StopTimeEntryImpl> stopTimes = readStopTimes("stops-03.txt"); DistanceAlongShapeLibrary library = new DistanceAlongShapeLibrary(); PointAndIndex[] points = library.getDistancesAlongShape(shapePoints, stopTimes); assertEquals(5, points.length); assertEquals(67.9, points[0].distanceAlongShape, 0.1); assertEquals(0, points[0].index); assertEquals(446.0, points[1].distanceAlongShape, 0.1); assertEquals(1, points[1].index); assertEquals(852.7, points[2].distanceAlongShape, 0.1); assertEquals(2, points[2].index); assertEquals(1247.0, points[3].distanceAlongShape, 0.1); assertEquals(3, points[3].index); }