Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 1004 Rev 1032
Line 1... Line 1...
1
<?php
1
<?php
2
class CartoGroupage {
2
class CartoGroupage {
Line 3... Line 3...
3
 
3
 
4
	private static $seuilClusterisation = 100;
4
	private static $seuilClusterisation = 200;
5
	private static $zoomDefaut = 3;
5
	private static $zoomDefaut = 3;
6
	private static $zoomMaxClustering = 12;
6
	private static $zoomMaxClustering = 12;
7
	private static $pasZoomDefaut = 1;
7
	private static $pasZoomDefaut = 1;
8
	private static $pasZoomMaxClustering = 0.05;
8
	private static $pasZoomMaxClustering = 0.05;
9
	private static $profondeurMin = 0;
9
	private static $profondeurMin = 0;
10
	private static $profondeurMax = 8;
10
	private static $profondeurMax = 8;
11
 
11
	
12
	private static $pasCorrectionCentre = null;
12
	private static $pasCorrectionCentre = null;
13
	private static $coefficientReductionPas = null;
13
	private static $coefficientReductionPas = null;	
14
	private static $coefficientProfondeurMax = null;
14
	private static $coefficientProfondeurMax = null;
15
 
15
	
Line 16... Line 16...
16
	private static $nbElements = array('stations' => 0,'communes' => 0, 'observations' => 0);
16
	private static $nbElements = array('stations' => 0,'communes' => 0, 'observations' => 0);
17
 
17
 
18
	private static $listeNoeudsSelectionnes = array();
18
	private static $listeNoeudsSelectionnes = array();
Line 19... Line 19...
19
 
19
	
20
	private static $pointsDejaTraites = array();
20
	private static $pointsDejaTraites = array();
21
 
21
 
Line 27... Line 27...
27
	  +---------*---------+
27
	  +---------*---------+
28
	  |         |         |
28
	  |         |         |
29
	  |    D    |    C    |
29
	  |    D    |    C    |
30
	  |         |         |
30
	  |         |         |
31
	  +---------+---------+
31
	  +---------+---------+
32
 
32
	  
33
	  Quatres cadrans sont considérés par le quad tree
33
	  Quatres cadrans sont considérés par le quad tree
34
	  * = centre de la fenetre
34
	  * = centre de la fenetre 
35
	 */
35
	 */
36
	public static function creerGroupesQuadtree(&$markers, $neLat, $neLng, $swLat, $swLng, $zoom = 3) {
36
	public static function creerGroupesQuadtree(&$markers, $neLat, $neLng, $swLat, $swLng, $zoom = 3) {
37
		if (count($markers) > self::$seuilClusterisation) {
37
		if(count($markers) > self::$seuilClusterisation) {
-
 
38
						
38
			self::calculerProfondeurMax($zoom);
39
			self::calculerProfondeurMax($zoom);
39
			self::calculerPasCorrectionCentre($zoom);
40
			self::calculerPasCorrectionCentre($zoom);
Line 40... Line 41...
40
 
41
 
41
			$noeudRacine = array('nbrePoints' => count($markers), 'points' => $markers);
42
			$noeudRacine = array('nbrePoints' => count($markers), 'points' => $markers);
-
 
43
			self::attribuerAuCadran($noeudRacine, $neLat, $neLng, $swLat, $swLng);	
42
			self::attribuerAuCadran($noeudRacine, $neLat, $neLng, $swLat, $swLng);
44
			
43
		} else {
-
 
44
 
45
		} else {
45
			foreach($markers as $marker) {
46
			foreach($markers as $marker) {
46
				$points = array($marker);
47
				$points = array($marker);
47
				$noeudSimple = array('points' => $points, 'nbrePoints' => 1);
48
				$noeudSimple = array('points' => $points, 'nbrePoints' => 1);
48
				self::$listeNoeudsSelectionnes[] = self::ajouterGroupeOuPoint($noeudSimple);
49
				self::$listeNoeudsSelectionnes[] = self::ajouterGroupeOuPoint($noeudSimple);
49
			}
50
			}
50
		}
51
		}
51
 
52
			
52
		return self::$listeNoeudsSelectionnes;
53
		return self::$listeNoeudsSelectionnes;
53
	}
54
	}
54
 
55
	
55
	private function calculerCoefficientReductionPas() {
56
	private function calculerCoefficientReductionPas() {
56
		if(self::$coefficientReductionPas == null) {
57
		if(self::$coefficientReductionPas == null) {
57
			self::$coefficientReductionPas = (self::$pasZoomMaxClustering - self::$pasZoomDefaut)/(self::$zoomMaxClustering - self::$zoomDefaut);
58
			self::$coefficientReductionPas = (self::$pasZoomMaxClustering - self::$pasZoomDefaut)/(self::$zoomMaxClustering - self::$zoomDefaut);
58
		}
59
		}
59
 
60
		
60
		return self::$coefficientReductionPas;
61
		return self::$coefficientReductionPas;
61
	}
62
	}
62
 
63
	
63
	private function calculerPasCorrectionCentre($zoom) {
64
	private function calculerPasCorrectionCentre($zoom) {
64
		self::$pasCorrectionCentre = ($zoom - self::$zoomDefaut) * self::calculerCoefficientReductionPas() + self::$pasZoomDefaut;
65
		self::$pasCorrectionCentre = ($zoom - self::$zoomDefaut) * self::calculerCoefficientReductionPas() + self::$pasZoomDefaut;
65
	}
66
	}
66
 
67
	
67
	private function calculerCoefficientProfondeurMax() {
68
	private function calculerCoefficientProfondeurMax() {
68
		if(self::$coefficientProfondeurMax == null) {
69
		if(self::$coefficientProfondeurMax == null) {
69
			self::$coefficientProfondeurMax = (self::$profondeurMax - self::$profondeurMin)/(self::$zoomMaxClustering - self::$zoomDefaut);
70
			self::$coefficientProfondeurMax = (self::$profondeurMax - self::$profondeurMin)/(self::$zoomMaxClustering - self::$zoomDefaut);
70
		}
71
		}
71
 
72
		
72
		return self::$coefficientProfondeurMax;
73
		return self::$coefficientProfondeurMax;
73
	}
74
	}
74
 
75
	
75
	private function calculerProfondeurMax($zoom) {
76
	private function calculerProfondeurMax($zoom) {	
76
		if($zoom > self::$zoomDefaut) {
77
		if($zoom > self::$zoomDefaut) {	
77
			//self::$profondeurMax = round(($zoom - self::$zoomDefaut) * self::calculerCoefficientProfondeurMax() + self::$profondeurMin,0);
-
 
78
			self::$profondeurMax = $zoom-1;
78
			self::$profondeurMax = round(($zoom - self::$zoomDefaut) * self::calculerCoefficientProfondeurMax() + self::$profondeurMin,0);
79
		} else {
79
		} else {
80
			self::$profondeurMax = 1;
80
			self::$profondeurMax = 1;
81
		}
81
		}
82
	}
82
	}
83
 
83
	
84
	public static function getNbElements() {
84
	public static function getNbElements() {
85
		return self::$nbElements;
85
		return self::$nbElements;
86
	}
86
	}
87
 
87
	
88
	/**
88
	/**
89
	 *
89
	 * 
90
	 * @param mixed $noeud Le noeud à traiter par le quadtree
90
	 * @param mixed $noeud Le noeud à traiter par le quadtree
91
	 * @param float $neLat Latitude du coin nord est de la fenetre
91
	 * @param float $neLat Latitude du coin nord est de la fenetre 
92
	 * @param float $neLng Longitude du coin nord est de la fenetre
92
	 * @param float $neLng Longitude du coin nord est de la fenetre 
93
	 * @param float $swLat Latitude du coin sud ouest de la fenetre
93
	 * @param float $swLat Latitude du coin sud ouest de la fenetre 
94
	 * @param float $swLng Longitude du coin sud ouest de la fenetre
94
	 * @param float $swLng Longitude du coin sud ouest de la fenetre 
95
	 * @param int $profondeur profondeur courante de l'arbre
95
	 * @param int $profondeur profondeur courante de l'arbre
96
	 */
96
	 */
-
 
97
	private static function attribuerAuCadran(&$noeud, $neLat, $neLng, $swLat, $swLng, $profondeur = 0) {
97
	private static function attribuerAuCadran(&$noeud, $neLat, $neLng, $swLat, $swLng, $profondeur = 0) {
98
			
98
		$latCentre = round((($neLat+$swLat)/2)/self::$pasCorrectionCentre,0)*self::$pasCorrectionCentre;
99
		$latCentre = round((($neLat+$swLat)/2)/self::$pasCorrectionCentre,0)*self::$pasCorrectionCentre;
99
		$lngCentre = round((($neLng+$swLng)/2)/self::$pasCorrectionCentre,0)*self::$pasCorrectionCentre;
100
		$lngCentre = round((($neLng+$swLng)/2)/self::$pasCorrectionCentre,0)*self::$pasCorrectionCentre;
100
 
101
						
101
		foreach ($noeud['points'] as &$point) {
102
		foreach ($noeud['points'] as &$point) {
102
				self::$nbElements['observations']++;
103
				self::$nbElements['observations']++;
103
				if (isset($point['type_emplacement'])) {
104
				$emplacement = isset($point['type_emplacement']) ? $point['type_emplacement'] : self::obtenirTypeEmplacementParId(&$point);
104
					self::$nbElements[$point['type_emplacement']]++;
-
 
105
				}
105
				self::$nbElements[$emplacement]++;
106
				unset($point['type_emplacement']);
106
				unset($point['type_emplacement']);
107
				$cadran = self::obtenirCadranPourPoint($latCentre, $lngCentre, $point);
107
				$cadran = self::obtenirCadranPourPoint($latCentre, $lngCentre, $point);
108
				self::ajouterFils($noeud,$cadran,$point);
108
				self::ajouterFils($noeud,$cadran,$point);
109
		}
109
		}
110
 
110
		
111
		$profondeur++;
111
		$profondeur++;
112
 
112
		
113
		if ($profondeur <= self::$profondeurMax) {
113
		if($profondeur <= self::$profondeurMax) {
114
			(isset($noeud['A'])) ? self::attribuerAuCadran($noeud['A'], $neLat, $lngCentre , $latCentre, $swLng, $profondeur) : '';
114
			(isset($noeud['A']) && $noeud['A'] != null) ? self::attribuerAuCadran($noeud['A'], $neLat, $lngCentre , $latCentre, $swLng, $profondeur) : '';
115
			(isset($noeud['B'])) ? self::attribuerAuCadran($noeud['B'], $neLat, $neLng, $latCentre, $lngCentre, $profondeur) : '';
115
			(isset($noeud['B']) && $noeud['B'] != null) ? self::attribuerAuCadran($noeud['B'], $neLat, $neLng, $latCentre, $lngCentre, $profondeur) : '';
116
			(isset($noeud['C'])) ? self::attribuerAuCadran($noeud['C'], $latCentre, $neLng, $swLat, $lngCentre, $profondeur) : '';
116
			(isset($noeud['C']) && $noeud['C'] != null) ? self::attribuerAuCadran($noeud['C'], $latCentre, $neLng, $swLat, $lngCentre, $profondeur) : '';
117
			(isset($noeud['D'])) ? self::attribuerAuCadran($noeud['D'], $latCentre, $lngCentre, $swLat, $swLng, $profondeur) : '';
117
			(isset($noeud['D']) && $noeud['D'] != null) ? self::attribuerAuCadran($noeud['D'], $latCentre, $lngCentre, $swLat, $swLng, $profondeur) : '';
118
		}
118
		}
119
 
119
		
120
		if(self::estUnParentFeuilles($noeud)) {
120
		if(self::estUnParentFeuilles($noeud)) {
121
			self::$listeNoeudsSelectionnes[] = self::ajouterGroupeOuPoint($noeud);
121
			self::$listeNoeudsSelectionnes[] = self::ajouterGroupeOuPoint($noeud);
122
		}
122
		}
123
	}
123
	}
-
 
124
	
-
 
125
	private static function obtenirTypeEmplacementParId($point) {
-
 
126
		$tableau_point_id = explode(':',$point['id'],2);
-
 
127
		switch($tableau_point_id[0]) {
-
 
128
			case 'STATION':
-
 
129
				$type_emplacement = 'stations';
-
 
130
			break;
-
 
131
			case 'COMMUNE':
-
 
132
				$type_emplacement = 'communes';
-
 
133
			break;
-
 
134
		}
-
 
135
		return $type_emplacement;
-
 
136
	}
124
 
137
	
125
	private function obtenirCadranPourPoint($latCentre,$lngCentre, &$point) {
138
	private function obtenirCadranPourPoint($latCentre,$lngCentre, &$point) {
126
		if ($point['lng'] < $lngCentre) {
139
		if ($point['lng'] < $lngCentre) {
127
			if ($point['lat'] > $latCentre) {
140
			if ($point['lat'] > $latCentre) {
128
					$cadran = 'A';
141
					$cadran = 'A';
Line 133... Line 146...
133
			if ($point['lat'] > $latCentre) {
146
			if ($point['lat'] > $latCentre) {
134
				$cadran = 'B';
147
				$cadran = 'B';
135
			} else {
148
			} else {
136
				$cadran = 'C';
149
				$cadran = 'C';
137
			}
150
			}
138
		}
151
		}		
139
		return $cadran;
152
		return $cadran;
140
	}
153
	}
141
 
154
	
142
	private static function ajouterFils(&$noeud, $cadran, &$point) {
155
	private static function ajouterFils(&$noeud, $cadran, &$point) {
143
		$fils = array('points' => array(), 'nbrePoints' => 0, 'latMoyenne' => 0, 'lngMoyenne' => 0);
-
 
144
		if (isset($noeud[$cadran])) {
156
		if(!isset($noeud[$cadran])) {
145
			$fils = $noeud[$cadran];
157
			$noeud[$cadran] = array('points' => array(),'nbrePoints' => 0, 'latMoyenne' => 0, 'lngMoyenne' => 0);
146
		}
158
		}	
147
 
-
 
148
		$fils['points'][] = $point;
159
		$noeud[$cadran]['points'][] = $point;
149
		$fils['nbrePoints']++;
160
		$noeud[$cadran]['nbrePoints']++;
150
		$fils['latMoyenne'] += $point['lat'];
161
		$noeud[$cadran]['latMoyenne'] += $point['lat'];
151
		$fils['lngMoyenne'] += $point['lng'];
162
		$noeud[$cadran]['lngMoyenne'] += $point['lng'];
152
		$noeud[$cadran] = $fils;
-
 
153
	}
163
	}
154
 
164
	
155
	private static function ajouterGroupeOuPoint(&$noeud) {
165
	private static function ajouterGroupeOuPoint(&$noeud) {
156
		$groupe = array();
166
		$groupe = array();
157
		if ($noeud['nbrePoints'] > 1) {
167
		if ($noeud['nbrePoints'] > 1) {
158
			$groupe['lat'] = $noeud['latMoyenne']/$noeud['nbrePoints'];
168
			$groupe['lat'] = $noeud['latMoyenne']/$noeud['nbrePoints'];
159
			$groupe['lng'] = $noeud['lngMoyenne']/$noeud['nbrePoints'];
169
			$groupe['lng'] = $noeud['lngMoyenne']/$noeud['nbrePoints'];
Line 162... Line 172...
162
		} else {
172
		} else {
163
			$groupe = $noeud['points'][0];
173
			$groupe = $noeud['points'][0];
164
		}
174
		}
165
		return $groupe;
175
		return $groupe;
166
	}
176
	}
167
 
177
	
168
	private static function estUnParentFeuilles(&$noeud) {
178
	private static function estUnParentFeuilles(&$noeud) {
169
		return  self::estUneFeuille($noeud['A']) &&
179
		return  self::estUneFeuille($noeud['A']) && 
170
				self::estUneFeuille($noeud['B']) &&
180
				self::estUneFeuille($noeud['B']) && 
171
				self::estUneFeuille($noeud['C']) &&
181
				self::estUneFeuille($noeud['C']) && 
172
				self::estUneFeuille($noeud['D']);
182
				self::estUneFeuille($noeud['D']);
173
	}
183
	}
174
 
184
	
175
	private static function estUneFeuille(&$noeud) {
185
	private static function estUneFeuille(&$noeud) {		
-
 
186
		return $noeud == null || 
176
		return $noeud == null || (!isset($noeud['A']) && !isset($noeud['B']) && !isset($noeud['C']) && !isset($noeud['D']));
187
		(!isset($noeud['A']) || $noeud['A'] == null) && 
-
 
188
		(!isset($noeud['B']) || $noeud['B'] == null) && 
-
 
189
		(!isset($noeud['C']) || $noeud['C'] == null) && 
-
 
190
		(!isset($noeud['D']) || $noeud['D'] == null);
177
	}
191
	}
178
}
192
}
179
?>
193
?>
180
194