New file |
0,0 → 1,162 |
<?php |
/** |
* Traitement de l'ordre : |
* |
* Fonction qui rajoute l'ordre et le sens de chaque way d'une relation dans la table `osm_relation_a_chemins` |
* |
* Exemple de lancement du script : |
* /opt/lampp/bin/php -d memory_limit=8000M cli.php osm -a ordre -m manuel |
* |
*/ |
class OrdonneurDeChemins { |
private $conteneur; |
private $bdd; |
private $messages; |
private $mode; |
|
private $infosRel = array(); |
private $infosNoeuds = array(); |
private $idRelation = null; |
private $idChemin = null; |
private $idNoeud = null; |
private $ordre = 0; |
|
public function __construct($conteneur) { |
$this->conteneur = $conteneur; |
$this->bdd = $this->conteneur->getBdd(); |
$this->messages = $this->conteneur->getMessages(); |
$this->mode = $this->conteneur->getParametre('m'); |
} |
|
public function executer() { |
$relations = $this->getToutesRelationsAChemins(); |
if ($this->mode == 'manuel') { |
$this->messages->traiterInfo("Nombre de relations : %s", array(count($relations))); |
} |
foreach ($relations as $relation) { |
// Traitement de la relation courante |
$this->idRelation = $relation['id_relation']; |
|
$this->chargerDonneesRelationActuelle(); |
|
// Selection du premier chemin comme chemin actuel |
$this->idChemin = $this->getIdPremierChemin(); |
$this->mettreAJourChemin('directe', __LINE__); |
|
// Selection du dernier noeud comme noeud actuel |
$idDernierNoeud = $this->getIdDernierNoeud(); |
if ($idDernierNoeud) { |
$this->idNoeud = $idDernierNoeud; |
$this->ordonnerChemins(); |
} |
|
// Affichage de l'avancement |
if ($this->mode == 'manuel') { |
$this->messages->afficherAvancement("Ordone les chemins de la relation : ", 1); |
} |
} |
} |
|
private function getToutesRelationsAChemins() { |
$requete = 'SELECT DISTINCT id_relation '. |
'FROM osm_relation_a_chemins '. |
' -- '.__FILE__.' : '.__LINE__; |
$relations = $this->bdd->recupererTous($requete); |
return $relations; |
} |
|
private function chargerDonneesRelationActuelle() { |
$requete = 'SELECT cn.id_chemin, cn.id_noeud, cn.ordre '. |
'FROM osm_relation_a_chemins AS rc '. |
' INNER JOIN osm_chemin_a_noeuds AS cn ON (rc.id_chemin = cn.id_chemin) '. |
"WHERE rc.id_relation = {$this->idRelation} ". |
"ORDER BY cn.ordre ASC ". |
' -- '.__FILE__.' : '.__LINE__; |
$infos = $this->bdd->recupererTous($requete); |
foreach ($infos as $info) { |
$this->infosRel[$info['id_chemin']][$info['id_noeud']] = $info['ordre']; |
if (! isset($this->infosNoeuds[$info['id_noeud']][$info['id_chemin']])) { |
$this->infosNoeuds[$info['id_noeud']][$info['id_chemin']] = 1; |
} else { |
$this->infosNoeuds[$info['id_noeud']][$info['id_chemin']]++; |
} |
} |
//print_r($this->infosNoeuds);exit(); |
$this->ordre = 0; |
} |
|
private function getIdPremierChemin() { |
$idChemin = null; |
if (count($this->infosRel) > 0) { |
reset($this->infosRel); |
$idChemin = key($this->infosRel); |
} |
return $idChemin; |
} |
|
private function mettreAJourChemin($sens, $ligne, $fichier = __FILE__) { |
$ordre = $this->ordre++; |
$requete = 'UPDATE osm_relation_a_chemins '. |
"SET ordre = '$ordre', sens = '$sens' ". |
"WHERE id_relation = {$this->idRelation} ". |
"AND id_chemin = {$this->idChemin} ". |
" -- $fichier : $ligne"; |
$retour = $this->bdd->requeter($requete); |
return $retour; |
} |
|
private function getIdDernierNoeud() { |
$idNoeud = false; |
if (count($this->infosRel[$this->idChemin]) > 0) { |
end($this->infosRel[$this->idChemin]); |
$idNoeud = key($this->infosRel[$this->idChemin]); |
} |
return $idNoeud; |
} |
|
private function ordonnerChemins() { |
foreach ($this->infosRel as $chemin) { |
// Selection du chemin qui possède le dernier noeud du précédent chemin et écarter l'actuel |
$idCheminSuivant = $this->getIdCheminSuivant(); |
if ($idCheminSuivant) { |
$this->idChemin = $idCheminSuivant; |
$idPremierNoeud = $this->getIdPremierNoeud(); |
$idDernierNoeud = $this->getIdDernierNoeud(); |
$sens = $this->getSens($idPremierNoeud); |
$this->mettreAJourChemin($sens, __LINE__); |
$this->idNoeud = ($sens == 'directe') ? $idDernierNoeud : $idPremierNoeud; |
} |
} |
} |
|
private function getIdCheminSuivant() { |
$idCheminSuivant = false; |
if (isset($this->infosNoeuds[$this->idNoeud])) { |
$cheminsIds = array_keys($this->infosNoeuds[$this->idNoeud]); |
foreach ($cheminsIds as $idChemin) { |
if ($idChemin != $this->idChemin) { |
$idCheminSuivant = $idChemin; |
break; |
} |
} |
} else { |
$msg = "Impossible de trouver le chemin suivant pour la relation : %s, le chemin %s et le noeud %s"; |
$this->messages->traiterAvertissement($msg, array($this->idRelation, $this->idChemin, $this->idNoeud)); |
} |
return $idCheminSuivant; |
} |
|
private function getSens($idPremierNoeud) { |
$sens = ( strcmp($idPremierNoeud, $this->idNoeud ) == 0 ) ? 'directe' : 'indirecte'; |
return $sens; |
} |
|
private function getIdPremierNoeud() { |
$idNoeud = false; |
if (count($this->infosRel[$this->idChemin]) > 0) { |
reset($this->infosRel[$this->idChemin]); |
$idNoeud = key($this->infosRel[$this->idChemin]); |
} |
return $idNoeud; |
} |
} |