1046 |
jpm |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* Traitement de l'ordre :
|
|
|
4 |
*
|
|
|
5 |
* Fonction qui rajoute l'ordre et le sens de chaque way d'une relation dans la table `osm_relation_a_chemins`
|
|
|
6 |
*
|
|
|
7 |
* Exemple de lancement du script :
|
|
|
8 |
* /opt/lampp/bin/php -d memory_limit=8000M cli.php osm -a ordre -m manuel
|
|
|
9 |
*
|
|
|
10 |
*/
|
|
|
11 |
class OrdonneurDeChemins {
|
|
|
12 |
private $conteneur;
|
|
|
13 |
private $bdd;
|
|
|
14 |
private $messages;
|
|
|
15 |
private $mode;
|
|
|
16 |
|
1055 |
jpm |
17 |
private $premierNoeudPolygon = null;
|
1047 |
jpm |
18 |
private $infosRel = array();
|
|
|
19 |
private $infosNoeuds = array();
|
1046 |
jpm |
20 |
private $idRelation = null;
|
|
|
21 |
private $idChemin = null;
|
|
|
22 |
private $idNoeud = null;
|
|
|
23 |
private $ordre = 0;
|
|
|
24 |
|
|
|
25 |
public function __construct($conteneur) {
|
|
|
26 |
$this->conteneur = $conteneur;
|
|
|
27 |
$this->bdd = $this->conteneur->getBdd();
|
|
|
28 |
$this->messages = $this->conteneur->getMessages();
|
|
|
29 |
$this->mode = $this->conteneur->getParametre('m');
|
|
|
30 |
}
|
|
|
31 |
|
|
|
32 |
public function executer() {
|
|
|
33 |
$relations = $this->getToutesRelationsAChemins();
|
|
|
34 |
if ($this->mode == 'manuel') {
|
|
|
35 |
$this->messages->traiterInfo("Nombre de relations : %s", array(count($relations)));
|
|
|
36 |
}
|
|
|
37 |
foreach ($relations as $relation) {
|
|
|
38 |
// Traitement de la relation courante
|
|
|
39 |
$this->idRelation = $relation['id_relation'];
|
|
|
40 |
|
1047 |
jpm |
41 |
$this->chargerDonneesRelationActuelle();
|
1046 |
jpm |
42 |
|
1055 |
jpm |
43 |
$numPolygon = 1;
|
|
|
44 |
while(count($this->chemins) > 0) {
|
|
|
45 |
reset($this->chemins);
|
|
|
46 |
$idChemin = key($this->chemins);
|
|
|
47 |
echo "--------------POLY : $numPolygon : $idChemin\n";
|
|
|
48 |
$this->ordonnerCheminsRelation($numPolygon, $idChemin);
|
|
|
49 |
$this->mettreAJourRelationAChemin();
|
|
|
50 |
$numPolygon++;
|
1046 |
jpm |
51 |
}
|
|
|
52 |
|
|
|
53 |
// Affichage de l'avancement
|
|
|
54 |
if ($this->mode == 'manuel') {
|
|
|
55 |
$this->messages->afficherAvancement("Ordone les chemins de la relation : ", 1);
|
|
|
56 |
}
|
|
|
57 |
}
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
private function getToutesRelationsAChemins() {
|
|
|
61 |
$requete = 'SELECT DISTINCT id_relation '.
|
|
|
62 |
'FROM osm_relation_a_chemins '.
|
1055 |
jpm |
63 |
'WHERE id_relation = 403823 '.
|
1046 |
jpm |
64 |
' -- '.__FILE__.' : '.__LINE__;
|
|
|
65 |
$relations = $this->bdd->recupererTous($requete);
|
|
|
66 |
return $relations;
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
private function chargerDonneesRelationActuelle() {
|
|
|
70 |
$requete = 'SELECT cn.id_chemin, cn.id_noeud, cn.ordre '.
|
|
|
71 |
'FROM osm_relation_a_chemins AS rc '.
|
1047 |
jpm |
72 |
' INNER JOIN osm_chemin_a_noeuds AS cn ON (rc.id_chemin = cn.id_chemin) '.
|
1046 |
jpm |
73 |
"WHERE rc.id_relation = {$this->idRelation} ".
|
1055 |
jpm |
74 |
"ORDER BY rc.ordre ASC, cn.ordre ASC ".
|
1046 |
jpm |
75 |
' -- '.__FILE__.' : '.__LINE__;
|
|
|
76 |
$infos = $this->bdd->recupererTous($requete);
|
1055 |
jpm |
77 |
$noeuds = array();
|
1046 |
jpm |
78 |
foreach ($infos as $info) {
|
1055 |
jpm |
79 |
$noeuds[$info['id_noeud']][$info['id_chemin']] = $info['ordre'];
|
|
|
80 |
if (! isset($this->chemins[$info['id_chemin']]) ) {
|
|
|
81 |
$this->chemins[$info['id_chemin']]['max'] == info['ordre'];
|
|
|
82 |
if ($info['ordre'] == 1) {
|
|
|
83 |
$this->chemins[$info['id_chemin']][0] == $info['id_noeud'];
|
|
|
84 |
}
|
1047 |
jpm |
85 |
} else {
|
1055 |
jpm |
86 |
|
1047 |
jpm |
87 |
}
|
1055 |
jpm |
88 |
if (count($noeuds[$info['id_noeud']]) == 2) {
|
|
|
89 |
list($premierChemin, $dernierChemin) = array_keys($noeuds[$info['id_noeud']]);
|
|
|
90 |
$this->chemins[$premierChemin][] = $info['id_noeud'];
|
|
|
91 |
$this->chemins[$dernierChemin][] = $info['id_noeud'];
|
|
|
92 |
$this->noeuds[$info['id_noeud']][$premierChemin] = $dernierChemin;
|
|
|
93 |
$this->noeuds[$info['id_noeud']][$dernierChemin] = $premierChemin;
|
|
|
94 |
}
|
1046 |
jpm |
95 |
}
|
1055 |
jpm |
96 |
//print_r($this->chemins);exit();
|
1046 |
jpm |
97 |
}
|
|
|
98 |
|
1055 |
jpm |
99 |
private function ordonnerCheminsRelation($numPolygon, $idChemin, $idCheminPrecedent = null, $ordre = 1) {
|
|
|
100 |
$this->infosRel[$idChemin] = array($ordre, $numPolygon);
|
|
|
101 |
|
|
|
102 |
list($premierNoeud, $dernierNoeud) = $this->chemins[$idChemin];
|
|
|
103 |
|
|
|
104 |
if ($idCheminPrecedent == null) {// Premier chemin à tester
|
|
|
105 |
$this->premierNoeudPolygon = $premierNoeud;
|
|
|
106 |
$noeudSuivant = ($dernierNoeud == $premierNoeud) ? $premierNoeud : $dernierNoeud;
|
|
|
107 |
echo "Chemin $idChemin :: premierNoeud: $premierNoeud, dernierNoeud: $dernierNoeud \n";
|
|
|
108 |
} else {
|
|
|
109 |
list($premierNoeudPrec, $dernierNoeudPrec) = $this->chemins[$idCheminPrecedent];
|
|
|
110 |
unset($this->chemins[$idCheminPrecedent]);
|
|
|
111 |
$noeudSuivant = ($dernierNoeudPrec == $dernierNoeud || $premierNoeudPrec == $dernierNoeud) ? $premierNoeud : $dernierNoeud;
|
|
|
112 |
echo "Chemin $idChemin :: premierNoeudPrec: $premierNoeudPrec, dernierNoeudPrec: $dernierNoeudPrec, premierNoeud: $premierNoeud, dernierNoeud: $dernierNoeud \n";
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
if ($this->premierNoeudPolygon != $noeudSuivant) {
|
|
|
116 |
if (isset($this->noeuds[$noeudSuivant][$idChemin])) {
|
|
|
117 |
$idCheminSuivant = $this->noeuds[$noeudSuivant][$idChemin];
|
|
|
118 |
if (! isset($this->infosRel[$idCheminSuivant])) {
|
|
|
119 |
$this->ordonnerCheminsRelation($numPolygon, $idCheminSuivant, $idChemin, ++$ordre);
|
|
|
120 |
} else {
|
|
|
121 |
$this->messages->traiterAvertissement("Chemins %s déjà pris en comtpe", array($idCheminSuivant));
|
|
|
122 |
}
|
|
|
123 |
} else {
|
|
|
124 |
$this->messages->traiterAvertissement("Relation %s a un polygone incomplet", array($this->idRelation));
|
|
|
125 |
}
|
|
|
126 |
} else {
|
|
|
127 |
unset($this->chemins[$idChemin]);
|
|
|
128 |
}
|
|
|
129 |
return null;
|
|
|
130 |
}
|
|
|
131 |
|
|
|
132 |
private function mettreAJourRelationAChemin() {
|
|
|
133 |
if (count($this->infosRel) > 0) {
|
|
|
134 |
foreach ($this->infosRel as $idC => $donnees) {
|
|
|
135 |
list($ordre, $numPolygon) = $this->bdd->proteger($donnees);
|
|
|
136 |
$requete = 'UPDATE osm_relation_a_chemins '.
|
|
|
137 |
"SET sens = $ordre, num_poly = $numPolygon ".
|
|
|
138 |
"WHERE id_relation = {$this->idRelation} ".
|
|
|
139 |
"AND id_chemin = $idC ".
|
|
|
140 |
' -- '.__FILE__.' : '.__LINE__;
|
|
|
141 |
$this->bdd->requeter($requete);
|
|
|
142 |
}
|
|
|
143 |
$this->infosRel = array();
|
|
|
144 |
}
|
|
|
145 |
}
|
|
|
146 |
|
|
|
147 |
private function creerSet($donnees) {
|
|
|
148 |
$values = array();
|
|
|
149 |
foreach ($donnees as $infos) {
|
|
|
150 |
$infosP = $this->bdd->proteger($infos);
|
|
|
151 |
$values[] = implode(',', $infosP);
|
|
|
152 |
}
|
|
|
153 |
$valuesClause = '('.implode('),(', $values).')';
|
|
|
154 |
return $valuesClause;
|
|
|
155 |
}
|
|
|
156 |
|
1046 |
jpm |
157 |
private function getIdPremierChemin() {
|
1047 |
jpm |
158 |
$idChemin = null;
|
|
|
159 |
if (count($this->infosRel) > 0) {
|
|
|
160 |
reset($this->infosRel);
|
|
|
161 |
$idChemin = key($this->infosRel);
|
|
|
162 |
}
|
|
|
163 |
return $idChemin;
|
1046 |
jpm |
164 |
}
|
|
|
165 |
|
|
|
166 |
private function mettreAJourChemin($sens, $ligne, $fichier = __FILE__) {
|
|
|
167 |
$ordre = $this->ordre++;
|
|
|
168 |
$requete = 'UPDATE osm_relation_a_chemins '.
|
|
|
169 |
"SET ordre = '$ordre', sens = '$sens' ".
|
|
|
170 |
"WHERE id_relation = {$this->idRelation} ".
|
|
|
171 |
"AND id_chemin = {$this->idChemin} ".
|
|
|
172 |
" -- $fichier : $ligne";
|
|
|
173 |
$retour = $this->bdd->requeter($requete);
|
|
|
174 |
return $retour;
|
|
|
175 |
}
|
|
|
176 |
|
|
|
177 |
private function getIdDernierNoeud() {
|
1047 |
jpm |
178 |
$idNoeud = false;
|
|
|
179 |
if (count($this->infosRel[$this->idChemin]) > 0) {
|
|
|
180 |
end($this->infosRel[$this->idChemin]);
|
1055 |
jpm |
181 |
$idNoeud = current($this->infosRel[$this->idChemin]);
|
1047 |
jpm |
182 |
}
|
|
|
183 |
return $idNoeud;
|
1046 |
jpm |
184 |
}
|
|
|
185 |
|
|
|
186 |
private function ordonnerChemins() {
|
1047 |
jpm |
187 |
foreach ($this->infosRel as $chemin) {
|
1046 |
jpm |
188 |
// Selection du chemin qui possède le dernier noeud du précédent chemin et écarter l'actuel
|
|
|
189 |
$idCheminSuivant = $this->getIdCheminSuivant();
|
|
|
190 |
if ($idCheminSuivant) {
|
|
|
191 |
$this->idChemin = $idCheminSuivant;
|
1047 |
jpm |
192 |
$idPremierNoeud = $this->getIdPremierNoeud();
|
|
|
193 |
$idDernierNoeud = $this->getIdDernierNoeud();
|
|
|
194 |
$sens = $this->getSens($idPremierNoeud);
|
|
|
195 |
$this->mettreAJourChemin($sens, __LINE__);
|
|
|
196 |
$this->idNoeud = ($sens == 'directe') ? $idDernierNoeud : $idPremierNoeud;
|
1046 |
jpm |
197 |
}
|
|
|
198 |
}
|
|
|
199 |
}
|
|
|
200 |
|
|
|
201 |
private function getIdCheminSuivant() {
|
1047 |
jpm |
202 |
$idCheminSuivant = false;
|
|
|
203 |
if (isset($this->infosNoeuds[$this->idNoeud])) {
|
1055 |
jpm |
204 |
$idCheminSuivant = next($this->infosNoeuds[$this->idNoeud]);
|
|
|
205 |
//echo $this->idChemin.'-'.$idCheminSuivant."\n".print_r($this->infosNoeuds[$this->idNoeud]); exit();
|
1047 |
jpm |
206 |
} else {
|
|
|
207 |
$msg = "Impossible de trouver le chemin suivant pour la relation : %s, le chemin %s et le noeud %s";
|
|
|
208 |
$this->messages->traiterAvertissement($msg, array($this->idRelation, $this->idChemin, $this->idNoeud));
|
|
|
209 |
}
|
1046 |
jpm |
210 |
return $idCheminSuivant;
|
|
|
211 |
}
|
|
|
212 |
|
1047 |
jpm |
213 |
private function getSens($idPremierNoeud) {
|
|
|
214 |
$sens = ( strcmp($idPremierNoeud, $this->idNoeud ) == 0 ) ? 'directe' : 'indirecte';
|
|
|
215 |
return $sens;
|
1046 |
jpm |
216 |
}
|
|
|
217 |
|
|
|
218 |
private function getIdPremierNoeud() {
|
1047 |
jpm |
219 |
$idNoeud = false;
|
|
|
220 |
if (count($this->infosRel[$this->idChemin]) > 0) {
|
|
|
221 |
reset($this->infosRel[$this->idChemin]);
|
1055 |
jpm |
222 |
$idNoeud = current($this->infosRel[$this->idChemin]);
|
1047 |
jpm |
223 |
}
|
|
|
224 |
return $idNoeud;
|
1046 |
jpm |
225 |
}
|
|
|
226 |
}
|