소스 검색

dodanie prefix i sciaganie przez ant danych z WFS

a.binder 9 년 전
부모
커밋
96f1375d4a

+ 0 - 329
SE/dev/php-cli/biale_plamy-find_ways.php

@@ -1,329 +0,0 @@
-<?php
-$_SERVER['SERVER_NAME'] = 'biuro.biall-net.pl';
-
-
-//when used in /Library/Server/Web/Data/Sites/bzyk-biale-plamy-php-temp/SE/dev on biuro.biall-net.pl
-if( file_exists ( "../../se-lib/bootstrap.php"))
-require("../../se-lib/bootstrap.php");
-//when used in  in native SE
-else require("../../../../SE-production-git/SE/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();   
-
-$ways2joins = unserialize(file_get_contents('/tmp/save_ways2joins.txt'));
-$joins2ways = unserialize(file_get_contents('/tmp/save_joins2ways.txt'));
-$points2joins = unserialize(file_get_contents('/tmp/save_points2joins.txt'));
-$joins_asText = unserialize(file_get_contents('/tmp/save_joins_asText.txt'));
-$ways_asText = unserialize(file_get_contents('/tmp/save_ways_asText.txt'));
-$points_asText = unserialize(file_get_contents('/tmp/save_points_asText.txt'));
-
-$edge_joins=simplexml_load_file("edge_joins.xml");
-$edge_joins->registerXPathNamespace('bp', 'https://procesy5.pl/biale_plamy-schema.xsd');
-
-//print_r($edge_joins);
-foreach($edge_joins->children() as $child)  {
- // echo "\n<br>";
-	   //$attrs=$child->attributes("ID_Way");
-
-	   foreach($child->attributes() as $a=>$b) {
-		   //	echo "#87Child";print_r($b[0]);
-		   $ID_Way=$b[0];
-	   }
-	  //echo $child->getName() . ": " . " ID_Way: ".$ID_Way. " : ";
-	
-	   $id_j=0; 
-	   settype($ID_Way, "integer");
-	   //$ID_Way=var_dump($ID_Way);
-	   
-	 //  echo "#88Child:"; print_r($ID_Way);
-	   //$edge_joins_path['ID_Way'][$attrs['ID_Way']]=array();
-	   foreach($child->children('https://procesy5.pl/biale_plamy-schema.xsd') as $edge_joins_xml)  {
-		   $id_j++;
-		   $attrs_join=$edge_joins_xml->attributes();
-		   //echo " #93 ID_Join ".$attrs_join["Joins"]." ";
-		   $Join=$attrs_join["Joins"][0];
-		   settype($Join, "integer");
-		   $edge_joins_path[$ID_Way][$id_j]=$attrs_join["Joins"][0];
-	   }
-}
-
-//print_r($edge_joins_path);
-
-
-
-function joins2lineString($joins_keys) {
-	global $joins_asText;
-	if ($joins_keys) {
-		foreach ($joins_keys as $join_key) {
-			$points[] = Vendor_Geophp::load($joins_asText[$join_key], 'wkt');
-		}
-		return new LineString($points);
-	} else return null;
-}
-
-function findWay($joinA, $joinB, $path = array()) {
-	global $ways2joins, $joins2ways, $points2joins, $ways_asText, $points_asText;
-	if ($joinA == $joinB) {
-		$joinsPath = array($joinB);
-		foreach (array_reverse($path) as $way_key) {
-			array_unshift($joinsPath, $ways2joins[$way_key][1 - array_search($joinsPath[0], $ways2joins[$way_key])]);
-		}
-		return $joinsPath;
-	} 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) {
-						$way = Vendor_Geophp::load($ways_asText[$way_key], 'wkt');
-						if ($way) $distance_cur += Vendor_Geophp::load($ways_asText[$way_key], 'wkt')->length();
-						else $distance_cur += 999;
-					}
-					if (!$shortestKey || ($shortestKey && $distance_cur < $distance)) {
-						$shortestKey = $key;
-						$distance = $distance_cur;
-					}
-				}
-				return $subPaths[$key];
-			}
-		}
-		else {
-			return null;
-		}
-	}
-}
-
-function findJoinInDB($id) {
-	global $joins_asText;
-	$join = DB::getPDO()->fetchValue("select astext(the_geom) from Rozdzielcza_test_bzyk_joins where ID='{$id}'");
-	if ($join) {
-		$join = Vendor_Geophp::load($join, 'wkt')->asText();
-		$key = array_search($join, $joins_asText);
-		if ($key) return $key;
-		else return null;
-	} else return null;
-}
-
-
-
-function array_to_xml( $data, &$xml_data ) {
-    foreach( $data as $key => $value ) {
-        $key_="";
-        
-        if( is_numeric($key) ){
-            $key_ = 'item';
-        }
-        
-        if( is_array($value) ) {
-            $subnode = $xml_data->addChild($key_);
-			$subnode->addAttribute('id', $key);
-            array_to_xml($value, $subnode);
-        } else {
-	       // $test_expl=explode(" ", $value);
-					//preg_match('/[a-zA-Z]/', $value[0])
-	        //if($key_=="" and !isset($test_expl[1])  )  $key_=htmlspecialchars("$value");
-	        //czy nie jest jeden element array
-	        if($key_=="" and  count($data[$key]==1)) {
-		   		 $subnode=$xml_data->addChild("$key",htmlspecialchars("$value"));
-		    } else  
-            $subnode=$xml_data->addChild("$key_",htmlspecialchars("$value"));
-            if( is_numeric($key) ){
-	            $subnode->addAttribute('id', $key);
-	        }
-        }
-     }
-}
-
-#echo joins2lineString($res = findWay(100,110))->asText();
-#echo joins2lineString($res = findWay(25690,20134))->asText();
-#$path = joins2lineString(findWay(25690,23039));
-
-
-
-//$path = joins2lineString(findWay(findJoinInDB(49),findJoinInDB(50)));
-
-
-//generujemy path do $edge_joins_filled_paths
- DB::getPDO()->query("truncate table Rozdzielcza_test_bzyk_paths");
-
-unset($ID_Way);
-
-$edge_joins_filled_paths=array();
-foreach($edge_joins_path as $ID_Way=>$Joins_arr) {
-	settype($ID_Way, "integer");
-	$edge_joins_filled_paths[$ID_Way]['tried']=1;
-	if(isset($Joins_arr[1]) and isset($Joins_arr[2]))  {
-			   $pkt_A=$Joins_arr[1];$pkt_B=$Joins_arr[2];
-			   settype($pkt_A, "integer"); settype($pkt_B, "integer");
-
-		echo "\n<br> Generuje dla ID_Way:".$ID_Way." i joins ".$pkt_A." , ".$pkt_B." ";
-		unset($res);unset($path);
-		$res = findWay($pkt_A,$pkt_B);
-		$path = joins2lineString($res)->asText();
-		//   joins2lineString(findWay(389,404));
-		settype($path, "string");
-		$edge_joins_filled_paths[$ID_Way]['asText'] = $path;
-			$distance = 0;
-				foreach ($res as $way_key) {
-					if(isset($ways_asText[$way_key]))
-					$distance += Vendor_Geophp::load($ways_asText[$way_key], 'wkt')->greatCircleLength();
-				}
-		$edge_joins_filled_paths[$ID_Way]['distance'] = $distance;
-		//joins2lineString(findWay($Joins_arr[1],$Joins_arr[2]));
-		//joins2lineString($res = findWay($joinAB['A'],$joinAB['B']))->asText();
-		$sql_insert_path="insert into Rozdzielcza_test_bzyk_paths (the_geom,ID_Way, A_RECORD_CREATE_DATE )
-		     values (ST_GeomFromText('".$edge_joins_filled_paths[$ID_Way]['asText']."'),'".$ID_Way."' , now()   )   ";
-		    echo "#216Query path ins:: ".$sql_insert_path." , distance:".$distance." ";
-		    if(strlen($edge_joins_filled_paths[$ID_Way]['asText'])>2)
-		      DB::getPDO()->query($sql_insert_path);
-		    else echo "#296 path nie wygenerowalo sie !! dla ".$ID_Way." i pkt ".$pkt_A." , ".$pkt_B." \n";
-
-	} else echo "\n#220 droga nie ma koncow ID_Way::".$ID_Way;
-}
-
-
-echo "<br>\n edge_joins_filled_paths:";
-print_r($edge_joins_filled_paths);
-
-
-//save
- 	unset($xml_data);
-
-file_put_contents('edge_joins_filled_paths.txt',serialize($edge_joins_filled_paths));
- 	ob_start();print_r($edge_joins_filled_paths); $contents = ob_get_contents();ob_end_clean();  
- 	file_put_contents('edge_joins_filled_paths_print_r.txt',$contents);
- 	$xml_data = new SimpleXMLElement('<?xml version="1.0"?><edge_joins_filled_paths></edge_joins_filled_paths>');
- 	array_to_xml($edge_joins_filled_paths,$xml_data);
- 	print $xml_data->asXML("edge_joins_filled_paths.xml");
- 	unset($xml_data);
-  
-
-
-//test
- 	$timeStart = microtime();
- 	$res = findWay(389,404);
- 	$path=joins2lineString($res)->asText();
-	$timeEnd = microtime();
-		
-		if ($path) {
-			echo $path."\n";
-		} else echo "Brak drogi";
-		
-		list($usecStart, $secStart) = explode(" ", $timeStart);
-		list($usecEnd, $secEnd) = explode(" ", $timeEnd);
-		$diff = $secEnd - $secStart + $usecEnd - $usecStart;
-		echo "\n\nCzas liczenia: ".$diff." s\n";
-		
-		  	
-		$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";
-//eof test
-echo "\n<br>test2";
-
-
-
-
-//test
- 	$timeStart = microtime();
- 	$res = findWay(389,404);
- 	$path=joins2lineString($res)->asText();
-	$timeEnd = microtime();
-		
-		if ($path) {
-			
-						echo $path."\n";
-		} else echo "Brak drogi";
-		
-		list($usecStart, $secStart) = explode(" ", $timeStart);
-		list($usecEnd, $secEnd) = explode(" ", $timeEnd);
-		$diff = $secEnd - $secStart + $usecEnd - $usecStart;
-		echo "\n\nCzas liczenia: ".$diff." s\n";
-		
-		  	
-		$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";
-//eof test
-
-
-
-//$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";

