|
|
@@ -61,10 +61,10 @@ class bialePlamy {
|
|
|
|
|
|
private $showProgress = false;
|
|
|
|
|
|
- private $getSourceData = false, $createTemporaryWaysTable = false, $createTemporaryJoinsTable = false, $createTemporaryPrzylaczaTable = false, $readyForFindWay = false;
|
|
|
+ private $getSourceData = false, $createTemporaryWaysTable = false, $createTemporaryJoinsTable = false, $createTemporaryPrzylaczaTable = false, $readyForFindWay = false, $createTemporaryLongWaysTable = false;
|
|
|
|
|
|
private $punktyAdresoweTable = null, $drogiTable = null;
|
|
|
- private $drogi_asText = array(), $joins_asText = array(), $ways_asText = array(), $xpoints_asText = array(), $points_asText = array(), $przylacza_asText = array(), $waysLengths = array();
|
|
|
+ private $drogi_asText = array(), $joins_asText = array(), $ways_asText = array(), $xpoints_asText = array(), $points_asText = array(), $przylacza_asText = array(), $waysLengths = array(), $longWays_asText = array();
|
|
|
private $ways2drogi = array(), $drogi2ways = array(), $ways2joins = array(), $joins2ways = array(), $points2xpoints = array(), $xpoints2points = array(), $przylacza2joins = array(), $przylacza2points = array(), $points2joins = array();
|
|
|
|
|
|
public function __construct($sourceTables) {
|
|
|
@@ -88,7 +88,7 @@ class bialePlamy {
|
|
|
$this->showProgress = false;
|
|
|
}
|
|
|
|
|
|
- private $dataArrays = array('drogi_asText', 'joins_asText', 'ways_asText', 'xpoints_asText', 'points_asText', 'przylacza_asText', 'waysLengths',
|
|
|
+ private $dataArrays = array('drogi_asText', 'joins_asText', 'ways_asText', 'xpoints_asText', 'points_asText', 'przylacza_asText', 'waysLengths', 'longWays_asText',
|
|
|
'ways2drogi', 'drogi2ways', 'ways2joins', 'joins2ways', 'points2xpoints', 'xpoints2points', 'przylacza2joins', 'przylacza2points', 'points2joins');
|
|
|
|
|
|
public function saveCache() {
|
|
|
@@ -185,6 +185,11 @@ class bialePlamy {
|
|
|
$this->saveDB("_temp_przylacza", $dst);
|
|
|
}
|
|
|
|
|
|
+ public function saveLongWaysTable($dst) {
|
|
|
+ if (!$this->createTemporaryLongWaysTable) $this->createTemporaryLongWaysTable();
|
|
|
+ $this->saveDB("_temp_long_ways", $dst);
|
|
|
+ }
|
|
|
+
|
|
|
private function arrayFrom1() {
|
|
|
$array = array('');
|
|
|
unset($array[0]);
|
|
|
@@ -223,6 +228,7 @@ class bialePlamy {
|
|
|
throw $e;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
private function createTemporaryWaysTable() {
|
|
|
try {
|
|
|
if ((!$this->ways_asText) || (!$this->ways2drogi)) throw new Exception("createTemporaryWaysTable() :: Ways not generated, use generateWays() first");
|
|
|
@@ -523,7 +529,7 @@ class bialePlamy {
|
|
|
$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])];
|
|
|
+ $new_join = $this->ways2joins[$way_key][1 - array_search($joinA, $this->ways2joins[$way_key])];
|
|
|
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;
|
|
|
@@ -573,24 +579,60 @@ class bialePlamy {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private function createTemporaryLongWaysTable() {
|
|
|
+ try {
|
|
|
+ if (!$this->longWays_asText) throw new Exception("createTemporaryLongWaysTable() :: longWays not generated, use generateLongWays() first");
|
|
|
+
|
|
|
+ DB::getPDO()->query("drop temporary table if exists `_temp_long_ways`");
|
|
|
+ DB::getPDO()->query("create temporary table `_temp_long_ways` (`ID` int(11), `the_geom` linestring not null, index(`ID`), spatial index(`the_geom`)) ENGINE=MyISAM");
|
|
|
+ if ($this->showProgress) $progress = new showProgress("Creating temporary longWays table", count($this->longWays_asText));
|
|
|
+ foreach ($this->longWays_asText as $longWay_key => $longWay_asText) {
|
|
|
+ DB::getPDO()->query("insert into `_temp_long_ways` values ('{$longWay_key}', LineFromText('{$longWay_asText}'))");
|
|
|
+ if ($this->showProgress) $progress->step();
|
|
|
+ }
|
|
|
+ if ($this->showProgress) $progress->stop();
|
|
|
+
|
|
|
+ $this->createTemporaryLongWaysTable = true;
|
|
|
+ } catch (Exception $e) {
|
|
|
+ throw $e;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
function generateLongWays() {
|
|
|
try {
|
|
|
if ((!$this->drogi2ways) || (!$this->drogi_asText)) $this->generateWays();
|
|
|
+ if (!$this->joins_asText) $this->generateJoins();
|
|
|
|
|
|
if ($this->showProgress) $progress = new showProgress("Generating longWays", count($this->drogi2ways));
|
|
|
-// print_r($this->drogi_asText);
|
|
|
- foreach ($this->drogi2ways as $droga_key => $way_keys) {
|
|
|
+ foreach ($this->drogi2ways as $droga_key => $ways_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]
|
|
|
+ $start_join_key = array_search($startPoint->asText(), $this->joins_asText);
|
|
|
+ $end_join_key = array_search($endPoint->asText(), $this->joins_asText);
|
|
|
+ $path = array($start_join_key);
|
|
|
+ $last_join_key = $start_join_key;
|
|
|
+ while (($last_join_key) != $end_join_key) {
|
|
|
+ $next_join_key = 0;
|
|
|
+ foreach ($this->joins2ways[$last_join_key] as $way_key) {
|
|
|
+ if (in_array($way_key, $ways_keys)) {
|
|
|
+ $next_join_key = $this->ways2joins[$way_key][1 - array_search($last_join_key, $this->ways2joins[$way_key])];
|
|
|
+ if (!in_array($next_join_key, $path)) {
|
|
|
+ $path[] = $next_join_key;
|
|
|
+ $last_join_key = $next_join_key;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!$next_join_key) throw new Exception("generateLongWays() :: Błąd spójności danych");
|
|
|
}
|
|
|
+ $points = array();
|
|
|
+ foreach ($path as $join_key) $points[] = Vendor_Geophp::load($this->joins_asText[$join_key], 'wkt');
|
|
|
+ $longWay = new LineString($points);
|
|
|
+ $longWays_asText[$droga_key] = $longWay->asText();
|
|
|
+ if ($this->showProgress) $progress->step();
|
|
|
}
|
|
|
+ $this->longWays_asText = $longWays_asText;
|
|
|
+ if ($this->showProgress) $progress->stop();
|
|
|
} catch (Exception $e) {
|
|
|
throw $e;
|
|
|
}
|