Browse Source

use p3k\utils and p3k\timezone

drops a bunch of duplicate code now that those libraries exist
pull/23/head
Aaron Parecki 7 years ago
parent
commit
f6b2ac206c
No known key found for this signature in database GPG Key ID: 276C2817346D6056
4 changed files with 100 additions and 22796 deletions
  1. +3
    -22692
      compass/app/Http/Controllers/LocalTime.php
  2. +2
    -99
      compass/app/Jobs/TripComplete.php
  3. +6
    -4
      compass/composer.json
  4. +89
    -1
      compass/composer.lock

+ 3
- 22692
compass/app/Http/Controllers/LocalTime.php
File diff suppressed because it is too large
View File


+ 2
- 99
compass/app/Jobs/TripComplete.php View File

@ -196,12 +196,12 @@ class TripComplete extends Job implements SelfHandling, ShouldQueue
$points = array_map(function($f){
return $f->geometry->coordinates;
}, $features);
$simple = $this->_ramerDouglasPeucker($points, 0.0001);
$simple = \p3k\geo\ramerDouglasPeucker($points, 0.0001);
$last = false;
$distance = 0;
foreach($simple as $p) {
if($last) {
$distance += $this->_gc_distance($p[1], $p[0], $last[1], $last[0]);
$distance += \p3k\geo\gc_distance($p[1], $p[0], $last[1], $last[0]);
}
$last = $p;
}
@ -262,101 +262,4 @@ class TripComplete extends Job implements SelfHandling, ShouldQueue
}
// TODO: move this to a library p3k/Geo
// http://www.loughrigg.org/rdp/
//The author has placed this work in the Public Domain, thereby relinquishing all copyrights.
//You may use, modify, republish, sell or give away this work without prior consent.
//This implementation comes with no warranty or guarantee of fitness for any purpose.
//=========================================================================
//An implementation of the Ramer-Douglas-Peucker algorithm for reducing
//the number of points on a polyline
//see http://en.wikipedia.org/wiki/Ramer%E2%80%93Douglas%E2%80%93Peucker_algorithm
//=========================================================================
//Finds the perpendicular distance from a point to a straight line.
//The coordinates of the point are specified as $ptX and $ptY.
//The line passes through points l1 and l2, specified respectively with their
//coordinates $l1x and $l1y, and $l2x and $l2y
public function _perpendicularDistance($ptX, $ptY, $l1x, $l1y, $l2x, $l2y)
{
$result = 0;
if ($l2x == $l1x)
{
//vertical lines - treat this case specially to avoid divide by zero
$result = abs($ptX - $l2x);
}
else
{
$slope = (($l2y-$l1y) / ($l2x-$l1x));
$passThroughY = (0-$l1x)*$slope + $l1y;
$result = (abs(($slope * $ptX) - $ptY + $passThroughY)) / (sqrt($slope*$slope + 1));
}
return $result;
}
//RamerDouglasPeucker
//Reduces the number of points on a polyline by removing those that are closer to the line
//than the distance $epsilon.
//The polyline is provided as an array of arrays, where each internal array is one point on the polyline,
//specified by easting (x-coordinate) with key "0" and northing (y-coordinate) with key "1".
//It is assumed that the coordinates and distance $epsilon are given in the same units.
//The result is returned as an array in a similar format.
//Each point returned in the result array will retain all its original data, including its E and N
//values along with any others.
public function _ramerDouglasPeucker($pointList, $epsilon)
{
if(count($pointList) == 0)
return array();
// Find the point with the maximum distance
$dmax = 0;
$index = 0;
$totalPoints = count($pointList);
for ($i = 1; $i < ($totalPoints - 1); $i++)
{
$d = $this->_perpendicularDistance($pointList[$i][0], $pointList[$i][1],
$pointList[0][0], $pointList[0][1],
$pointList[$totalPoints-1][0], $pointList[$totalPoints-1][1]);
if ($d > $dmax)
{
$index = $i;
$dmax = $d;
}
}
$resultList = array();
// If max distance is greater than epsilon, recursively simplify
if ($dmax >= $epsilon)
{
// Recursive call
$recResults1 = $this->_ramerDouglasPeucker(array_slice($pointList, 0, $index + 1), $epsilon);
$recResults2 = $this->_ramerDouglasPeucker(array_slice($pointList, $index, $totalPoints - $index), $epsilon);
// Build the result list
$resultList = array_merge(array_slice($recResults1, 0, count($recResults1) - 1),
array_slice($recResults2, 0, count($recResults2)));
}
else
{
$resultList = array($pointList[0], $pointList[$totalPoints-1]);
}
// Return the result
return $resultList;
}
function _gc_distance($lat1, $lng1, $lat2, $lng2) {
return ( 6378100 * acos( cos( deg2rad($lat1) ) * cos( deg2rad($lat2) ) * cos( deg2rad($lng2) - deg2rad($lng1) ) + sin( deg2rad($lat1) ) * sin( deg2rad($lat2) ) ) );
}
}

