Subversion Repositories eFlore/Applications.cel

Rev

Rev 1515 | Rev 1518 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1515 Rev 1517
Line 37... Line 37...
37
		// Récupération de paramétres
37
		// Récupération de paramétres
38
		// Lancement de l'action demandée
38
		// Lancement de l'action demandée
39
		$cmd = $this->getParametre('a');
39
		$cmd = $this->getParametre('a');
40
		switch ($cmd) {
40
		switch ($cmd) {
41
			case 'tout' :
41
			case 'tout' :
-
 
42
				// à effectuer manuellement au premier lancement du script
42
				$this->creerColonne();
43
				$this->creerColonne();
43
				$this->calculerCodeInsee();
44
				$this->calculerCodeInsee();
-
 
45
				// modifierCodeInsee semble poser problème sur le serveur après beaucoup de requetes
44
				$this->modifierCodeInsee();
46
				//$this->modifierCodeInsee();
45
				break;
47
				break;
-
 
48
			case 'sanscorrespondance' :
-
 
49
				// devrait être être l'option utilisée dans le cron quotidien
-
 
50
				$this->calculerCodeInseeSansCorrespondance();
-
 
51
				// modifierCodeInsee semble poser problème sur le serveur après beaucoup de requetes
-
 
52
				//$this->modifierCodeInsee();
-
 
53
			break;
46
			case 'colonne' :
54
			case 'colonne' :
47
				$this->creerColonne();
55
				$this->creerColonne();
48
				break;
56
				break;
49
			case 'calculer' :
57
			case 'calculer' :
50
				$this->calculerCodeInsee();
58
				$this->calculerCodeInsee();
Line 61... Line 69...
61
 
69
 
62
	private function creerColonne() {
70
	private function creerColonne() {
63
		$this->dao->creerColonneCodeInseeCalculee();
71
		$this->dao->creerColonneCodeInseeCalculee();
Line -... Line 72...
-
 
72
	}
-
 
73
	
-
 
74
	private function calculerCodeInseeSansCorrespondance() {
-
 
75
		$liste_coordonnees = $this->dao->rechercherCoordonneesSansCorrespondances();
-
 
76
		$this->traiterCoordonnees($liste_coordonnees);
64
	}
77
	}
65
	
78
	
-
 
79
	private function calculerCodeInsee() {
-
 
80
		$liste_coordonnees = $this->dao->rechercherCoordonnees();
-
 
81
		$this->traiterCoordonnees($liste_coordonnees);
-
 
82
	}
-
 
83
	
-
 
84
	private function traiterCoordonnees($liste_coordonnees) {
-
 
85
		echo "-------------------------------------------------------------------\n";
-
 
86
		echo "  Traitement et calcul des codes INSEE (".count($liste_coordonnees)." coordonnées en tout) ... \n";
-
 
87
		echo "-------------------------------------------------------------------\n";
-
 
88
		$debut = microtime(true);
66
	private function calculerCodeInsee() {
89
		$i = 0;
67
		$liste_coordonnees = $this->dao->rechercherCoordonnees();
90
		$total = count($liste_coordonnees);
68
		foreach ($liste_coordonnees as $coordonnees) {
91
		foreach ($liste_coordonnees as $coordonnees) {
69
			if ($this->testerCoordonneesWgsFrance($coordonnees['latitude'], $coordonnees['longitude'])) {
92
			if ($this->testerCoordonneesWgsFrance($coordonnees['latitude'], $coordonnees['longitude'])) {
70
				$code_insee = $this->chercherCodeCommune('osm', $coordonnees['latitude'], $coordonnees['longitude']);
93
				$code_insee = $this->chercherCodeCommune('osm', $coordonnees['latitude'], $coordonnees['longitude']);
Line 75... Line 98...
75
					if ($code_insee != "") {
98
					if ($code_insee != "") {
76
						$this->dao->ajouterCodeInseeCalculee($coordonnees['latitude'], $coordonnees['longitude'], $code_insee);
99
						$this->dao->ajouterCodeInseeCalculee($coordonnees['latitude'], $coordonnees['longitude'], $code_insee);
77
					}
100
					}
78
				}
101
				}
79
			}
102
			}
-
 
103
			$i++;
-
 
104
			$this->afficherAvancement('  Lignes traitées ', $i);
80
		}
105
		}
-
 
106
		echo "\n";
-
 
107
		$fin = microtime(true);
-
 
108
		echo "-------------------------------------------------------------------\n";
-
 
109
		echo "  Fin du traitement, ".($fin - $debut)." secondes écoulées \n";
-
 
110
		echo "-------------------------------------------------------------------\n";
-
 
111
		echo "\n";
81
	}
112
	}
Line 82... Line 113...
82
	
113
	
83
	private function modifierCodeInsee() {
114
	private function modifierCodeInsee() {
84
		$this->dao->modifierCodeInsee();
115
		$this->dao->modifierCodeInsee();
Line 85... Line 116...
85
	}
116
	}
86
	
117
	
87
	private function chercherCodeCommune($projet, $latitude, $longitude) {
118
	private function chercherCodeCommune($projet, $latitude, $longitude) {
88
		$code_insee = '';
119
		$code_insee = '';
-
 
120
		$url_service = "www.tela-botanica.org/service:eflore:0.1/{$projet}/nom-commune".
89
		$url_service = "www.tela-botanica.org/service:eflore:0.1/{$projet}/nom-commune".
121
					"?lat={$latitude}&lon={$longitude}";
90
					"?lat={$latitude}&lon={$longitude}";
122
		
91
		$url_service = str_replace(',', '.', $url_service);
123
		$url_service = str_replace(',', '.', $url_service);
92
		$ch = curl_init($url_service);
124
		$ch = curl_init($url_service);
93
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
125
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
94
		$reponse = curl_exec($ch);
126
		$reponse = curl_exec($ch);
95
		$reponse = json_decode($reponse);
127
		$reponse = json_decode($reponse);
96
		if (isset($reponse->codeINSEE)) {
128
		if (isset($reponse->codeINSEE)) {
97
			$code_insee = $reponse->codeINSEE;
129
			$code_insee = $reponse->codeINSEE;
-
 
130
		} 
98
		} 
131
		curl_close($ch);
99
		curl_close($ch);
132
		
Line 100... Line 133...
100
		return $code_insee;
133
		return $code_insee;
101
	}
134
	}
Line 150... Line 183...
150
			$ligneDecoupe['latitude'] = null;
183
			$ligneDecoupe['latitude'] = null;
151
			$ligneDecoupe['longitude'] = null;
184
			$ligneDecoupe['longitude'] = null;
152
		}
185
		}
153
		return $ligneDecoupe;
186
		return $ligneDecoupe;
154
	}
187
	}
155
	
-
 
156
	/*SELECT distinct `ce_zone_geo`,`zone_geo`,`ce_zone_geo_calculee` FROM `cel_obs` 
-
 
157
	 WHERE `ce_zone_geo_calculee`!= "" and `ce_zone_geo`!= "" and 
-
 
158
	 `ce_zone_geo` != concat("INSEE-C:",`ce_zone_geo_calculee`)
-
 
159
*/
-
 
160
 
-
 
161
 
-
 
162
}
188
}
163
?>
189
?>