Subversion Repositories eFlore/Applications.cel

Rev

Rev 2452 | Rev 2454 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2452 Rev 2453
1
<?php
1
<?php
2
class CelRadiusPoints extends Cel {
2
class CelRadiusPoints extends Cel {
3
	
3
	
4
	/**
4
	/**
5
	 * Méthode appelée avec une requête de type GET.
5
	 * Méthode appelée avec une requête de type GET.
6
	 */
6
	 */
7
	public function getRessource() {
7
	public function getRessource() {
8
		return $this->getElement(array());
8
		return $this->getElement(array());
9
	}
9
	}
10
	
10
	
11
	/**
11
	/**
12
	 * Méthode appelée avec une requête de type GET.
12
	 * Méthode appelée avec une requête de type GET.
13
	 */
13
	 */
14
	public function getElement($params) {
14
	public function getElement($params) {
15
 
15
 
16
		$lat_centre = str_replace(',', '.', floatval($_GET['lat']));
16
		$lat_centre = str_replace(',', '.', round(floatval($_GET['lat']), 3));
17
		$lon_centre = str_replace(',', '.', floatval($_GET['lon']));
17
		$lon_centre = str_replace(',', '.', round(floatval($_GET['lon']), 3));
18
		$radius = str_replace(',', '.', floatval($_GET['radius']/1000));
18
		$radius = str_replace(',', '.', floatval($_GET['radius']/1000));
19
		
19
		
20
		$retour = array();
20
		$retour = array();
21
		
21
		
22
		$retour['points'] = $this->obtenirPointsPourCentreEtRadius($lat_centre, $lon_centre, $radius);
22
		$retour['points'] = $this->obtenirPointsPourCentreEtRadius($lat_centre, $lon_centre, $radius);
23
		if(empty($retour['points'])) {
23
		if(empty($retour['points'])) {
24
			$retour['plus_proche'] = $this->obtenirPointPlusProche($lat_centre, $lon_centre);
24
			$retour['plus_proche'] = $this->obtenirPointPlusProche($lat_centre, $lon_centre);
25
		}
25
		}
26
 
26
 
27
		$this->envoyerJson($retour);
27
		$this->envoyerJson($retour);
28
	}
28
	}
29
 
29
 
30
	public function obtenirPointsPourCentreEtRadius($lat_centre, $lon_centre, $radius) {
30
	public function obtenirPointsPourCentreEtRadius($lat_centre, $lon_centre, $radius) {
31
		$requete = "SELECT ".
31
		$requete = "SELECT ".
32
			"id_observation, nom_sel, ( ".
32
			"id_observation, nom_sel, ( ".
33
					"6371 * acos ( ".
33
					"6371 * acos ( ".
34
							"cos ( radians(".$lat_centre.") ) ".
34
							"cos ( radians(".$lat_centre.") ) ".
35
							"* cos( radians( latitude ) ) ".
35
							"* cos( radians( latitude ) ) ".
36
							"* cos( radians( longitude ) - radians(".$lon_centre.") ) ".
36
							"* cos( radians( longitude ) - radians(".$lon_centre.") ) ".
37
							"+ sin ( radians(".$lat_centre.") ) ".
37
							"+ sin ( radians(".$lat_centre.") ) ".
38
							"* sin( radians( latitude ) ) ".
38
							"* sin( radians( latitude ) ) ".
39
					") ".
39
					") ".
40
			") AS distance, latitude, longitude, COUNT(id_observation) as nb_obs ".
40
			") AS distance, latitude, longitude, COUNT(id_observation) as nb_obs ".
41
			"FROM cel_obs ".
41
			"FROM cel_obs ".
42
			"WHERE latitude != 0 AND longitude != 0 ".
42
			"WHERE latitude != 0 AND longitude != 0 ".
43
			"GROUP BY latitude, longitude ".
43
			"GROUP BY latitude, longitude ".
44
			"HAVING distance < ".$radius." ".
44
			"HAVING distance < ".$radius." ".
45
			"ORDER BY distance ";
45
			"ORDER BY distance ";
46
 
46
 
47
		$points = Cel::db()->requeter($requete);
47
		$points = Cel::db()->requeter($requete);
48
		return $points;
48
		return $points;
49
	}
49
	}
50
	
50
	
51
	public function obtenirPointPlusProche($lat_centre, $lon_centre) {
51
	public function obtenirPointPlusProche($lat_centre, $lon_centre) {
52
		$requete = "SELECT ".
52
		$requete = "SELECT ".
53
				"id_observation, nom_sel, ( ".
53
				"id_observation, nom_sel, ( ".
54
				"6371 * acos ( ".
54
				"6371 * acos ( ".
55
				"cos ( radians(".$lat_centre.") ) ".
55
				"cos ( radians(".$lat_centre.") ) ".
56
				"* cos( radians( latitude ) ) ".
56
				"* cos( radians( latitude ) ) ".
57
				"* cos( radians( longitude ) - radians(".$lon_centre.") ) ".
57
				"* cos( radians( longitude ) - radians(".$lon_centre.") ) ".
58
				"+ sin ( radians(".$lat_centre.") ) ".
58
				"+ sin ( radians(".$lat_centre.") ) ".
59
				"* sin( radians( latitude ) ) ".
59
				"* sin( radians( latitude ) ) ".
60
				") ".
60
				") ".
61
				") AS distance, latitude, longitude, COUNT(id_observation) as nb_obs ".
61
				") AS distance, latitude, longitude, COUNT(id_observation) as nb_obs ".
62
				"FROM cel_obs ".
62
				"FROM cel_obs ".
63
				"WHERE latitude != 0 AND longitude != 0 ".
63
				"WHERE latitude != 0 AND longitude != 0 ".
64
				"GROUP BY latitude, longitude ".
64
				"GROUP BY latitude, longitude ".
65
				"HAVING distance = MIN(distance) ".
65
				"HAVING distance = MIN(distance) ".
66
				"ORDER BY distance ";
66
				"ORDER BY distance ";
67
		
67
		
68
		$point = Cel::db()->requeterLigne($requete);
68
		$point = Cel::db()->requeterLigne($requete);
69
		return $point;
69
		return $point;
70
	}
70
	}
71
	
71
	
72
	
72
	
73
}
73
}