Subversion Repositories eFlore/Applications.cel

Rev

Rev 2460 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2460 Rev 2785
1
<?php
1
<?php
2
// declare(encoding='UTF-8');
2
// declare(encoding='UTF-8');
3
/**
3
/**
4
 * Classe de groupage des obs par quadtree pour la carto.
4
 * Classe de groupage des obs par quadtree pour la carto.
5
 *
5
 *
6
 * @internal   Mininum PHP version : 5.2
6
 * @internal   Mininum PHP version : 5.2
7
 * @category   CEL
7
 * @category   CEL
8
 * @package    Services
8
 * @package    Services
9
 * @subpackage Bibliothèques
9
 * @subpackage Bibliothèques
10
 * @version    0.1
10
 * @version    0.1
11
 * @author     Mathias CHOUET <mathias@tela-botanica.org>
11
 * @author     Mathias CHOUET <mathias@tela-botanica.org>
12
 * @author     Jean-Pascal MILCENT <jpm@tela-botanica.org>
12
 * @author     Jean-Pascal MILCENT <jpm@tela-botanica.org>
13
 * @author     Aurelien PERONNET <aurelien@tela-botanica.org>
13
 * @author     Aurelien PERONNET <aurelien@tela-botanica.org>
14
 * @license    GPL v3 <http://www.gnu.org/licenses/gpl.txt>
14
 * @license    GPL v3 <http://www.gnu.org/licenses/gpl.txt>
15
 * @license    CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
15
 * @license    CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
16
 * @copyright  1999-2014 Tela Botanica <accueil@tela-botanica.org>
16
 * @copyright  1999-2014 Tela Botanica <accueil@tela-botanica.org>
17
 */
17
 */
