1,8 → 1,24 |
<?php |
// declare(encoding='UTF-8'); |
/** |
* Service renvoyant les observations présentent au sein d'un cercle de rayon donné. |
* |
* @internal Mininum PHP version : 5.2 |
* @category CEL |
* @package Services |
* @subpackage Bibliothèques |
* @version 0.1 |
* @author Mathias CHOUET <mathias@tela-botanica.org> |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org> |
* @author Aurelien PERONNET <aurelien@tela-botanica.org> |
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt> |
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt> |
* @copyright 1999-2014 Tela Botanica <accueil@tela-botanica.org> |
*/ |
class CelRadiusPoints extends Cel { |
|
private $champs = array("id_observation", "nom_sel", "latitude", "longitude", "COUNT(id_observation) as nb_obs"); |
private $champs_min = array("latitude", "longitude"); |
private $champs = array('id_observation', 'nom_sel', 'latitude', 'longitude', 'COUNT(id_observation) AS nb_obs'); |
private $champs_min = array('latitude', 'longitude'); |
|
private $champs_mode = null; |
|
18,7 → 34,6 |
* Méthode appelée avec une requête de type GET. |
*/ |
public function getElement($params) { |
|
$lat_centre = str_replace(',', '.', round(floatval($_GET['lat']), 3)); |
$lon_centre = str_replace(',', '.', round(floatval($_GET['lon']), 3)); |
$radius = str_replace(',', '.', floatval($_GET['radius']/1000)); |
29,18 → 44,16 |
if(empty($retour['points'])) { |
$retour['plus_proche'] = $this->obtenirPointPlusProche($lat_centre, $lon_centre); |
} |
|
$this->envoyerJson($retour); |
} |
|
public function obtenirPointsPourCentreEtRadius($lat_centre, $lon_centre, $radius) { |
$requete = "SELECT ". |
implode(", ", $this->champs_mode)." ". |
"FROM cel_obs ". |
"WHERE latitude != 0 AND longitude != 0 ". |
"AND ".$this->renvoyerDistanceSql($lat_centre, $lon_centre)." < ".$radius." ". |
"GROUP BY latitude, longitude "; |
|
$requete = 'SELECT '.implode(', ', $this->champs_mode).' '. |
'FROM cel_obs '. |
'WHERE latitude != 0 AND longitude != 0 '. |
'AND '.$this->renvoyerDistanceSql($lat_centre, $lon_centre)." < $radius ". |
'GROUP BY latitude, longitude '. |
' -- '.__FILE__.':'.__LINE__; |
$points = Cel::db()->requeter($requete); |
return $points; |
} |
49,10 → 62,10 |
$sous_requete = |
"( ". |
"6371 * acos ( ". |
"cos ( radians(".$lat_centre.") ) ". |
"cos ( radians($lat_centre) ) ". |
"* cos( radians( latitude ) ) ". |
"* cos( radians( longitude ) - radians(".$lon_centre.") ) ". |
"+ sin ( radians(".$lat_centre.") ) ". |
"* cos( radians( longitude ) - radians($lon_centre) ) ". |
"+ sin ( radians($lat_centre) ) ". |
"* sin( radians( latitude ) ) ". |
") ". |
") "; |
61,17 → 74,15 |
|
public function obtenirPointPlusProche($lat_centre, $lon_centre) { |
// TODO: faire moins moche et plus efficace |
$requete = "SELECT ". |
$requete = 'SELECT '. |
implode(", ", $this->champs_mode).", ".$this->renvoyerDistanceSql($lat_centre, $lon_centre)." AS distance ". |
"FROM cel_obs ". |
"WHERE latitude != 0 AND longitude != 0 ". |
"GROUP BY latitude, longitude ". |
"ORDER BY distance ". |
"LIMIT 1"; |
|
'FROM cel_obs '. |
'WHERE latitude != 0 AND longitude != 0 '. |
'GROUP BY latitude, longitude '. |
'ORDER BY distance '. |
'LIMIT 1 '. |
' -- '.__FILE__.':'.__LINE__; |
$point = Cel::db()->requeterLigne($requete); |
return $point; |
} |
|
|
} |