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);
|
50 |
$points = array($marker);
|
- |
|
51 |
$noeudSimple = array('points' => $points, 'nbrePoints' => 1);
|
- |
|
52 |
self::$nbElements['observations']++;
|
52 |
$points = array($marker);
|
53 |
$emplacement = isset($marker['type_emplacement']) ? $marker['type_emplacement'] : self::obtenirTypeEmplacementParId(&$marker);
|
- |
|
54 |
self::$nbElements[$emplacement]++;
|
53 |
$noeudSimple = array('points' => $points, 'nbrePoints' => 1);
|
55 |
unset($marker['type_emplacement']);
|
54 |
self::$nbElements[$emplacement]++;
|
- |
|
55 |
self::$listeNoeudsSelectionnes[] = self::ajouterGroupeOuPoint($noeudSimple);
|
- |
|
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 91... |
Line 91... |
91 |
public static function getNbElements() {
|
91 |
public static function getNbElements() {
|
92 |
return self::$nbElements;
|
92 |
return self::$nbElements;
|
93 |
}
|
93 |
}
|
Line 94... |
Line 94... |
94 |
|
94 |
|
- |
|
95 |
public static function mettreAJourBornes(&$point) {
|
- |
|
96 |
|
- |
|
97 |
if(!is_numeric($point['lat']) || abs($point['lat']) > 90) return;
|
- |
|
98 |
if(!is_numeric($point['lng']) || abs($point['lng']) > 180) return;
|
95 |
public static function mettreAJourBornes(&$point) {
|
99 |
|
96 |
self::$bornesMax['latMin'] = (is_numeric($point['lat']) && $point['lat'] < self::$bornesMax['latMin'] || self::$bornesMax['latMin'] == null) ? $point['lat'] : self::$bornesMax['latMin'] ;
|
100 |
self::$bornesMax['latMin'] = ($point['lat'] < self::$bornesMax['latMin'] || self::$bornesMax['latMin'] == null) ? $point['lat'] : self::$bornesMax['latMin'] ;
|
97 |
self::$bornesMax['lngMin'] = (is_numeric($point['lng']) && $point['lng'] < self::$bornesMax['lngMin'] || self::$bornesMax['lngMin'] == null) ? $point['lng'] : self::$bornesMax['lngMin'] ;
|
101 |
self::$bornesMax['lngMin'] = ($point['lng'] < self::$bornesMax['lngMin'] || self::$bornesMax['lngMin'] == null) ? $point['lng'] : self::$bornesMax['lngMin'] ;
|
98 |
self::$bornesMax['latMax'] = (is_numeric($point['lat']) && $point['lat'] > self::$bornesMax['latMax'] || self::$bornesMax['latMax'] == null) ? $point['lat'] : self::$bornesMax['latMax'] ;
|
102 |
self::$bornesMax['latMax'] = ($point['lat'] > self::$bornesMax['latMax'] || self::$bornesMax['latMax'] == null) ? $point['lat'] : self::$bornesMax['latMax'] ;
|
99 |
self::$bornesMax['lngMax'] = (is_numeric($point['lng']) && $point['lng'] > self::$bornesMax['lngMax'] || self::$bornesMax['lngMax'] == null) ? $point['lng'] : self::$bornesMax['lngMax'] ;
|
103 |
self::$bornesMax['lngMax'] = ($point['lng'] > self::$bornesMax['lngMax'] || self::$bornesMax['lngMax'] == null) ? $point['lng'] : self::$bornesMax['lngMax'] ;
|
Line 100... |
Line 104... |
100 |
}
|
104 |
}
|
101 |
|
105 |
|
102 |
public static function getBornes() {
|
106 |
public static function getBornes() {
|
Line 116... |
Line 120... |
116 |
|
120 |
|
117 |
$latCentre = round((($neLat+$swLat)/2)/self::$pasCorrectionCentre,0)*self::$pasCorrectionCentre;
|
121 |
$latCentre = round((($neLat+$swLat)/2)/self::$pasCorrectionCentre,0)*self::$pasCorrectionCentre;
|
Line 118... |
Line 122... |
118 |
$lngCentre = round((($neLng+$swLng)/2)/self::$pasCorrectionCentre,0)*self::$pasCorrectionCentre;
|
122 |
$lngCentre = round((($neLng+$swLng)/2)/self::$pasCorrectionCentre,0)*self::$pasCorrectionCentre;
|
- |
|
123 |
|
- |
|
124 |
foreach ($noeud['points'] as &$point) {
|
119 |
|
125 |
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]++;
|
126 |
$emplacement = self::formaterPointPourAjout(&$point);
|
125 |
unset($point['type_emplacement']);
|
127 |
self::mettreAJourBornes(&$point);
|
- |
|
128 |
$cadran = self::obtenirCadranPourPoint($latCentre, $lngCentre, $point);
|
- |
|
129 |
self::ajouterFils($noeud,$cadran,$point);
|
- |
|
130 |
self::$nbElements[$emplacement]++;
|
126 |
$cadran = self::obtenirCadranPourPoint($latCentre, $lngCentre, $point);
|
131 |
}
|
Line 127... |
Line 132... |
127 |
self::ajouterFils($noeud,$cadran,$point);
|
132 |
self::$nbElements['observations']++;
|
Line 128... |
Line 133... |
128 |
}
|
133 |
}
|
Line 139... |
Line 144... |
139 |
if(self::estUnParentFeuilles($noeud)) {
|
144 |
if(self::estUnParentFeuilles($noeud)) {
|
140 |
self::$listeNoeudsSelectionnes[] = self::ajouterGroupeOuPoint($noeud);
|
145 |
self::$listeNoeudsSelectionnes[] = self::ajouterGroupeOuPoint($noeud);
|
141 |
}
|
146 |
}
|
142 |
}
|
147 |
}
|
Line 143... |
Line 148... |
143 |
|
148 |
|
- |
|
149 |
private static function estUnPointAExclure(&$point) {
|
144 |
private static function obtenirTypeEmplacementParId($point) {
|
150 |
return self::estSensible($point) &&
|
- |
|
151 |
self::coordonneesCommuneSontNulles($point);
|
- |
|
152 |
}
|
- |
|
153 |
|
- |
|
154 |
private static function coordonneesCommuneSontNulles(&$point) {
|
145 |
$tableau_point_id = explode(':',$point['id'],2);
|
155 |
$coord_nulles = ($point['wgs84_latitude'] == null ||
|
- |
|
156 |
$point['wgs84_latitude'] == '' ||
|
- |
|
157 |
$point['wgs84_longitude'] == null ||
|
146 |
switch($tableau_point_id[0]) {
|
158 |
$point['wgs84_longitude'] == '');
|
- |
|
159 |
return $coord_nulles;
|
- |
|
160 |
}
|
- |
|
161 |
|
- |
|
162 |
private static function coordonneesSontNulles(&$point) {
|
- |
|
163 |
|
- |
|
164 |
$coord_nulles = ($point['coord_x'] == '000null' ||
|
147 |
case 'STATION':
|
165 |
$point['coord_x'] == '' ||
|
- |
|
166 |
$point['coord_y'] == '000null' ||
|
- |
|
167 |
$point['coord_y'] == '');
|
- |
|
168 |
return $coord_nulles;
|
- |
|
169 |
}
|
- |
|
170 |
|
- |
|
171 |
private static function estSensible(&$point) {
|
148 |
$type_emplacement = 'stations';
|
172 |
$sensible = isset($point['mots_cles_texte']) && substr_count($point['mots_cles_texte'], 'sensible') != 0;
|
- |
|
173 |
return $sensible;
|
- |
|
174 |
}
|
- |
|
175 |
|
149 |
break;
|
176 |
private static function formaterNomStation(&$point) {
|
- |
|
177 |
$station = '';
|
150 |
case 'COMMUNE':
|
178 |
if($point['station'] != '' && $point['station'] != '000null') {
|
151 |
$type_emplacement = 'communes';
|
179 |
$station = $point['station'];
|
- |
|
180 |
} else {
|
- |
|
181 |
$station = $point['location'].(($point['id_location'] != '' && $point['id_location'] != '000null') ? '('.$point['id_location'].')' : '');
|
- |
|
182 |
}
|
- |
|
183 |
|
- |
|
184 |
return $station;
|
- |
|
185 |
}
|
- |
|
186 |
|
- |
|
187 |
private static function formaterPointPourAjout(&$point) {
|
- |
|
188 |
|
- |
|
189 |
if(isset($point['type_emplacement'])) {
|
152 |
break;
|
190 |
return $point['type_emplacement'];
|
- |
|
191 |
}
|
- |
|
192 |
|
- |
|
193 |
if(self::coordonneesSontNulles($point) || self::estSensible($point)) {
|
- |
|
194 |
$point['id'] = self::MARQUEUR_COMMUNE.':'.$point['wgs84_latitude'].'|'.$point['wgs84_longitude'];
|
- |
|
195 |
$point['type_emplacement'] = 'communes';
|
- |
|
196 |
$point['lat'] = (float)$point['wgs84_latitude'];
|
- |
|
197 |
$point['lng'] = (float)$point['wgs84_longitude'];
|
- |
|
198 |
} else {
|
- |
|
199 |
$point_allege = array();
|
- |
|
200 |
$point_allege['id'] = self::MARQUEUR_STATION.':'.$point['coord_x'].'|'.$point['coord_y'];
|
- |
|
201 |
$point_allege['type_emplacement'] = 'stations';
|
- |
|
202 |
$point_allege['nom'] = self::formaterNomStation($point);
|
- |
|
203 |
$point_allege['lat'] = (float)$point['coord_x'];
|
- |
|
204 |
$point_allege['lng'] = (float)$point['coord_y'];
|
- |
|
205 |
|
- |
|
206 |
$point = $point_allege;
|
- |
|
207 |
}
|
153 |
}
|
208 |
|
154 |
return $type_emplacement;
|
209 |
return $point['type_emplacement'];
|
Line 155... |
Line 210... |
155 |
}
|
210 |
}
|
156 |
|
211 |
|
157 |
private function obtenirCadranPourPoint($latCentre,$lngCentre, &$point) {
|
212 |
private function obtenirCadranPourPoint($latCentre,$lngCentre, &$point) {
|
Line 181... |
Line 236... |
181 |
$noeud[$cadran]['lngMoyenne'] += $point['lng'];
|
236 |
$noeud[$cadran]['lngMoyenne'] += $point['lng'];
|
182 |
}
|
237 |
}
|
Line 183... |
Line 238... |
183 |
|
238 |
|
184 |
private static function ajouterGroupeOuPoint(&$noeud) {
|
239 |
private static function ajouterGroupeOuPoint(&$noeud) {
|
185 |
$groupe = array();
|
240 |
$groupe = array();
|
186 |
if ($noeud['nbrePoints'] > 1) {
|
241 |
if ($noeud['nbrePoints'] > 1 && isset($noeud['latMoyenne']) && isset($noeud['lngMoyenne'])) {
|
187 |
$groupe['lat'] = $noeud['latMoyenne']/$noeud['nbrePoints'];
|
242 |
$groupe['lat'] = $noeud['latMoyenne']/$noeud['nbrePoints'];
|
188 |
$groupe['lng'] = $noeud['lngMoyenne']/$noeud['nbrePoints'];
|
243 |
$groupe['lng'] = $noeud['lngMoyenne']/$noeud['nbrePoints'];
|
189 |
$groupe['id'] = 'GROUPE:'.$groupe['lat'].';'.$groupe['lng'];
|
244 |
$groupe['id'] = 'GROUPE:'.$groupe['lat'].';'.$groupe['lng'];
|
190 |
$groupe['nbreMarqueur'] = $noeud['nbrePoints'];
|
245 |
$groupe['nbreMarqueur'] = $noeud['nbrePoints'];
|