+ 0 - 361
SE/dev/php-cli/biale_plamy-generate_data.php

@@ -1,361 +0,0 @@
-<?php
-	
-	ini_set('display_errors', 'On');
-error_reporting(E_ALL);
-
-
-$_SERVER['SERVER_NAME'] = 'biuro.biall-net.pl';
-//when used in /Library/Server/Web/Data/Sites/bzyk-biale-plamy-php-temp/SE/dev on biuro.biall-net.pl
-if( file_exists ( "../../se-lib/bootstrap.php"))
-require("../../se-lib/bootstrap.php");
-//when used in  in native SE
-else require("../../../../SE-production-git/SE/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();   
-
-$query = "select astext(the_geom) as multiway ,ID as ID_Way from Rozdzielcza_test_bzyk_drogi where numpoints(the_geom)>1";
-$result = DB::getPDO()->fetchall($query);
-$joins_asText = array();
-foreach ($result as $row) {
-	$multiway = Vendor_Geophp::load($row['multiway'], 'wkt');
-//echo $multiway->length();
-	for ($i = 1; $i < $n = $multiway->numPoints(); $i++) {
-		$way = new LineString(array($multiway->pointN($i), $multiway->pointN($i+1)));
-		$ways_asText[] = $way->asText();
-		$ways_2ID_Way[]=$row['ID_Way'];
-		if (!in_array($multiway->pointN($i)->asText(), $joins_asText)) $joins_asText[] = $multiway->pointN($i)->asText();
-	}
-	if (!in_array($multiway->pointN($n)->asText(), $joins_asText)) $joins_asText[] = $multiway->pointN($n)->asText();
-}
-
-$query = "select ID, astext(the_geom) as point, astext(the_geom_nearest_way) as way, astext(the_geom_xpoint) as xpoint, ID_Way from Rozdzielcza_test_bzyk_punkty_adresowe";
-$result = DB::getPDO()->fetchall($query);
-$xpoints = array();
-foreach ($result as $row) {
-        $points[$row['ID']] = Vendor_Geophp::load($row['point'], 'wkt');
-        $points2ID_Way[$row['ID']] = $row['ID_Way'] ;
-	$points_asText[$row['ID']] = $points[$row['ID']]->asText();
-        $xpoint = Vendor_Geophp::load($row['xpoint'], 'wkt');
-     //blad dziwny sqix
-     if($xpoints) {
-		if (!($key = array_search($xpoint->asText(), $xpoints))) $key = array_push($xpoints, $xpoint->asText())-1;
-			$xpoints2points[$key][] = $row['ID'];
-			$points2xpoints[$row['ID']] = $key;
-		
-		        $way = Vendor_Geophp::load($row['way'], 'wkt');
-		}
-		//errory sieje z die
-	if($xpoint) {
-		if (!(in_array($xpoint->asText(), $joins_asText))) {
-			if (@!in_array($key, $ways2cut[array_search($way->asText(), $ways_asText)])) {
-				$ways2cut[array_search($way->asText(), $ways_asText)][] = array('key'=>$key,'ID_Way'=>$row['ID_Way']);
-			} else echo ".";
-		};
-	}
-}
-
-function pointsDistance($a, $b) {
-	$line = new LineString(array($a, $b));
-	return $line->length();
-}
-
-foreach ($ways2cut as $way_key => $xpoint_keys) {
-	$distances = array();
-	//$xpoint_keys=$value_arr['key'];
-	$way = Vendor_Geophp::load($ways_asText[$way_key], 'wkt');
-	foreach ($xpoint_keys as $xpoint_key_arr) {
-	
-	if($joins_asText   ) {
-		$xpoint_key=$xpoint_key_arr['key'];
-		$ID_Way=$xpoint_key_arr['ID_Way'];
-		if($xpoints[$xpoint_key]) //error sypie
-		$xpoint = Vendor_Geophp::load($xpoints[$xpoint_key], 'wkt');
-		if($xpoint) { ///sypie errorem
-			$key = array_push($joins_asText, $xpoint->asText())-1; //blad
-			foreach ($xpoints2points[$xpoint_key] as $point_key) {
-				$points2joins[$point_key] = $key;
-			}
-		}
-		$distances[$xpoint_key] = pointsDistance($way->startPoint(), $xpoint);
-	}
-	}
-	asort($distances);
-
-	$sub_xpoints = array();
-	foreach (array_keys($distances) as $xpoint_key) {
-		if($xpoints[$xpoint_key]) // if sypie errorami
-		$sub_xpoints[] = Vendor_Geophp::load($xpoints[$xpoint_key]);
-	}
-
-	$startPoint = $way->startPoint();
-	$endPoint = $way->endPoint();
-	if($sub_xpoints[0] and $startPoint) { // sypie erorrami
-		$way = new LineString(array($startPoint, $sub_xpoints[0]));
-		$ways_asText[$way_key] = $way->asText();
-		$ways_2ID_Way[$way_key]=$ID_Way;
-	}
-	
-	for ($i = 0; $i < $n = count($sub_xpoints) - 1; $i++) {
-		$way = new LineString(array($sub_xpoints[$i], $sub_xpoints[$i+1]));
-		$ways_asText[] = $way->asText();
-		$ways_2ID_Way[]=$ID_Way;
-	}
-	if($sub_xpoints[$n] and $endPoint) {
-		$way = new LineString(array($sub_xpoints[$n], $endPoint));
-		$ways_asText[] = $way->asText();
-		$ways_2ID_Way[]=$ID_Way;
-	}
-}
-
-foreach (array_keys($ways_asText) as $way_key) {
-	$way = Vendor_Geophp::load($ways_asText[$way_key], 'wkt');
-	$ways_lenghts[$way_key] = $way->length();
-	for ($i = 1; $i <= 2; $i++) {
-		$join = $way->pointN($i)->asText();
-		$join_key = array_search($join, $joins_asText);
-//if (!$join_key) echo ".";
-		$ways2joins[$way_key][] = $join_key;
-		$joins2ways[$join_key][] = $way_key;
-	}
-}
-/*
-// $val=array(A=>asd,B=>cos) ---
-// <xml>
-//  <A>cos</A>
-	<B>cos></B>
-   </xml>
-   array(0=asd,1=asd)
-   <xml>
-    <item id=0>asd</>
-    <item id=2>asd</>
-   
-   array(A=>asd,B=>array(0=>asd,1=>asd))
-   <xml>
-     <A>asd</>
-     <B><item id=0>asd</>
-        <item id=1>asd</>
-
-// $pozA[1]=dupa
-// $pozA[2]=jasiu
-*/
-// function defination to convert array to xml
-function array_to_xml( $data, &$xml_data ) {
-    foreach( $data as $key => $value ) {
-        $key_="";
-        
-        if( is_numeric($key) ){
-            $key_ = 'item';
-        }
-        
-        if( is_array($value) ) {
-            $subnode = $xml_data->addChild($key_);
-			$subnode->addAttribute('id', $key);
-            array_to_xml($value, $subnode);
-        } else {
-            $subnode=$xml_data->addChild("$key_",htmlspecialchars("$value"));
-            if( is_numeric($key) ){
-	            $subnode->addAttribute('id', $key);
-	        }
-        }
-     }
-}
-
-
-
-
-
-
-file_put_contents('points2ID_Way.txt',serialize($points2ID_Way));
-//for better debug to see variables in editor i make also print_r 
- 	ob_start();print_r($points2ID_Way); $contents = ob_get_contents();ob_end_clean();  
- 	file_put_contents('points2ID_Way_print_r.txt',$contents);
- 
- 	$xml_data = new SimpleXMLElement('<?xml version="1.0"?><points2ID_Way></points2ID_Way>');
- 	array_to_xml($points2ID_Way,$xml_data);
- 	print $xml_data->asXML("points2ID_Way.xml");
- 	unset($xml_data);
-  
-  
-  
-
-file_put_contents('ways_2ID_Way.txt',serialize($ways_2ID_Way));
-//for better debug to see variables in editor i make also print_r 
- 	ob_start();print_r($ways_2ID_Way); $contents = ob_get_contents();ob_end_clean();  
- 	file_put_contents('ways_2ID_Way_print_r.txt',$contents);
- 
- 	$xml_data = new SimpleXMLElement('<?xml version="1.0"?><ways_2ID_Way></ways_2ID_Way>');
- 	array_to_xml($ways_2ID_Way,$xml_data);
- 	print $xml_data->asXML("ways_2ID_Way.xml");
- 	unset($xml_data);
-  
-
-
-
-
-
-
-
-file_put_contents('ways2joins.txt',serialize($ways2joins));
-//for better debug to see variables in editor i make also print_r 
- 	ob_start();print_r($ways2joins); $contents = ob_get_contents();ob_end_clean();  
- 	file_put_contents('ways2joins_print_r.txt',$contents);
- 
- 	$xml_data = new SimpleXMLElement('<?xml version="1.0"?><ways2joins></ways2joins>');
- 	array_to_xml($ways2joins,$xml_data);
- 	print $xml_data->asXML("ways2joins.xml");
- 	unset($xml_data);
-  
-  
-  
-  
-
-file_put_contents('joins2ways.txt',serialize($joins2ways));
- 	ob_start();print_r($joins2ways); $contents = ob_get_contents();ob_end_clean();  
- 	file_put_contents('joins2ways_print_r.txt',$contents);
- 	$xml_data = new SimpleXMLElement('<?xml version="1.0"?><joins2ways></joins2ways>');
- 	array_to_xml($joins2ways,$xml_data);
- 	print $xml_data->asXML("joins2ways.xml");
- 	unset($xml_data);
-  
- 	
-
-file_put_contents('points2joins.txt',serialize($points2joins));
-	ob_start();print_r($points2joins); $contents = ob_get_contents();ob_end_clean();  
-	file_put_contents('points2joins_print_r.txt',$contents);
-	$xml_data = new SimpleXMLElement('<?xml version="1.0"?><points2joins></points2joins>');
- 	array_to_xml($points2joins,$xml_data);
- 	print $xml_data->asXML("points2joins.xml");
- 	unset($xml_data);
-
-file_put_contents('joins_asText.txt',serialize($joins_asText));
-	ob_start();print_r($joins_asText); $contents = ob_get_contents();ob_end_clean();  
-	file_put_contents('joins_asText_print_r.txt',$contents);
-	$xml_data = new SimpleXMLElement('<?xml version="1.0"?><joins_asText></joins_asText>');
- 	array_to_xml($joins_asText,$xml_data);
- 	print $xml_data->asXML("joins_asText.xml");
- 	unset($xml_data);
-
-
-file_put_contents('ways_asText.txt',serialize($ways_asText));
-	ob_start();print_r($ways_asText); $contents = ob_get_contents();ob_end_clean();  
-	file_put_contents('ways_asText_print_r.txt',$contents);
-	$xml_data = new SimpleXMLElement('<?xml version="1.0"?><ways_asText></ways_asText>');
- 	array_to_xml($ways_asText,$xml_data);
- 	print $xml_data->asXML("ways_asText.xml");
- 	unset($xml_data);
-
-
-file_put_contents('points_asText.txt',serialize($points_asText));
-	ob_start();print_r($points_asText); $contents = ob_get_contents();ob_end_clean();  
-	file_put_contents('points_asText_print_r.txt',$contents);
-	$xml_data = new SimpleXMLElement('<?xml version="1.0"?><points_asText></points_asText>');
- 	array_to_xml($points_asText,$xml_data);
- 	print $xml_data->asXML("points_asText.xml");
- 	unset($xml_data);
-
-
-
-/*
-function findWay($join_key, $point_key, $path = array()) {
-	global $ways2joins, $joins2ways, $points2joins, $ways_asText, $joins2ways, $points, $points2xpoints, $xpoints2joins, $ways_lengths, $res;
-//echo implode('->',$path)."\n\n";
-	if ($join_key == $points2joins[$point_key]) $res[] = $path;
-	else {
-		foreach ($joins2ways[$join_key] as $way_key) {
-			if (!in_array($way_key, $path)) {
-//				$joins = $ways2joins[$way_key];
-//				$back_join_subkey = array_search($join_key, $joins);
-//				$new_join_subkey = 1 - $back_join_subkey;
-//				$new_join = $joins[$new_join_subkey];
-				$new_join = $ways2joins[$way_key][1 - array_search($join_key,  $ways2joins[$way_key])];
-				findWay($new_join, $point_key, array_merge($path,array($way_key)));
-			}
-		}
-	}
-}
-*/
-//print_r($ways2joins);
-//for ($i = 0; $i < count($points); $i++) {
-//	if (isset($res)) unset($res);
-//	findWay(2000, $i);
-//	print_r($res);
-//}
-//print_r($ways);
-
-echo "ways count: ".count($ways_asText)."\n";
-
-
-$db = DB::getDB();
-$db->query("truncate table Rozdzielcza_test_bzyk_ways");
-$db->query("truncate table Rozdzielcza_test_bzyk_joins");
-
-
-foreach ($ways_asText as $way) {
-	$query = "insert into Rozdzielcza_test_bzyk_ways (the_geom) values (linefromtext('".$way."'))";
-	$db->query($query);
-	//echo $query."\n";
-}
-
-foreach ($joins_asText as $join) {
-	$query = "insert into Rozdzielcza_test_bzyk_joins (the_geom) values (pointfromtext('".$join."'))";
-	$db->query($query);
-}
-

+ 0 - 198
SE/dev/php-cli/biale_plamy.php

@@ -1,198 +0,0 @@
-<?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','Rozdzielcza_test_bzyk_punkty_adresowe','Rozdzielcza_test_bzyk_ways',
-                    'Rozdzielcza_test_bzyk_joins_HIST','Rozdzielcza_test_bzyk_przylacza_HIST',
-                    'Rozdzielcza_test_bzyk_przylacza_HIST','Rozdzielcza_test_bzyk_punkty_adresowe_HIST','Rozdzielcza_test_bzyk_ways_HIST');
-
-    //$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 Ajest 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');
-            
-            echo "<br> w get som content ".strlen($sql) ;
-			unset($result);
-             //return $exception;
-            try{
-                $result2 = DB::getPDO()->fetchall('select 1+1;');
-                //mam blad dziwny na mac pro :  Call to a member function fetchall() on null??? dpiero za drugim razem?
-            } catch(Exception $exception2) {
-                echo "<br>\n jest blad dump dla tbl:".$tbl;
-            }
-        } 
-        //	print_r($exception);
-        echo "<br> 64";
-        print_r($result2);
-    }
-}
-
-init_sh_check();   
-
-$query = "select astext(the_geom) as multiway from Rozdzielcza_test_bzyk_drogi where numpoints(the_geom)>1";
-$result = DB::getPDO()->fetchall($query);
-$joins_asText = array();
-foreach ($result as $row) {
-	$multiway = Vendor_Geophp::load($row['multiway'], 'wkt');
-//echo $multiway->length();
-	for ($i = 1; $i < $n = $multiway->numPoints(); $i++) {
-		$way = new LineString(array($multiway->pointN($i), $multiway->pointN($i+1)));
-		$ways_asText[] = $way->asText();
-		if (!in_array($multiway->pointN($i)->asText(), $joins_asText)) $joins_asText[] = $multiway->pointN($i)->asText();
-	}
-	if (!in_array($multiway->pointN($n)->asText(), $joins_asText)) $joins_asText[] = $multiway->pointN($n)->asText();
-}
-
-$query = "select ID, astext(the_geom) as point, astext(the_geom_nearest_way) as way, astext(the_geom_xpoint) as xpoint from Rozdzielcza_test_bzyk_punkty_adresowe limit 100";
-$result = DB::getPDO()->fetchall($query);
-$xpoints = array();
-foreach ($result as $row) {
-        $points[$row['ID']] = Vendor_Geophp::load($row['point'], 'wkt');
-
-        $xpoint = Vendor_Geophp::load($row['xpoint'], 'wkt');
-	if (!($key = array_search($xpoint->asText(), $xpoints))) $key = array_push($xpoints, $xpoint->asText())-1;
-	$xpoints2points[$key][] = $row['ID'];
-	$points2xpoints[$row['ID']] = $key;
-
-        $way = Vendor_Geophp::load($row['way'], 'wkt');
-
-	if (!(in_array($xpoint->asText(), $joins_asText))) {
-		if (@!in_array($key, $ways2cut[array_search($way->asText(), $ways_asText)])) {
-			$ways2cut[array_search($way->asText(), $ways_asText)][] = $key;
-		} else echo ".";
-	};
-}
-
-function pointsDistance($a, $b) {
-	$line = new LineString(array($a, $b));
-	return $line->length();
-}
-
-foreach ($ways2cut as $way_key => $xpoint_keys) {
-	$distances = array();
-	$way = Vendor_Geophp::load($ways_asText[$way_key], 'wkt');
-	foreach ($xpoint_keys as $xpoint_key) {
-		$xpoint = Vendor_Geophp::load($xpoints[$xpoint_key], 'wkt');
-		$key = array_push($joins_asText, $xpoint->asText())-1;
-		foreach ($xpoints2points[$xpoint_key] as $point_key) {
-			$points2joins[$point_key] = $key;
-		}
-		$distances[$xpoint_key] = pointsDistance($way->startPoint(), $xpoint);
-	}
-	asort($distances);
-
-	$sub_xpoints = array();
-	foreach (array_keys($distances) as $xpoint_key) {
-		$sub_xpoints[] = Vendor_Geophp::load($xpoints[$xpoint_key]);
-	}
-
-	$startPoint = $way->startPoint();
-	$endPoint = $way->endPoint();
-	$way = new LineString(array($startPoint, $sub_xpoints[0]));
-	$ways_asText[$way_key] = $way->asText();
-	for ($i = 0; $i < $n = count($sub_xpoints) - 1; $i++) {
-		$way = new LineString(array($sub_xpoints[$i], $sub_xpoints[$i+1]));
-		$ways_asText[] = $way->asText();
-	}
-	$way = new LineString(array($sub_xpoints[$n], $endPoint));
-	$ways_asText[] = $way->asText();
-}
-echo "\n";
-foreach (array_keys($ways_asText) as $way_key) {
-	$way = Vendor_Geophp::load($ways_asText[$way_key], 'wkt');
-	$ways_lenghts[$way_key] = $way->length();
-	for ($i = 1; $i <= 2; $i++) {
-		$join = $way->pointN($i)->asText();
-		$join_key = array_search($join, $joins_asText);
-//if (!$join_key) echo ".";
-		$ways2joins[$way_key][] = $join_key;
-		$joins2ways[$join_key][] = $way_key;
-	}
-}
-
-
-function findWay($join_key, $point_key, $path = array()) {
-	global $ways2joins, $joins2ways, $points2joins, $ways_asText, $joins2ways, $points, $points2xpoints, $xpoints2joins, $ways_lengths, $res;
-//echo implode('->',$path)."\n\n";
-	if ($join_key == $points2joins[$point_key]) $res[] = $path;
-	else {
-		foreach ($joins2ways[$join_key] as $way_key) {
-			if (!in_array($way_key, $path)) {
-//				$joins = $ways2joins[$way_key];
-//				$back_join_subkey = array_search($join_key, $joins);
-//				$new_join_subkey = 1 - $back_join_subkey;
-//				$new_join = $joins[$new_join_subkey];
-				$new_join = $ways2joins[$way_key][1 - array_search($join_key,  $ways2joins[$way_key])];
-				findWay($new_join, $point_key, array_merge($path,array($way_key)));
-			}
-		}
-	}
-}
-
-//print_r($ways2joins);
-for ($i = 0; $i < count($points); $i++) {
-//	$res = array();
-	if (isset($res)) unset($res);
-	findWay(2000, $i);
-	print_r($res);
-}
-//print_r($ways);
-
-echo "ways count: ".count($ways_asText)."\n";
-
-/*
-$db = DB::getDB();
-$db->query("truncate table Rozdzielcza_test_bzyk_ways");
-$db->query("truncate table Rozdzielcza_test_bzyk_joins");
-
-
-foreach ($ways_asText as $way) {
-	$query = "insert into Rozdzielcza_test_bzyk_ways (the_geom) values (linefromtext('".$way."'))";
-	$db->query($query);
-	//echo $query."\n";
-}
-
-foreach ($joins_asText as $join) {
-	$query = "insert into Rozdzielcza_test_bzyk_joins (the_geom) values (pointfromtext('".$join."'))";
-	$db->query($query);
-}
-*/

