61,7 → 61,8 |
*/ |
public function getStations($params) { |
$json = null; |
$requete = 'SELECT sector, x_utm, y_utm, wgs84_latitude AS coord_x, wgs84_longitude AS coord_y '. |
$requete = 'SELECT sector, x_utm, y_utm, wgs84_latitude AS commune_latitude, wgs84_longitude AS commune_longitude, '. |
' coord_x AS point_latitude, coord_y AS point_longitude '. |
'FROM cel_inventory AS i '. |
' LEFT JOIN locations AS l '. |
' ON (l.name = i.location AND l.code = i.id_location) '. |
79,14 → 80,9 |
$resultats = $this->requeter($requete); |
|
// Traitement des résultats |
$obs_nbre = $this->traiterNbreObs($resultats); |
$stations = $this->traiterStations($resultats); |
$json['donnees'] = $this->traiterStations($resultats); |
|
// Création des infos du widget |
$json['donnees']['points'] = $stations; |
$json['donnees']['stats']['communes'] = count($stations); |
$json['donnees']['stats']['observations'] = $obs_nbre; |
|
$json['type'] = (isset($this->formatRetour)) ? $this->formatRetour : 'jsonVar'; |
$json['variable_js'] = 'stations'; |
|
102,24 → 98,44 |
} |
|
private function traiterStations($resultats) { |
$stations = array(); |
$stations = array( |
'stats' => array('stations' => 0, 'communes' => 0, 'observations' => 0), |
'points' => null |
); |
$stations['stats']['observations'] = $this->traiterNbreObs($resultats); |
|
$points = array(); |
if ($resultats !== false) { |
foreach ($resultats as $enrg) { |
if ($enrg['coord_x'] != null && $enrg['coord_y'] != null) { |
$id = $enrg['coord_x'].'-'.$enrg['coord_y']; |
if (!isset($stations[$id])) { |
$enrg['id'] = 'UTM:'.$enrg['x_utm'].'-'.$enrg['y_utm'].'-'.$enrg['sector']; |
unset($enrg['x_utm']); |
unset($enrg['y_utm']); |
unset($enrg['sector']); |
$stations[$id] = $enrg; |
$stations[$id]['nbre'] = 1; |
if (!$this->etreNull($enrg['point_latitude'])&& !$this->etreNull($enrg['point_longitude'])) { |
$lat = $enrg['point_latitude']; |
$lng = $enrg['point_longitude']; |
$id = $lat.'-'.$lng; |
if (!isset($points[$id])) { |
$points[$id]['id'] = "POINT:$lat-$lng"; |
$points[$id]['lat'] = round($lat, 5); |
$points[$id]['lng'] = round($lng, 5); |
$points[$id]['nbre'] = 1; |
$stations['stats']['stations']++; |
} else { |
$stations[$id]['nbre']++; |
$points[$id]['nbre']++; |
} |
} |
} else if (!$this->etreNull($enrg['commune_latitude'])&& !$this->etreNull($enrg['commune_longitude'])) { |
$lat = $enrg['commune_latitude']; |
$lng = $enrg['commune_longitude']; |
$id = $lat.'-'.$lng; |
if (!isset($points[$id])) { |
$points[$id]['id'] = "COMMUNE:$lat-$lng"; |
$points[$id]['lat'] = round($lat, 5); |
$points[$id]['lng'] = round($lng, 5); |
$points[$id]['nbre'] = 1; |
$stations['stats']['communes']++; |
} else { |
$points[$id]['nbre']++; |
} |
} |
} |
$stations = array_values($stations); |
$stations['points'] = array_values($points); |
} |
return $stations; |
} |
328,17 → 344,14 |
// Récupération des coordonnées depuis l'id station |
extract($this->decomposerParametreStation()); |
if (isset($type)) { |
if ($type == 'UTM') { |
$secteur = $this->proteger($secteur); |
$x_utm = $this->proteger($x_utm); |
$y_utm = $this->proteger($y_utm); |
|
$sql = " AND (sector = $secteur AND x_utm = $x_utm AND y_utm = $y_utm ) "; |
} else if ($type == 'LngLat') { |
$coord_x = $this->proteger($coord_x); |
$coord_y = $this->proteger($coord_y); |
|
$sql = " AND (coord_x = $coord_x AND coord_y = $coord_y ) "; |
if ($type == 'COMMUNE') { |
$lat = $this->proteger($lat); |
$lng = $this->proteger($lng); |
$sql = " AND (wgs84_latitude = $lat AND wgs84_longitude = $lng) "; |
} else if ($type == 'POINT') { |
$lat = $this->proteger($lat); |
$lng = $this->proteger($lng); |
$sql = " AND (coord_x = $lat AND coord_y = $lng) "; |
} |
} |
return $sql; |
818,15 → 831,9 |
$station = $this->parametres['station']; |
$this->debug[] = $station; |
list($type, $coord) = explode(':', $station); |
list($lat, $lng) = explode('-', $coord); |
|
if ($type == 'UTM') { |
list($x_utm, $y_utm, $secteur) = explode('-', $coord); |
$station_infos = array('x_utm' => $x_utm, 'y_utm' => $y_utm, 'secteur' => $secteur); |
} else if ($type == 'LngLat') { |
list($coord_y, $coord_x) = explode('-', $coord); |
$station_infos = array('coord_y' => $coord_y, 'coord_x' => $coord_x); |
} |
$station_infos['type'] = $type; |
$station_infos = array('type' => $type, 'lat' => $lat, 'lng' => $lng); |
} |
return $station_infos; |
} |