GeoreferencesManager.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. Lib::loadClass('RouteBase');
  3. Lib::loadClass('EpsgConversion');
  4. class Route_GeoreferencesManager extends RouteBase {
  5. protected $ACTION, $REFERER;
  6. const TABLE = "WMS_MAP_GEOREFERENCES";
  7. public function handleAuth() {
  8. if (!User::logged()) {
  9. User::authByRequest();
  10. }
  11. $this->REFERER = $_SERVER['HTTP_REFERER'];
  12. $this->ACTION = V::get('action', '', $_GET, '');
  13. }
  14. public function defaultAction() {
  15. SE_Layout::gora();
  16. SE_Layout::menu();
  17. ?>
  18. <div class="container" style="margin-top:20px">
  19. <legend>Zarządzanie punktami georeferencyjnymi</legend>
  20. <div class="form-group">
  21. <div class="col-sm-12">
  22. <a href="?_route=GeoreferencesManager&action=verifyPoints" class="btn-sm btn-primary">Zweryfikuj punkty</a>
  23. </div>
  24. </div>
  25. <?php
  26. switch ($this->ACTION) {
  27. case "verifyPoints":
  28. $this->verifyPoints();
  29. break;
  30. }
  31. ?>
  32. </div>
  33. <?php
  34. SE_Layout::dol();
  35. }
  36. public function reinstallAction() {
  37. $this->reinstall();
  38. die('OK');
  39. }
  40. public function reinstall() {
  41. }
  42. private function verifyPoints() {
  43. $points = DB::getPDO()->fetchall("select `ID`, `EPSG`, x(`the_geom`) as `gx`, y(`the_geom`) as `gy`, `x`, `y` from `" . self::TABLE . "`");
  44. $errors = [];
  45. foreach ($points as $point) {
  46. if ($point['x'] && $point['y']) {
  47. if ($point['gx'] && $point['gy']) {
  48. try {
  49. $test = epsgConversion::LatLonToPUWGWGS84($point['gx'], $point['gy']);
  50. } catch (Exception $e) {
  51. SE_Layout::alert('danger', $e->getMessage());
  52. }
  53. if ((abs($point['x'] - $test->x) > 1 ) || (abs($point['y'] - $test->y) > 1) || ($point['EPSG'] != $test->epsg)) {
  54. $error = "[{$point['ID']}] x = <span style='color:" . ((abs($point['x'] - $test->x) > 1) ? "red" : "green") .
  55. ";'>{$point['x']}</span> ({$test->x}), y = <span style='color:" . ((abs($point['y'] - $test->y) > 1) ? "red" : "green") .
  56. ";'>{$point['y']}</span> ({$test->y}), epsg = <span style='color:" . (($point['EPSG'] != $test->epsg) ? "red" : "green") .
  57. ";'>{$point['EPSG']}</span>" . (($point['EPSG'] != $test->epsg) ? " ({$test->epsg})" : "");
  58. $errors[] = $error;
  59. }
  60. }
  61. }
  62. }
  63. ?>
  64. <div class="form-group">
  65. <div class="col-sm-12"><br/>
  66. <?php
  67. //$errors = [];
  68. // if ($errors) echo "<pre>" . implode("<br/>", $errors) . "</pre>";
  69. if ($errors) {
  70. SE_Layout::alert('danger', "<pre>" . implode("<br/>", $errors) . "</pre>");
  71. ?>
  72. <div style="text-align:center;"><a href="?_route=GeoreferencesManager&action=repairPoints" class="btn btn-primary">Napraw wszystkie</a></div>
  73. <?php
  74. } else SE_Layout::alert('success', "Wszystko OK"); //echo "<span style='color:green;'>Wszystko OK</span>";
  75. ?>
  76. </div>
  77. </div>
  78. <?php
  79. }
  80. }