Просмотр исходного кода

Merge branch 'master' of bn.git:plabudda/se

Piotr Labudda 9 лет назад
Родитель
Сommit
9d596c6fe4

+ 30 - 0
SE/dev/php-cli/asText.xsl

@@ -34,4 +34,34 @@
             </bp:Path_Point>
         </xsl:for-each>
     </xsl:template>
+    
+    
+    <xsl:template match="asText" mode="POINT">
+        <xsl:variable name="LINESTRING" select=" substring-before( substring-after(normalize-space(.),'POINT (') , ')')  "/>
+        <!--<test1><xsl:copy-of select="$LINESTRING"/></test1>-->
+        <xsl:for-each select="tokenize($LINESTRING,',')">
+            <bp:Path_Point>
+                <!--<xsl:attribute name="test2" select="."/>-->
+                <xsl:variable name="pos">
+                    <xsl:for-each select="tokenize(.,' ')">
+                        <pos>
+                            <xsl:attribute name="pos" select="position()"/>
+                            <xsl:value-of select="."/>
+                        </pos>
+                    </xsl:for-each>
+                </xsl:variable>
+                <xsl:choose>
+                    <xsl:when test="string-length($pos/pos[@pos=1]/text())&gt;0">
+                        <xsl:attribute name="X" select="$pos/pos[@pos=1]"/>
+                        <xsl:attribute name="Y" select="$pos/pos[@pos=2]"/>
+                    </xsl:when>
+                    <xsl:otherwise>
+                        <xsl:attribute name="X" select="$pos/pos[@pos=2]"/>
+                        <xsl:attribute name="Y" select="$pos/pos[@pos=3]"/>
+                    </xsl:otherwise>
+                </xsl:choose>
+                <!--<test3><xsl:copy-of select="$pos"/></test3>-->
+            </bp:Path_Point>
+        </xsl:for-each>
+    </xsl:template>
 </xsl:stylesheet>

+ 8 - 8
SE/dev/php-cli/biale_plamy-find_ways.php

@@ -68,12 +68,12 @@ function check() {
 
 init_sh_check();   
 
-$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'));
+$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');
@@ -238,8 +238,8 @@ foreach($edge_joins_path as $ID_Way=>$Joins_arr) {
 		$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)
-		     values (ST_GeomFromText('".$edge_joins_filled_paths[$ID_Way]['asText']."'),'".$ID_Way."'   )   ";
+		$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);

+ 12 - 7
SE/dev/php-cli/biale_plamy-generate_data.php

