148 |
jpm |
1 |
<?php
|
|
|
2 |
//declare(encoding='UTF-8');
|
|
|
3 |
/**
|
|
|
4 |
* Classe permettant de :
|
|
|
5 |
* - convertir la latitude et longitude en degre, et rajouter l'objet point centroide de la commune.
|
|
|
6 |
* - charger la bdd
|
|
|
7 |
* Exemple de lancement du script : :
|
|
|
8 |
* /opt/lampp/bin/php cli.php lion1906 -a chargerTous
|
|
|
9 |
*
|
|
|
10 |
* @category php 5.2
|
|
|
11 |
* @package eFlore/Scripts
|
|
|
12 |
* @author Mohcen BENMOUNAH <mohcen@tela-botanica.org>
|
|
|
13 |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
|
|
|
14 |
* @copyright Copyright (c) 2011, Tela Botanica (accueil@tela-botanica.org)
|
|
|
15 |
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
|
|
|
16 |
* @license http://www.gnu.org/licenses/gpl.html Licence GNU-GPL
|
|
|
17 |
* @version $Id$
|
|
|
18 |
*/
|
|
|
19 |
class Lion1906 extends EfloreScript {
|
|
|
20 |
|
|
|
21 |
public function executer() {
|
|
|
22 |
$this->initialiserProjet('lion1906');
|
|
|
23 |
|
|
|
24 |
// Lancement de l'action demandée
|
|
|
25 |
$cmd = $this->getParametre('a');
|
|
|
26 |
switch ($cmd) {
|
|
|
27 |
case 'chargerTous' :
|
|
|
28 |
$this->chargerStructureSql();
|
|
|
29 |
$this->chargerMetaDonnees();
|
|
|
30 |
$this->chargerLion1906();
|
|
|
31 |
$this->preparerTable();
|
|
|
32 |
$this->convertirRadianEnDegre();
|
|
|
33 |
break;
|
|
|
34 |
case 'convertir' :
|
|
|
35 |
$this->preparerTable();
|
|
|
36 |
$this->convertirRadianEnDegre();
|
|
|
37 |
break;
|
|
|
38 |
case 'supprimerTous' :
|
|
|
39 |
$this->supprimerTous();
|
|
|
40 |
break;
|
|
|
41 |
default :
|
|
|
42 |
$this->traiterErreur('Erreur : la commande "%s" n\'existe pas!', array($cmd));
|
|
|
43 |
}
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
protected function chargerMetaDonnees() {
|
|
|
47 |
$contenuSql = $this->recupererContenu(Config::get('chemins.lion1906Meta'));
|
|
|
48 |
$this->executerScripSql($contenuSql);
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
private function chargerLion1906() {
|
|
|
52 |
$chemin = Config::get('chemins.lion1906');
|
|
|
53 |
$table = Config::get('tables.lion1906');
|
|
|
54 |
$requete = "LOAD DATA INFILE '$chemin' ".
|
|
|
55 |
"REPLACE INTO TABLE $table ".
|
|
|
56 |
'CHARACTER SET latin1 '.
|
|
|
57 |
'FIELDS '.
|
|
|
58 |
" TERMINATED BY ';' ".
|
|
|
59 |
" ENCLOSED BY '' ".
|
|
|
60 |
" ESCAPED BY '\\\' ".
|
|
|
61 |
'IGNORE 1 LINES';
|
|
|
62 |
$this->getBdd()->requeter($requete);
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
private function convertirRadianEnDegre() {
|
|
|
66 |
$table = Config::get('tables.lion1906');
|
|
|
67 |
$requete = 'SELECT insee, latitude_radian, longitude_radian '.
|
|
|
68 |
"FROM $table ";
|
|
|
69 |
$LatLons = $this->getBdd()->recupererTous($requete);
|
|
|
70 |
|
|
|
71 |
foreach ($LatLons as $LatLon) {
|
|
|
72 |
$insee = $LatLon['insee'] ;
|
|
|
73 |
$latitude_degre = $LatLon['latitude_radian'] * 180 / pi();
|
|
|
74 |
$longitude_degre = $LatLon['longitude_radian'] * 180 / pi();
|
|
|
75 |
$latitude_degre = str_replace(',', '.', $latitude_degre);
|
|
|
76 |
$longitude_degre = str_replace(',', '.', $longitude_degre);
|
|
|
77 |
$this->formerPointCentre($latitude_degre, $longitude_degre, $insee);
|
|
|
78 |
$this->afficherAvancement('Analyse des communes Lion1906');
|
|
|
79 |
}
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
private function preparerTable() {
|
|
|
83 |
$table = Config::get('tables.lion1906');
|
|
|
84 |
$requete = "ALTER TABLE $table ".
|
|
|
85 |
'DROP latitude_degre, '.
|
|
|
86 |
'DROP longitude_degre, '.
|
|
|
87 |
'DROP centroide, '.
|
|
|
88 |
'DROP INDEX insee ';
|
|
|
89 |
$this->getBdd()->requeter($requete);
|
|
|
90 |
|
|
|
91 |
$requete = "ALTER TABLE $table ".
|
|
|
92 |
' ADD latitude_degre double NOT NULL , '.
|
|
|
93 |
' ADD longitude_degre double NOT NULL , '.
|
|
|
94 |
' ADD centroide point NOT NULL ';
|
|
|
95 |
$this->getBdd()->requeter($requete);
|
|
|
96 |
|
|
|
97 |
$requete = "ALTER TABLE $table ".
|
|
|
98 |
'ADD INDEX insee (insee, latitude_degre, longitude_degre, centroide) ';
|
|
|
99 |
$this->getBdd()->requeter($requete);
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
private function formerPointCentre($latitude_degre, $longitude_degre, $insee) {
|
|
|
103 |
$centre = "$latitude_degre $longitude_degre" ;
|
|
|
104 |
$table = Config::get('tables.lion1906');
|
|
|
105 |
$requete = "UPDATE $table ".
|
|
|
106 |
"SET latitude_degre = '$latitude_degre', longitude_degre = '$longitude_degre', ".
|
|
|
107 |
" centroide = POINTFROMTEXT('POINT($centre)') ".
|
|
|
108 |
"WHERE insee = '$insee' ";
|
|
|
109 |
$this->getBdd()->requeter($requete);
|
|
|
110 |
}
|
|
|
111 |
|
|
|
112 |
private function supprimerTous() {
|
|
|
113 |
$requete = "DROP TABLE lion1906_meta, lion1906_communes_v2008";
|
|
|
114 |
$this->getBdd()->requeter($requete);
|
|
|
115 |
}
|
|
|
116 |
|
|
|
117 |
}
|
|
|
118 |
?>
|