calculatedName = uniqueNames.get(0);
} else {
calculatedName = resources.getString("unnamedStreet");
}
}
StreetLocation closest = new StreetLocation(graph, "corner " + Math.random(), coord,
calculatedName);
FreeEdge e = new FreeEdge(closest, intersection);
closest.getExtra().add(e);
e = new FreeEdge(intersection, closest);
closest.getExtra().add(e);
return closest;
}
}
// if no intersection vertices were found, then find the closest transit stop
// (we can return stops here because this method is not used when street-transit linking)
double closestStopDistance = Double.POSITIVE_INFINITY;
Vertex closestStop = null;
// elsewhere options=null means no restrictions, find anything.
// here we skip examining stops, as they are really only relevant when transit is being used
if (options != null && options.modes.isTransit()) {
for (TransitStop v : getNearbyTransitStops(coord, 1000)) {
if (!v.isStreetLinkable()) continue;
double d = distanceLibrary.distance(v.getCoordinate(), coord);
if (d < closestStopDistance) {
closestStopDistance = d;
closestStop = v;
}
}
}
LOG.debug(" best stop: {} distance: {}", closestStop, closestStopDistance);
// then find closest walkable street
StreetLocation closestStreet = null;
CandidateEdgeBundle bundle = getClosestEdges(location, options, extraEdges, null, false);
CandidateEdge candidate = bundle.best;
double closestStreetDistance = Double.POSITIVE_INFINITY;
if (candidate != null) {
StreetEdge bestStreet = candidate.edge;
Coordinate nearestPoint = candidate.nearestPointOnEdge;
closestStreetDistance = distanceLibrary.distance(coord, nearestPoint);
LOG.debug("best street: {} dist: {}", bestStreet.toString(), closestStreetDistance);
if (calculatedName == null || "".equals(calculatedName)) {
calculatedName = bestStreet.getName();
}
String closestName = String.format("%s_%s", bestStreet.getName(), location.toString());
closestStreet = StreetLocation.createStreetLocation(graph, closestName, calculatedName,
bundle.toEdgeList(), nearestPoint, coord);
}
// decide whether to return street, or street + stop
if (closestStreet == null) {
// no street found, return closest stop or null
LOG.debug("returning only transit stop (no street found)");
return closestStop; // which will be null if none was found
} else {
// street found
if (closestStop != null) {
// both street and stop found
double relativeStopDistance = closestStopDistance / closestStreetDistance;
if (relativeStopDistance < 1.5) {
LOG.debug("linking transit stop to street (distances are comparable)");
closestStreet.addExtraEdgeTo(closestStop);
}
}
LOG.debug("returning split street");
return closestStreet;
}