public function LineString::haversineLength in geoPHP 7
Same name and namespace in other branches
- 8 geoPHP/lib/geometry/LineString.class.php \LineString::haversineLength()
Overrides Collection::haversineLength
File
- geoPHP/
lib/ geometry/ LineString.class.php, line 107
Class
- LineString
- LineString. A collection of Points representing a line. A line can have more than one segment.
Code
public function haversineLength() {
$degrees = 0;
$points = $this
->getPoints();
for ($i = 0; $i < $this
->numPoints() - 1; $i++) {
$point = $points[$i];
$next_point = $points[$i + 1];
if (!is_object($next_point)) {
continue;
}
$degree = rad2deg(acos(sin(deg2rad($point
->getY())) * sin(deg2rad($next_point
->getY())) + cos(deg2rad($point
->getY())) * cos(deg2rad($next_point
->getY())) * cos(deg2rad(abs($point
->getX() - $next_point
->getX())))));
$degrees += $degree;
}
// Returns degrees
return $degrees;
}