+ 0 - 164
SE/dev/php-cli/biale_plamy_class_findWay.php

@@ -1,164 +0,0 @@
-<?php
-
-require("biale_plamy_class.php");
-
-
-	$test = new bialePlamy(array("pointsTable"=>"Rozdzielcza_test2_bzyk_punkty_adresowe", "origWaysTable"=>"Rozdzielcza_test2_bzyk_drogi"));
-	//$test->enableShowProgress();
-	$test->loadCache();
-	
-	
-function array_to_xml( $data, &$xml_data ) {
-    foreach( $data as $key => $value ) {
-        $key_="";
-        
-        if( is_numeric($key) ){
-            $key_ = 'item';
-        }
-        
-        if( is_array($value) ) {
-            $subnode = $xml_data->addChild($key_);
-			$subnode->addAttribute('id', $key);
-            array_to_xml($value, $subnode);
-        } else {
-	       // $test_expl=explode(" ", $value);
-					//preg_match('/[a-zA-Z]/', $value[0])
-	        //if($key_=="" and !isset($test_expl[1])  )  $key_=htmlspecialchars("$value");
-	        //czy nie jest jeden element array
-	        if($key_=="" and  count($data[$key]==1)) {
-		   		 $subnode=$xml_data->addChild("$key",htmlspecialchars("$value"));
-		    } else  
-            $subnode=$xml_data->addChild("$key_",htmlspecialchars("$value"));
-            if( is_numeric($key) ){
-	            $subnode->addAttribute('id', $key);
-	        }
-        }
-     }
-}
-
-	
-	
-	
-	
-$ways2joins = unserialize(file_get_contents('/tmp/save_ways2joins.txt'));
-$joins2ways = unserialize(file_get_contents('/tmp/save_joins2ways.txt'));
-$points2joins = unserialize(file_get_contents('/tmp/save_points2joins.txt'));
-$joins_asText = unserialize(file_get_contents('/tmp/save_joins_asText.txt'));
-$ways_asText = unserialize(file_get_contents('/tmp/save_ways_asText.txt'));
-$points_asText = unserialize(file_get_contents('/tmp/save_points_asText.txt'));
-
-$edge_joins=simplexml_load_file("edge_joins.xml");
-$edge_joins->registerXPathNamespace('bp', 'https://procesy5.pl/biale_plamy-schema.xsd');
-
-//print_r($edge_joins);
-foreach($edge_joins->children() as $child)  {
- // echo "\n<br>";
-	   //$attrs=$child->attributes("ID_Way");
-
-	   foreach($child->attributes() as $a=>$b) {
-		   //	echo "#87Child";print_r($b[0]);
-		   $ID_Way=$b[0];
-	   }
-	  //echo $child->getName() . ": " . " ID_Way: ".$ID_Way. " : ";
-	
-	   $id_j=0; 
-	   settype($ID_Way, "integer");
-	   //$ID_Way=var_dump($ID_Way);
-	   
-	 //  echo "#88Child:"; print_r($ID_Way);
-	   //$edge_joins_path['ID_Way'][$attrs['ID_Way']]=array();
-	   foreach($child->children('https://procesy5.pl/biale_plamy-schema.xsd') as $edge_joins_xml)  {
-		   $id_j++;
-		   $attrs_join=$edge_joins_xml->attributes();
-		   //echo " #93 ID_Join ".$attrs_join["Joins"]." ";
-		   $Join=$attrs_join["Joins"][0];
-		   settype($Join, "integer");
-		   $edge_joins_path[$ID_Way][$id_j]=$attrs_join["Joins"][0];
-	   }
-}
-
-	
-	
-	
-	
-	/////////
-	
-	 DB::getPDO()->query("truncate table Rozdzielcza_test_bzyk_paths");
-
-unset($ID_Way);
-
-$edge_joins_filled_paths=array();
-foreach($edge_joins_path as $ID_Way=>$Joins_arr) {
-	settype($ID_Way, "integer");
-	$edge_joins_filled_paths[$ID_Way]['tried']=1;
-	if(isset($Joins_arr[1]) and isset($Joins_arr[2]))  {
-			   $pkt_A=$Joins_arr[1];$pkt_B=$Joins_arr[2];
-			   settype($pkt_A, "integer"); settype($pkt_B, "integer");
-
-		echo "\n<br> Generuje dla ID_Way:".$ID_Way." i joins ".$pkt_A." , ".$pkt_B." ";
-		unset($res);unset($path);
-		
-		
-		
-	
-			$res = $test->findWay($pkt_A, $pkt_B);
-			$lineStringObj = $test->joins2lineString($res);
-			if($lineStringObj) {
-						$path = $lineStringObj->asText();
-					
-					
-					
-					//$res = findWay($pkt_A,$pkt_B);
-					//$path = joins2lineString($res)->asText();
-					//   joins2lineString(findWay(389,404));
-					settype($path, "string");
-					$edge_joins_filled_paths[$ID_Way]['asText'] = $path;
-						$distance = 0;
-							foreach ($res as $way_key) {
-								if(isset($ways_asText[$way_key]))
-								$distance += Vendor_Geophp::load($ways_asText[$way_key], 'wkt')->greatCircleLength();
-							}
-					$edge_joins_filled_paths[$ID_Way]['distance'] = $distance;
-					//joins2lineString(findWay($Joins_arr[1],$Joins_arr[2]));
-					//joins2lineString($res = findWay($joinAB['A'],$joinAB['B']))->asText();
-					$sql_insert_path="insert into Rozdzielcza_test_bzyk_paths (the_geom,ID_Way, A_RECORD_CREATE_DATE )
-					     values (ST_GeomFromText('".$edge_joins_filled_paths[$ID_Way]['asText']."'),'".$ID_Way."' , now()   )   ";
-					    echo "#216Query path ins:: ".$sql_insert_path." , distance:".$distance." ";
-					    if(strlen($edge_joins_filled_paths[$ID_Way]['asText'])>2)
-					      DB::getPDO()->query($sql_insert_path);
-					    else echo "#296 path nie wygenerowalo sie !! dla ".$ID_Way." i pkt ".$pkt_A." , ".$pkt_B." \n";
-
-			} else { 
-				echo "ERROR 131 dla pkt: ID_WAY:".$ID_Way;
-				print_r($Joins_arr);
-			}
-
-
-	} else echo "\n#220 droga nie ma koncow ID_Way::".$ID_Way;
-}
-
-
-echo "<br>\n edge_joins_filled_paths:";
-print_r($edge_joins_filled_paths);
-
-
-//save
- 	unset($xml_data);
-
-file_put_contents('edge_joins_filled_paths.txt',serialize($edge_joins_filled_paths));
- 	ob_start();print_r($edge_joins_filled_paths); $contents = ob_get_contents();ob_end_clean();  
- 	file_put_contents('edge_joins_filled_paths_print_r.txt',$contents);
- 	$xml_data = new SimpleXMLElement('<?xml version="1.0"?><edge_joins_filled_paths></edge_joins_filled_paths>');
- 	array_to_xml($edge_joins_filled_paths,$xml_data);
- 	print $xml_data->asXML("edge_joins_filled_paths.xml");
- 	unset($xml_data);
-  
-
-
-	
-	
-	
-	
-	
-	
-	

