/** * Connects a route to this walk, and sets relevant data (e.g. length) * * * The route may be able to give us: * * Distance * - Calculated * * Location * - Which region are most of the points in? * * Linearity * - Is the end within 500m of the start? * * Start grid ref * - Convert to OSGB36 * * Start place name * - May be stored as a waypoint in the route * - List of known start points * - Reverse geocoding * * End grid ref * * TODO: End place name * If any of these aren't available (i.e. start/end place names), * they are left unchanged. All others are always overwritten. * * @param Route $r Route to set * @param bool $setData If true, update walk data with the values from this route. Default is false. */ public function setRoute(Route &$r, $setData = false) { $this->route =& $r; if ($setData) { // Get start and end places $start = $r->getWaypoint(0); $this->startGridRef = $start->osRef->toSixFigureString(); $this->startPlaceName = $start->reverseGeocode(); $end = $r->getWaypoint($r->numWaypoints() - 1); $this->endGridRef = $end->osRef->toSixFigureString(); $this->endPlaceName = $end->reverseGeocode(); // Is this a linear walk? // TODO: Magic number $this->isLinear = $start->distanceTo($end) > 500; // Convert distance to miles, get the distance grade // Resolution is half a mile $this->miles = round($r->getDistance() * 0.000621371192 * 2) / 2; $this->distanceGrade = $this->getDistanceGrade($this->miles); } }