@@ -126,6 +126,7 @@ foreach ($ways2cut as $way_key => $xpoint_keys) {
 	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
@@ -140,24 +141,28 @@ foreach ($ways2cut as $way_key => $xpoint_keys) {
 
 	$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();
-	$way = new LineString(array($startPoint, $sub_xpoints[0]));
-	$ways_asText[$way_key] = $way->asText();
-	$ways_2ID_Way[$way_key]=$ID_Way;
-
+	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;
 	}
-	$way = new LineString(array($sub_xpoints[$n], $endPoint));
-	$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) {

+ 562 - 0
SE/dev/php-cli/biale_plamy_class.php

@@ -0,0 +1,562 @@
+<?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");
+
+class showProgress {
+
+	private $startTime;
+	private $i = 0, $l = 0, $left = 0, $diff = 0, $n, $msg;
+	private $strlen = 40;
+
+	public function __construct($msg, $n = null) {
+		$this->msg = str_pad($msg, $this->strlen);
+		echo "{$this->msg}:   0%";
+		$this->n = $n;
+		list($usec, $sec) = explode(" ", microtime());
+		$this->startTime = $sec + $usec;
+	}
+
+	public function step($int = 1) {
+		if ($this->n) {
+			$this->i += $int;
+			$p = floor(100 * $this->i / $this->n);
+			list($usec, $sec) = explode(" ", microtime());
+			$curTime = $sec + $usec;
+			$diff = $curTime - $this->startTime;
+			$left = floor((($this->n / $this->i) - 1) * $diff);
+			$diff = floor($diff);
+			if ($p > $this->l || $left != $this->left || $diff != $this->diff) {
+				$this->l = $p;
+				$this->diff = $diff;
+				$this->left = $left;
+				if ($left > 59) $left = floor($left / 60) . "m " . ($left % 60);
+				if ($diff > 59) $diff = floor($diff / 60) . "m " . ($diff % 60);
+				echo "\r".str_pad("", $this->strlen+60);
+				echo "\r{$this->msg}: {$p}% (elapsed {$diff}s, estimated remaining {$left}s)";
+			}
+		}	
+	}
+
+	public function stop() {
+		list($usec, $sec) = explode(" ", microtime());
+		$curTime = $sec + $usec;
+		$diff = $curTime - $this->startTime;
+		$diff = floor($diff);
+		if ($diff > 59) $diff = floor($diff / 60) . "m " . ($diff % 60);
+		echo "\r".str_pad("", $this->strlen+60);
+		echo "\r{$this->msg}: OK (done in {$diff}s)\n";
+	}
+}
+
+
+class bialePlamy {
+
+	private $showProgress = false;
+
+	private $getSourceData = false, $createTemporaryWaysTable = false, $createTemporaryJoinsTable = false, $createTemporaryPrzylaczaTable = false, $readyForFindWay = false;
+
+	private $punktyAdresoweTable = null, $drogiTable = null;
+	private $joins_asText = array(), $ways_asText = array(), $xpoints_asText = array(), $points_asText = array(), $przylacza_asText = array();
+	private $ways2drogi = array(), $ways2joins = array(), $joins2ways = array(), $points2xpoints = array(), $xpoints2points = array(), $przylacza2joins = array(), $przylacza2points = array(), $points2joins = array();
+
+	public function __construct($sourceTables) {
+		$tables = array('pointsTable' => 'punktyAdresoweTable', 'origWaysTable' => 'drogiTable');
+		try {
+			if (!is_array($sourceTables)) throw new Exception("bialePlamy :: Wrong parameters");
+			foreach ($tables as $arg => $table) {
+				if (!isset($sourceTables[$arg])) throw new Exception("bialePlamy :: Missing parameter {$arg}");
+				$this->$table = $sourceTables[$arg];
+			}
+		} catch (Exception $e) {
+			throw $e;
+		}
+	}
+
+	public function enableShowProgress() {
+		$this->showProgress = true;
+	}
+
+	public function disableShowProgress() {
+		$this->showProgress = false;
+	}
+
+	private $dataArrays = array('joins_asText', 'ways_asText', 'xpoints_asText', 'points_asText', 'przylacza_asText',
+		'ways2drogi', 'ways2joins', 'joins2ways', 'points2xpoints', 'xpoints2points', 'przylacza2joins', 'przylacza2points', 'points2joins');
+
+	public function saveCache() {
+		foreach ($this->dataArrays as $array) if ($this->$array) {
+			if ($this->showProgress) $progress = new showProgress("Saving {$array}");
+			file_put_contents('/tmp/save_'.$array.'.txt', serialize($this->$array));
+			if ($this->showProgress) $progress->stop();
+		}
+	}
+
+	public function saveXML() {
+		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);
+				}
+			}
+		}
+
+		foreach ($this->dataArrays as $array) if ($this->$array) {
+			if ($this->showProgress) $progress = new showProgress("Generating XML for {$array}");
+			$xml = new SimpleXMLElement("<?xml version=\"1.0\"?><{$array}></{$array}>");
+			array_to_xml($this->$array, $xml);
+			$xml->asXML("{$array}.xml");
+			if ($this->showProgress) $progress->stop();
+		}
+	}
+
+	public function printArray($array) {
+		if (isset($this->$array) && is_array($this->$array)) {
+			return print_r($this->$array, true);
+		} else return null;
+	}
+
+	public function saveArrays() {
+		foreach ($this->dataArrays as $array) if ($this->$array) {
+			if ($this->showProgress) $progress = new showProgress("Saving array {$array} to file");
+			file_put_contents("/tmp/array_{$array}.txt", $this->printArray($array));
+			if ($this->showProgress) $progress->stop();
+		}
+	}
+
+	public function loadCache() {
+		try {
+			foreach ($this->dataArrays as $array) if (file_exists('/tmp/save_'.$array.'.txt')) {
+				if ($this->showProgress) $progress = new showProgress("Loading {$array}");
+				$this->$array = unserialize(file_get_contents('/tmp/save_'.$array.'.txt'));
+				if ($this->showProgress) $progress->stop();
+			}
+		} catch (Exception $e) {
+			throw $e;
+		}
+	}
+
+	private function saveDB($src, $dst) {
+		try {
+			if ($this->showProgress) $progress = new showProgress("Saving points table");
+			DB::getPDO()->query("truncate table `{$dst}`");
+			$result = DB::getPDO()->fetchall("show fields from `{$src}`");
+			foreach ($result as $col) $cols[] = "`{$col['Field']}`";
+			$query = "insert into `{$dst}` (".implode(", ", $cols).") select * from `{$src}`";
+			DB::getPDO()->query($query);
+			if ($this->showProgress) $progress->stop();
+		} catch (Exception $e) {
+			throw $e;
+		}
+	}
+
+	public function savePointsTable($dst) {
+		if (!$this->getSourceData) $this->getSourceData();
+		if ($this->xpoints2points) $this->updateTemporaryPointsTable();
+		$this->saveDB("_temp_punkty_adresowe", $dst);
+	}
+
+	public function saveWaysTable($dst) {
+		if (!$this->createTemporaryWaysTable) $this->createTemporaryWaysTable();
+		$this->saveDB("_temp_ways", $dst);
+	}
+
+	public function saveJoinsTable($dst) {
+		if (!$this->createTemporaryJoinsTable) $this->createTemporaryJoinsTable();
+		$this->saveDB("_temp_joins", $dst);
+	}
+
+	public function savePrzylaczaTable($dst) {
+		if (!$this->createTemporaryPrzylaczaTable) $this->createTemporaryPrzylaczaTable();
+		$this->saveDB("_temp_przylacza", $dst);
+	}
+
+	private function arrayFrom1() {
+		$array = array('');
+		unset($array[0]);
+		return $array;
+	}
+
+	private function pointsDistance($a, $b) {
+		$line = new LineString(array($a, $b));
+		return $line->length();		
+	}
+
+	private function getSourceData() {
+		try {
+			if ($this->showProgress) $progress = new showProgress("Loading source data from database");
+			DB::getPDO()->query("create temporary table `_temp_punkty_adresowe` select * from `{$this->punktyAdresoweTable}`");
+			DB::getPDO()->query("create temporary table `_temp_drogi` select * from `{$this->drogiTable}` where numpoints(the_geom)>1");
+			DB::getPDO()->query("create index `ID` on `_temp_punkty_adresowe` (`ID`)");
+			DB::getPDO()->query("create index `ID` on `_temp_drogi` (`ID`)");
+			$this->getSourceData = true;
+			if ($this->showProgress) $progress->stop();
+		} catch (Exception $e) {
+			throw $e;
+		}
+	}
+
+	private function generatePoints() {
+		try {
+			if (!$this->getSourceData) $this->getSourceData();
+			if ($this->showProgress) $progress = new showProgress("Generating points");
+			$result = DB::getPDO()->query("select `ID`, astext(`the_geom`) as `point_asText` from `_temp_punkty_adresowe`");
+			foreach ($result as $row) $points_asText[$row['ID']] = $row['point_asText'];
+			$this->points_asText = $points_asText;
+			$this->readyForFindWay = false;
+			if ($this->showProgress) $progress->stop();
+		} catch (Exception $e) {
+			throw $e;
+		}
+	}
+	private function createTemporaryWaysTable() {
+		try {
+			if ((!$this->ways_asText) || (!$this->ways2drogi)) throw new Exception("createTemporaryWaysTable() :: Ways not generated, use generateWays() first");
+
+			DB::getPDO()->query("drop temporary table if exists `_temp_ways`");
+			DB::getPDO()->query("create temporary table `_temp_ways` (`ID` int(11), `droga_id` int(11), `the_geom` linestring not null, index(`ID`), index(`droga_id`), spatial index(`the_geom`)) ENGINE=MyISAM");
+			if ($this->showProgress) $progress = new showProgress("Creating temporary ways table", count($this->ways_asText));
+			foreach ($this->ways_asText as $way_key => $way_asText) {
+				DB::getPDO()->query("insert into `_temp_ways` values ('{$way_key}', '{$this->ways2drogi[$way_key]}', LineFromText('{$way_asText}'))");
+				if ($this->showProgress) $progress->step();
+			}
+			if ($this->showProgress) $progress->stop();
+
+			$this->createTemporaryWaysTable = true;
+		} catch (Exception $e) {
+			throw $e;
+		}
+	}
+
+	public function generateWays() {
+		try {
+			if (!$this->getSourceData) $this->getSourceData();
+
+			$ways_asText = $this->arrayFrom1();
+			$ways2drogi = $this->arrayFrom1();
+
+			$result = DB::getPDO()->fetchall("select ID as droga_id, astext(the_geom) as multiway from `_temp_drogi`");
+			if ($this->showProgress) $progress = new showProgress("Generating ways", count($result));
+			foreach ($result as $row) {
+				$multiway = Vendor_Geophp::load($row['multiway'], 'wkt');
+				for ($i = 1; $i < $n = $multiway->numPoints(); $i++) {
+					$way = new LineString(array($multiway->pointN($i), $multiway->pointN($i+1)));
+					$ways_asText[] = $way->asText();
+					$ways2drogi[] = $row['droga_id'];
+				}
+				if ($this->showProgress) $progress->step();
+			}
+			if ($this->showProgress) $progress->stop();
+
+			$this->ways_asText = $ways_asText;
+			$this->ways2drogi = $ways2drogi;
+
+			$this->joins_asText = array();
+			$this->ways2joins = array();
+			$this->joins2ways = array();
+			$this->xpoints_asText = array();
+			$this->points2xpoints = array();
+			$this->xpoints2points = array();
+			$this->readyForFindWay = false;
+		} catch (Exception $e) {
+			throw $e;
+		}
+		
+	}
+
+	private function createTemporaryJoinsTable() {
+		try {
+			if (!$this->joins_asText) throw new Exception("createTemporaryJoinsTable() :: Joins not generated, use generateJoins() first");
+
+			DB::getPDO()->query("drop temporary table if exists `_temp_joins`");
+			DB::getPDO()->query("create temporary table `_temp_joins` (`ID` int(11), `the_geom` point not null, index(`ID`), spatial index(`the_geom`)) ENGINE=MyISAM");
+			if ($this->showProgress) $progress = new showProgress("Generating temporary joins table", count($this->joins_asText));
+			foreach ($this->joins_asText as $join_key => $join_asText) {
+				DB::getPDO()->query("insert into `_temp_joins` values ('{$join_key}', PointFromText('{$join_asText}'))");
+				if ($this->showProgress) $progress->step();
+			}
+			if ($this->showProgress) $progress->stop();
+			$this->createTemporaryJoinsTable = true;
+		} catch (Exception $e) {
+			throw $e;
+		}
+	}
+
+	public function generateJoins() {
+		try {
+			if (!$this->ways_asText) throw new Exception("generateJoins() :: Ways not generated, use generateWays() first");
+
+			$joins_asText = $this->arrayFrom1();
+			$ways2joins = array();
+			$joins2ways = array();
+
+			if ($this->showProgress) $progress = new showProgress("Generating joins", count($this->ways_asText));
+			foreach ($this->ways_asText as $way_key => $way_asText) {
+				$way = Vendor_Geophp::load($way_asText, 'wkt');
+				$points_asText = array($way->startPoint()->asText(), $way->endPoint()->asText());
+				foreach ($points_asText as $point_asText) {
+					if (!($join_key=array_search($point_asText, $joins_asText))) $join_key = array_push($joins_asText, $point_asText);
+					$ways2joins[$way_key][] = $join_key;
+					$joins2ways[$join_key][] = $way_key;						
+				}
+				if ($this->showProgress) $progress->step();
+			}
+			if ($this->showProgress) $progress->stop();
+
+			$this->joins_asText = $joins_asText;
+			$this->ways2joins = $ways2joins;
+			$this->joins2ways = $joins2ways;
+			$this->readyForFindWay = false;
+		} catch (Exception $e) {
+			throw $e;
+		}
+	}
+
+	private function updateTemporaryPointsTable() {
+		try {
+			if ((!$this->points2xpoints) || (!$this->xpoints_asText)) throw new Exception("updateTemporaryPointsTable() :: Xpoints not generated, use generateXpoints() first");
+			if (!$this->getSourceData) $this->getSourceData();
+
+			if ($this->showProgress) $progress = new showProgress("Updating temporary points table", count($this->points2xpoints));
+			foreach ($this->points2xpoints as $point_key => $xpoint_key) {
+				DB::getPDO()->query("update `_temp_punkty_adresowe` set `the_geom_xpoint` = pointfromtext('{$this->xpoints_asText[$xpoint_key]}')  where `ID` = '{$point_key}'");
+				if ($this->showProgress) $progress->step();
+			}
+			if ($this->showProgress) $progress->stop();
+		} catch (Exception $e) {
+			throw $e;
+		}
+	}
+
+	public function generateXpoints() {
+		try {
+			if (!$this->ways_asText) throw new Exception("generateXpoints() :: Ways not generated, use generateWays() first");
+			if (!$this->getSourceData) $this->getSourceData();
+			if (!$this->createTemporaryWaysTable) $this->createTemporaryWaysTable();
+
+			$xpoints_asText = $this->arrayFrom1();
+			$result = DB::getPDO()->fetchall("select `ID`, astext(`the_geom`) as `point_asText` from `_temp_punkty_adresowe`");
+			if ($this->showProgress) $progress = new showProgress("Generating xpoints", count($result));
+			foreach ($result as $row) {
+				if (!($way_key = DB::getPDO()->fetchValue("select `ID` from (select w.`ID`, st_distance(p.`the_geom`, w.`the_geom`) as `distance` from `_temp_punkty_adresowe` p join `_temp_ways` w on p.`ID` = '{$row['ID']}' order by `distance` limit 1) as ways"))) throw new Exception("generateXpoints() :: błąd spójnosci danych - nie znaleziono najbliższej drogi");
+				$way = Vendor_Geophp::load($this->ways_asText[$way_key], 'wkt');
+
+				$a = $way->startPoint();
+				$b = $way->endPoint();
+				$p = Vendor_Geophp::load($row['point_asText'], 'wkt');
+
+				if ($a->y() == $b->y()) {
+					$xp = $p->x();
+					$yp = $a->y();
+					$deltaA = $p->x() - $a->x();
+					$deltaB = $p->x() - $b->x();
+				} else {
+					if ($a->x() == $b->x()) {
+						$xp = $a->x();
+						$yp = $p->y();
+						$a2 = 0;
+						$b2 = $p->y();
+					} else {
+						$a1 = ($a->y() - $b->y()) / ($a->x() - $b->x());
+						$b1 = $a->y() - $a1 * $a->x();
+
+						$a2 = -1 / $a1;
+						$b2 = $p->y() - $a2 * $p->x();
+
+						$xp = ($b2 - $b1) / ($a1 - $a2);
+						$yp = $a1 * $xp + $b1;
+					}
+					$deltaA = $a2 * $a->x() + $b2 - $a->y();
+					$deltaB = $a2 * $b->x() + $b2 - $b->y();
+				}
+
+				if ($deltaA * $deltaB >= 0) { // punkt poza linia, ustalamy na blizszy koniec linii
+					if (abs($deltaA) < abs($deltaB) ) $xpoint = $a;
+					else $xpoint = $b;
+				} else { // punkt w linii - trzeba podzielic linie na dwie
+					$xpoint = new Point($xp, $yp);
+					$wayA = new LineString(array($a, $xpoint));
+					$wayB = new LineString(array($xpoint, $b));
+					$this->ways_asText[$way_key] = $wayA->asText();
+					$new_way_key = array_push($this->ways_asText, $wayB->asText());
+					$this->ways2drogi[$new_way_key] = $this->ways2drogi[$way_key];
+					DB::getPDO()->query("update `_temp_ways` set `the_geom` = linefromtext('{$wayA->asText()}') where `ID` = '{$way_key}'");
+					DB::getPDO()->query("insert into `_temp_ways` values ('{$new_way_key}', '{$this->ways2drogi[$way_key]}', linefromtext('{$wayB->asText()}'))");
+				}
+				if (!($xpoint_key = array_search($xpoint->asText(), $xpoints_asText))) $xpoint_key = array_push($xpoints_asText, $xpoint->asText());
+				$points2xpoints[$row['ID']] = $xpoint_key;
+				$xpoints2points[$xpoint_key][] = $row['ID'];
+				if ($this->showProgress) $progress->step();
+			}
+			if ($this->showProgress) $progress->stop();
+
+			$this->xpoints_asText = $xpoints_asText;
+			$this->points2xpoints = $points2xpoints;
+			$this->xpoints2points = $xpoints2points;
+			$this->generateJoins();
+			$this->updateTemporaryPointsTable();
+			$this->readyForFindWay = false;
+		} catch (Exception $e) {
+			throw $e;
+		}
+	}
+
+	private function createTemporaryPrzylaczaTable() {
+		try {
+			if ((!$this->przylacza_asText) || (!$this->przylacza2joins) || (!$this->przylacza2points)) throw new Exception("createTemporaryPrzylaczaTable() :: Przylacza not generated, use generatePrzylacza() first");
+
+			if ($this->showProgress) $progress = new showProgress("Generating temporary table przylacza", count($this->przylacza_asText));
+			DB::getPDO()->query("drop temporary table if exists `_temp_przylacza`");
+			DB::getPDO()->query("create temporary table `_temp_przylacza` (`ID` int(11), `points_id` int(11), `joins_id` int(11), `the_geom` linestring not null, index(`ID`)) ENGINE=MyISAM");
+			foreach ($this->przylacza_asText as $przylacze_key => $przylacze_asText) {
+				$query = "insert into `_temp_przylacza` values ('{$przylacze_key}', '{$this->przylacza2points[$przylacze_key]}', '{$this->przylacza2joins[$przylacze_key]}', linefromtext('{$przylacze_asText}'))";
+				DB::getPDO()->query($query);
+				if ($this->showProgress) $progress->step();
+			}
+			if ($this->showProgress) $progress->stop();
+
+			$this->createTemporaryPrzylaczaTable = true;
+		} catch (Exception $e) {
+			throw $e;
+		}
+	}
+
+	public function generatePrzylacza() {
+		try {
+			if ((!$this->points2xpoints) || (!$this->xpoints_asText)) throw new Exception("generatePrzylaczaTable() :: Xpoints not generated, use generateXpoints() first");
+			if (!$this->joins_asText) throw new Exception("generatePrzylaczaTable() :: Joins not generated, use generateJoins() first");
+			if (!$this->points_asText) $this->generatePoints();
+
+			$przylacza_asText = $this->arrayFrom1();
+			$przylacza2joins = $this->arrayFrom1();
+			$przylacza2points = $this->arrayFrom1();
+
+			if ($this->showProgress) $progress = new showProgress("Generating przylacza", count($this->points_asText));
+			foreach ($this->points_asText as $point_key => $point_asText) {
+				$xpoint_key = $this->points2xpoints[$point_key];
+				$join_key = array_search($this->xpoints_asText[$xpoint_key], $this->joins_asText);
+				$point = Vendor_Geophp::load($this->points_asText[$point_key], 'wkt');
+				$xpoint = Vendor_Geophp::load($this->xpoints_asText[$xpoint_key], 'wkt');
+				$przylacze = new Linestring(array($point, $xpoint));
+				$przylacza_asText[] = $przylacze->asText();
+				$przylacza2joins[] = $join_key;
+				$przylacza2points[] = $point_key;
+				$points2joins[$point_key] = $join_key;
+				if ($this->showProgress) $progress->step();
+			}
+			if ($this->showProgress) $progress->stop();
+
+			$this->przylacza_asText = $przylacza_asText;
+			$this->przylacza2joins = $przylacza2joins;
+			$this->przylacza2points = $przylacza2points;
+			$this->points2joins = $points2joins;
+			$this->readyForFindWay = false;
+		} catch (Exception $e) {
+			throw $e;
+		}
+	}
+
+	private function checkDataForFindWay() {
+		try {
+			if (!$this->readyForFindWay) {
+				if (!$this->ways_asText) {
+					$this->generateWays();
+					$this->generateXpoints();
+				}
+				if ((!$this->ways2joins) || (!$this->joins2ways)) $this->generateJoins();
+				if (!$this->points_asText) $this->generatePoints();
+				if (!$this->points2joins) $this->generatePrzylacza();
+				$this->readyForFindWay = true;
+			}
+		} catch (Exception $e) {
+			throw $e;
+		}
+	}
+
+	public function findWay($joinA, $joinB, $path = array()) {
+		try {
+			$this->checkDataForFindWay();
+			if ($joinA == $joinB) {
+				$joinsPath = array($joinB);
+				foreach (array_reverse($path) as $way_key) {
+					array_unshift($joinsPath, $this->ways2joins[$way_key][1 - array_search($joinsPath[0], $this->ways2joins[$way_key])]);
+				}
+				return $joinsPath;
+			} else {
+				$subPaths = array();
+				foreach ($this->joins2ways[$joinA] as $way_key) {
+					if (!in_array($way_key, $path)) {
+						$new_join = $this->ways2joins[$way_key][1 - array_search($joinA,  $this->ways2joins[$way_key])];
+						if ($subPath = $this->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($this->ways_asText[$way_key], 'wkt');
+								if ($way) $distance_cur += Vendor_Geophp::load($this->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;
+				}
+			}
+		} catch (Exception $e) {
+			throw $e;
+		}
+	}
+
+	function joins2lineString($joins_keys) {
+		try {
+			if (!$this->points_asText) $this->generatePoints();
+			if ($joins_keys) {
+				foreach ($joins_keys as $join_key) {
+					$points[] = Vendor_Geophp::load($this->joins_asText[$join_key], 'wkt');
+				}
+				return new LineString($points);
+			} else return null;
+		} catch (Exception $e) {
+			throw $e;
+		}
+	}
+
+}
+
+//$test = new bialePlamy(array("pointsTable"=>"Rozdzielcza_test2_bzyk_punkty_adresowe", "origWaysTable"=>"Rozdzielcza_test2_bzyk_drogi"));
+//$test->enableShowProgress();
+//$test->loadCache();
+//$test->generateWays();
+//$test->generateXpoints();
+//$test->generatePrzylacza();
+//$test->saveCache();
+//$test->saveXML();
+//$test->saveWaysTable("Rozdzielcza_test2_bzyk_ways");
+//$test->saveJoinsTable("Rozdzielcza_test2_bzyk_joins");
+//$test->savePrzylaczaTable("Rozdzielcza_test2_bzyk_przylacza");
+

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

@@ -0,0 +1,157 @@
+<?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);
+			$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 "\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);
+  
+
+
+	
+	
+	
+	
+	
+	
+	

+ 23 - 0
SE/dev/php-cli/biale_plamy_class_usage.php

@@ -0,0 +1,23 @@
+<?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();
+
+
+$test->generateWays();
+$test->generateXpoints();
+////$test->generateJoins();
+$test->generatePrzylacza();
+$test->saveCache();
+
+$test->saveXML();
+
+//$test->saveArrays();
+
+//echo $test->printArray('joins2ways');
+//$test->saveWaysTable("Rozdzielcza_test2_bzyk_ways");
+//$test->saveJoinsTable("Rozdzielcza_test2_bzyk_joins");
+//$test->savePrzylaczaTable("Rozdzielcza_test2_bzyk_przylacza");

+ 1 - 0
SE/dev/php-cli/biale_plamy_joins2ways_do_paths.xsl

@@ -109,6 +109,7 @@
                 
                 <EdgeWayJoinsPair>
                     <xsl:attribute name="ID_Way" select="@ID_Way"/>
+                    <!-- debug -->
                     <!--<xsl:copy-of select="$guess_edges/guess_join[@ID_Way=$ID_Way]"></xsl:copy-of>-->
                     <xsl:for-each select="$guess_edges/guess_join[@ID_Way=$ID_Way]/EdgeWayJoinsPair_cand">
                         <bp:Joins>

+ 0 - 4
SE/dev/php-cli/biale_put_Cables_to_PE.php

@@ -122,7 +122,6 @@ $id_j=0;
 foreach($cables_from_joins_to_PE->xpath('cable_to_PE_to_be_calculated') as $child)  { //cable_to_PE_to_be_calculated
  // echo "\n<br>";
 	   //$attrs=$child->attributes("ID_Way");
-
 	   foreach($child->attributes() as $a=>$b) {
 		   //	echo "#87Child";print_r($b[0]);
 		   if($a=='ID_Way') $ID_Way=$b[0];
@@ -147,9 +146,6 @@ foreach($cables_from_joins_to_PE->xpath('cable_to_PE_to_be_calculated') as $chil
 		   $cables_from_joins_to_PE_arr[$id_j]['Joins']=$Joins;
 		   $cables_from_joins_to_PE_arr[$id_j]['ID_Way']=$ID_Way;
 		   $cables_from_joins_to_PE_arr[$id_j]['ID_Point']=$ID_Point;
-
-
-
 	   }
 }
 

Разница между файлами не показана из-за своего большого размера
+ 28 - 0
SE/dev/php-cli/biale_put_xml_paths_to_mysql.php


+ 140 - 24
SE/dev/php-cli/build__biale_plamy.xml

@@ -1,27 +1,41 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <project
     xmlns:bp="https://procesy5.pl/biale_plamy-schema.xsd"
-    basedir="." name="biale_plamy-generate_data" default="biale_plamy-generate_data">
+    basedir="." name="biale_plamy-generate_data" default="biale_plamy-generate_data_by_nosql">
     <!-- 
     
     
     -->
+    <property name="biale_plamy_class.php" value="biale_plamy_class.php"/>
     <property name="biale_plamy-prepare_sql_data.php" value="biale_plamy-prepare_sql_data.php"/>
     <property name="biale_plamy-generate_data.php" value="biale_plamy-generate_data.php"/>
-    <property name="biale_plamy-find_ways.php" value="biale_plamy-find_ways.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="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="ways_2ID_Way.xml" value="ways_2ID_Way.xml"/>
+        <property name="ways2drogi.xml" value="ways2drogi.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="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="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="points_asText.xml" value="points_asText.xml"/>
         <property name="points2joins.xml" value="points2joins.xml"/>
         <property name="edge_joins.xml" value="edge_joins.xml"/>
+        
+            <property name="joins_asText_xml.xsl" value="joins_asText_xml.xsl"/>
+            <property name="joins_asText_xml.xml" value="joins_asText_xml.xml"/> 
+            <!-- sciezki -->
             <property name="edge_joins_filled_paths.xml" value="edge_joins_filled_paths.xml"/>
             <property name="edge_joins_filled_paths.xsl" value="edge_joins_filled_paths.xsl"/>
     
@@ -41,12 +55,9 @@
     </target>
     
     <target name="biale_plamy-generate_data" >
-        
-         
-        <!--<antcall target="biale_plamy_prepare_mysql_data"/>-->
-        
+        <!-- stary sposob -->
+        <antcall target="biale_plamy_prepare_mysql_data"/>        
         <antcall target="biale_plamy-generate_data_sql"/>
-        
         <echo message="odpalam biale_plamy-generate_data "/>
         <delete file="${joins2ways_z_ID_Way.xml}"/>
         <antcall target="biale_plamy_points2ID_Way_do_Joins"/>
@@ -54,32 +65,80 @@
         <antcall target="biale_plamy_joins2ways_do_paths"/>
         <!-- tymczasowy rem bo dziala -->
         <antcall target="biale_plamy_paths_to_findways_php"/>
+        <antcall target="PE_and_Cables"/>
+    </target>
+    
+    
+    
+    <target name="biale_plamy-generate_data_by_nosql">
+        <!-- nowy sposob -->
+        <antcall target="biale_plamy_prepare_php_data_by_class"/>  
+        <delete file="${joins2ways_z_ID_Way.xml}"/>
+        <antcall target="biale_plamy_points2ID_Way_do_Joins"/>
+        
+        <delete file="${joins_asText_xml.xml}"/>
+        <antcall  target="joins_asText_xml"/>
+        
+        <delete file="${edge_joins.xml}"/>
+        <antcall target="biale_plamy_joins2ways_do_paths"/>
+        
+        <delete file="${edge_joins_filled_paths.xml}"/>
+        <antcall target="edge_joins_filled_paths_make"/>
         
+        <!--<antcall target="biale_plamy_paths_to_findways_php"/>-->
         <antcall target="PE_and_Cables"/>
+    </target>
+    
+    
+    <target name="biale_plamy-just_xsl_PE_cables">
+        <!-- nowy sposob -->
+          
+        <delete file="${joins2ways_z_ID_Way.xml}"/>
+        <antcall target="biale_plamy_points2ID_Way_do_Joins"/>
+        
+        <delete file="${ways_as_Text_z_ID_xml.xml}"/>
+        <antcall target="ways_as_Text_z_ID_xml"/>
+        
+        <delete file="${joins_asText_xml.xml}"/>
+        <antcall  target="joins_asText_xml"/>
+        
+        <delete file="${edge_joins.xml}"/>
+        <antcall target="biale_plamy_joins2ways_do_paths"/>
         
+        <delete file="${edge_joins_filled_paths.xml}"/>
+        <antcall target="edge_joins_filled_paths_make"/>
+        
+        <antcall target="biale_plamy_paths_to_findways_php"/>
+        <antcall target="PE_and_Cables"/>
     </target>
     
+    
+    
+    
     <target name="clean">
+        <delete file="${joins2ways_z_ID_Way.xml}"/>
+        <delete file="${edge_joins_filled_paths.xml}"/>
+        <delete file="${edge_paths_with_PE.xml}"/>
+        <delete file="${cables_from_joins_to_PE.xml}"/>
+        <delete file="${joins_asText_xml.xml}"/>
+        <delete file="${ways_as_Text_z_ID_xml.xml}"/>
+    </target>
+    
+    <target name="clean_input">
+        <delete file="${points2ID_Way.xml}"/>
         <delete file="${points2joins.xml}"/>
         <delete file="${ways2joins.xml}"/>
         <delete file="${ways_asText.xml}"/>
         <delete file="${joins_asText.xml}"/>
-        <delete file="${joins2ways_z_ID_Way.xml}"/>
         <delete file="${edge_joins.xml}"/>
         <delete file="${joins2ways.xml}"/>
-        <delete file="${points2ID_Way.xml}"/>
-        <delete file="${ways_2ID_Way.xml}"/>
-        <delete file="${joins2ways_z_ID_Way.xml}"/>
+        <delete file="${ways2drogi.xmll}"/>
         <delete file="${points_asText.xml}"/>
-        <delete file="${points2joins.xml}"/>
         <delete file="${edge_joins.xml}"/>
-        <delete file="${edge_joins_filled_paths.xml}"/>
-        <delete file="${edge_paths_with_PE.xml}"/>
-        <delete file="${cables_from_joins_to_PE.xml}"/>
+        <delete file="${points2joins.xml}"/>
     </target>
     
     
-    
     <target name="check_files_for_PE_and_Cables" >
         <echo message="czy sa wymagane pliki do wygenerowania samych PE_and_Cables"/>
         <condition property="files_PE_and_Cables" taskname="PE_and_Cables" value="AVIABLE">
@@ -109,6 +168,13 @@
         </exec>
     </target>
     
+    <target name="biale_plamy_prepare_php_data_by_class">
+        <echo message=" przygotowuje punkty xpoint przez biale_plamy_class.php"/>
+        <exec executable="php" failonerror="true" dir=".">
+            <arg file="${biale_plamy_class.php}"/>
+        </exec>
+    </target>
+   
    
    
     <target name="biale_plamy-generate_data_sql">
@@ -121,6 +187,8 @@
         <echo message="Teraz Przelec arraya joins2ways pod katem 1-elementowych subarrayow"/>
     </target> 
    
+   
+   
     <target name="biale_plamy_points2ID_Way_do_Joins">
         <echo message="przygotownie z joins2ways xsl biale_plamy_joins2ways_do_paths.xsl pod katem 1  katem 1-elementowych subarrayow aby zrobic paths "/>
         <delete file="${joins2ways_z_ID_Way.xml}"/>
@@ -131,10 +199,26 @@
                 <!--<attribute name="http://saxon.sf.net/feature/initialTemplate" value="asd"/>-->
             </factory>
             <classpath location="/opt/local/share/java/saxon9he.jar"/>
-            <param name="points2ID_Way.xml"  expression="${ways_2ID_Way.xml}"/>
+            <param name="points2ID_Way.xml"  expression="${ways2drogi.xml}"/>
+        </xslt>
+    </target>
+   
+   
+    <target name="joins_asText_xml">
+        <echo message="uporzadkowanie Joins as text aby mialy xmlowe wspolrzedne"/>
+        <delete file="${joins_asText_xml.xml}"/>
+        <xslt basedir="./" style="${joins_asText_xml.xsl}" in="${joins_asText.xml}"  destdir="./" out="${joins_asText_xml.xml}" >
+            <factory name="net.sf.saxon.TransformerFactoryImpl">    
+                <attribute name="http://saxon.sf.net/feature/xinclude-aware" value="true"/>
+                <!--<attribute name="http://saxon.sf.net/feature/initialMode" value="DITA_PARSE_templ"/>-->
+                <!--<attribute name="http://saxon.sf.net/feature/initialTemplate" value="asd"/>-->
+            </factory>
+            <classpath location="/opt/local/share/java/saxon9he.jar"/>
+            <!--<param name="points2ID_Way.xml"  expression="${ways2drogi.xml}"/>-->
         </xslt>
     </target>
    
+   
     <target name="biale_plamy_joins2ways_do_paths">
         <echo message="przygotownie z joins2ways xsl biale_plamy_joins2ways_do_paths.xsl pod katem 1  katem 1-elementowych subarrayow aby zrobic paths "/>
         <delete file="${edge_joins.xml}"/>
@@ -149,13 +233,45 @@
         </xslt>
     </target>
    
-    <!-- wyznaczenie sciezek do ulozenia PE - dziala-->
-    <target name="biale_plamy_paths_to_findways_php">
-        <exec executable="php" failonerror="true" dir=".">
-            <arg file="${biale_plamy-find_ways.php}"/>
-        </exec>
-        <!-- to wyrzuca edge_joins_filled_paths.xml-->
+    <!-- wyznaczenie sciezek do ulozenia PE - dziala -  -->
+    <target name="ways_as_Text_z_ID_xml">
+         <echo message="przygotownie z joins2ways xsl biale_plamy_joins2ways_do_paths.xsl pod katem 1  katem 1-elementowych subarrayow aby zrobic paths "/>
+         <delete file="${ways_as_Text_z_ID_xml.xml}"/>
+         <xslt basedir="./" style="${ways_as_Text_z_ID_xml.xsl}" in="${ways_asText.xml}"  destdir="./" out="${ways_as_Text_z_ID_xml.xml}" >
+             <factory name="net.sf.saxon.TransformerFactoryImpl">    
+                 <attribute name="http://saxon.sf.net/feature/xinclude-aware" value="true"/>
+                 <!--<attribute name="http://saxon.sf.net/feature/initialMode" value="DITA_PARSE_templ"/>-->
+                 <!--<attribute name="http://saxon.sf.net/feature/initialTemplate" value="asd"/>-->
+             </factory>
+             <classpath location="/opt/local/share/java/saxon9he.jar"/>
+             <param name="ways2drogi.xml" expression="${ways2drogi.xml}"/>
+         </xslt>
+     </target>
+    
+    <target name="edge_joins_filled_paths_make">
+        <echo message="przygotownie z joins2ways xsl biale_plamy_joins2ways_do_paths.xsl pod katem 1  katem 1-elementowych subarrayow aby zrobic paths "/>
+        <delete file="${ways_as_Text_z_ID_xml.xml}"/>
+        <xslt basedir="./" style="${edge_joins_filled_paths_make.xsl}" in="${edge_joins.xml}"  destdir="./" out="${edge_joins_filled_paths.xml}" >
+            <factory name="net.sf.saxon.TransformerFactoryImpl">    
+                <attribute name="http://saxon.sf.net/feature/xinclude-aware" value="true"/>
+                <!--<attribute name="http://saxon.sf.net/feature/initialMode" value="DITA_PARSE_templ"/>-->
+                <!--<attribute name="http://saxon.sf.net/feature/initialTemplate" value="asd"/>-->
+            </factory>
+            <classpath location="/opt/local/share/java/saxon9he.jar"/>
+            <param name="ways_as_Text_z_ID_xml.xml" expression="${ways_as_Text_z_ID_xml.xml}"/>
+            <param name="joins_asText_xml.xml" expression="${joins_asText_xml.xml}"/>
+        </xslt>
     </target>
+    
+    
+     <target name="biale_plamy_paths_to_findways_php">
+         <exec executable="php" failonerror="true" dir=".">
+             <arg file="${biale_plamy_class_findWay.php}"/>
+         </exec>
+         <!-- to wyrzuca edge_joins_filled_paths.xml-->
+     </target>
+    
+   
    
     <!-- postawienie PE po trasach -->
     <target name="biale_plamy_from_paths_php_to_place_PE">

+ 234 - 0
SE/dev/php-cli/edge_joins_filled_paths_make.xsl

@@ -0,0 +1,234 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+    xmlns:xs="http://www.w3.org/2001/XMLSchema"
+    xmlns:bp="https://procesy5.pl/biale_plamy-schema.xsd"
+    exclude-result-prefixes="xs"
+    version="2.0">
+    
+    <xsl:param name="ways_as_Text_z_ID_xml.xml" select="'ways_as_Text_z_ID_xml.xml'"/>
+    <xsl:variable name="ways_asText_z_ID_xml" select="doc($ways_as_Text_z_ID_xml.xml)"/>
+    
+    <xsl:param name="joins_asText_xml.xml" select="'joins_asText_xml.xml'"/>
+    <xsl:variable name="joins_asText_xml" select="doc($joins_asText_xml.xml)"/>
+    
+    
+    <xsl:output indent="yes"/>
+    <xsl:strip-space elements="*"/>
+    
+    <xsl:template match="EdgeWayJoins">
+        <edge_joins_filled_paths>
+            <xsl:attribute name="stylesheet" select="'edge_joins_filled_paths_make.xsl'"/>
+        <xsl:apply-templates/>
+        </edge_joins_filled_paths>
+    </xsl:template>
+    
+    
+    <xsl:template match="EdgeWayJoinsPair">
+        <item>
+            <xsl:attribute name="id" select="@ID_Way"/>
+            <xsl:variable name="ID_Way" select="@ID_Way"/>
+            <asText>
+                <xsl:variable name="bp:Joins">
+                    <xsl:for-each select="bp:Joins">
+                        <bp:Joins>
+                            <xsl:copy-of select="@*"/>
+                            <xsl:copy-of select="$joins_asText_xml/joins_asText_xml/item[@id= current()/@Joins]/bp:Path_Point/@X"/>
+                            <xsl:copy-of select="$joins_asText_xml/joins_asText_xml/item[@id= current()/@Joins]/bp:Path_Point/@Y"/>
+                            <xsl:attribute name="position" select="position()"/>
+                            <!--<xsl:copy-of select="$joins_asText_xml/joins_asText_xml/item[@id= current()/@id]/"/>-->
+                        </bp:Joins>
+                    </xsl:for-each>
+                </xsl:variable>
+                <!--<Joins>
+                    <xsl:copy-of select="$bp:Joins"/>
+                </Joins>-->
+                <xsl:variable name="Join_X1" select="$bp:Joins/bp:Joins[@position=1]/@X"/>
+                <xsl:variable name="Join_Y1" select="$bp:Joins/bp:Joins[@position=1]/@Y"/>
+                <xsl:variable name="Join_X2" select="$bp:Joins/bp:Joins[@position=2]/@X"/>
+                <xsl:variable name="Join_Y2" select="$bp:Joins/bp:Joins[@position=2]/@Y"/>
+                <!-- na podstawie joina ustalamy jego wspolrzedne -->
+                
+                <xsl:variable name="Ways">
+                <Ways>
+                    <xsl:attribute name="Join_X1" select="$Join_X1"/>
+                    <xsl:attribute name="Join_Y1" select="$Join_Y1"/>
+                    <xsl:attribute name="Join_X2" select="$Join_X2"/>
+                    <xsl:attribute name="Join_Y2" select="$Join_Y2"/>
+                    <xsl:variable name="Ways">
+                        <xsl:for-each select="$ways_asText_z_ID_xml/ways_asText_z_ID_xml/item[@ID_Way=$ID_Way]">
+                            <Way>
+                                <xsl:attribute name="id" select="@id"/>
+                                <xsl:variable name="bp:Path_Point">
+                                    <xsl:for-each select="bp:Path_Point">
+                                    <bp:Path_Point>
+                                        <xsl:copy-of select="@*"/>
+                                        <xsl:attribute name="position" select="position()"/>
+                                    </bp:Path_Point>
+                                    </xsl:for-each>
+                                </xsl:variable>
+                               <!-- <xsl:variable name="Way_X1" select="$bp:Path_Point/bp:Path_Point[@position=1]/@X"/>
+                                <xsl:variable name="Way_Y1" select="$bp:Path_Point/bp:Path_Point[@position=1]/@Y"/>
+                                <xsl:variable name="Way_X2" select="$bp:Path_Point/bp:Path_Point[@position=2]/@X"/>
+                                <xsl:variable name="Way_Y2" select="$bp:Path_Point/bp:Path_Point[@position=2]/@Y"/>-->
+                                <xsl:attribute name="Way_X1" select="$bp:Path_Point/bp:Path_Point[@position=1]/@X"/>
+                                <xsl:attribute name="Way_Y1" select="$bp:Path_Point/bp:Path_Point[@position=1]/@Y"/>
+                                <xsl:attribute name="Way_X2" select="$bp:Path_Point/bp:Path_Point[@position=2]/@X"/>
+                                <xsl:attribute name="Way_Y2" select="$bp:Path_Point/bp:Path_Point[@position=2]/@Y"/>
+                            </Way>
+                        </xsl:for-each> 
+                    </xsl:variable>
+                    <xsl:copy-of select="$Ways"/>
+                    
+                    <!-- teraz trzeba wiedziec ktory punkt wziac z drogi - czy pierwszy czy drugi jaki pasuje do pary -->
+                    <xsl:variable name="Ways_J1_W1">
+                        <xsl:for-each select="$Ways/Way[@Way_X1=$Join_X1 and @Way_Y1=$Join_Y1]">
+                            <Way_next_cand>
+                                <xsl:copy-of select="@id"/>
+                                <xsl:copy-of select="@Way_X2"/>
+                                <xsl:copy-of select="@Way_Y2"/>
+                            </Way_next_cand>
+                        </xsl:for-each>
+                    </xsl:variable>
+                    <xsl:copy-of select="$Ways_J1_W1"/>
+                    
+                    <xsl:variable name="Ways_J2_W1">
+                        <xsl:for-each select="$Ways/Way[@Way_X1=$Join_X2 and @Way_Y1=$Join_Y2]">
+                            <Way_next_cand>
+                                <xsl:copy-of select="@id"/>
+                                <xsl:copy-of select="@Way_X2"/>
+                                <xsl:copy-of select="@Way_Y2"/>
+                            </Way_next_cand>
+                        </xsl:for-each>
+                    </xsl:variable>
+                    <xsl:copy-of select="$Ways_J2_W1"/>
+                    
+                    <xsl:variable name="Ways_J1_W2">
+                        <xsl:for-each select="$Ways/Way[@Way_X2=$Join_X1 and @Way_Y2=$Join_Y1]">
+                            <Way_next_cand>
+                                <xsl:copy-of select="@id"/>
+                                <xsl:copy-of select="@Way_X1"/>
+                                <xsl:copy-of select="@Way_Y1"/>
+                            </Way_next_cand>
+                        </xsl:for-each>
+                    </xsl:variable>
+                    <xsl:copy-of select="$Ways_J1_W2"/>
+                    
+                    <xsl:variable name="Ways_J2_W2">
+                        <xsl:for-each select="$Ways/Way[@Way_X2=$Join_X2 and @Way_Y2=$Join_Y2]">
+                            <Way_next_cand>
+                                <xsl:copy-of select="@id"/>
+                                <xsl:copy-of select="@Way_X1"/>
+                                <xsl:copy-of select="@Way_Y1"/>
+                            </Way_next_cand>
+                        </xsl:for-each>
+                    </xsl:variable>
+                    <xsl:copy-of select="$Ways_J2_W2"/>
+                    <!-- poszukamy czy Way_X2 wystepuje -->
+                </Ways>
+                </xsl:variable>
+                <!--<xsl:copy-of select="$Ways"/>-->
+                <!--<xsl:variable name="Way_1_or_2">
+                <xsl:choose>
+                    <xsl:when test="$Ways/Ways/Way_next_cand[1]/@Way_X2">
+                        <xsl:value-of select="1"/>
+                    </xsl:when>
+                    <xsl:otherwise><xsl:value-of select="2"/></xsl:otherwise>
+                </xsl:choose>
+                </xsl:variable>-->
+                <!--<Way_1_or_2><xsl:value-of select="$Way_1_or_2"/></Way_1_or_2>-->
+                <xsl:variable name="LineString">
+                    <xsl:call-template name="PlaceWay">
+                        <xsl:with-param name="Ways" select="$Ways"/>
+                        <xsl:with-param name="Cur_X1" select="$Ways/Ways/@Join_X1"/>
+                        <xsl:with-param name="Cur_Y1" select="$Ways/Ways/@Join_Y1"/>
+                        <xsl:with-param name="Last_X2" select="$Ways/Ways/@Join_X2"/>
+                        <xsl:with-param name="Last_Y2" select="$Ways/Ways/@Join_Y2"/>
+                        <!--<xsl:with-param name="Way_1_or_2" select="$Way_1_or_2"/>-->
+                        <!--<xsl:with-param name="not_id" select="$Ways/Ways/Way_next_cand/@id"/>-->
+                    </xsl:call-template>
+                </xsl:variable>
+                <xsl:call-template name="AsText_XML">
+                    <xsl:with-param name="LineString" select="$LineString"/>
+                </xsl:call-template>
+            </asText>
+        </item>
+    </xsl:template>
+    
+    
+   
+    <xsl:template name="AsText_XML">
+        <xsl:param name="LineString" required="yes"/>
+        <xsl:value-of select="'LINESTRING ('"/>
+        <xsl:for-each select="$LineString/LineString">
+            <xsl:value-of select="concat(@X,' ',@Y)"/>
+            <xsl:if test="not(position()= last())">
+                <xsl:value-of select="', '"/>
+            </xsl:if>
+        </xsl:for-each>
+        <xsl:value-of select="')'"/>
+    </xsl:template>
+    
+    
+    <xsl:template name="PlaceWay">
+        <xsl:param name="Ways" required="yes"/>
+        <xsl:param name="Cur_X1" required="yes"/>
+        <xsl:param name="Cur_Y1" required="yes"/>
+        <!--<xsl:param name="Way_1_or_2" required="yes"/>-->
+        <xsl:param name="Last_X2" required="yes"/>
+        <xsl:param name="Last_Y2" required="yes"/>
+        <xsl:param name="loop" select="1"/>
+        <xsl:param name="not_id" required="no"/>
+        <!--<LineString>
+            <xsl:attribute name="X1" select="$Cur_X1"/>
+            <xsl:attribute name="Y1" select="$Cur_Y1"/>
+        </LineString>-->
+        <!--<xsl:choose>
+            <xsl:when test="$Way_1_or_2"></xsl:when>
+        </xsl:choose>-->
+        <!--<debug>
+            <xsl:attribute name="Cur_X1" select="$Cur_X1"/>
+            <xsl:attribute name="Cur_Y1" select="$Cur_Y1"/>
+            <xsl:attribute name="not_id" select="$not_id"/>
+        </debug>-->
+        <xsl:variable name="Linestring">
+        <xsl:for-each select="$Ways/Ways/Way[@Way_X1=$Cur_X1 and @Way_Y1=$Cur_Y1 and ( not($not_id) or not(@id=$not_id)) ]">
+            <LineString>
+                <xsl:attribute name="X" select="@Way_X2"/>
+                <xsl:attribute name="Y" select="@Way_Y2"/>
+                <xsl:attribute name="not_id" select="@id"/>
+            </LineString>
+        </xsl:for-each>
+            <xsl:for-each select="$Ways/Ways/Way[@Way_X2=$Cur_X1 and @Way_Y2=$Cur_Y1 and ( not($not_id) or not(@id=$not_id))  ]">
+            <LineString>
+                <xsl:attribute name="X" select="@Way_X1"/>
+                <xsl:attribute name="Y" select="@Way_Y1"/>
+                <xsl:attribute name="not_id" select="@id"/>
+            </LineString>
+        </xsl:for-each>
+        </xsl:variable>
+        <xsl:copy-of select="$Linestring"/>
+        <xsl:choose>
+            <xsl:when test="$loop &gt; 100000">
+                <loop_limit/>
+            </xsl:when>
+            <xsl:when test="$Linestring/LineString/@X = $Last_X2 and $Linestring/LineString/@Y = $Last_Y2 ">
+                <ostatni/>
+            </xsl:when>
+            <xsl:otherwise>
+                <xsl:call-template name="PlaceWay">
+                    <xsl:with-param name="Ways" select="$Ways"/>
+                    <xsl:with-param name="Cur_X1" select="$Linestring/LineString/@X"/>
+                    <xsl:with-param name="Cur_Y1" select="$Linestring/LineString/@Y"/>
+                    <xsl:with-param name="Last_X2" select="$Last_X2"/>
+                    <xsl:with-param name="Last_Y2" select="$Last_Y2"/>
+                    <xsl:with-param name="not_id" select="$Linestring/LineString/@not_id"/>
+                    <xsl:with-param name="loop" select="$loop+1"/>
+                </xsl:call-template>
+            </xsl:otherwise>
+        </xsl:choose>
+        
+        
+    </xsl:template>
+    
+    
+</xsl:stylesheet>

+ 5 - 4
SE/dev/php-cli/joins2ways_z_ID_Way.xsl

@@ -6,8 +6,9 @@
     version="2.0">
     <xsl:output indent="yes"/>
     <xsl:strip-space elements="*"/>
-    <xsl:param name="ways_2ID_Way.xml"  select="'ways_2ID_Way.xml'"/>
-    <xsl:variable name="ways_2ID_Way" select="doc($ways_2ID_Way.xml)"/>
+    <xsl:param name="ways2drogi.xml"  select="'ways2drogi.xml'"/>
+    <!--<xsl:variable name="ways_2ID_Way" select="doc($ways_2ID_Way.xml)"/>-->
+    <xsl:variable name="ways2drogi" select="doc($ways2drogi.xml)"/>
     <xsl:variable name="points2joins" select="doc('points2joins.xml')"/>
     
     <xsl:template match="joins2ways">
@@ -28,7 +29,7 @@
             <xsl:for-each select="item">
                         <item>
                             <xsl:copy-of select="$item/@*"/>
-                            <xsl:attribute name="ID_Way" select="$ways_2ID_Way/ways_2ID_Way/item[@id=current()/text()]/text()"/>
+                            <xsl:attribute name="ID_Way" select="$ways2drogi/ways2drogi/item[@id=current()/text()]/text()"/>
                             <xsl:if test="$ID_Point">
                                 <xsl:attribute name="ID_Point" select="$ID_Point"/>
                             </xsl:if>
@@ -36,7 +37,7 @@
                             <xsl:for-each select="$item/item">
                                 <xsl:element name="item">
                                     <xsl:attribute name="id" select="@id"/>
-                                    <xsl:attribute name="ID_WAY" select="$ways_2ID_Way/ways_2ID_Way/item[@id=current()/text()]/text()"/>
+                                    <xsl:attribute name="ID_WAY" select="$ways2drogi/ways2drogi/item[@id=current()/text()]/text()"/>
                                     <xsl:copy-of select="text()"/>
                                 </xsl:element>
                             </xsl:for-each>

+ 33 - 0
SE/dev/php-cli/joins_asText_xml.xsl

@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+    xmlns:xs="http://www.w3.org/2001/XMLSchema"
+    xmlns:bp="https://procesy5.pl/biale_plamy-schema.xsd"
+    exclude-result-prefixes="xs"
+    version="2.0">
+    
+    <xsl:import href="asText.xsl"/>
+    <xsl:output indent="yes"/>
+    <xsl:strip-space elements="*"/>
+    
+    <xsl:template match="joins_asText">
+        <joins_asText_xml>
+            <xsl:apply-templates/>
+        </joins_asText_xml>    
+    </xsl:template>
+    
+    
+    <xsl:template match="item">
+        <item>
+            <xsl:copy-of select="@id"/>
+            <xsl:variable name="asText">
+                <asText>
+                    <xsl:value-of select="text()"/>
+                </asText>
+            </xsl:variable>
+            <xsl:apply-templates mode="POINT" select="$asText"/>
+        </item>
+        
+    </xsl:template>
+    
+    
+</xsl:stylesheet>

+ 40 - 0
SE/dev/php-cli/ways_as_Text_z_ID_xml.xsl

@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+    xmlns:xs="http://www.w3.org/2001/XMLSchema"
+    xmlns:bp="https://procesy5.pl/biale_plamy-schema.xsd"
+    exclude-result-prefixes="xs"
+    version="2.0">
+    
+    <xsl:import href="asText.xsl"/>
+    <xsl:param name="ways2drogi.xml" select="'ways2drogi.xml'"/>
+    <xsl:variable name="ways2drogi" select="doc($ways2drogi.xml)"/>
+    
+    <xsl:output indent="yes"/>
+    <xsl:strip-space elements="*"/>
+    
+    
+    <xsl:template match="ways_asText">
+        <ways_asText_z_ID_xml>
+            <xsl:apply-templates/>
+        </ways_asText_z_ID_xml>
+    </xsl:template>
+    
+    <xsl:template match="item">
+        <item>
+        <xsl:copy-of select="@*"/>
+            <xsl:attribute name="pos" select="position()"/>
+            <xsl:attribute name="ID_Way" select="$ways2drogi/ways2drogi/item[@id= current()/@id]/text()"/>
+        <xsl:apply-templates/>
+        </item>
+    </xsl:template>
+    
+    
+    <xsl:template match="text()">
+        <xsl:variable name="asText">
+            <asText>
+                <xsl:copy-of select="."/>
+            </asText>
+        </xsl:variable>
+        <xsl:apply-templates select="$asText"/>
+    </xsl:template>
+</xsl:stylesheet>

Некоторые файлы не были показаны из-за большого количества измененных файлов