+ 48 - 4
SE/dev/php-cli/biale_plamy_class_regenerate.php

@@ -2,7 +2,51 @@
 
 require("biale_plamy_class.php");
 
-$test = new bialePlamy(array("pointsTable"=>"Rozdzielcza_test2_bzyk_punkty_adresowe", "origWaysTable"=>"Rozdzielcza_test2_bzyk_drogi"));
+
+
+
+
+echo "\n<br> Params (example) are :
+	pointsTable=Rozdzielcza_test2_bzyk_punkty_adresowe 
+	origWaysTable=Rozdzielcza_test2_bzyk_drogi
+	prefix=test2	
+	
+	";
+
+$pointsTable="Rozdzielcza_test2_bzyk_punkty_adresowe";
+$origWaysTable="Rozdzielcza_test2_bzyk_drogi";
+$prefix="test2";
+
+//przylaczaTable=Rozdzielcza_test2_bzyk_przylacza
+//	joinsTable=Rozdzielcza_test2_bzyk_joins
+//	waysTable=Rozdzielcza_test2_bzyk_ways
+print_r($_SERVER["argv"]);
+
+if($_SERVER["argv"] ) {
+	
+	foreach($_SERVER["argv"]  as $id=>$argv) {
+		echo "\n argv:".$argv." \n";
+		$par_arr= explode('=',$argv); 
+		print_r($par_arr);
+		if($par_arr[1])
+		eval("\$par_arr[0]=\"$par_arr[1]\";");
+		
+	}
+
+echo "
+  ustawiono nowe parametry: 
+
+  pointsTable=".$pointsTable." 
+  origWaysTable=".$origWaysTable." 
+  prefix=".$prefix."   \n <br>"	;	
+} 
+
+
+
+
+
+
+$test = new bialePlamy(array("pointsTable"=>"Rozdzielcza_".$prefix."_bzyk_punkty_adresowe", "origWaysTable"=>"Rozdzielcza_".$prefix."_bzyk_drogi"));
 //$test->enableShowProgress();
 //$test->loadCache();
 