18
class CartoGroupage {
18
class CartoGroupage {
19
	const MARQUEUR_GROUPE = 'GROUPE';
19
	const MARQUEUR_GROUPE = 'GROUPE';
20
	const MARQUEUR_COMMUNE = 'COMMUNE';
20
	const MARQUEUR_COMMUNE = 'COMMUNE';
21
	const MARQUEUR_STATION = 'STATION';
21
	const MARQUEUR_STATION = 'STATION';
22
 
22
 
23
	private static $seuilClusterisation = 200;
23
	private static $seuilClusterisation = 200;
24
	private static $zoomDefaut = 3;
24
	private static $zoomDefaut = 3;
25
	private static $zoomMaxClustering = 12;
25
	private static $zoomMaxClustering = 12;
26
	private static $pasZoomDefaut = 1;
26
	private static $pasZoomDefaut = 1;
27
	private static $pasZoomMaxClustering = 0.05;
27
	private static $pasZoomMaxClustering = 0.05;
28
	private static $profondeurMin = 0;
28
	private static $profondeurMin = 0;
29
	private static $profondeurMax = 8;
29
	private static $profondeurMax = 8;
30
 
30
 
31
	private static $pasCorrectionCentre = null;
31
	private static $pasCorrectionCentre = null;
32
	private static $coefficientReductionPas = null;
32
	private static $coefficientReductionPas = null;
33
	private static $coefficientProfondeurMax = null;
33
	private static $coefficientProfondeurMax = null;
34
 
34
 
35
	private static $nbElements = array('stations' => 0,'communes' => 0, 'points' => 0);
35
	private static $nbElements = array('stations' => 0,'communes' => 0, 'points' => 0);
36
	private static $listeNoeudsSelectionnes = array();
36
	private static $listeNoeudsSelectionnes = array();
37
	private static $bornesMax = array('latMin' => null, 'lngMin' => null, 'latMax' => null, 'lngMax' => null);
37
	private static $bornesMax = array('latMin' => null, 'lngMin' => null, 'latMax' => null, 'lngMax' => null);
38
	private static $id_traites = array();
38
	private static $id_traites = array();
39
	/*
39
	/*
40
	  +---------+---------+
40
	  +---------+---------+
41
	  |         |         |
41
	  |         |         |
42
	  |    A    |    B    |
42
	  |    A    |    B    |
43
	  |         |         |
43
	  |         |         |
44
	  +---------*---------+
44
	  +---------*---------+
45
	  |         |         |
45
	  |         |         |
46
	  |    D    |    C    |
46
	  |    D    |    C    |
47
	  |         |         |
47
	  |         |         |
48
	  +---------+---------+
48
	  +---------+---------+
49
 
49
 
50
	  Quatres cadrans sont considérés par le quad tree
50
	  Quatres cadrans sont considérés par le quad tree
51
	  * = centre de la fenetre
51
	  * = centre de la fenetre
52
	 */
52
	 */
53
	public static function creerGroupesQuadtree(&$markers, $neLat, $neLng, $swLat, $swLng, $zoom = 3) {
53
	public static function creerGroupesQuadtree(&$markers, $neLat, $neLng, $swLat, $swLng, $zoom = 3) {
54
		if (count($markers) > self::$seuilClusterisation) {
54
		if (count($markers) > self::$seuilClusterisation) {
55
			self::calculerProfondeurMax($zoom);
55
			self::calculerProfondeurMax($zoom);
56
			self::calculerPasCorrectionCentre($zoom);
56
			self::calculerPasCorrectionCentre($zoom);
57
 
57
 
58
			$noeudRacine = array('nbrePoints' => count($markers), 'points' => $markers);
58
			$noeudRacine = array('nbrePoints' => count($markers), 'points' => $markers);
59
			self::attribuerAuCadran($noeudRacine, $neLat, $neLng, $swLat, $swLng);
59
			self::attribuerAuCadran($noeudRacine, $neLat, $neLng, $swLat, $swLng);
60
		} else {
60
		} else {
61
			foreach ($markers as &$marker) {
61
			foreach ($markers as &$marker) {
62
				if (!self::estUnPointAExclure($marker)) {
62
				if (!self::estUnPointAExclure($marker)) {
63
					$emplacement = self::formaterPointPourAjout($marker);
63
					$emplacement = self::formaterPointPourAjout($marker);
64
					self::mettreAJourBornes($marker);
64
					self::mettreAJourBornes($marker);
65
					$points = array($marker);
65
					$points = array($marker);
66
					$noeudSimple = array('points' => $points, 'nbrePoints' => 1);
66
					$noeudSimple = array('points' => $points, 'nbrePoints' => 1);
67
					self::$nbElements[$emplacement]++;
67
					self::$nbElements[$emplacement]++;
68
					self::$listeNoeudsSelectionnes[] = self::ajouterGroupeOuPoint($noeudSimple);
68
					self::$listeNoeudsSelectionnes[] = self::ajouterGroupeOuPoint($noeudSimple);
69
				}
69
				}
70
				self::$nbElements['points']++;
70
				self::$nbElements['points']++;
71
			}
71
			}
72
		}
72
		}
73
		return self::$listeNoeudsSelectionnes;
73
		return self::$listeNoeudsSelectionnes;
74
	}
74
	}
75
 
75
 
76
	private function calculerCoefficientReductionPas() {
76
	private function calculerCoefficientReductionPas() {
77
		if (self::$coefficientReductionPas == null) {
77
		if (self::$coefficientReductionPas == null) {
78
			self::$coefficientReductionPas = (self::$pasZoomMaxClustering - self::$pasZoomDefaut)/(self::$zoomMaxClustering - self::$zoomDefaut);
78
			self::$coefficientReductionPas = (self::$pasZoomMaxClustering - self::$pasZoomDefaut)/(self::$zoomMaxClustering - self::$zoomDefaut);
79
		}
79
		}
80
		return self::$coefficientReductionPas;
80
		return self::$coefficientReductionPas;
81
	}
81
	}
82
 
82
 
83
	private function calculerPasCorrectionCentre($zoom) {
83
	private function calculerPasCorrectionCentre($zoom) {
84
		self::$pasCorrectionCentre = ($zoom - self::$zoomDefaut) * self::calculerCoefficientReductionPas() + self::$pasZoomDefaut;
84
		self::$pasCorrectionCentre = ($zoom - self::$zoomDefaut) * self::calculerCoefficientReductionPas() + self::$pasZoomDefaut;
85
	}
85
	}
86
 
86
 
87
	private function calculerCoefficientProfondeurMax() {
87
	private function calculerCoefficientProfondeurMax() {
88
		if (self::$coefficientProfondeurMax == null) {
88
		if (self::$coefficientProfondeurMax == null) {
89
			self::$coefficientProfondeurMax = (self::$profondeurMax - self::$profondeurMin)/(self::$zoomMaxClustering - self::$zoomDefaut);
89
			self::$coefficientProfondeurMax = (self::$profondeurMax - self::$profondeurMin)/(self::$zoomMaxClustering - self::$zoomDefaut);
90
		}
90
		}
91
		return self::$coefficientProfondeurMax;
91
		return self::$coefficientProfondeurMax;
92
	}
92
	}
93
 
93
 
94
	private function calculerProfondeurMax($zoom) {
94
	private function calculerProfondeurMax($zoom) {
95
		if ($zoom > self::$zoomDefaut) {
95
		if ($zoom > self::$zoomDefaut) {
96
			self::$profondeurMax = round(($zoom - self::$zoomDefaut) * self::calculerCoefficientProfondeurMax() + self::$profondeurMin,0);
96
			self::$profondeurMax = round(($zoom - self::$zoomDefaut) * self::calculerCoefficientProfondeurMax() + self::$profondeurMin,0);
97
		} else {
97
		} else {
98
			self::$profondeurMax = 1;
98
			self::$profondeurMax = 1;
99
		}
99
		}
100
	}
100
	}
101
 
101
 
102
	public static function getNbElements() {
102
	public static function getNbElements() {
103
		return self::$nbElements;
103
		return self::$nbElements;
104
	}
104
	}
105
 
105
 
106
	public static function mettreAJourBornes(&$point) {
106
	public static function mettreAJourBornes(&$point) {
107
		if (!is_numeric($point['lat']) || abs($point['lat']) > 90) return;
107
		if (!is_numeric($point['lat']) || abs($point['lat']) > 90) return;
108
		if (!is_numeric($point['lng']) || abs($point['lng']) > 180) return;
108
		if (!is_numeric($point['lng']) || abs($point['lng']) > 180) return;
109
 
109
 
110
		self::$bornesMax['latMin'] = ($point['lat'] < self::$bornesMax['latMin'] || self::$bornesMax['latMin'] == null) ? $point['lat'] : self::$bornesMax['latMin'] ;
110
		self::$bornesMax['latMin'] = ($point['lat'] < self::$bornesMax['latMin'] || self::$bornesMax['latMin'] == null) ? $point['lat'] : self::$bornesMax['latMin'] ;
111
		self::$bornesMax['lngMin'] = ($point['lng'] < self::$bornesMax['lngMin'] || self::$bornesMax['lngMin'] == null) ? $point['lng'] : self::$bornesMax['lngMin'] ;
111
		self::$bornesMax['lngMin'] = ($point['lng'] < self::$bornesMax['lngMin'] || self::$bornesMax['lngMin'] == null) ? $point['lng'] : self::$bornesMax['lngMin'] ;
112
		self::$bornesMax['latMax'] = ($point['lat'] > self::$bornesMax['latMax'] || self::$bornesMax['latMax'] == null) ? $point['lat'] : self::$bornesMax['latMax'] ;
112
		self::$bornesMax['latMax'] = ($point['lat'] > self::$bornesMax['latMax'] || self::$bornesMax['latMax'] == null) ? $point['lat'] : self::$bornesMax['latMax'] ;
113
		self::$bornesMax['lngMax'] = ($point['lng'] > self::$bornesMax['lngMax'] || self::$bornesMax['lngMax'] == null) ? $point['lng'] : self::$bornesMax['lngMax'] ;
113
		self::$bornesMax['lngMax'] = ($point['lng'] > self::$bornesMax['lngMax'] || self::$bornesMax['lngMax'] == null) ? $point['lng'] : self::$bornesMax['lngMax'] ;
114
	}
114
	}
115
 
115
 
116
	public static function getBornes() {
116
	public static function getBornes() {
117
		return self::$bornesMax;
117
		return self::$bornesMax;
118
	}
118
	}
119
 
119
 
120
	/**
120
	/**
121
	 *
121
	 *
122
	 * @param mixed $noeud Le noeud à traiter par le quadtree
122
	 * @param mixed $noeud Le noeud à traiter par le quadtree
123
	 * @param float $neLat Latitude du coin nord est de la fenetre
123
	 * @param float $neLat Latitude du coin nord est de la fenetre
124
	 * @param float $neLng Longitude du coin nord est de la fenetre
124
	 * @param float $neLng Longitude du coin nord est de la fenetre
125
	 * @param float $swLat Latitude du coin sud ouest de la fenetre
125
	 * @param float $swLat Latitude du coin sud ouest de la fenetre
126
	 * @param float $swLng Longitude du coin sud ouest de la fenetre
126
	 * @param float $swLng Longitude du coin sud ouest de la fenetre
127
	 * @param int $profondeur profondeur courante de l'arbre
127
	 * @param int $profondeur profondeur courante de l'arbre
128
	 */
128
	 */
129
	private static function attribuerAuCadran(&$noeud, $neLat, $neLng, $swLat, $swLng, $profondeur = 0) {
129
	private static function attribuerAuCadran(&$noeud, $neLat, $neLng, $swLat, $swLng, $profondeur = 0) {
130
		$latCentre = round((($neLat+$swLat)/2)/self::$pasCorrectionCentre,0)*self::$pasCorrectionCentre;
130
		$latCentre = round((($neLat+$swLat)/2)/self::$pasCorrectionCentre,0)*self::$pasCorrectionCentre;
131
		$lngCentre = round((($neLng+$swLng)/2)/self::$pasCorrectionCentre,0)*self::$pasCorrectionCentre;
131
		$lngCentre = round((($neLng+$swLng)/2)/self::$pasCorrectionCentre,0)*self::$pasCorrectionCentre;
132
 
132
 
133
		foreach ($noeud['points'] as &$point) {
133
		foreach ($noeud['points'] as &$point) {
134
			if(!self::estUnPointAExclure($point)) {
134
			if(!self::estUnPointAExclure($point)) {
135
				$emplacement = self::formaterPointPourAjout($point);
135
				$emplacement = self::formaterPointPourAjout($point);
136
				self::mettreAJourBornes($point);
136
				self::mettreAJourBornes($point);
137
				$cadran = self::obtenirCadranPourPoint($latCentre, $lngCentre, $point);
137
				$cadran = self::obtenirCadranPourPoint($latCentre, $lngCentre, $point);
138
				self::ajouterFils($noeud,$cadran,$point);
138
				self::ajouterFils($noeud,$cadran,$point);
-
 
139
				// Les stations ne doivent être comptées que la première fois !
-
 
140
				if ($emplacement != 'stations' || $profondeur == 0) {
139
				self::$nbElements[$emplacement]++;
141
					self::$nbElements[$emplacement]++;
-
 
142
				}
140
			}
143
			}
141
			self::$nbElements['points']++;
144
			self::$nbElements['points']++;
142
		}
145
		}
143
 
146
 
144
		$profondeur++;
147
		$profondeur++;
145
 
148
 
146
		if($profondeur <= self::$profondeurMax) {
149
		if($profondeur <= self::$profondeurMax) {
147
			(isset($noeud['A']) && $noeud['A'] != null) ? self::attribuerAuCadran($noeud['A'], $neLat, $lngCentre , $latCentre, $swLng, $profondeur) : '';
150
			(isset($noeud['A']) && $noeud['A'] != null) ? self::attribuerAuCadran($noeud['A'], $neLat, $lngCentre , $latCentre, $swLng, $profondeur) : '';
148
			(isset($noeud['B']) && $noeud['B'] != null) ? self::attribuerAuCadran($noeud['B'], $neLat, $neLng, $latCentre, $lngCentre, $profondeur) : '';
151
			(isset($noeud['B']) && $noeud['B'] != null) ? self::attribuerAuCadran($noeud['B'], $neLat, $neLng, $latCentre, $lngCentre, $profondeur) : '';
149
			(isset($noeud['C']) && $noeud['C'] != null) ? self::attribuerAuCadran($noeud['C'], $latCentre, $neLng, $swLat, $lngCentre, $profondeur) : '';
152
			(isset($noeud['C']) && $noeud['C'] != null) ? self::attribuerAuCadran($noeud['C'], $latCentre, $neLng, $swLat, $lngCentre, $profondeur) : '';
150
			(isset($noeud['D']) && $noeud['D'] != null) ? self::attribuerAuCadran($noeud['D'], $latCentre, $lngCentre, $swLat, $swLng, $profondeur) : '';
153
			(isset($noeud['D']) && $noeud['D'] != null) ? self::attribuerAuCadran($noeud['D'], $latCentre, $lngCentre, $swLat, $swLng, $profondeur) : '';
151
		}
154
		}
152
 
155
 
153
		if(self::estUnParentFeuilles($noeud)) {
156
		if(self::estUnParentFeuilles($noeud)) {
154
			self::$listeNoeudsSelectionnes[] = self::ajouterGroupeOuPoint($noeud);
157
			self::$listeNoeudsSelectionnes[] = self::ajouterGroupeOuPoint($noeud);
155
		}
158
		}
156
	}
159
	}
157
 
160
 
158
	private static function estUnPointAExclure(&$point) {
161
	private static function estUnPointAExclure(&$point) {
159
		return self::estSensible($point) &&
162
		return self::estSensible($point) &&
160
		self::coordonneesCommuneSontNulles($point);
163
		self::coordonneesCommuneSontNulles($point);
161
	}
164
	}
162
 
165
 
163
	private static function coordonneesCommuneSontNulles(&$point) {
166
	private static function coordonneesCommuneSontNulles(&$point) {
164
		$coord_nulles = ($point['wgs84_latitude'] == null ||
167
		$coord_nulles = ($point['wgs84_latitude'] == null ||
165
		$point['wgs84_latitude'] == '' ||
168
		$point['wgs84_latitude'] == '' ||
166
		$point['wgs84_longitude'] == null ||
169
		$point['wgs84_longitude'] == null ||
167
		$point['wgs84_longitude'] == '');
170
		$point['wgs84_longitude'] == '');
168
		return $coord_nulles;
171
		return $coord_nulles;
169
	}
172
	}
170
 
173
 
171
	private static function coordonneesSontNulles(&$point) {
174
	private static function coordonneesSontNulles(&$point) {
172
		$coord_nulles = ($point['latitude'] == '000null' ||
175
		$coord_nulles = ($point['latitude'] == '000null' ||
173
			$point['latitude'] == 0 ||
176
			$point['latitude'] == 0 ||
174
			$point['latitude'] == '' ||
177
			$point['latitude'] == '' ||
175
			$point['longitude'] == '000null' ||
178
			$point['longitude'] == '000null' ||
176
			$point['longitude'] == 0 ||
179
			$point['longitude'] == 0 ||
177
			$point['longitude'] == '');
180
			$point['longitude'] == '');
178
		return $coord_nulles;
181
		return $coord_nulles;
179
	}
182
	}
180
 
183
 
181
	private static function estSensible(&$point) {
184
	private static function estSensible(&$point) {
182
		$sensible = isset($point['mots_cles_texte']) && substr_count(strtolower($point['mots_cles_texte']), 'sensible') != 0;
185
		$sensible = isset($point['mots_cles_texte']) && substr_count(strtolower($point['mots_cles_texte']), 'sensible') != 0;
183
		return $sensible;
186
		return $sensible;
184
	}
187
	}
185
 
188
 
186
	private static function formaterNomStation(&$point, $type_emplacement) {
189
	private static function formaterNomStation(&$point, $type_emplacement) {
187
		$station = '';
190
		$station = '';
188
		if ($type_emplacement == 'stations' && $point['station'] != '' && $point['station'] != '000null') {
191
		if ($type_emplacement == 'stations' && $point['station'] != '' && $point['station'] != '000null') {
189
			$station = $point['station'];
192
			$station = $point['station'];
190
		} else {
193
		} else {
191
			$id_zone_geo = $point['ce_zone_geo'];
194
			$id_zone_geo = $point['ce_zone_geo'];
192
			$station = $point['zone_geo'].(($id_zone_geo != '' && $id_zone_geo != '000null') ? ' ('.self::formaterNomZoneGeo($id_zone_geo).')' : '');
195
			$station = $point['zone_geo'].(($id_zone_geo != '' && $id_zone_geo != '000null') ? ' ('.self::formaterNomZoneGeo($id_zone_geo).')' : '');
193
		}
196
		}
194
 
197
 
195
		return $station;
198
		return $station;
196
	}
199
	}
197
 
200
 
198
	private static function formaterNomZoneGeo($zone_geo) {
201
	private static function formaterNomZoneGeo($zone_geo) {
199
		$zone_geo = str_replace('INSEE-C:', '', $zone_geo);
202
		$zone_geo = str_replace('INSEE-C:', '', $zone_geo);
200
		$zone_geo = strlen($zone_geo) >= 2 ? substr($zone_geo, 0, 2) : $zone_geo;
203
		$zone_geo = strlen($zone_geo) >= 2 ? substr($zone_geo, 0, 2) : $zone_geo;
201
		return $zone_geo;
204
		return $zone_geo;
202
	}
205
	}
203
 
206
 
204
	private static function formaterPointPourAjout(&$point) {
207
	private static function formaterPointPourAjout(&$point) {
205
		if (isset($point['type_emplacement'])) {
208
		if (isset($point['type_emplacement'])) {
206
			return $point['type_emplacement'];
209
			return $point['type_emplacement'];
207
		}
210
		}
208
 
211
 
209
		if (self::coordonneesSontNulles($point) || self::estSensible($point)) {
212
		if (self::coordonneesSontNulles($point) || self::estSensible($point)) {
210
			$point_allege = array();
213
			$point_allege = array();
211
			$point_allege['id'] = self::MARQUEUR_COMMUNE.':'.$point['wgs84_latitude'].'|'.$point['wgs84_longitude'];
214
			$point_allege['id'] = self::MARQUEUR_COMMUNE.':'.$point['wgs84_latitude'].'|'.$point['wgs84_longitude'];
212
			$point_allege['type_emplacement'] = 'communes';
215
			$point_allege['type_emplacement'] = 'communes';
213
			$point_allege['nom'] = self::formaterNomStation($point, 'communes');
216
			$point_allege['nom'] = self::formaterNomStation($point, 'communes');
214
			$point_allege['lat'] = (float)$point['wgs84_latitude'];
217
			$point_allege['lat'] = (float)$point['wgs84_latitude'];
215
			$point_allege['lng'] = (float)$point['wgs84_longitude'];
218
			$point_allege['lng'] = (float)$point['wgs84_longitude'];
216
			$point_allege['zonegeo'] = $point['ce_zone_geo'];
219
			$point_allege['zonegeo'] = $point['ce_zone_geo'];
217
 
220
 
218
			$point = $point_allege;
221
			$point = $point_allege;
219
		} else {
222
		} else {
220
			$point_allege = array();
223
			$point_allege = array();
221
			$point_allege['id'] = self::MARQUEUR_STATION.':'.$point['latitude'].'|'.$point['longitude'];
224
			$point_allege['id'] = self::MARQUEUR_STATION.':'.$point['latitude'].'|'.$point['longitude'];
222
			$point_allege['type_emplacement'] = 'stations';
225
			$point_allege['type_emplacement'] = 'stations';
223
			$point_allege['nom'] = self::formaterNomStation($point, 'stations');
226
			$point_allege['nom'] = self::formaterNomStation($point, 'stations');
224
			$point_allege['lat'] = (float)$point['latitude'];
227
			$point_allege['lat'] = (float)$point['latitude'];
225
			$point_allege['lng'] = (float)$point['longitude'];
228
			$point_allege['lng'] = (float)$point['longitude'];
226
			$point_allege['zonegeo'] = $point['ce_zone_geo'];
229
			$point_allege['zonegeo'] = $point['ce_zone_geo'];
227
 
230
 
228
			$point = $point_allege;
231
			$point = $point_allege;
229
		}
232
		}
230
		return $point['type_emplacement'];
233
		return $point['type_emplacement'];
231
	}
234
	}
232
 
235
 
233
	private function obtenirCadranPourPoint($latCentre,$lngCentre, &$point) {
236
	private function obtenirCadranPourPoint($latCentre,$lngCentre, &$point) {
234
		if ($point['lng'] < $lngCentre) {
237
		if ($point['lng'] < $lngCentre) {
235
			if ($point['lat'] > $latCentre) {
238
			if ($point['lat'] > $latCentre) {
236
					$cadran = 'A';
239
					$cadran = 'A';
237
				} else {
240
				} else {
238
					$cadran = 'D';
241
					$cadran = 'D';
239
				}
242
				}
240
		} else {
243
		} else {
241
			if ($point['lat'] > $latCentre) {
244
			if ($point['lat'] > $latCentre) {
242
				$cadran = 'B';
245
				$cadran = 'B';
243
			} else {
246
			} else {
244
				$cadran = 'C';
247
				$cadran = 'C';
245
			}
248
			}
246
		}
249
		}
247
		return $cadran;
250
		return $cadran;
248
	}
251
	}
249
 
252
 
250
	private static function ajouterFils(&$noeud, $cadran, &$point) {
253
	private static function ajouterFils(&$noeud, $cadran, &$point) {
251
		if(!isset($noeud[$cadran])) {
254
		if(!isset($noeud[$cadran])) {
252
			$noeud[$cadran] = array('points' => array(),'nbrePoints' => 0, 'latMoyenne' => 0, 'lngMoyenne' => 0);
255
			$noeud[$cadran] = array('points' => array(),'nbrePoints' => 0, 'latMoyenne' => 0, 'lngMoyenne' => 0);
253
		}
256
		}
254
		$noeud[$cadran]['points'][] = $point;
257
		$noeud[$cadran]['points'][] = $point;
255
		$noeud[$cadran]['nbrePoints']++;
258
		$noeud[$cadran]['nbrePoints']++;
256
		$noeud[$cadran]['latMoyenne'] += $point['lat'];
259
		$noeud[$cadran]['latMoyenne'] += $point['lat'];
257
		$noeud[$cadran]['lngMoyenne'] += $point['lng'];
260
		$noeud[$cadran]['lngMoyenne'] += $point['lng'];
258
	}
261
	}
259
 
262
 
260
	private static function ajouterGroupeOuPoint(&$noeud) {
263
	private static function ajouterGroupeOuPoint(&$noeud) {
261
		$groupe = array();
264
		$groupe = array();
262
		if ($noeud['nbrePoints'] > 1 && isset($noeud['latMoyenne']) && isset($noeud['lngMoyenne'])) {
265
		if ($noeud['nbrePoints'] > 1 && isset($noeud['latMoyenne']) && isset($noeud['lngMoyenne'])) {
263
			$groupe['lat'] = $noeud['latMoyenne']/$noeud['nbrePoints'];
266
			$groupe['lat'] = $noeud['latMoyenne']/$noeud['nbrePoints'];
264
			$groupe['lng'] = $noeud['lngMoyenne']/$noeud['nbrePoints'];
267
			$groupe['lng'] = $noeud['lngMoyenne']/$noeud['nbrePoints'];
265
			$groupe['id'] = 'GROUPE:'.$groupe['lat'].';'.$groupe['lng'];
268
			$groupe['id'] = 'GROUPE:'.$groupe['lat'].';'.$groupe['lng'];
266
			$groupe['nbreMarqueur'] = $noeud['nbrePoints'];
269
			$groupe['nbreMarqueur'] = $noeud['nbrePoints'];
267
		} else {
270
		} else {
268
			$groupe = $noeud['points'][0];
271
			$groupe = $noeud['points'][0];
269
		}
272
		}
270
		return $groupe;
273
		return $groupe;
271
	}
274
	}
272
 
275
 
273
	private static function estUnParentFeuilles(&$noeud) {
276
	private static function estUnParentFeuilles(&$noeud) {
274
		return  self::estUneFeuille($noeud['A']) &&
277
		return  self::estUneFeuille($noeud['A']) &&
275
				self::estUneFeuille($noeud['B']) &&
278
				self::estUneFeuille($noeud['B']) &&
276
				self::estUneFeuille($noeud['C']) &&
279
				self::estUneFeuille($noeud['C']) &&
277
				self::estUneFeuille($noeud['D']);
280
				self::estUneFeuille($noeud['D']);
278
	}
281
	}
279
 
282
 
280
	private static function estUneFeuille(&$noeud) {
283
	private static function estUneFeuille(&$noeud) {
281
		return $noeud == null ||
284
		return $noeud == null ||
282
		(!isset($noeud['A']) || $noeud['A'] == null) &&
285
		(!isset($noeud['A']) || $noeud['A'] == null) &&
283
		(!isset($noeud['B']) || $noeud['B'] == null) &&
286
		(!isset($noeud['B']) || $noeud['B'] == null) &&
284
		(!isset($noeud['C']) || $noeud['C'] == null) &&
287
		(!isset($noeud['C']) || $noeud['C'] == null) &&
285
		(!isset($noeud['D']) || $noeud['D'] == null);
288
		(!isset($noeud['D']) || $noeud['D'] == null);
286
	}
289
	}
287
}
290
}