Permalink
Browse files

Merge pull request #108 from borazslo/master

Reworked OSM connection
  • Loading branch information...
borazslo committed Apr 30, 2018
2 parents 7394e64 + 5b7d4e9 commit 6da0e5155eb8551497c791bce98af267918f8741
Showing with 13,876 additions and 370 deletions.
  1. +101 −24 classes/distance.php
  2. +15 −0 classes/eloquent/boundary.php
  3. +291 −107 classes/eloquent/church.php
  4. +2 −0 classes/eloquent/cron.php
  5. +1 −1 classes/eloquent/distance.php
  6. +1 −5 classes/eloquent/osmtag.php
  7. +1 −1 classes/externalapi/mapquestapi.php
  8. +33 −16 classes/externalapi/overpassapi.php
  9. +1 −19 classes/html/church/catalogue.php
  10. +26 −20 classes/html/church/church.php
  11. +15 −4 classes/html/collection.php
  12. +27 −20 classes/html/diocesecatalogue.php
  13. +62 −15 classes/html/josm.php
  14. +93 −16 classes/osm.php
  15. +13 −0 fontawesome/css/fa-brands.css
  16. +5 −0 fontawesome/css/fa-brands.min.css
  17. +14 −0 fontawesome/css/fa-regular.css
  18. +5 −0 fontawesome/css/fa-regular.min.css
  19. +15 −0 fontawesome/css/fa-solid.css
  20. +5 −0 fontawesome/css/fa-solid.min.css
  21. +2,855 −0 fontawesome/css/fontawesome-all.css
  22. +5 −0 fontawesome/css/fontawesome-all.min.css
  23. +2,825 −0 fontawesome/css/fontawesome.css
  24. +5 −0 fontawesome/css/fontawesome.min.css
  25. +19 −0 fontawesome/less/_animated.less
  26. +16 −0 fontawesome/less/_bordered-pulled.less
  27. +12 −0 fontawesome/less/_core.less
  28. +6 −0 fontawesome/less/_fixed-width.less
  29. +876 −0 fontawesome/less/_icons.less
  30. +27 −0 fontawesome/less/_larger.less
  31. +18 −0 fontawesome/less/_list.less
  32. +57 −0 fontawesome/less/_mixins.less
  33. +23 −0 fontawesome/less/_rotated-flipped.less
  34. +5 −0 fontawesome/less/_screen-reader.less
  35. +22 −0 fontawesome/less/_stacked.less
  36. +885 −0 fontawesome/less/_variables.less
  37. +21 −0 fontawesome/less/fa-brands.less
  38. +22 −0 fontawesome/less/fa-regular.less
  39. +23 −0 fontawesome/less/fa-solid.less
  40. +16 −0 fontawesome/less/fontawesome.less
  41. +20 −0 fontawesome/scss/_animated.scss
  42. +20 −0 fontawesome/scss/_bordered-pulled.scss
  43. +16 −0 fontawesome/scss/_core.scss
  44. +6 −0 fontawesome/scss/_fixed-width.scss
  45. +876 −0 fontawesome/scss/_icons.scss
  46. +23 −0 fontawesome/scss/_larger.scss
  47. +18 −0 fontawesome/scss/_list.scss
  48. +57 −0 fontawesome/scss/_mixins.scss
  49. +23 −0 fontawesome/scss/_rotated-flipped.scss
  50. +5 −0 fontawesome/scss/_screen-reader.scss
  51. +31 −0 fontawesome/scss/_stacked.scss
  52. +889 −0 fontawesome/scss/_variables.scss
  53. +21 −0 fontawesome/scss/fa-brands.scss
  54. +22 −0 fontawesome/scss/fa-regular.scss
  55. +23 −0 fontawesome/scss/fa-solid.scss
  56. +16 −0 fontawesome/scss/fontawesome.scss
  57. BIN fontawesome/webfonts/fa-brands-400.eot
  58. +1,011 −0 fontawesome/webfonts/fa-brands-400.svg
  59. BIN fontawesome/webfonts/fa-brands-400.ttf
  60. BIN fontawesome/webfonts/fa-brands-400.woff
  61. BIN fontawesome/webfonts/fa-brands-400.woff2
  62. BIN fontawesome/webfonts/fa-regular-400.eot
  63. +366 −0 fontawesome/webfonts/fa-regular-400.svg
  64. BIN fontawesome/webfonts/fa-regular-400.ttf
  65. BIN fontawesome/webfonts/fa-regular-400.woff
  66. BIN fontawesome/webfonts/fa-regular-400.woff2
  67. BIN fontawesome/webfonts/fa-solid-900.eot
  68. +1,644 −0 fontawesome/webfonts/fa-solid-900.svg
  69. BIN fontawesome/webfonts/fa-solid-900.ttf
  70. BIN fontawesome/webfonts/fa-solid-900.woff
  71. BIN fontawesome/webfonts/fa-solid-900.woff2
  72. +8 −0 load.php
  73. +2 −2 templates/_panelchurchlist.twig
  74. +50 −20 templates/church/_panellocation.twig
  75. +9 −14 templates/church/_panelneighbours.twig
  76. +8 −8 templates/church/catalogue.twig
  77. +1 −4 templates/church/church.twig
  78. +52 −39 templates/church/edit.twig
  79. +5 −0 templates/collection.twig
  80. +85 −0 templates/diocesecatalogue.twig
  81. +1 −1 templates/home.twig
  82. +92 −32 templates/josm.twig
  83. +12 −2 templates/layout.twig
  84. BIN tests/sqlite/miserend_v1.sqlite3
  85. BIN tests/sqlite/miserend_v2.sqlite3
  86. BIN tests/sqlite/miserend_v3.sqlite3
