| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- <?php
- $_SERVER['SERVER_NAME'] = 'biuro.biall-net.pl';
- require("../../se-lib/bootstrap.php");
- Lib::loadClass("Vendor_Geophp");
- function init_sh_check() {
- //check if run from bash
- if(isset($_SERVER["argv"])) {
- if(@$_SERVER["argv"][1]=='--help') {
- echo "
- Options are:
- php ".$_SERVER["argv"][0]." --check - control if we have needed tables/data
-
- .EOF
- ";
- } else if(@$_SERVER["argv"][1]=='--check') {
- check();
- } else echo " bad option, try:
- php ".$_SERVER["argv"][0]." --help
-
- .EOF
- ";
- } else {
- echo "<br> this script could be run from bash e.g. php biale_plamy.php --help <br>" ;
- check();
- }
- }
- function check() {
- echo "<br>\n i run check()";
- //todo to set arguments to rebuild tables etc:
- $check_tbls=array('Rozdzielcza_test_bzyk_drogi','Rozdzielcza_test_bzyk_joins','Rozdzielcza_test_bzyk_przylacza_HIST',
- 'Rozdzielcza_test_bzyk_przylacza','Rozdzielcza_test_bzyk_punkty_adresowe','Rozdzielcza_test_bzyk_ways');
- //$tables = DB::getPDO()->list_tables();
- foreach($check_tbls as $tbl) {
- $query = "select ID from ".$tbl." limit 1 ";
- echo "<br>\nresult chk for tbl:".$tbl." ;";
-
- try{
- $result = DB::getPDO()->fetchall($query);
- } catch(Exception $exception) {
- // return $exception;
- 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!";
- $sql = file_get_contents('../sql/'.$tbl.'.sql');
-
- try{
- $result = DB::getPDO()->fetchall($sql);
- } catch(Exception $exception2) {
- echo "<br>\n jest blad dump dla tbl:".$tbl;
- }
- }
- // print_r($exception);
- print_r($result);
- }
- }
- init_sh_check();
- function pointsDistance($a, $b) {
- $line = new LineString(array($a, $b));
- return $line->length();
- }
- $ways2joins = unserialize(file_get_contents('ways2joins.txt'));
- $joins2ways = unserialize(file_get_contents('joins2ways.txt'));
- $points2joins = unserialize(file_get_contents('points2joins.txt'));
- $joins_asText = unserialize(file_get_contents('joins_asText.txt'));
- $ways_asText = unserialize(file_get_contents('ways_asText.txt'));
- $points_asText = unserialize(file_get_contents('points_asText.txt'));
- function findWay($joinA, $joinB, $path = array()) {
- global $ways2joins, $joins2ways, $points2joins, $ways_asText, $points_asText;
- if ($joinA == $joinB) return $path;
- else {
- $subPaths = array();
- foreach ($joins2ways[$joinA] as $way_key) {
- if (!in_array($way_key, $path)) {
- $new_join = $ways2joins[$way_key][1 - array_search($joinA, $ways2joins[$way_key])];
- if ($subPath = findWay($new_join, $joinB, array_merge($path,array($way_key)))) $subPaths[] = $subPath;
- }
- }
- if ($subPaths) {
- if (count($subPaths) == 1) return $subPaths[0];
- else {
- $shortestKey = 0;
- foreach ($subPaths as $key => $subPath) {
- $distance_cur = 0;
- foreach ($subPath as $way_key) {
- $distance_cur += Vendor_Geophp::load($ways_asText[$way_key], 'wkt')->length();
- }
- if (!$shortestKey || ($shortestKey && $distance_cur < $distance)) {
- $shortestKey = $key;
- $distance = $distance_cur;
- }
- }
- return $subPaths[$key];
- }
- }
- else return null;
- }
- }
- $res = findWay(100,110);
- $distance = 0;
- foreach ($res as $way_key) {
- $distance += Vendor_Geophp::load($ways_asText[$way_key], 'wkt')->greatCircleLength();
- }
- print_r($res);
- echo "Distance: ".$distance."m\n";
|