-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Calculate Bounds when not in original GPX file (#71)
* added a BoundsCalculator to compute it when not in the original GPX. Plus tests. * reverted some useless code related to PHP 8 and minor reformats.
- Loading branch information
Showing
16 changed files
with
533 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
/** | ||
* DistanceCalculator.php | ||
* | ||
* @author miqwit | ||
* @since 03/2024 | ||
* @version 1.0 | ||
*/ | ||
|
||
namespace phpGPX\Helpers; | ||
|
||
use phpGPX\Models\Point; | ||
use phpGPX\phpGPX; | ||
|
||
/** | ||
* This helper will return the boundaries of a group of points, | ||
* e.g. the lowest latitude, lowest longitude, highest latitude, highest longitude. | ||
* This can be useful to display a segment on a map and to zoom the map | ||
* properly, so it shows all the points. | ||
*/ | ||
class BoundsCalculator | ||
{ | ||
/** | ||
* @return array of array Only two points with latitude and longitude that correspond to the | ||
* most northwestern and southeastern points of the track | ||
*/ | ||
public static function calculate(array $points): array | ||
{ | ||
$pointCount = count($points); | ||
|
||
$north = $east = -PHP_FLOAT_MAX; // look for longest lat and lon | ||
$south = $west = PHP_FLOAT_MAX; // look for shortest lat and lon | ||
|
||
for ($p = 0; $p < $pointCount; $p++) { | ||
$curPoint = $points[$p]; | ||
|
||
$lng = $curPoint->longitude; | ||
$lat = $curPoint->latitude; | ||
|
||
// Update northWest and southEast points if needed | ||
if ($lat > $north) {$north = $lat;} | ||
if ($lng > $east) {$east = $lng;} | ||
if ($lat < $south) {$south = $lat;} | ||
if ($lng < $west) {$west = $lng;} | ||
} | ||
|
||
return [ | ||
["lat" => $north, "lng" => $west], | ||
["lat" => $south, "lng" => $east] | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"ageofdgpsdata": null, | ||
"cmt": null, | ||
"desc": null, | ||
"dgpsid": null, | ||
"difference": null, | ||
"distance": null, | ||
"ele": 2419, | ||
"extensions": null, | ||
"fix": null, | ||
"geoidheight": null, | ||
"hdop": null, | ||
"lat": 46.571948, | ||
"link": [], | ||
"lon": 8.414757, | ||
"magvar": null, | ||
"name": null, | ||
"pdop": null, | ||
"sat": null, | ||
"src": null, | ||
"sym": null, | ||
"time": "2017-08-13T07:10:41+00:00", | ||
"type": null, | ||
"vdop": null | ||
} |
Oops, something went wrong.