|
2 | 2 |
|
3 | 3 | import java.util.ArrayList; |
4 | 4 | import java.util.Collection; |
| 5 | +import java.util.Collections; |
5 | 6 | import java.util.HashSet; |
6 | 7 | import java.util.List; |
7 | 8 | import java.util.Set; |
|
24 | 25 | import org.opentripplanner.api.thrift.definition.GraphVertex; |
25 | 26 | import org.opentripplanner.api.thrift.definition.GraphVerticesRequest; |
26 | 27 | import org.opentripplanner.api.thrift.definition.GraphVerticesResponse; |
| 28 | +import org.opentripplanner.api.thrift.definition.Location; |
27 | 29 | import org.opentripplanner.api.thrift.definition.OTPService; |
28 | 30 | import org.opentripplanner.api.thrift.definition.PathOptions; |
29 | 31 | import org.opentripplanner.api.thrift.definition.TripParameters; |
|
44 | 46 | import org.opentripplanner.routing.graph.Graph; |
45 | 47 | import org.opentripplanner.routing.graph.Vertex; |
46 | 48 | import org.opentripplanner.routing.impl.CandidateEdge; |
| 49 | +import org.opentripplanner.routing.impl.CandidateEdge.CandidateEdgeScoreComparator; |
47 | 50 | import org.opentripplanner.routing.impl.CandidateEdgeBundle; |
48 | 51 | import org.opentripplanner.routing.services.GraphService; |
49 | 52 | import org.opentripplanner.routing.services.PathService; |
@@ -184,23 +187,28 @@ public FindNearestVertexResponse FindNearestVertex(FindNearestVertexRequest req) |
184 | 187 |
|
185 | 188 | @Override |
186 | 189 | public FindNearestEdgesResponse FindNearestEdges(FindNearestEdgesRequest req) throws TException { |
187 | | - LOG.info("FindNearestEdges called"); |
| 190 | + LOG.info("FindNearestEdges called with query {}", req.getLocation()); |
188 | 191 | long startTime = System.currentTimeMillis(); |
189 | 192 |
|
190 | 193 | // Set up the TraversalRequirements. |
191 | 194 | TraversalRequirements requirements = new TraversalRequirements(); |
192 | 195 | requirements.setModes(new TravelModeSet(req.getAllowed_modes()).toTraverseModeSet()); |
193 | | - |
194 | | - // Set up the LocationObservation. |
195 | | - GenericLocation loc = new LatLngExtension(req.getLocation().getLat_lng()).toGenericLocation(); |
196 | | - if (req.isSetHeading()) loc.setHeading(req.getHeading()); |
197 | 196 |
|
| 197 | + // Set up the LocationObservation. |
| 198 | + Location queryLoc = req.getLocation(); |
| 199 | + GenericLocation loc = new LatLngExtension(queryLoc.getLat_lng()).toGenericLocation(); |
| 200 | + if (queryLoc.isSetHeading()) loc.setHeading(queryLoc.getHeading()); |
| 201 | + |
198 | 202 | // Find the candidate edges. |
199 | 203 | // NOTE(flamholz): for now this will return at smallish number of edges because of |
200 | 204 | // the internal binning that's going on. I'd rather get more edges just in case... |
201 | 205 | StreetVertexIndexService streetVertexIndex = getStreetIndex(); |
202 | 206 | CandidateEdgeBundle edges = streetVertexIndex.getClosestEdges(loc, requirements); |
203 | 207 |
|
| 208 | + // Sort them by score. |
| 209 | + CandidateEdgeScoreComparator comp = new CandidateEdgeScoreComparator(); |
| 210 | + Collections.sort(edges, comp); |
| 211 | + |
204 | 212 | // Add matches to the response. |
205 | 213 | FindNearestEdgesResponse res = new FindNearestEdgesResponse(); |
206 | 214 | int maxEdges = req.getMax_edges(); |
|
0 commit comments