@@ -31,6 +75,6 @@ echo "\n saveArrays complete";
 
 
 //echo $test->printArray('joins2ways');
-$test->saveWaysTable("Rozdzielcza_test2_bzyk_ways");
-$test->saveJoinsTable("Rozdzielcza_test2_bzyk_joins");
-$test->savePrzylaczaTable("Rozdzielcza_test2_bzyk_przylacza");
+$test->saveWaysTable("Rozdzielcza_".$prefix."_bzyk_ways");
+$test->saveJoinsTable("Rozdzielcza_".$prefix."_bzyk_joins");
+$test->savePrzylaczaTable("Rozdzielcza_".$prefix."_bzyk_przylacza");

+ 40 - 2
SE/dev/php-cli/biale_plamy_class_usage.php

@@ -2,7 +2,45 @@
 
 require("biale_plamy_class.php");
 
-$test = new bialePlamy(array("pointsTable"=>"Rozdzielcza_test2_bzyk_punkty_adresowe", "origWaysTable"=>"Rozdzielcza_test2_bzyk_drogi"));
+
+
+echo "\n<br> Params (example) are :
+	pointsTable=Rozdzielcza_test2_bzyk_punkty_adresowe 
+	origWaysTable=Rozdzielcza_test2_bzyk_drogi
+	prefix=test2	
+	
+	";
+
+$pointsTable="Rozdzielcza_test2_bzyk_punkty_adresowe";
+$origWaysTable="Rozdzielcza_test2_bzyk_drogi";
+$prefix="test2";
+
+//przylaczaTable=Rozdzielcza_test2_bzyk_przylacza
+//	joinsTable=Rozdzielcza_test2_bzyk_joins
+//	waysTable=Rozdzielcza_test2_bzyk_ways
+print_r($_SERVER["argv"]);
+
+if($_SERVER["argv"] ) {
+	
+	foreach($_SERVER["argv"]  as $id=>$argv) {
+		echo "\n argv:".$argv." \n";
+		$par_arr= explode('=',$argv); 
+		print_r($par_arr);
+		if($par_arr[1])
+		eval("\$par_arr[0]=\"$par_arr[1]\";");
+		
+	}
+
+echo "
+  ustawiono nowe parametry: 
+
+  pointsTable=".$pointsTable." 
+  origWaysTable=".$origWaysTable." 
+  prefix=".$prefix."   \n <br>"	;	
+} 
+
+$test = new bialePlamy(array("pointsTable"=>"Rozdzielcza_".$prefix."_bzyk_punkty_adresowe",
+						     "origWaysTable"=>"Rozdzielcza_".$prefix."_bzyk_drogi"));
 $test->enableShowProgress();
 $test->loadCache("dupa");
 
