|
|
@@ -0,0 +1,91 @@
|
|
|
+<?php
|
|
|
+$_SERVER['SERVER_NAME'] = 'biuro.biall-net.pl';
|
|
|
+require("../../se-lib/bootstrap.php");
|
|
|
+Lib::loadClass("Vendor_Geophp");
|
|
|
+
|
|
|
+//
|
|
|
+
|
|
|
+
|
|
|
+$query = "select astext(the_geom) as multiway from Rozdzielcza_test_bzyk_drogi where numpoints(the_geom)>1";
|
|
|
+$result = DB::getPDO()->fetchall($query);
|
|
|
+$joins = array();
|
|
|
+foreach ($result as $row) {
|
|
|
+ $multiway = Vendor_Geophp::load($row['multiway'], 'wkt');
|
|
|
+//echo $multiway->length();
|
|
|
+ for ($i = 1; $i < $n = $multiway->numPoints(); $i++) {
|
|
|
+ $ways[] = new LineString(array($multiway->pointN($i), $multiway->pointN($i+1)));
|
|
|
+ if (!in_array($multiway->pointN($i)->asText(), $joins)) $joins[] = $multiway->pointN($i)->asText();
|
|
|
+ }
|
|
|
+ if (!in_array($multiway->pointN($n)->asText(), $joins)) $joins[] = $multiway->pointN($n)->asText();
|
|
|
+}
|
|
|
+
|
|
|
+// todo relacje ways <-> joins
|
|
|
+
|
|
|
+$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";
|
|
|
+$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))) {
|
|
|
+ if (@!in_array($key, $ways2cut[array_search($way, $ways)])) {
|
|
|
+ $ways2cut[array_search($way, $ways)][] = $key;
|
|
|
+ }
|
|
|
+ };
|
|
|
+}
|
|
|
+
|
|
|
+function pointsDistance($a, $b) {
|
|
|
+ $line = new LineString(array($a, $b));
|
|
|
+ return $line->length();
|
|
|
+}
|
|
|
+
|
|
|
+foreach ($ways2cut as $way_key => $xpoint_keys) {
|
|
|
+ $distances = array();
|
|
|
+ foreach ($xpoint_keys as $xpoint_key) {
|
|
|
+ $xpoint = Vendor_Geophp::load($xpoints[$xpoint_key], 'wkt');
|
|
|
+ $joins[] = $xpoint;
|
|
|
+ $distances[$xpoint_key] = pointsDistance($ways[$way_key]->startPoint(), $xpoint);
|
|
|
+ }
|
|
|
+ asort($distances);
|
|
|
+
|
|
|
+ $sub_xpoints = array();
|
|
|
+ foreach (array_keys($distances) as $xpoint_key) {
|
|
|
+ $sub_xpoints[] = Vendor_Geophp::load($xpoints[$xpoint_key]);
|
|
|
+ }
|
|
|
+
|
|
|
+ $startPoint = $ways[$way_key]->startPoint();
|
|
|
+ $endPoint = $ways[$way_key]->endPoint();
|
|
|
+ $ways[$way_key] = new LineString(array($startPoint, $sub_xpoints[0]));
|
|
|
+ for ($i = 0; $i < $n = count($sub_xpoints) - 1; $i++) {
|
|
|
+ $ways[] = new LineString(array($sub_xpoints[$i], $sub_xpoints[$i+1]));
|
|
|
+ }
|
|
|
+ $ways[] = new LineString(array($sub_xpoints[$n], $endPoint));
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+//print_r($ways);
|
|
|
+
|
|
|
+/*
|
|
|
+$db = DB::getDB();
|
|
|
+$db->query("truncate table Rozdzielcza_test_bzyk_ways");
|
|
|
+$db->query("truncate table Rozdzielcza_test_bzyk_joins");
|
|
|
+
|
|
|
+
|
|
|
+foreach ($ways as $way) {
|
|
|
+ $query = "insert into Rozdzielcza_test_bzyk_ways (the_geom) values (linefromtext('".$way->asText()."'))";
|
|
|
+ $db->query($query);
|
|
|
+}
|
|
|
+
|
|
|
+foreach ($xpoints as $xpoint) {
|
|
|
+ $xpoint2 = Vendor_Geophp::load($xpoint, 'wkt');
|
|
|
+ $query = "insert into Rozdzielcza_test_bzyk_joins (the_geom) values (pointfromtext('".$xpoint2->asText()."'))";
|
|
|
+ $db->query($query);
|
|
|
+}
|
|
|
+*/
|