|
|
@@ -64,8 +64,8 @@ class bialePlamy {
|
|
|
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();
|
|
|
+ private $drogi_asText = array(), $joins_asText = array(), $ways_asText = array(), $xpoints_asText = array(), $points_asText = array(), $przylacza_asText = array(), $waysLengths = array();
|
|
|
+ private $ways2drogi = array(), $drogi2ways = 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');
|
|
|
@@ -88,8 +88,8 @@ class bialePlamy {
|
|
|
$this->showProgress = false;
|
|
|
}
|
|
|
|
|
|
- private $dataArrays = array('joins_asText', 'ways_asText', 'xpoints_asText', 'points_asText', 'przylacza_asText',
|
|
|
- 'ways2drogi', 'ways2joins', 'joins2ways', 'points2xpoints', 'xpoints2points', 'przylacza2joins', 'przylacza2points', 'points2joins');
|
|
|
+ private $dataArrays = array('drogi_asText', 'joins_asText', 'ways_asText', 'xpoints_asText', 'points_asText', 'przylacza_asText', 'waysLengths',
|
|
|
+ 'ways2drogi', 'drogi2ways', 'ways2joins', 'joins2ways', 'points2xpoints', 'xpoints2points', 'przylacza2joins', 'przylacza2points', 'points2joins');
|
|
|
|
|
|
public function saveCache() {
|
|
|
foreach ($this->dataArrays as $array) if ($this->$array) {
|
|
|
@@ -199,8 +199,8 @@ class bialePlamy {
|
|
|
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 temporary table `_temp_punkty_adresowe` select * from `{$this->punktyAdresoweTable}` where the_geom is not null");
|
|
|
+ DB::getPDO()->query("create temporary table `_temp_drogi` select * from `{$this->drogiTable}` where coalesce(numpoints(the_geom),0)>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;
|
|
|
@@ -242,6 +242,22 @@ class bialePlamy {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public function generateWaysLenghts() {
|
|
|
+ try {
|
|
|
+ if (!$this->ways_asText) $this->generateWays;
|
|
|
+ if ($this->showProgress) $progress = new showProgress("Generating waysLengths", count($this->ways_asText));
|
|
|
+ foreach ($this->ways_asText as $way_key => $way_asText) {
|
|
|
+ $way = Vendor_Geophp::load($way_asText, 'wkt');
|
|
|
+ $waysLengths[$way_key] = $way->greatCircleLength();
|
|
|
+ if ($this->showProgress) $progress->step();
|
|
|
+ }
|
|
|
+ $this->waysLengths = $waysLengths;
|
|
|
+ if ($this->showProgress) $progress->stop();
|
|
|
+ } catch (Exception $e) {
|
|
|
+ throw $e;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public function generateWays() {
|
|
|
try {
|
|
|
if (!$this->getSourceData) $this->getSourceData();
|
|
|
@@ -257,13 +273,17 @@ class bialePlamy {
|
|
|
$way = new LineString(array($multiway->pointN($i), $multiway->pointN($i+1)));
|
|
|
$ways_asText[] = $way->asText();
|
|
|
$ways2drogi[] = $row['droga_id'];
|
|
|
+ $drogi2ways[$row['droga_id']][] = count($ways2drogi);
|
|
|
}
|
|
|
+ $drogi_asText[$row['droga_id']] = $multiway->asText();
|
|
|
if ($this->showProgress) $progress->step();
|
|
|
}
|
|
|
if ($this->showProgress) $progress->stop();
|
|
|
|
|
|
$this->ways_asText = $ways_asText;
|
|
|
$this->ways2drogi = $ways2drogi;
|
|
|
+ $this->drogi2ways = $drogi2ways;
|
|
|
+ $this->drogi_asText = $drogi_asText;
|
|
|
|
|
|
$this->joins_asText = array();
|
|
|
$this->ways2joins = array();
|
|
|
@@ -272,6 +292,7 @@ class bialePlamy {
|
|
|
$this->points2xpoints = array();
|
|
|
$this->xpoints2points = array();
|
|
|
$this->readyForFindWay = false;
|
|
|
+ $this->generateWaysLenghts();
|
|
|
} catch (Exception $e) {
|
|
|
throw $e;
|
|
|
}
|
|
|
@@ -394,6 +415,7 @@ class bialePlamy {
|
|
|
$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];
|
|
|
+ $this->drogi2ways[$this->ways2drogi[$way_key]][] = $new_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()}'))");
|
|
|
}
|
|
|
@@ -409,6 +431,7 @@ class bialePlamy {
|
|
|
$this->xpoints2points = $xpoints2points;
|
|
|
$this->generateJoins();
|
|
|
$this->updateTemporaryPointsTable();
|
|
|
+ $this->generateWaysLenghts();
|
|
|
$this->readyForFindWay = false;
|
|
|
} catch (Exception $e) {
|
|
|
throw $e;
|
|
|
@@ -487,7 +510,7 @@ class bialePlamy {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public function findWay($joinA, $joinB, $path = array()) {
|
|
|
+ public function findWay($joinA, $joinB, $path = array(), $joins = array()) {
|
|
|
try {
|
|
|
$this->checkDataForFindWay();
|
|
|
if ($joinA == $joinB) {
|
|
|
@@ -501,7 +524,11 @@ class bialePlamy {
|
|
|
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 (!in_array($new_join, $joins)) {
|
|
|
+ if ($subPath = $this->findWay($new_join, $joinB, array_merge($path, array($way_key)), array_merge($joins, array($new_join)))) {
|
|
|
+ $subPaths[] = $subPath;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
if ($subPaths) {
|
|
|
@@ -546,6 +573,29 @@ class bialePlamy {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ function generateLongWays() {
|
|
|
+ try {
|
|
|
+ if ((!$this->drogi2ways) || (!$this->drogi_asText)) $this->generateWays();
|
|
|
+
|
|
|
+ if ($this->showProgress) $progress = new showProgress("Generating longWays", count($this->drogi2ways));
|
|
|
+// print_r($this->drogi_asText);
|
|
|
+ foreach ($this->drogi2ways as $droga_key => $way_keys) {
|
|
|
+ $droga = Vendor_Geophp::load($this->drogi_asText[$droga_key], 'wkt');
|
|
|
+ $startPoint = $droga->startPoint();
|
|
|
+ $endPoint = $droga->endPoint();
|
|
|
+ $join_key_start = array_search($startPoint->asText(), $this->joins_asText);
|
|
|
+ $join_key_end = array_search($endPoint->asText(), $this->joins_asText);
|
|
|
+ $path[] = $join_key_start;
|
|
|
+ $last_join_key = $join_key_start;
|
|
|
+ while (($next_join = 0) != $join_key_end) {
|
|
|
+ foreach ($this->joins2ways[$last_join_key]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception $e) {
|
|
|
+ throw $e;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
//$test = new bialePlamy(array("pointsTable"=>"Rozdzielcza_test2_bzyk_punkty_adresowe", "origWaysTable"=>"Rozdzielcza_test2_bzyk_drogi"));
|