@@ -23,4 +61,4 @@ $test->generateLongWays();
 //$test->saveWaysTable("Rozdzielcza_test2_bzyk_ways");
 //$test->saveJoinsTable("Rozdzielcza_test2_bzyk_joins");
 //$test->savePrzylaczaTable("Rozdzielcza_test2_bzyk_przylacza");
-$test->saveLongWaysTable("Rozdzielcza_test2_bzyk_long_ways");
+$test->saveLongWaysTable("Rozdzielcza_".$prefix."_bzyk_long_ways");

+ 128 - 29
SE/dev/php-cli/build.xml

@@ -1,15 +1,22 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <project
     xmlns:bp="https://procesy5.pl/biale_plamy-schema.xsd"
+    xmlns:ogc="http://www.opengis.net/ogc"
     basedir="." name="biale_plamy-generate_data" default="default">
     
     
     <tstamp><format property="TODAY_UK" pattern="yyyy-mm-dd"/></tstamp>
    
-   
+    <property name="plamy_prefix" value="" /><!-- prefiks dla danych -->
+    <property name="pointsTable" value="Rozdzielcza_test2_bzyk_punkty_adresowe" />
+    <property name="origWaysTable" value="Rozdzielcza_test2_bzyk_drogi"/>
+    
+    <property  name="username_p5_admin" value="a.binder"/>
+    <property  name="username_p5_admin_pass" value="set_as_param_-Dusername_p5_admin_pass=pass" />
     
     <property name="bypass_errors" value="1"/><!-- to continue transform even with errors -->
-    <property name="build.log" value="build.log"/><property name="build.log.old" value="${build.log}.old"/>
+         <property name="build.log" value="build${plamy_prefix}.log"/>
+         <property name="build.log.old" value="${build.log}.old"/>
     
     <target name="build_log_exists">
         
@@ -40,47 +47,52 @@
     <property name="logic" value="grouped"/>
     <!--<xsl:param name="logic" select="'sorted'"/>--> <!-- tutaj robi grupy ale analizyje w grupie tylko wazniejsze/bardziej oblozone wezly -->
     
