/** * Returns elevation data for points along a path. * * @param array $points Array containing data points with indices [lat,lng] * @param int $points_per_mile Number of data points per mile * @return array Elevation data as array with form [distance, elevation] */ public static function getElevationForPath($points, $points_per_mile = 5) { if (!is_array($points)) { return false; } $mark_dist = 1 / $points_per_mile; $prev_dist = 0; $markers = array(); $count = count($points); for ($i = 0; $i < $count - 1; $i++) { $point1 = $points[$i]; $point2 = $points[$i + 1]; $dist = self::_getLatLngDistance($point1, $point2); $avail_dist = $prev_dist + $dist; while ($avail_dist >= $mark_dist) { $cover_dist = $prev_dist > 0 ? $mark_dist - $prev_dist : $mark_dist; $scale = $cover_dist / $dist; $lat = $point1["lat"] + $scale * ($point2["lat"] - $point1["lat"]); $lng = $point1["lng"] + $scale * ($point2["lng"] - $point1["lng"]); $markers[] = array("lat" => $lat, "lng" => $lng, "dist" => (count($markers) + 1) * $mark_dist); $avail_dist -= $mark_dist; $prev_dist = 0; } $prev_dist = $avail_dist; } $elevations = array(); foreach ($markers as $marker) { if ($elevation = Elevation::getElevation($marker["lat"], $marker["lng"])) { $elevations[] = array($marker["dist"], $elevation); } else { return false; } } return $elevations; }
/** * This test is to help determine the parameters for the nearest * elevation search. * * @return unknown_type */ public function testGetNearestReturnCount() { $lat = 39.90574640039131; $lng = -86.18072318611667; $points = 3; $data = Elevation::_getNearestElevations($lat, $lng, 3); //make sure we have data $this->assertNotEqual(false, $data); //make sure we have enough points // TODO: use a supported assertion //$this->assertGreaterThanOrEqual($points, count($data)); //make sure we do not have too many //$this->assertLessThan(6, count($data)); }
public function action_elevation_add_packed() { if ($_FILES["packed_hdr"]) { move_uploaded_file($_FILES["packed_hdr"]["tmp_name"], SYSTEM_ROOT . "/elev_packed.hdr"); } if ($_FILES["packed_flt"]) { move_uploaded_file($_FILES["packed_flt"]["tmp_name"], SYSTEM_ROOT . "/elev_packed.flt"); } $region = array_safe($_POST, "region_name", "Elevation data"); Elevation::addElevationToDatabase(SYSTEM_ROOT . "/elev_packed", 1, $region); unlink(SYSTEM_ROOT . "/elev_packed.hdr"); unlink(SYSTEM_ROOT . "/elev_packed.flt"); Notification::add("Elevation data has been added"); Page::redirect("/admin/elevation"); }
/** * Function is called to update the elevation data of the route. * * @return int|bool Number of rows affected. false indicates no data nearby. */ public function _updateElevationData() { $points = json_decode($this->points); if (!isset($points->points)) { return false; } $points = $points->points; $points = $this->_decodePolylineToArray($points); if (($elevations = Elevation::getElevationForPath($points)) === false) { return false; } $this->elevation = json_encode($elevations); $stmt = Database::getDB()->prepare("\r\n\t\t\tUPDATE routes\r\n\t\t\tSET\r\n\t\t\t\tr_elevation = ?\r\n\t\t\tWHERE \r\n\t\t\t\tr_id = ?\r\n\t\t"); $stmt->bind_param("si", $this->elevation, $this->id); $stmt->execute(); $stmt->store_result(); $rows = $stmt->affected_rows; $stmt->close(); return $rows; }