+ 6
- 4
compass/composer.json View File

@ -1,7 +1,7 @@
{
"name": "laravel/lumen",
"description": "The Laravel Lumen Framework.",
"keywords": ["framework", "laravel", "lumen"],
"name": "p3k/Compass",
"description": "Compass is a GPS tracking server that stores data in flat files.",
"keywords": ["p3k", "gps"],
"license": "MIT",
"type": "project",
"require": {
@ -12,7 +12,9 @@
"indieauth/client": "0.2.*",
"guzzlehttp/guzzle":"~6.0",
"illuminate/redis": "^5.1",
"p3k/multipart": "*"
"p3k/multipart": "*",
"p3k/utils": ">=1.1.0",
"p3k/timezone": "^0.1.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0",

+ 89
- 1
compass/composer.lock View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"content-hash": "84f1171b6758a3d1faeb01e70431961e",
"content-hash": "38dc6c50ab57209879f289b71dc895ee",
"packages": [
{
"name": "barnabywalters/mf-cleaner",
@ -1998,6 +1998,94 @@
"description": "A flat-file database optimized to hold time-series data.",
"time": "2016-01-29T00:39:52+00:00"
},
{
"name": "p3k/timezone",
"version": "0.1.0",
"source": {
"type": "git",
"url": "https://github.com/aaronpk/p3k-timezone.git",
"reference": "68d3490d896f98cf0727dc937f0bb6b045050c83"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/aaronpk/p3k-timezone/zipball/68d3490d896f98cf0727dc937f0bb6b045050c83",
"reference": "68d3490d896f98cf0727dc937f0bb6b045050c83",
"shasum": ""
},
"require": {
"php": ">=5.4.0"
},
"type": "library",
"autoload": {
"files": [
"src/p3k/Timezone.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Apache-2.0"
],
"authors": [
{
"name": "Aaron Parecki",
"homepage": "https://aaronparecki.com"
}
],
"description": "Find the timezone of a given location",
"homepage": "https://github.com/aaronpk/p3k-timezone",
"keywords": [
"date",
"p3k",
"timezone"
],
"time": "2017-01-12T17:30:08+00:00"
},
{
"name": "p3k/utils",
"version": "1.1.0",
"source": {
"type": "git",
"url": "https://github.com/aaronpk/p3k-utils.git",
"reference": "1117e29c697b54eb05279b73b62515de1595dbb2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/aaronpk/p3k-utils/zipball/1117e29c697b54eb05279b73b62515de1595dbb2",
"reference": "1117e29c697b54eb05279b73b62515de1595dbb2",
"shasum": ""
},
"require": {
"php": ">=5.5"
},
"require-dev": {
"phpunit/phpunit": "^4.8.13",
"predis/predis": "1.1.*"
},
"type": "library",
"autoload": {
"files": [
"src/global.php",
"src/url.php",
"src/utils.php",
"src/date.php",
"src/cache.php",
"src/geo.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Aaron Parecki",
"homepage": "https://aaronparecki.com"
}
],
"description": "Some helpful functions used by https://p3k.io projects",
"homepage": "https://github.com/aaronpk/p3k-utils",
"time": "2018-01-28T22:18:37+00:00"
},
{
"name": "paragonie/random_compat",
"version": "1.1.6",

Loading…
Cancel
Save