Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 2453 Rev 2454
Line 27... Line 27...
27
		$this->envoyerJson($retour);
27
		$this->envoyerJson($retour);
28
	}
28
	}
Line 29... Line 29...
29
 
29
 
30
	public function obtenirPointsPourCentreEtRadius($lat_centre, $lon_centre, $radius) {
30
	public function obtenirPointsPourCentreEtRadius($lat_centre, $lon_centre, $radius) {
31
		$requete = "SELECT ".
-
 
32
			"id_observation, nom_sel, ( ".
-
 
33
					"6371 * acos ( ".
-
 
34
							"cos ( radians(".$lat_centre.") ) ".
-
 
35
							"* cos( radians( latitude ) ) ".
-
 
36
							"* cos( radians( longitude ) - radians(".$lon_centre.") ) ".
-
 
37
							"+ sin ( radians(".$lat_centre.") ) ".
-
 
38
							"* sin( radians( latitude ) ) ".
-
 
39
					") ".
31
		$requete = "SELECT ".
40
			") AS distance, latitude, longitude, COUNT(id_observation) as nb_obs ".
32
			"id_observation, nom_sel, latitude, longitude, COUNT(id_observation) as nb_obs ".
41
			"FROM cel_obs ".
33
			"FROM cel_obs ".
42
			"WHERE latitude != 0 AND longitude != 0 ".
-
 
43
			"GROUP BY latitude, longitude ".
34
			"WHERE latitude != 0 AND longitude != 0 ".
44
			"HAVING distance < ".$radius." ".
35
			"AND ".$this->renvoyerDistanceSql($lat_centre, $lon_centre)." < ".$radius." ".
Line 45... Line 36...
45
			"ORDER BY distance ";
36
			"GROUP BY latitude, longitude ";
46
 
37
 
47
		$points = Cel::db()->requeter($requete);
38
		$points = Cel::db()->requeter($requete);
Line -... Line 39...
-
 
39
		return $points;
-
 
40
	}
-
 
41
	
-
 
42
	private function renvoyerDistanceSql($lat_centre, $lon_centre) {
-
 
43
		$sous_requete = 
-
 
44
				"( ".
-
 
45
					"6371 * acos ( ".
-
 
46
						"cos ( radians(".$lat_centre.") ) ".
-
 
47
						"* cos( radians( latitude ) ) ".
-
 
48
						"* cos( radians( longitude ) - radians(".$lon_centre.") ) ".
-
 
49
						"+ sin ( radians(".$lat_centre.") ) ".
-
 
50
						"* sin( radians( latitude ) ) ".
-
 
51
					") ".
-
 
52
				") ";
48
		return $points;
53
		return $sous_requete;
49
	}
54
	}
50
	
-
 
51
	public function obtenirPointPlusProche($lat_centre, $lon_centre) {
-
 
52
		$requete = "SELECT ".
-
 
53
				"id_observation, nom_sel, ( ".
-
 
54
				"6371 * acos ( ".
55
	
55
				"cos ( radians(".$lat_centre.") ) ".
-
 
56
				"* cos( radians( latitude ) ) ".
-
 
57
				"* cos( radians( longitude ) - radians(".$lon_centre.") ) ".
-
 
58
				"+ sin ( radians(".$lat_centre.") ) ".
56
	public function obtenirPointPlusProche($lat_centre, $lon_centre) {
59
				"* sin( radians( latitude ) ) ".
57
		$requete = "SELECT ".
60
				") ".
58
				"id_observation, nom_sel, ".$this->renvoyerDistanceSql($lat_centre, $lon_centre)." AS distance, ".
61
				") AS distance, latitude, longitude, COUNT(id_observation) as nb_obs ".
59
				"latitude, longitude, COUNT(id_observation) as nb_obs ".
62
				"FROM cel_obs ".
60
				"FROM cel_obs ".
63
				"WHERE latitude != 0 AND longitude != 0 ".
61
				"WHERE latitude != 0 AND longitude != 0 ".