biale_put_PE_to_mysql.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. $_SERVER['SERVER_NAME'] = 'biuro.biall-net.pl';
  3. //when used in /Library/Server/Web/Data/Sites/bzyk-biale-plamy-php-temp/SE/dev on biuro.biall-net.pl
  4. if( file_exists ( "../../se-lib/bootstrap.php"))
  5. require("../../se-lib/bootstrap.php");
  6. //when used in in native SE
  7. else require("../../../../SE-production-git/SE/se-lib/bootstrap.php");
  8. Lib::loadClass("Vendor_Geophp");
  9. function init_sh_check() {
  10. //check if run from bash
  11. if(isset($_SERVER["argv"])) {
  12. if(@$_SERVER["argv"][1]=='--help') {
  13. echo "
  14. Options are:
  15. php ".$_SERVER["argv"][0]." --check - control if we have needed tables/data
  16. .EOF
  17. ";
  18. } else if(@$_SERVER["argv"][1]=='--check') {
  19. check();
  20. } else echo " bad option, try:
  21. php ".$_SERVER["argv"][0]." --help
  22. .EOF
  23. ";
  24. } else {
  25. echo "<br> this script could be run from bash e.g. php biale_plamy.php --help <br>" ;
  26. check();
  27. }
  28. }
  29. function check() {
  30. echo "<br>\n i run check()";
  31. //todo to set arguments to rebuild tables etc:
  32. $check_tbls=array('Rozdzielcza_test_bzyk_drogi','Rozdzielcza_test_bzyk_joins','Rozdzielcza_test_bzyk_przylacza_HIST',
  33. 'Rozdzielcza_test_bzyk_przylacza','Rozdzielcza_test_bzyk_punkty_adresowe','Rozdzielcza_test_bzyk_ways');
  34. //$tables = DB::getPDO()->list_tables();
  35. foreach($check_tbls as $tbl) {
  36. $query = "select ID from ".$tbl." limit 1 ";
  37. echo "<br>\nresult chk for tbl:".$tbl." ;";
  38. try{
  39. $result = DB::getPDO()->fetchall($query);
  40. } catch(Exception $exception) {
  41. // return $exception;
  42. 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!";
  43. $sql = file_get_contents('../sql/'.$tbl.'.sql');
  44. try{
  45. $result = DB::getPDO()->fetchall($sql);
  46. } catch(Exception $exception2) {
  47. echo "<br>\n jest blad dump dla tbl:".$tbl;
  48. }
  49. }
  50. // print_r($exception);
  51. print_r($result);
  52. }
  53. }
  54. init_sh_check();
  55. $edge_paths_with_PE=simplexml_load_file("edge_paths_with_PE.xml");
  56. $edge_paths_with_PE->registerXPathNamespace('bp', 'https://procesy5.pl/biale_plamy-schema.xsd');
  57. /*
  58. <PE_candidates_dump xmlns:bp="https://procesy5.pl/biale_plamy-schema.xsd"
  59. desc="brakuje ominiecia punktow ways tylko do przylaczy i analizy dlugosci">
  60. <LINESTRING ID_Way="3"
  61. Count="15"
  62. distance="1168.1143169402"
  63. dumb_frequency="10">
  64. <bp:Path_Point Pos="10" X="18.63765" Y="51.255476599079"/>
  65. </LINESTRING>
  66. */
  67. //print_r($edge_joins);
  68. $edge_paths_with_PE_arr=array();
  69. foreach($edge_paths_with_PE->children() as $child) {
  70. // echo "\n<br>";
  71. //$attrs=$child->attributes("ID_Way");
  72. foreach($child->attributes() as $a=>$b) {
  73. // echo "#87Child";print_r($b[0]);
  74. if($a=='ID_Way') $ID_Way=$b[0];
  75. //if($a=='Count') $Count=$b[0];
  76. }
  77. //echo $child->getName() . ": " . " ID_Way: ".$ID_Way. " : ";
  78. settype($ID_Way, "integer");
  79. //$ID_Way=var_dump($ID_Way);
  80. // echo "#88Child:"; print_r($ID_Way);
  81. //$edge_joins_path['ID_Way'][$attrs['ID_Way']]=array();
  82. // $result = $xml->xpath('/a/b/c');
  83. $id_j=0;
  84. foreach($child->xpath('bp:Path_Point') as $Path_Point_xml) {
  85. $id_j++;
  86. $Path_Point=$Path_Point_xml->attributes();
  87. //echo " #93 ID_Join ".$attrs_join["Joins"]." ";
  88. $Path_Point['Pos']=$Path_Point['Pos'][0]; settype($Path_Point['Pos'], "integer");
  89. $Path_Point['X']=$Path_Point['X'][0]; settype($Path_Point['X'], "string");
  90. $Path_Point['Y']=$Path_Point['Y'][0]; settype($Path_Point['Y'], "string");
  91. $Path_Point['ID_Join']=$Path_Point['ID_Join'][0]; settype($Path_Point['ID_Join'], "integer");
  92. $edge_paths_with_PE_arr[$ID_Way][$id_j]=$Path_Point;
  93. }
  94. }
  95. echo "\n<br>edge_paths_with_PE_arr";
  96. print_r($edge_paths_with_PE_arr);
  97. DB::getPDO()->query("truncate table Rozdzielcza_test_bzyk_PE");
  98. unset($ID_Way);
  99. $edge_joins_filled_paths=array();
  100. foreach($edge_paths_with_PE_arr as $ID_Way=>$Path_Point) {
  101. foreach($Path_Point as $Path_Point_val) {
  102. $sql_Path_Point_val="insert into Rozdzielcza_test_bzyk_PE (the_geom,ID_Way,ID_Join)
  103. values (ST_GeomFromText('POINT(".$Path_Point_val['X']." ".$Path_Point_val['Y'].")'),'".$ID_Way."' ,
  104. '".$Path_Point_val['ID_Join']."' ) ";
  105. echo "#216Query path ins:: ".$sql_Path_Point_val." ";
  106. //if(strlen($edge_joins_filled_paths[$ID_Way]['asText'])>2)
  107. if( strlen($Path_Point_val['X'])>1 and strlen($Path_Point_val['Y'])>1 ) DB::getPDO()->query($sql_Path_Point_val);
  108. //else echo "#296 path nie wygenerowalo sie !! dla ".$ID_Way." i pkt ".$pkt_A." , ".$pkt_B." \n";
  109. }
  110. }