biale_plamy_class_findWay.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. require("biale_plamy_class.php");
  3. $test = new bialePlamy(array("pointsTable"=>"Rozdzielcza_test2_bzyk_punkty_adresowe", "origWaysTable"=>"Rozdzielcza_test2_bzyk_drogi"));
  4. //$test->enableShowProgress();
  5. $test->loadCache();
  6. function array_to_xml( $data, &$xml_data ) {
  7. foreach( $data as $key => $value ) {
  8. $key_="";
  9. if( is_numeric($key) ){
  10. $key_ = 'item';
  11. }
  12. if( is_array($value) ) {
  13. $subnode = $xml_data->addChild($key_);
  14. $subnode->addAttribute('id', $key);
  15. array_to_xml($value, $subnode);
  16. } else {
  17. // $test_expl=explode(" ", $value);
  18. //preg_match('/[a-zA-Z]/', $value[0])
  19. //if($key_=="" and !isset($test_expl[1]) ) $key_=htmlspecialchars("$value");
  20. //czy nie jest jeden element array
  21. if($key_=="" and count($data[$key]==1)) {
  22. $subnode=$xml_data->addChild("$key",htmlspecialchars("$value"));
  23. } else
  24. $subnode=$xml_data->addChild("$key_",htmlspecialchars("$value"));
  25. if( is_numeric($key) ){
  26. $subnode->addAttribute('id', $key);
  27. }
  28. }
  29. }
  30. }
  31. $ways2joins = unserialize(file_get_contents('/tmp/save_ways2joins.txt'));
  32. $joins2ways = unserialize(file_get_contents('/tmp/save_joins2ways.txt'));
  33. $points2joins = unserialize(file_get_contents('/tmp/save_points2joins.txt'));
  34. $joins_asText = unserialize(file_get_contents('/tmp/save_joins_asText.txt'));
  35. $ways_asText = unserialize(file_get_contents('/tmp/save_ways_asText.txt'));
  36. $points_asText = unserialize(file_get_contents('/tmp/save_points_asText.txt'));
  37. $edge_joins=simplexml_load_file("edge_joins.xml");
  38. $edge_joins->registerXPathNamespace('bp', 'https://procesy5.pl/biale_plamy-schema.xsd');
  39. //print_r($edge_joins);
  40. foreach($edge_joins->children() as $child) {
  41. // echo "\n<br>";
  42. //$attrs=$child->attributes("ID_Way");
  43. foreach($child->attributes() as $a=>$b) {
  44. // echo "#87Child";print_r($b[0]);
  45. $ID_Way=$b[0];
  46. }
  47. //echo $child->getName() . ": " . " ID_Way: ".$ID_Way. " : ";
  48. $id_j=0;
  49. settype($ID_Way, "integer");
  50. //$ID_Way=var_dump($ID_Way);
  51. // echo "#88Child:"; print_r($ID_Way);
  52. //$edge_joins_path['ID_Way'][$attrs['ID_Way']]=array();
  53. foreach($child->children('https://procesy5.pl/biale_plamy-schema.xsd') as $edge_joins_xml) {
  54. $id_j++;
  55. $attrs_join=$edge_joins_xml->attributes();
  56. //echo " #93 ID_Join ".$attrs_join["Joins"]." ";
  57. $Join=$attrs_join["Joins"][0];
  58. settype($Join, "integer");
  59. $edge_joins_path[$ID_Way][$id_j]=$attrs_join["Joins"][0];
  60. }
  61. }
  62. /////////
  63. DB::getPDO()->query("truncate table Rozdzielcza_test_bzyk_paths");
  64. unset($ID_Way);
  65. $edge_joins_filled_paths=array();
  66. foreach($edge_joins_path as $ID_Way=>$Joins_arr) {
  67. settype($ID_Way, "integer");
  68. $edge_joins_filled_paths[$ID_Way]['tried']=1;
  69. if(isset($Joins_arr[1]) and isset($Joins_arr[2])) {
  70. $pkt_A=$Joins_arr[1];$pkt_B=$Joins_arr[2];
  71. settype($pkt_A, "integer"); settype($pkt_B, "integer");
  72. echo "\n<br> Generuje dla ID_Way:".$ID_Way." i joins ".$pkt_A." , ".$pkt_B." ";
  73. unset($res);unset($path);
  74. {
  75. $res = $test->findWay(42366, 42376);
  76. $lineStringObj = $test->joins2lineString($res);
  77. $path = $lineStringObj->asText();
  78. }
  79. //$res = findWay($pkt_A,$pkt_B);
  80. //$path = joins2lineString($res)->asText();
  81. // joins2lineString(findWay(389,404));
  82. settype($path, "string");
  83. $edge_joins_filled_paths[$ID_Way]['asText'] = $path;
  84. $distance = 0;
  85. foreach ($res as $way_key) {
  86. if(isset($ways_asText[$way_key]))
  87. $distance += Vendor_Geophp::load($ways_asText[$way_key], 'wkt')->greatCircleLength();
  88. }
  89. $edge_joins_filled_paths[$ID_Way]['distance'] = $distance;
  90. //joins2lineString(findWay($Joins_arr[1],$Joins_arr[2]));
  91. //joins2lineString($res = findWay($joinAB['A'],$joinAB['B']))->asText();
  92. $sql_insert_path="insert into Rozdzielcza_test_bzyk_paths (the_geom,ID_Way, A_RECORD_CREATE_DATE )
  93. values (ST_GeomFromText('".$edge_joins_filled_paths[$ID_Way]['asText']."'),'".$ID_Way."' , now() ) ";
  94. echo "#216Query path ins:: ".$sql_insert_path." , distance:".$distance." ";
  95. if(strlen($edge_joins_filled_paths[$ID_Way]['asText'])>2)
  96. DB::getPDO()->query($sql_insert_path);
  97. else echo "#296 path nie wygenerowalo sie !! dla ".$ID_Way." i pkt ".$pkt_A." , ".$pkt_B." \n";
  98. } else echo "\n#220 droga nie ma koncow ID_Way::".$ID_Way;
  99. }
  100. echo "<br>\n edge_joins_filled_paths:";
  101. print_r($edge_joins_filled_paths);
  102. //save
  103. unset($xml_data);
  104. file_put_contents('edge_joins_filled_paths.txt',serialize($edge_joins_filled_paths));
  105. ob_start();print_r($edge_joins_filled_paths); $contents = ob_get_contents();ob_end_clean();
  106. file_put_contents('edge_joins_filled_paths_print_r.txt',$contents);
  107. $xml_data = new SimpleXMLElement('<?xml version="1.0"?><edge_joins_filled_paths></edge_joins_filled_paths>');
  108. array_to_xml($edge_joins_filled_paths,$xml_data);
  109. print $xml_data->asXML("edge_joins_filled_paths.xml");
  110. unset($xml_data);