View
@@ -33,44 +33,121 @@ function update($church_id = false, $limit = false) {
}
foreach ($churches as $churchFrom) {
$this->MupdateChurch($churchFrom);
}
}
function MupdateChurch($churchFrom, $maxDistance = 5000) { //maxDistance in meter
set_time_limit('600');
$counter = 0;
if($churchFrom->location->lat == '' OR $churchFrom->location->lon == '')
return false;
$point = ['lon' => $churchFrom->location->lon, 'lat' => $churchFrom->location->lat];
//TODO: Delete BBOX-on belüli távolságok. Vagy minden távolság?
for($i=1;$i<10;$i++) {
$bbox = $this->getBBox($point, $maxDistance);
$churchesInBBox = \Eloquent\Church::inBBox($bbox)->where('id', '!=', $churchFrom->id)->get();
if(count($churchesInBBox) > 12) break;
$maxDistance = $maxDistance * ( 120 / 100 );
}
$highestDistance = 0;
foreach ($churchesInBBox as $churchTo) {
$processingDistance = \Eloquent\Distance::findOrNew(['fromLat' => $churchFrom->lat, 'fromLon' => $churchFrom->lon, 'toLat' => $churchTo->lat, 'toLon' => $churchTo->lon])->first();
$processingDistance = \Eloquent\Distance::where('fromLat',$churchFrom->lat)
->where('fromLon',$churchFrom->lon)
->where('toLat',$churchTo->lat)
->where('toLon',$churchTo->lon)->first();
if(!$processingDistance) {
$processingDistance = new \Eloquent\Distance();
$processingDistance->fromLat = $churchFrom->lat;
$processingDistance->fromLon = $churchFrom->lon;
$processingDistance->toLat = $churchTo->lat;
$processingDistance->toLon = $churchTo->lon;
}
if ($churchFrom->updated_at > $processingDistance->updated_at
OR $churchTo->updated_at > $processingDistance->updated_at) {
$point = ['lon' => $churchFrom->osm->lon, 'lat' => $churchFrom->osm->lat];
$maxDistance = 10000; //meter
$bbox = $this->getBBox($point, $maxDistance);
$query = \Eloquent\Church::inBBox($bbox)->where('id', '!=', $churchFrom->id);
$churchesInBBox = $query->get();
foreach ($churchesInBBox as $churchTo) {
$processingDistance = \Eloquent\Distance::findOrNew(['church_from' => $churchFrom->id, 'church_to' => $churchTo->id])->first();
if ($churchFrom->update_at > $processingDistance->update_at
OR $churchTo->update_at > $processingDistance->update_at) {
$pointFrom = ['lat' => $churchFrom->osm->lat, 'lon' => $churchFrom->osm->lon];
$pointTo = ['lat' => $churchTo->osm->lat, 'lon' => $churchTo->osm->lon];
$pointFrom = ['lat' => $churchFrom->location->lat, 'lon' => $churchFrom->location->lon];
$pointTo = ['lat' => $churchTo->location->lat, 'lon' => $churchTo->location->lon];
$rawDistance = $this->getRawDistance($pointFrom, $pointTo);
if ($rawDistance < $maxDistance AND $rawDistance > 0) {
$mapquest = new \ExternalApi\MapquestApi();
$mapquestDistance = $mapquest->distance($pointFrom, $pointTo);
if ($mapquestDistance == -2) {
return;
} elseif ($mapquestDistance > 0) {
$processingDistance->distance = $mapquestDistance;
if($mapquestDistance > $highestDistance)
$highestDistance = $mapquestDistance;
$processingDistance->save();
}
} else {
$processingDistance->distance = $rawDistance;
}
$processingDistance->save();
$counter++;
if ($counter >= $limit) {
return true;
}
//Pontatlant inkább soha senem mentünk el.
//$processingDistance->distance = $rawDistance;
}
$counter++;
}
}
}
/*
* Ha találtunk olyat, hogy útvonalon annyival hosszabb, akkor
* lehetséges, hogy van annál közelebbi is, ezért ki kell tágítani
* a kört.
*/
if($highestDistance > $maxDistance) {
//echo "Van nagyobb kör is. Bocsesz.";
//TODO: duplicated code
$bbox = $this->getBBox($point, $highestDistance);
$churchesInBBox = \Eloquent\Church::inBBox($bbox)->where('id', '!=', $churchFrom->id);
foreach ($churchesInBBox as $churchTo) {
$processingDistance = \Eloquent\Distance::findOrNew(['fromLat' => $churchFrom->lat, 'fromLon' => $churchFrom->lon, 'toLat' => $churchTo->lat, 'toLon' => $churchTo->lon])->first();
$processingDistance = \Eloquent\Distance::where('fromLat',$churchFrom->lat)
->where('fromLon',$churchFrom->lon)
->where('toLat',$churchTo->lat)
->where('toLon',$churchTo->lon)->first();
if(!$processingDistance) {
$processingDistance = new \Eloquent\Distance();
$processingDistance->fromLat = $churchFrom->lat;
$processingDistance->fromLon = $churchFrom->lon;
$processingDistance->toLat = $churchTo->lat;
$processingDistance->toLon = $churchTo->lon;
}
$highestDistance = 0;
if ($churchFrom->updated_at > $processingDistance->updated_at
OR $churchTo->updated_at > $processingDistance->updated_at OR 4 == 4) {
$pointFrom = ['lat' => $churchFrom->location->lat, 'lon' => $churchFrom->location->lon];
$pointTo = ['lat' => $churchTo->location->lat, 'lon' => $churchTo->location->lon];
$rawDistance = $this->getRawDistance($pointFrom, $pointTo);
if ($rawDistance < $maxDistance AND $rawDistance > 0) {
$mapquest = new \ExternalApi\MapquestApi();
$mapquestDistance = $mapquest->distance($pointFrom, $pointTo);
if ($mapquestDistance == -2) {
return;
} elseif ($mapquestDistance > 0) {
$processingDistance->distance = $mapquestDistance;
$processingDistance->save();
}
} else {
//Pontatlant inkább soha senem mentünk el.
//$processingDistance->distance = $rawDistance;
}
$counter++;
}
}
}
return $counter;
}
function getRawDistance($pointFrom, $pointTo) {
@@ -0,0 +1,15 @@
<?php
namespace Eloquent;
class Boundary extends \Illuminate\Database\Eloquent\Model {
#protected $table = 'osmtags';
protected $fillable = array('osmtype', 'osmid','boundary','denomination','admin_level','name');
protected $appends = array('url');
function getUrlAttribute($value) {
return 'https://www.openstreetmap.org/'.$this->osmtype.'/'.$this->osmid;
}
}
Oops, something went wrong.

0 comments on commit 6da0e51

Please sign in to comment.