biale_plamy-find_ways_old.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. $_SERVER['SERVER_NAME'] = 'biuro.biall-net.pl';
  3. require("../../se-lib/bootstrap.php");
  4. Lib::loadClass("Vendor_Geophp");
  5. function init_sh_check() {
  6. //check if run from bash
  7. if(isset($_SERVER["argv"])) {
  8. if(@$_SERVER["argv"][1]=='--help') {
  9. echo "
  10. Options are:
  11. php ".$_SERVER["argv"][0]." --check - control if we have needed tables/data
  12. .EOF
  13. ";
  14. } else if(@$_SERVER["argv"][1]=='--check') {
  15. check();
  16. } else echo " bad option, try:
  17. php ".$_SERVER["argv"][0]." --help
  18. .EOF
  19. ";
  20. } else {
  21. echo "<br> this script could be run from bash e.g. php biale_plamy.php --help <br>" ;
  22. check();
  23. }
  24. }
  25. function check() {
  26. echo "<br>\n i run check()";
  27. //todo to set arguments to rebuild tables etc:
  28. $check_tbls=array('Rozdzielcza_test_bzyk_drogi','Rozdzielcza_test_bzyk_joins','Rozdzielcza_test_bzyk_przylacza_HIST',
  29. 'Rozdzielcza_test_bzyk_przylacza','Rozdzielcza_test_bzyk_punkty_adresowe','Rozdzielcza_test_bzyk_ways');
  30. //$tables = DB::getPDO()->list_tables();
  31. foreach($check_tbls as $tbl) {
  32. $query = "select ID from ".$tbl." limit 1 ";
  33. echo "<br>\nresult chk for tbl:".$tbl." ;";
  34. try{
  35. $result = DB::getPDO()->fetchall($query);
  36. } catch(Exception $exception) {
  37. // return $exception;
  38. echo "<br>\n jest blad z tbl:".$tbl." i get sample table structure with data from ../sql/".$tbl.".sql - it should be manually replaced by correct/newer!";
  39. $sql = file_get_contents('../sql/'.$tbl.'.sql');
  40. try{
  41. $result = DB::getPDO()->fetchall($sql);
  42. } catch(Exception $exception2) {
  43. echo "<br>\n jest blad dump dla tbl:".$tbl;
  44. }
  45. }
  46. // print_r($exception);
  47. print_r($result);
  48. }
  49. }
  50. init_sh_check();
  51. function pointsDistance($a, $b) {
  52. $line = new LineString(array($a, $b));
  53. return $line->length();
  54. }
  55. $ways2joins = unserialize(file_get_contents('ways2joins.txt'));
  56. $joins2ways = unserialize(file_get_contents('joins2ways.txt'));
  57. $points2joins = unserialize(file_get_contents('points2joins.txt'));
  58. $joins_asText = unserialize(file_get_contents('joins_asText.txt'));
  59. $ways_asText = unserialize(file_get_contents('ways_asText.txt'));
  60. $points_asText = unserialize(file_get_contents('points_asText.txt'));
  61. function findWay($joinA, $joinB, $path = array()) {
  62. global $ways2joins, $joins2ways, $points2joins, $ways_asText, $points_asText, $res;
  63. //echo implode('->',$path)."\n\n";
  64. if ($joinA == $joinB) $res[] = $path;
  65. else {
  66. foreach ($joins2ways[$joinA] as $way_key) {
  67. if (!in_array($way_key, $path)) {
  68. // $joins = $ways2joins[$way_key];
  69. // $back_join_subkey = array_search($join_key, $joins);
  70. // $new_join_subkey = 1 - $back_join_subkey;
  71. // $new_join = $joins[$new_join_subkey];
  72. $new_join = $ways2joins[$way_key][1 - array_search($joinA, $ways2joins[$way_key])];
  73. findWay($new_join, $joinB, array_merge($path,array($way_key)));
  74. }
  75. }
  76. }
  77. }
  78. findWay(100,110);
  79. print_r($res);