+    <property name="API_address" value="biuro.biall-net.pl"/>
+    <property name="API_wfst_url" value="https://${API_address}/SE/version-git/wfs-data.php/default_db/"/>
+    <property name="cert.pem" value="cert.pem"/> <!-- api certificate -->
+    <property name="cacert_dir" value="${java.home}/lib/security/cacerts"/>
     <property name="mail_inform" value="a.binder@biall-net.pl"/> <!-- to inform about job complete -->
-    
-    
+    <property name="gnutls-cli" value="/opt/local/bin/gnutls-cli"/>
+    <property name="Password_for_cacerts" value="changeit"/><!-- stupid thing to not change-->
     <property name="biale_plamy_class_regenerate.php" value="biale_plamy_class_regenerate.php"/>
+    <!-- parametry dla biale_plamy_class_regenerate.php  -->
     
     <property name="ways_as_Text_z_ID_xml.xsl" value="ways_as_Text_z_ID_xml.xsl"/>
-    <property name="ways_as_Text_z_ID_xml.xml" value="ways_as_Text_z_ID_xml.xml"/>
+    <property name="ways_as_Text_z_ID_xml.xml" value="ways_as_Text_z_ID_xml${plamy_prefix}.xml"/>
     
-    <property name="biale_plamy_class_findWay.php" value="biale_plamy_class_findWay.php"/><!--<property name="biale_plamy-find_ways.php" value="biale_plamy-find_ways.php"/>-->
-        <property name="joins_asText.xml" value="joins_asText.xml"/>
-        <property name="joins2ways.xml" value="joins2ways.xml"/>
-        <property name="points2ID_Way.xml" value="points2ID_Way.xml"/>
-        <property name="ways2drogi.xml" value="ways2drogi.xml"/><!--<property name="ways_2ID_Way.xml" value="ways_2ID_Way.xml"/>-->
+    <!--<property name="biale_plamy_class_findWay.php" value="biale_plamy_class_findWay.php"/>--><!-- - uzywamy wlasnej klasy php do znalezienia drog <property name="biale_plamy-find_ways.php" value="biale_plamy-find_ways.php"/>-->
+    <property name="joins_asText.xml" value="joins_asText${plamy_prefix}.xml"/>
+    <property name="joins2ways.xml" value="joins2ways${plamy_prefix}.xml"/>
+    <property name="points2ID_Way.xml" value="points2ID_Way${plamy_prefix}.xml"/>
+    <property name="ways2drogi.xml" value="ways2drogi${plamy_prefix}.xml"/><!--<property name="ways_2ID_Way.xml" value="ways_2ID_Way.xml"/>-->
         
-            <property name="points2joins.xml" value="points2joins.xml"/>
-            <property name="ways2joins.xml" value="ways2joins.xml"/>
-             <property name="ways_asText.xml" value="ways_asText.xml"/>
+    <property name="points2joins.xml" value="points2joins${plamy_prefix}.xml"/>
+    <property name="ways2joins.xml" value="ways2joins${plamy_prefix}.xml"/>
+    <property name="ways_asText.xml" value="ways_asText${plamy_prefix}.xml"/>
     
-        <property name="waysLengths.xmll" value="waysLengths.xml"/>
+    <property name="waysLengths.xml" value="waysLengths${plamy_prefix}.xml"/>
             <property name="joins2ways_z_ID_Way.xsl" value="joins2ways_z_ID_Way.xsl"/>
-             <property name="joins2ways_z_ID_Way.xml" value="joins2ways_z_ID_Way.xml"/>
-                <property name="joins2ways_z_ID_Way_tempdir" value="joins2ways_z_ID_Way"/><!-- do trzymania tempow - nie wiadomo czy potrzebne bo duzo plikow -->
+    <property name="joins2ways_z_ID_Way.xml" value="joins2ways_z_ID_Way${plamy_prefix}.xml"/>
+    <property name="joins2ways_z_ID_Way_tempdir" value="joins2ways_z_ID_Way${plamy_prefix}"/><!-- do trzymania tempow - nie wiadomo czy potrzebne bo duzo plikow -->
             <property name="biale_plamy_joins2ways_do_paths.xsl" value="biale_plamy_joins2ways_do_paths.xsl"/>
         
             <property name="edge_joins_filled_paths_make.xsl" value="edge_joins_filled_paths_make.xsl"/>
             <property name="biale_put_xml_paths_to_mysql.php" value="biale_put_xml_paths_to_mysql.php"/>
     
-        <property name="points_asText.xml" value="points_asText.xml"/>
+    <property name="points_asText.xml" value="points_asText${plamy_prefix}.xml"/>
         
-        <property name="edge_joins.xml" value="edge_joins.xml"/>
+    <property name="edge_joins.xml" value="edge_joins${plamy_prefix}.xml"/>
         
             <property name="joins_asText_xml.xsl" value="joins_asText_xml.xsl"/>
-            <property name="joins_asText_xml.xml" value="joins_asText_xml.xml"/> 
+    <property name="joins_asText_xml.xml" value="joins_asText_xml${plamy_prefix}.xml"/> 
             <!-- sciezki -->
-            <property name="edge_joins_filled_paths.xml" value="edge_joins_filled_paths.xml"/>
-             <property name="edge_joins_filled_paths" value="edge_joins_filled_paths"/> <!-- katalog do zapisywania sciezek -->
+    <property name="edge_joins_filled_paths.xml" value="edge_joins_filled_paths${plamy_prefix}.xml"/>
+    <property name="edge_joins_filled_paths" value="edge_joins_filled_paths${plamy_prefix}"/> <!-- katalog do zapisywania sciezek -->
               
               
               
           
-            <property name="build_edge_paths_with_PE_controll_loop.xml" value="build_edge_paths_with_PE_controll_loop.xml"/>
+    <property name="build_edge_paths_with_PE_controll_loop.xml" value="build_edge_paths_with_PE_controll_loop${plamy_prefix}.xml"/>
              <property name="build_edge_paths_with_PE_controll_loop.xsl" value="build_edge_paths_with_PE_controll_loop.xsl"/>
                 <property name="edge_paths_with_PE_controll_to_PE_collection.xsl" value="edge_paths_with_PE_controll_to_PE_collection.xsl"/>
     
@@ -88,22 +100,22 @@
                 <property name="edge_paths_with_PE_controll_to_PE.xsl" value="edge_paths_with_PE_controll_to_PE.xsl"/>
     
                 <property name="edge_paths_with_PE_controll.xsl" value="edge_paths_with_PE_controll.xsl"/><!-- nowy point matrix-->   
-                <property name="edge_paths_with_PE_controll_temp" value="edge_paths_with_PE_controll_temp"/>
-                <property name="edge_paths_with_PE_controll_paths_temp" value="edge_paths_with_PE_controll_paths_temp"/><!-- do oszukania silnika aby korzystac z petli i przekazywac dane do siebie -->
-                <property name="edge_paths_with_PE_controll_temp.alias" value="edge_paths_with_PE_controll_temp.alias"/>
+    <property name="edge_paths_with_PE_controll_temp" value="edge_paths_with_PE_controll_temp${plamy_prefix}"/>
+    <property name="edge_paths_with_PE_controll_paths_temp" value="edge_paths_with_PE_controll_paths_temp${plamy_prefix}"/><!-- do oszukania silnika aby korzystac z petli i przekazywac dane do siebie -->
+    <property name="edge_paths_with_PE_controll_temp.alias" value="edge_paths_with_PE_controll_temp.alias${plamy_prefix}"/>
     
