| Line 1... |
Line 1... |
| 1 |
<?php
|
1 |
<?php
|
| 2 |
class CartoGroupage {
|
2 |
class CartoGroupage {
|
| Line -... |
Line 3... |
| - |
|
3 |
|
| - |
|
4 |
const MARQUEUR_GROUPE = 'GROUPE';
|
| - |
|
5 |
const MARQUEUR_COMMUNE = 'COMMUNE';
|
| - |
|
6 |
const MARQUEUR_STATION = 'STATION';
|
| 3 |
|
7 |
|
| 4 |
private static $seuilClusterisation = 200;
|
8 |
private static $seuilClusterisation = 200;
|
| 5 |
private static $zoomDefaut = 3;
|
9 |
private static $zoomDefaut = 3;
|
| 6 |
private static $zoomMaxClustering = 12;
|
10 |
private static $zoomMaxClustering = 12;
|
| 7 |
private static $pasZoomDefaut = 1;
|
11 |
private static $pasZoomDefaut = 1;
|
| Line 12... |
Line 16... |
| 12 |
private static $pasCorrectionCentre = null;
|
16 |
private static $pasCorrectionCentre = null;
|
| 13 |
private static $coefficientReductionPas = null;
|
17 |
private static $coefficientReductionPas = null;
|
| 14 |
private static $coefficientProfondeurMax = null;
|
18 |
private static $coefficientProfondeurMax = null;
|
| Line 15... |
Line 19... |
| 15 |
|
19 |
|
| 16 |
private static $nbElements = array('stations' => 0,'communes' => 0, 'observations' => 0);
|
- |
|
| 17 |
|
20 |
private static $nbElements = array('stations' => 0,'communes' => 0, 'observations' => 0);
|
| 18 |
private static $listeNoeudsSelectionnes = array();
|
- |
|
| 19 |
|
- |
|
| 20 |
private static $pointsDejaTraites = array();
|
- |
|
| 21 |
|
21 |
private static $listeNoeudsSelectionnes = array();
|
| 22 |
private static $bornesMax = array('latMin' => null, 'lngMin' => null, 'latMax' => null, 'lngMax' => null);
|
- |
|
| - |
|
22 |
private static $bornesMax = array('latMin' => null, 'lngMin' => null, 'latMax' => null, 'lngMax' => null);
|
| 23 |
|
23 |
private static $id_traites = array();
|
| 24 |
/*
|
24 |
/*
|
| 25 |
+---------+---------+
|
25 |
+---------+---------+
|
| 26 |
| | |
|
26 |
| | |
|
| 27 |
| A | B |
|
27 |
| A | B |
|
| Line 43... |
Line 43... |
| 43 |
|
43 |
|
| 44 |
$noeudRacine = array('nbrePoints' => count($markers), 'points' => $markers);
|
44 |
$noeudRacine = array('nbrePoints' => count($markers), 'points' => $markers);
|
| Line 45... |
Line 45... |
| 45 |
self::attribuerAuCadran($noeudRacine, $neLat, $neLng, $swLat, $swLng);
|
45 |
self::attribuerAuCadran($noeudRacine, $neLat, $neLng, $swLat, $swLng);
|
| 46 |
|
46 |
|
| - |
|
47 |
} else {
|
| - |
|
48 |
foreach($markers as &$marker) {
|
| 47 |
} else {
|
49 |
if(!self::estUnPointAExclure($marker)) {
|
| 48 |
foreach($markers as $marker) {
|
50 |
$emplacement = self::formaterPointPourAjout(&$marker);
|
| 49 |
self::mettreAJourBornes(&$marker);
|
51 |
self::mettreAJourBornes(&$marker);
|
| - |
|
52 |
$points = array($marker);
|
| - |
|
53 |
$noeudSimple = array('points' => $points, 'nbrePoints' => 1);
|
| - |
|
54 |
self::$nbElements[$emplacement]++;
|
| 50 |
$points = array($marker);
|
55 |
self::$listeNoeudsSelectionnes[] = self::ajouterGroupeOuPoint($noeudSimple);
|
| 51 |
$noeudSimple = array('points' => $points, 'nbrePoints' => 1);
|
- |
|
| 52 |
self::$nbElements['observations']++;
|
- |
|
| 53 |
$emplacement = isset($marker['type_emplacement']) ? $marker['type_emplacement'] : self::obtenirTypeEmplacementParId(&$marker);
|
- |
|
| 54 |
self::$nbElements[$emplacement]++;
|
- |
|
| 55 |
unset($marker['type_emplacement']);
|
56 |
}
|
| 56 |
self::$listeNoeudsSelectionnes[] = self::ajouterGroupeOuPoint($noeudSimple);
|
57 |
self::$nbElements['observations']++;
|
| 57 |
}
|
- |
|
| 58 |
}
|
58 |
}
|
| 59 |
|
59 |
}
|
| Line 60... |
Line 60... |
| 60 |
return self::$listeNoeudsSelectionnes;
|
60 |
return self::$listeNoeudsSelectionnes;
|
| 61 |
}
|
61 |
}
|
| Line 115... |
Line 115... |
| 115 |
private static function attribuerAuCadran(&$noeud, $neLat, $neLng, $swLat, $swLng, $profondeur = 0) {
|
115 |
private static function attribuerAuCadran(&$noeud, $neLat, $neLng, $swLat, $swLng, $profondeur = 0) {
|
| Line 116... |
Line 116... |
| 116 |
|
116 |
|
| 117 |
$latCentre = round((($neLat+$swLat)/2)/self::$pasCorrectionCentre,0)*self::$pasCorrectionCentre;
|
117 |
$latCentre = round((($neLat+$swLat)/2)/self::$pasCorrectionCentre,0)*self::$pasCorrectionCentre;
|
| Line 118... |
Line 118... |
| 118 |
$lngCentre = round((($neLng+$swLng)/2)/self::$pasCorrectionCentre,0)*self::$pasCorrectionCentre;
|
118 |
$lngCentre = round((($neLng+$swLng)/2)/self::$pasCorrectionCentre,0)*self::$pasCorrectionCentre;
|
| - |
|
119 |
|
| - |
|
120 |
foreach ($noeud['points'] as &$point) {
|
| 119 |
|
121 |
if(!self::estUnPointAExclure($point)) {
|
| 120 |
foreach ($noeud['points'] as &$point) {
|
- |
|
| 121 |
self::mettreAJourBornes(&$point);
|
- |
|
| 122 |
self::$nbElements['observations']++;
|
- |
|
| 123 |
$emplacement = isset($point['type_emplacement']) ? $point['type_emplacement'] : self::obtenirTypeEmplacementParId(&$point);
|
- |
|
| 124 |
self::$nbElements[$emplacement]++;
|
122 |
$emplacement = self::formaterPointPourAjout(&$point);
|
| 125 |
unset($point['type_emplacement']);
|
123 |
self::mettreAJourBornes(&$point);
|
| - |
|
124 |
$cadran = self::obtenirCadranPourPoint($latCentre, $lngCentre, $point);
|
| - |
|
125 |
self::ajouterFils($noeud,$cadran,$point);
|
| - |
|
126 |
self::$nbElements[$emplacement]++;
|
| 126 |
$cadran = self::obtenirCadranPourPoint($latCentre, $lngCentre, $point);
|
127 |
}
|
| Line 127... |
Line 128... |
| 127 |
self::ajouterFils($noeud,$cadran,$point);
|
128 |
self::$nbElements['observations']++;
|
| Line 128... |
Line 129... |
| 128 |
}
|
129 |
}
|
| Line 139... |
Line 140... |
| 139 |
if(self::estUnParentFeuilles($noeud)) {
|
140 |
if(self::estUnParentFeuilles($noeud)) {
|
| 140 |
self::$listeNoeudsSelectionnes[] = self::ajouterGroupeOuPoint($noeud);
|
141 |
self::$listeNoeudsSelectionnes[] = self::ajouterGroupeOuPoint($noeud);
|
| 141 |
}
|
142 |
}
|
| 142 |
}
|
143 |
}
|
| Line 143... |
Line 144... |
| 143 |
|
144 |
|
| - |
|
145 |
private static function estUnPointAExclure(&$point) {
|
| 144 |
private static function obtenirTypeEmplacementParId($point) {
|
146 |
return self::estSensible($point) &&
|
| - |
|
147 |
self::coordonneesCommuneSontNulles($point);
|
| - |
|
148 |
}
|
| - |
|
149 |
|
| - |
|
150 |
private static function coordonneesCommuneSontNulles(&$point) {
|
| 145 |
$tableau_point_id = explode(':',$point['id'],2);
|
151 |
$coord_nulles = ($point['wgs84_latitude'] == null ||
|
| - |
|
152 |
$point['wgs84_latitude'] == '' ||
|
| - |
|
153 |
$point['wgs84_longitude'] == null ||
|
| 146 |
switch($tableau_point_id[0]) {
|
154 |
$point['wgs84_longitude'] == '');
|
| - |
|
155 |
return $coord_nulles;
|
| - |
|
156 |
}
|
| - |
|
157 |
|
| - |
|
158 |
private static function coordonneesSontNulles(&$point) {
|
| - |
|
159 |
|
| - |
|
160 |
$coord_nulles = ($point['coord_x'] == '000null' ||
|
| 147 |
case 'STATION':
|
161 |
$point['coord_x'] == '' ||
|
| - |
|
162 |
$point['coord_y'] == '000null' ||
|
| - |
|
163 |
$point['coord_y'] == '');
|
| - |
|
164 |
return $coord_nulles;
|
| - |
|
165 |
}
|
| - |
|
166 |
|
| - |
|
167 |
private static function estSensible(&$point) {
|
| 148 |
$type_emplacement = 'stations';
|
168 |
$sensible = isset($point['mots_cles_texte']) && substr_count($point['mots_cles_texte'], 'sensible') != 0;
|
| - |
|
169 |
return $sensible;
|
| - |
|
170 |
}
|
| - |
|
171 |
|
| 149 |
break;
|
172 |
private static function formaterNomStation(&$point) {
|
| - |
|
173 |
$station = '';
|
| 150 |
case 'COMMUNE':
|
174 |
if($point['station'] != '' && $point['station'] != '000null') {
|
| 151 |
$type_emplacement = 'communes';
|
175 |
$station = $point['station'];
|
| - |
|
176 |
} else {
|
| - |
|
177 |
$station = $point['location'].(($point['id_location'] != '' && $point['id_location'] != '000null') ? '('.$point['id_location'].')' : '');
|
| - |
|
178 |
}
|
| - |
|
179 |
|
| - |
|
180 |
return $station;
|
| - |
|
181 |
}
|
| - |
|
182 |
|
| - |
|
183 |
private static function formaterPointPourAjout(&$point) {
|
| - |
|
184 |
|
| - |
|
185 |
if(isset($point['type_emplacement'])) {
|
| 152 |
break;
|
186 |
return $point['type_emplacement'];
|
| - |
|
187 |
}
|
| - |
|
188 |
|
| - |
|
189 |
if(self::coordonneesSontNulles($point) || self::estSensible($point)) {
|
| - |
|
190 |
$point['id'] = self::MARQUEUR_COMMUNE.':'.$point['wgs84_latitude'].'|'.$point['wgs84_longitude'];
|
| - |
|
191 |
$point['type_emplacement'] = 'communes';
|
| - |
|
192 |
$point['lat'] = (float)$point['wgs84_latitude'];
|
| - |
|
193 |
$point['lng'] = (float)$point['wgs84_longitude'];
|
| - |
|
194 |
} else {
|
| - |
|
195 |
$point_allege = array();
|
| - |
|
196 |
$point_allege['id'] = self::MARQUEUR_STATION.':'.$point['coord_x'].'|'.$point['coord_y'];
|
| - |
|
197 |
$point_allege['type_emplacement'] = 'stations';
|
| - |
|
198 |
$point_allege['nom'] = self::formaterNomStation($point);
|
| - |
|
199 |
$point_allege['lat'] = (float)$point['coord_x'];
|
| - |
|
200 |
$point_allege['lng'] = (float)$point['coord_y'];
|
| - |
|
201 |
|
| - |
|
202 |
$point = $point_allege;
|
| - |
|
203 |
}
|
| 153 |
}
|
204 |
|
| 154 |
return $type_emplacement;
|
205 |
return $point['type_emplacement'];
|
| Line 155... |
Line 206... |
| 155 |
}
|
206 |
}
|
| 156 |
|
207 |
|
| 157 |
private function obtenirCadranPourPoint($latCentre,$lngCentre, &$point) {
|
208 |
private function obtenirCadranPourPoint($latCentre,$lngCentre, &$point) {
|
| Line 181... |
Line 232... |
| 181 |
$noeud[$cadran]['lngMoyenne'] += $point['lng'];
|
232 |
$noeud[$cadran]['lngMoyenne'] += $point['lng'];
|
| 182 |
}
|
233 |
}
|
| Line 183... |
Line 234... |
| 183 |
|
234 |
|
| 184 |
private static function ajouterGroupeOuPoint(&$noeud) {
|
235 |
private static function ajouterGroupeOuPoint(&$noeud) {
|
| 185 |
$groupe = array();
|
236 |
$groupe = array();
|
| 186 |
if ($noeud['nbrePoints'] > 1) {
|
237 |
if ($noeud['nbrePoints'] > 1 && isset($noeud['latMoyenne']) && isset($noeud['lngMoyenne'])) {
|
| 187 |
$groupe['lat'] = $noeud['latMoyenne']/$noeud['nbrePoints'];
|
238 |
$groupe['lat'] = $noeud['latMoyenne']/$noeud['nbrePoints'];
|
| 188 |
$groupe['lng'] = $noeud['lngMoyenne']/$noeud['nbrePoints'];
|
239 |
$groupe['lng'] = $noeud['lngMoyenne']/$noeud['nbrePoints'];
|
| 189 |
$groupe['id'] = 'GROUPE:'.$groupe['lat'].';'.$groupe['lng'];
|
240 |
$groupe['id'] = 'GROUPE:'.$groupe['lat'].';'.$groupe['lng'];
|
| 190 |
$groupe['nbreMarqueur'] = $noeud['nbrePoints'];
|
241 |
$groupe['nbreMarqueur'] = $noeud['nbrePoints'];
|