-            <property name="edge_paths_with_PE_controll.xml" value="edge_paths_with_PE_controll.xml"/>  
+    <property name="edge_paths_with_PE_controll.xml" value="edge_paths_with_PE_controll${plamy_prefix}.xml"/>  
             
-            <property name="edge_paths_with_PE.xml" value="edge_paths_with_PE.xml"/><!--     biale_plamy_from_paths_php_to_place_PE-->
+    <property name="edge_paths_with_PE.xml" value="edge_paths_with_PE${plamy_prefix}.xml"/><!--     biale_plamy_from_paths_php_to_place_PE-->
          
             <property name="biale_put_PE_to_mysql.php" value="biale_put_PE_to_mysql.php"/>
             
             <property name="cables_from_joins_to_PE.xsl" value="cables_from_joins_to_PE.xsl"/>
-            <property name="cables_from_joins_to_PE.xml" value="cables_from_joins_to_PE.xml"/><!-- xml do wygenerowania  -->
+    <property name="cables_from_joins_to_PE.xml" value="cables_from_joins_to_PE${plamy_prefix}.xml"/><!-- xml do wygenerowania  -->
         
             <property name="biale_put_Cables_to_PE.php" value="biale_put_Cables_to_PE.php"/>
     
-    
+    <property name="PE_fixings.xml" value="PE_fixings${plamy_prefix}.xml"/>
     
     <!--<include file="${build_edge_paths_with_PE_controll_loop.xml}" optional=""/>-->
     
@@ -263,6 +275,9 @@
    
    
    
+   
+   
+   
     <target name="biale_plamy_class_regenerate.php">
         <!--<antcall target="install_in_file_db_query">
             <param name="sql_query" value="select 1+1;"/>
@@ -270,6 +285,7 @@
         <record name="${build.log}" loglevel="verbose" append="true"/>
         <exec executable="php" failonerror="true" dir=".">
             <arg file="${biale_plamy_class_regenerate.php}"/>
+            <arg line="plamy_prefix=${plamy_prefix}"/>
         </exec>
         <echo message="Teraz Przelec arraya joins2ways pod katem 1-elementowych subarrayow"/>
     </target> 
@@ -542,6 +558,87 @@
             <arg file="${biale_put_Cables_to_PE.php}"/>
         </exec>
     </target>
+    
+    
+    <target name="import_ssl_certificates_to_system" description="niezbedne jest sciagniecie certyfikatow bo nie dzialaja przy requestach WFS">
+<!--        openssl s_client -showcerts -connect server.edu:443 </dev/null 2>/dev/null|openssl x509 -outform PEM >mycertfile.pem
+-->     
+        <!--openssl s_client -connect "biuro.biall-net.pl:443" -showcerts-->
+        
+        <!--
+        1) Get the site's certificate
+        
+        With IE, bring up the page with the URL,
+        Go to File->Properties.
+        Click on Certificates button on lower right.
+        Click on the details tab.
+        Click on copy to file.
+        Hit next through the dialog until you save it to a file (e.g
+        mycert.ce).
+        
+        2) Add it to the java certificate keystore
+        $ keytool -keystore <jdk home>/jre/lib/security/cacerts -import
+            -alias mycert -file ./mycert.ce-->
+        <echo >  bedzie wgrany certyfikat do ${java.home}/ ant home: ${ant.home}  dokl do ${cacert_dir}  </echo>
+        
+        <!-- keytool -import -file selfsigned.pem -alias server -keystore server.jks -->
+        <!-- sudo rm -f cert.pem && sudo echo -n | openssl s_client -connect localhost:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ./cert.pem -->
+        <delete file="${cert.pem}"/>
+        <exec output="${cert.pem}.txt"  executable="${gnutls-cli}" >
+            <arg line=" --print-cert ${API_address}:443 &lt; /dev/null "/>
+        </exec>
+        <exec  input="${cert.pem}.txt" output="${API_address}.cert" executable="openssl">
+            <arg line="x509"/>
+        </exec>
+        <exec executable="keytool">
+            <arg line="-import -v -trustcacerts -alias ${API_address} -file ${API_address}.cert -keystore client.store -storepass ${Password_for_cacerts}"/>
+        </exec>
+        <exec executable="keytool">
+            <arg line="-import -v -trustcacerts  -file Letss_Encrypt_Authority_X3.cer -keystore client.store -storepass ${Password_for_cacerts}"/>
+        </exec>
+        <exec executable="keytool">
+            <arg line="-import -v -trustcacerts -file DST_Root_CA_X3.cer -keystore client.store -storepass ${Password_for_cacerts}"/>
+        </exec>
+        
+    </target>
+    
+    <target name="get_PE_fixings_from_db" description="sciagniecie zmian PE glownie usunietych aby wyliczyc ponownie kable do innych wezlow">
+        <!--wget -\-http-user=$usr -\-password=$passwd  
+            https://biuro.biall-net.pl/SE/version-git/api.php/xml/table/default_db/_S_ADDRESS_STREETS_distincts/items -\-no-check-certificate -O _S_ADDRESS_STREETS_distincts.xml ;-->
+        <property name="WFS_VERSION" value="&amp;VERSION=1.0.0"/>
+        <property name="TYPENAME" value="&amp;TYPENAME=p5_default_db:Rozdzielcza_test_bzyk_PE"/>
+        <property name="username_p5_admin_pass" value="Vis11on69B"/>
+
+        <!--<property name="OGC_Filter"> 
+            &amp;Filter=
+            &lt;ogc:Filter&gt;
+            &lt;ogc:Or&gt;
+            &lt;ogc:Not&gt;
+            &lt;ogc:PropertyIsNull&gt;
+            &lt;ogc:PropertyName&gt;the_geom&lt;/ogc:PropertyName&gt;
+            &lt;/ogc:PropertyIsNull&gt;
+            &lt;/ogc:Not&gt;
+            &lt;ogc:PropertyIsEqualTo&gt;
+            &lt;ogc:PropertyName&gt;ID&lt;/ogc:PropertyName&gt;
+            &lt;ogc:Literal&gt;2&lt;/ogc:Literal&gt;
+            &lt;/ogc:PropertyIsEqualTo&gt;
+            &lt;/ogc:Or&gt;
+            &lt;/ogc:Filter&gt;</property>-->
+        <property name="OGC_Filter" value=""/>
+            
+        <property name="URL_get_PE_fixings_from_db" value="${API_wfst_url}?SERVICE=WFS${WFS_VERSION}&amp;${TYPENAME}&amp;REQUEST=GetFeature&amp;SRSNAME=EPSG:3003${OGC_Filter}"/>
+        <!--<echo output="OGC_Filter">
+           
+        </echo>-->
+        
+        <echo message="we get data from URL: ${URL_get_PE_fixings_from_db}"></echo>
+        
+        <get dest="${PE_fixings.xml}"  username="${username_p5_admin}" password="${username_p5_admin_pass}">
+            <url  url="${URL_get_PE_fixings_from_db}"/>
+
+        </get>
+        
+    </target>
    
     <!--<target name="1_install_mysql_functions">
         <property name="php_script_header"><?php
@@ -625,6 +722,8 @@
     
     <!--<property name="biale_plamy-prepare_sql_data.php" value="biale_plamy-prepare_sql_data.php"/>-->
     
+    
+    
     <target name="mail_inform">
         
         <echo message="informujemy o kompletnej pracy"/>