Subversion Repositories eFlore/Applications.moissonnage

Compare Revisions

Ignore whitespace Rev 34 → Rev 31

/trunk/services/bibliotheque/EnteteHttp.php
File deleted
\ No newline at end of file
/trunk/services/bibliotheque/FormateurWfs.php
File deleted
\ No newline at end of file
/trunk/services/bibliotheque/ResultatService.php
File deleted
\ No newline at end of file
/trunk/services/bibliotheque/squelettes/GetCapabilities.tpl.xml
File deleted
\ No newline at end of file
/trunk/services/bibliotheque/squelettes/GetFeature.tpl.xml
File deleted
/trunk/services/bibliotheque/squelettes/DescribeFeatureType.tpl.xml
File deleted
\ No newline at end of file
/trunk/services/bibliotheque/squelettes/Exception.tpl.xml
File deleted
\ No newline at end of file
/trunk/services/bibliotheque/Maille.php
9,8 → 9,10
private $indexLatitude;
private $indexLongitude;
private $stations = array();
private $points = array();
private $nombrePoints;
private $observations = array();
private $nombreObservations;
public function __construct($sud, $ouest, $nord, $est, $indexLat, $indexLng) {
22,14 → 24,11
$this->indexLongitude = $indexLng;
}
public function ajouterStation($station, $source) {
if (!array_key_exists($source, $this->stations)) {
$this->stations[$source] = 1;
$this->observations[$source] = $station['observations'];
} else {
$this->stations[$source] += 1;
$this->observations[$source] += intval($station['observations']);
}
public function ajouterPoint($point) {
$this->points[] = $point;
$this->nombrePoints ++;
$this->observations[] = $point['observations'];
$this->nombreObservations += $point['observations'];
}
public function getLatitudeNord() {
56,12 → 55,12
return $this->indexLongitude;
}
public function getStations() {
return $this->stations;
public function getPoints() {
return $this->points;
}
public function getNombreStations() {
return count($this->stations);
public function getNombrePoints() {
return $this->nombrePoints;
}
public function getObservations() {
68,28 → 67,19
return $this->observations;
}
public function combinerMailles($maille, $sourceReference) {
if (is_array($maille['stations'])) {
foreach ($maille['stations'] as $source => $nombreStations) {
if (!array_key_exists($source, $this->stations)) {
$this->stations[$source] = $nombreStations;
$this->observations[$source] = $maille['observations'][$source];
} else {
$this->stations[$source] += $nombreStations;
$this->observations[$source] += $maille['observations'][$source];
}
}
} else {
if (!array_key_exists($sourceReference, $this->stations)) {
$this->stations[$sourceReference] = $maille['stations'];
$this->observations[$sourceReference] = $maille['observations'];
} else {
$this->stations[$sourceReference] += $maille['stations'];
$this->observations[$sourceReference] += $maille['observations'];
}
}
public function getNombreObservations() {
return $this->nombreObservations;
}
 
public function totalNonNul() {
return count($this->points) > 0;
}
public function combinerMailles(& $maille) {
$this->nombrePoints += $maille->nombre_sites;
$this->nombreObservations += $maille->nombre_observations;
}
}
 
?>
/trunk/services/bibliotheque/Referentiel.php
39,7 → 39,6
private $nomCourt;
private $taxon;
private $bdd = null;
private $nomsChampsBdtfx = array('nn' => 'num_nom_retenu', 'nt' => 'num_taxonomique', 'ns' => 'nom_sci');
private $nomsChampsBdtxa = array('nn' => 'num_nom_retenu', 'nt' => 'num_tax', 'ns' => 'nom_sci');
private $champs;
88,30 → 87,46
if (is_null($this->bdd)) {
$this->bdd = new Bdd();
}
$nomBdd = Config::get('bdd_nom');
$nomBdd = Config::get('bdd_eflore');
if (is_null($nomBdd)) {
$nomBdd = Config::get('bdd_nom');
}
$this->bdd->requeter("USE ".$nomBdd);
return $this->bdd;
}
public function recupererSynonymesEtSousEspeces() {
public function recupererTaxonsSousEspeces($listeNn = null) {
$sousTaxons = array();
if (!is_null($this->taxon) && $this->taxon['rang'] >= Config::get('rang.espece')) {
if (!is_null($this->taxon) && $this->taxon['rang'] == Config::get('rang.espece')) {
if (is_null($listeNn)) {
$listeNn = $this->taxon['nn'];
}
$requete =
"SELECT ".$this->champs['nn']." AS nn, ".$this->champs['nt']." AS nt, ".
$this->champs['ns']." AS nom, rang FROM ".$this->nomComplet. " WHERE ".
$this->champs['nt']."=".$this->taxon['nt']." OR hierarchie LIKE '%-".$this->champs['nn']."-%'";
$sousTaxons = $this->getBdd()->recupererTous($requete);
"SELECT ".$this->champs['nn']." AS nn, ".$this->champs['nt']." AS nt, ".
$this->champs['ns']." AS nom, rang FROM ".$this->nomComplet." WHERE ".
"num_tax_sup IN ({$listeNn}) AND num_nom=".$this->champs['nn'];
$resultats = $this->getBdd()->recupererTous($requete);
$nouvelleListeNn = '';
foreach ($resultats as $sousTaxon) {
$sousTaxons[] = $sousTaxon;
$nouvelleListeNn .= (strlen($nouvelleListeNn) == 0 ? '' : ',') . $sousTaxon['nn'];
}
// recherche de sous taxons au niveau inferieur (parcours recursif de la methode)
if (count($resultats) > 0) {
$sousTaxons = array_merge($sousTaxons, $this->recupererTaxonsSousEspeces($nouvelleListeNn));
}
}
return $sousTaxons;
}
public function recupererGenres() {
public function recupererTaxonsFamilles() {
$sousTaxons = array();
if (!is_null($this->taxon) && $this->taxon['rang'] == Config::get('rang.famille')) {
if (!is_null($this->taxon) && $this->taxon['rang'] == Config::get('rang.genre')) {
$requete =
"SELECT ".$this->champs['nn']." AS nn, ".$this->champs['nt']." AS nt, ".
$this->champs['ns']." AS nom, rang FROM ".$this->nomComplet. " WHERE ".
"num_tax_sup=".$this->taxon['nn']." AND num_nom=".$this->champs['nn'];
"SELECT ".$this->champs['nn']." AS nn, ".$this->champs['nt']." AS nt, ".
$this->champs['ns']." AS nom, rang FROM ".$this->nomComplet." WHERE ".
"num_tax_sup=".$this->taxon['nn']." AND num_nom=".$this->champs['nn'];
$sousTaxons = $this->getBdd()->recupererTous($requete);
}
return $sousTaxons;
134,13 → 149,10
return $tableau;
}
public function obtenirNumeroNomenclatural($nomScientifique, $numeroNomenclatural = null) {
public function obtenirNumeroNomenclatural($nomScientifique) {
$aProteger = $this->getBdd()->proteger(trim($nomScientifique) . '%');
$requete = "SELECT ".$this->champs['nn']." AS nn FROM ".$this->nomComplet." ".
"WHERE ".$this->champs['ns']." LIKE ".$aProteger;
if (!is_null($numeroNomenclatural) || strlen($numeroNomenclatural) > 0) {
$requete .= " OR ".$this->champs['nn']."={$numeroNomenclatural}";
}
$taxon = $this->getBdd()->recuperer($requete);
if ($taxon == false) {
$taxon = null;
151,5 → 163,4
}
}
 
?>
/trunk/services/bibliotheque/Maillage.php
3,47 → 3,40
 
class Maillage {
private $bbox = array();
private $zoom = '';
private $source = '';
private $bbox;
private $zoom;
private $indexLongitude = array();
private $indexLatitude = array();
private $mailles = array();
private $indexLongitude;
private $indexLatitude;
private $mailles;
private $bdd = null;
public function __construct($bbox, $zoom, $source) {
$this->bbox = $this->calculerLimiteBboxGlobale($bbox);
$this->zoom = $zoom;
$this->source = $source;
public function __construct($bbox, $zoom) {
$this->bbox = $bbox;
$this->zoom = $zoom;
$this->indexLongitude = array();
$this->indexLatitude = array();
$this->indexLatitude = array();
$this->mailles = array();
}
private function calculerLimiteBboxGlobale($bbox) {
$bboxGlobale = $bbox[0];
for ($index = 1; $index < count($bbox); $index ++) {
if ($bbox[$index]['ouest'] < $bboxGlobale['ouest']) {
$bboxGlobale['ouest'] = $bbox[$index]['ouest'];
}
if ($bbox[$index]['sud'] < $bboxGlobale['sud']) {
$bboxGlobale['sud'] = $bbox[$index]['sud'];
}
if ($bbox[$index]['est'] > $bboxGlobale['est']) {
$bboxGlobale['est'] = $bbox[$index]['est'];
}
if ($bbox[$index]['nord'] > $bboxGlobale['nord']) {
$bboxGlobale['nord'] = $bbox[$index]['nord'];
}
public function __destruct() {
while (count($this->indexLatitude) > 0) {
array_pop($this->indexLatitude);
}
return $bboxGlobale;
while (count($this->indexLongitude) > 0) {
array_pop($this->indexLongitude);
}
while (count($this->mailles) > 0) {
array_pop($this->mailles);
}
unset($this);
}
public function genererMaillesVides() {
$this->recupererIndexMaillesDansBbox();
foreach ($this->indexLatitude as $indexLat => $intervalleLat) {
58,6 → 51,7
private function recupererIndexMaillesDansBbox() {
// recuperer toutes les mailles qui couvrent l'espace a requeter
$conditionsLongitude = "";
if ($this->bbox['ouest'] > $this->bbox['est']) {
$conditionsLongitude = "NOT(debut>=".$this->bbox['ouest']." AND fin<=".$this->bbox['est'].")";
72,6 → 66,7
") ORDER BY axe, position";
$indexMailles = $this->getBdd()->recupererTous($requete);
foreach ($indexMailles as $index) {
if ($index['axe'] == 'lng') {
$this->indexLongitude[$index['position']] = array($index['debut'], $index['fin']);
79,36 → 74,51
$this->indexLatitude[$index['position']] = array($index['debut'], $index['fin']);
}
}
}
}
private function getBdd() {
if (is_null($this->bdd)) {
$this->bdd = new Bdd();
}
$nomBdd = Config::get('bdd_nom_eflore');
$nomBdd = Config::get('bdd_eflore');
if (is_null($nomBdd)) {
$nomBdd = Config::get('bdd_nom');
}
$this->bdd->requeter("USE ".$nomBdd);
return $this->bdd;
}
public function ajouterStations(& $stations) {
foreach ($stations as $station) {
$longitude = $station['longitude'];
$latitude = $station['latitude'];
public function ajouterPoints(& $points) {
foreach ($points as $point) {
list($longitude, $latitude) = $this->obtenirCoordonneesPoint($point);
list($indexLongitude, $indexLatitude) = $this->rechercherIndexMaille($longitude, $latitude);
$this->mailles[$indexLatitude][$indexLongitude]->ajouterStation($station, $this->source);
$this->mailles[$indexLatitude][$indexLongitude]->ajouterPoint($point);
}
}
public function ajouterMailles(& $mailles) {
foreach ($mailles as $maille) {
$longitude = ($maille['ouest'] + $maille['est']) / 2;
$latitude = ($maille['sud'] + $maille['nord']) / 2;
$longitude = ($maille->longitudeOuest + $maille->longitudeEst) / 2;
$latitude = ($maille->latitudeSud + $maille->latitudeNord) / 2;
list($indexLongitude, $indexLatitude) = $this->rechercherIndexMaille($longitude, $latitude);
$this->mailles[$indexLatitude][$indexLongitude]->combinerMailles($maille, $this->source);
$this->mailles[$indexLatitude][$indexLongitude]->combinerMailles($maille);
}
}
private function obtenirCoordonneesPoint($point) {
$longitude = 0;
$latitude = 0;
if (!isset($point['type_site']) || $point['type_site'] == 'STATION') {
$longitude = $point['longitude'];
$latitude = $point['latitude'];
} else {
$longitude = $point['lng_commune'];
$latitude = $point['lat_commune'];
}
return array($longitude, $latitude);
}
private function rechercherIndexMaille($longitude, $latitude) {
$indexLatitude = 0;
$indexLongitude = 0;
118,25 → 128,26
}
while ($indexLongitude < count($this->indexLongitude) - 1
&& $this->mailles[$indexLatitude][$indexLongitude]->getLongitudeEst() < $longitude) {
$indexLongitude ++;
$indexLongitude ++;
}
return array($indexLongitude, $indexLatitude);
}
 
public function formaterSortie() {
public function formaterSortie($toutesLesMailles = false) {
$mailles_resume = array();
foreach ($this->mailles as $ligne) {
foreach ($ligne as $maille) {
$nombreStations = $maille->getNombrestations();
if ($nombreStations > 0) {
$nombrePoints = $maille->getNombrePoints();
if ($nombrePoints > 0 || $toutesLesMailles) {
$mailles_resume[] = array(
'type_site' => 'MAILLE',
'zoom' => $this->zoom,
'sud' => $maille->getLatitudeSud(),
'ouest' => $maille->getLongitudeOuest(),
'nord' => $maille->getLatitudeNord(),
'est' => $maille->getLongitudeEst(),
'stations' => $maille->getStations(),
'observations' => $maille->getObservations()
'points' => $nombrePoints,
'observations' => $maille->getNombreObservations(),
'type_site' => 'MAILLE'
);
}
}
146,6 → 157,7
return $mailles_resume;
}
 
}
 
?>
/trunk/services/bibliotheque/ReponseHttp.php
2,11 → 2,16
 
class ReponseHttp {
 
private $resultatService = null;
private $mime = 'application/json';
private $encodage = 'utf-8';
private $codeHttp = RestServeur::HTTP_CODE_OK;
private $corps = '';
private $erreurs = array();
 
public function __construct() {
$this->resultatService = new ResultatService();
if (function_exists('json_decode') == false){
require_once (dirname(__FILE__).'/JSON.php');
function json_decode($content, $assoc = false){
27,21 → 32,18
}
}
 
public function setResultatService($resultat) {
if (!($resultat instanceof ResultatService)) {
$this->resultatService->corps = $resultat;
} else {
$this->resultatService = $resultat;
}
$this->corps = $resultat;
}
 
public function getCorps() {
if ($this->etreEnErreur()) {
$this->resultatService->corps = $this->erreurs[0]['message'];
$this->corps = $this->erreurs[0]['message'];
} else {
$this->transformerReponseCorpsSuivantMime();
}
return $this->resultatService->corps;
return $this->corps;
}
 
public function ajouterErreur(Exception $e) {
49,16 → 51,17
}
 
public function emettreLesEntetes() {
$enteteHttp = new EnteteHttp();
if ($this->etreEnErreur()) {
$enteteHttp->code = $this->erreurs[0]['entete'];
$enteteHttp->mime = 'text/html';
$codeHttp = $this->erreurs[0]['entete'];
$encodage = 'utf-8';
$mime = 'text/html';
} else {
$enteteHttp->encodage = $this->resultatService->encodage;
$enteteHttp->mime = $this->resultatService->mime;
$codeHttp = $this->codeHttp;
$encodage = $this->encodage;
$mime = $this->mime;
}
header("Content-Type: $enteteHttp->mime; charset=$enteteHttp->encodage");
RestServeur::envoyerEnteteStatutHttp($enteteHttp->code);
header("Content-Type: $mime; charset=$encodage");
RestServeur::envoyerEnteteStatutHttp($codeHttp);
}
 
private function etreEnErreur() {
70,14 → 73,14
}
 
private function transformerReponseCorpsSuivantMime() {
switch ($this->resultatService->mime) {
switch ($this->mime) {
case 'application/json' :
if (isset($_GET['callback'])) {
$contenu = $_GET['callback'].'('.json_encode($this->resultatService->corps).');';
$contenu = $_GET['callback'].'('.json_encode($this->corps).');';
} else {
$contenu = json_encode($this->resultatService->corps);
$contenu = json_encode($this->corps);
}
$this->resultatService->corps = $contenu;
$this->corps = $contenu;
break;
}
}
/trunk/services/bibliotheque/VerificateurParametres.php
14,9 → 14,8
* On va verifier que c'est une serie de quatre nombre decimaux delimites par des virgules
* et compris dans l'espace representant le monde a partir du systeme de projection WGS84 (EPSG:4326)
*
* - stations : liste de points d'observations. C'est une serie de stations qui est passee en parametres
* de cette maniere, separees entre elles par un seperateur vertical |. Chaque station est decrite
* par sa source de donnees, le type de site et ses coordonnees longitude et latitude.
* - longitude et latitude : representent les coordonnees d'un point dans l'espace
* On va verifier que ces coordonnees soient valides dans le systeme de projection utilise
*
* - referentiel : referentiel taxonomique a utiliser. On peut passer aussi bien en parametres
* son nom court que son nom complet (incluant le numero de version)
32,12 → 31,12
*
* - auteur : l'auteur de l'observation
*
* - type_site : pour les observations, le type de point correspondant a la station cliquee
* (STATION ou COMMUNE). Cela indique le niveau de precision ramene aux coordonnees des observations
*
* - date_debut et date_fin : intervalle de dates d'observation. On verifie que ce sont des dates valides
* et que date_debut <= date_fin. Le programme peut accepter la presence d'un seul de ces deux
* parametres : soit une date de debut, soit une date de fin
*
* - nb_jours : valeur entiere qui indique de recuperer les observations effectuees ou transmises
* sur les derniers jours avant la date d'execution du script
*
* La fonction principale de verification des parametres va parcourir tous les parametres, et verifier
* pour chacun d'eux la validite de leurs valeurs. Dans le cas ou une valeur anormale est detectee
71,7 → 70,9
public function __construct($parametres) {
foreach ($parametres as $nomParametre => $valeur) {
$this->parametres[$nomParametre] = $valeur;
if ($nomParametre != 'source') {
$this->parametres[$nomParametre] = $valeur;
}
}
$this->bboxMonde = array(
'ouest' => floatval(Config::get('carte.limite_ouest')),
89,7 → 90,9
break;
case 'bbox' : $this->traiterParametreBbox($valeur);
break;
case 'stations' : $this->traiterParametreStations($this->parametres['stations']);
case 'longitude' :
case 'latitude' : $this->traiterParametresCoordonnees($this->parametres['longitude'],
$this->parametres['latitude']);
break;
case 'dept' : $this->traiterParametreDepartement($valeur);
break;
115,7 → 118,6
}
break;
}
case 'format' : $this->validation->format = strtolower($valeur); break;
// autres parametres ==> les ignorer
default : break;
}
162,20 → 164,7
}
}
private function traiterParametreBbox($chaineBbox) {
$listeBbox = explode('|', trim($chaineBbox));
$critereBbox = array();
foreach ($listeBbox as $bbox) {
$bboxVerifiee = $this->verifierCoordonneesBbox($bbox);
if (!is_null($bboxVerifiee)) {
$critereBbox[] = $bboxVerifiee;
}
}
$this->validation->bbox = $critereBbox;
}
private function verifierCoordonneesBbox($bbox) {
$bboxVerifiee = null;
private function traiterParametreBbox($bbox) {
// verifier que la chaine de caracteres $bbox est une serie de chaque nombre decimaux
// separes entre eux par une virgule
if (preg_match('/^(-?\d{1,3}(.\d+)?,){3}(-?\d{1,3}(.\d+)?)$/', $bbox) == 0) {
192,7 → 181,7
}
// verifier que les coordonnees de chaque bord de la bbox sont valides
if ($this->estUneBboxValide($bbox)) {
$bboxVerifiee = $bbox;
$this->validation->bbox = $bbox;
} else {
$message = "Certaines coordonnées de la bounding box sont situés en dehors des limites ".
"de notre monde";
199,7 → 188,6
$this->ajouterErreur($message);
}
}
return $bboxVerifiee;
}
private function estUneBboxValide($bbox) {
210,34 → 198,13
&& floatval($bbox['sud']) >= $monde['sud'] && floatval($bbox['sud']) <= $monde['nord']);
}
private function traiterParametreStations($listeStations) {
$stations = explode('|', trim($listeStations));
$critereStations = array();
foreach ($stations as $station) {
preg_match("/([a-z]+):([a-z]+):(-?\d{1,3}.\d+),(-?\d{1,3}.\d+)/", $station, $matches);
if (count($matches) < 5) {
$message = "Les données transmises sur la station à interroger sont incomplètes. ".
"Le format suivant doit être respecté : source:type_site:longitude:latitude";
$this->ajouterErreur($message);
} else {
$matches = array_splice($matches, 1, count($matches));
$this->verifierCoordonneesStation($matches);
$this->verifierSourceStation($matches[0]);
$this->verifierTypeStation($matches[1]);
$critereStations[] = $matches;
}
}
$this->validation->stations = $critereStations;
}
private function verifierCoordonneesStation(& $station) {
$longitude = floatval($station[2]);
$latitude = floatval($station[3]);
private function traiterParametresCoordonnees($longitude, $latitude) {
if ($this->sontDesCoordonneesValides($longitude, $latitude)) {
$station[2] = $latitude;
$station[3] = $longitude;
$this->validation->latitude = $latitude;
$this->validation->longitude = $longitude;
} else {
$message = "Les coordonnees du point passées en parametres sont en dehors des limites de notre monde";
$message = "Les coordonnees du point passées en parametres sont en dehors des limites de ".
"notre monde";
$this->ajouterErreur($message);
}
}
248,23 → 215,6
&& floatval($latitude) >= $monde['sud'] && floatval($latitude) <= $monde['nord']);
}
private function verifierTypeStation($typeStation) {
$typeStationsValides = array('station', 'commune');
if (!in_array($typeStation, $typeStationsValides)) {
$message = "'$typeStation' n'est pas un type de station reconnu. Sont acceptés seulement 'station' et 'commune'.";
$this->ajouterErreur($message);
}
}
private function verifierSourceStation($source) {
$sourcesARequeter = explode(',', trim($this->parametres['source']));
if (!in_array($source, $sourcesARequeter)) {
$message = "La source '$source' n'est pas listée dans le paramètre source de l'URL (sont disponibles ".
implode(',', $sourcesARequeter).").";
$this->ajouterErreur($message);
}
}
private function traiterParametreDepartement($numeroDepartement) {
if ($numeroDepartement != '*') {
$departements = explode(',', trim($numeroDepartement));
450,7 → 400,7
private function verifierPresenceParametreSpatial() {
$presenceParametreSpatial = false;
if (isset($this->parametres['bbox'])
|| (isset($this->parametres['stations']))) {
|| (isset($this->parametres['longitude']) && isset($this->parametres['latitude']))) {
$presenceParametreSpatial = true;
}
if ($presenceParametreSpatial == false) {
/trunk/services/bibliotheque/FormateurJson.php
3,8 → 3,11
 
class FormateurJson {
private $sourceDonnees;
public function __construct() {}
public function __construct($source = '') {
$this->sourceDonnees = $source;
}
public function formaterStations($stations) {
11,76 → 14,74
$objetJSON = new StdClass();
$objetJSON->type = "FeatureCollection";
$objetJSON->stats = new StdClass();
$objetJSON->stats->source = array();
$objetJSON->stats->source = $this->sourceDonnees;
$objetJSON->stats->formeDonnees = '';
if (count($stations) > 0) {
$objetJSON->stats->formeDonnees = ($stations[0]['type_site'] == 'MAILLE') ? 'maille' : 'point';
}
$objetJSON->stats->stations = 0;
$objetJSON->stats->sites = 0;
$objetJSON->stats->observations = 0;
$objetJSON->features = array();
foreach ($stations as $station) {
$stationJSON = null;
$stationJSON = NULL;
if ($station['type_site'] == 'MAILLE') {
$stationJSON = $this->formaterMaille($station);
$objetJSON->stats->stations += array_sum($station['stations']);
$objetJSON->stats->observations += array_sum($station['observations']);
$objetJSON->stats->sites += $station['points'];
} else {
$objetJSON->stats->sites ++;
$stationJSON = $this->formaterPoint($station);
$objetJSON->stats->stations ++;
$objetJSON->stats->observations += $station['observations'];
}
$objetJSON->features[] = $stationJSON;
$this->ajouterSourcesAuxStats($station, $objetJSON->stats);
$objetJSON->stats->observations += $station['observations'];
if (!is_null($stationJSON)) {
$objetJSON->features[] = $stationJSON;
}
}
return $objetJSON;
}
private function ajouterSourcesAuxStats($station, & $stats) {
if ($station['type_site'] == 'MAILLE') {
foreach ($station['stations'] as $source => $nombreStations) {
if (!in_array($source, $stats->source)) {
$stats->source[] = $source;
}
}
} else {
if (!in_array($station['source'], $stats->source)) {
$stats->source[] = $station['source'];
}
}
}
private function formaterPoint(& $station) {
private function formaterPoint($station) {
$json = new StdClass();
$json->type = "Feature";
$json->geometry = new StdClass();
$json->properties = new StdClass();
$json->geometry->type = "Point";
$json->properties->source = $station['source'];
$json->properties->source = $this->sourceDonnees;
$json->properties->typeSite = $station['type_site'];
$json->geometry->coordinates = array($station['latitude'], $station['longitude']);
$codeInsee = isset($station['code_insee']) ? $station['code_insee'] : substr($station['ce_zone_geo'],-5);
$codeDepartement = $this->extraireCodeDepartement($codeInsee);
$nom = '';
if ($station['source'] != 'floradata') {
$json->properties->nom = trim($station['nom'])." ({$codeDepartement})";
if ($this->sourceDonnees == 'floradata' && $station['type_site'] == 'COMMUNE') {
$json->geometry->coordinates = array($station['lat_commune'], $station['lng_commune']);
} else {
$station['station'] = (is_null($station['station']) || strlen(trim($station['station'])) == 0)
? $station['zone_geo'] : $station['station'];
$nom = $station['type_site'] == 'COMMUNE' ? $station['zone_geo'] : $station['station'];
$json->properties->nom = trim($nom)." ({$codeDepartement})";
$json->geometry->coordinates = array($station['latitude'], $station['longitude']);
}
if ($this->sourceDonnees == 'floradata') {
$json->properties->nom = $this->construireNomStationFloradata($station);
} else {
$codeDepartement = $this->extraireCodeDepartement($station['code_insee']);
$json->properties->nom = trim($station['nom'])." ({$codeDepartement})";
}
return $json;
}
private function construireNomStation(& $station) {
private function construireNomStationFloradata($station) {
$nom = ($station['type_site'] == 'COMMUNE') ? trim($station['nom_commune']) : trim($station['station']);
$codeDepartement = $this->extraireCodeDepartement($station['ce_zone_geo']);
if ($station['type_site'] == 'COMMUNE') {
$nom = $station['zone_geo'] . " ({$codeDepartement})";
} else {
if (strlen($nom) == 0) {
$nom = 'station sans nom, '.trim($station['zone_geo']);
}
$nom .= " ({$codeDepartement})";
}
return $nom;
}
private function extraireCodeDepartement($codeInsee) {
$codeInsee = substr($codeInsee,-5);
$codeDepartement = substr($codeInsee, 0 ,2);
if (intval($codeDepartement) > 95) {
$codeDepartement = substr($codeInsee, 0 ,3);
substr($codeInsee, 0 ,3);
}
return $codeDepartement;
}
99,26 → 100,20
array(floatval($maille['sud']), floatval($maille['ouest']))
);
$json->properties = new StdClass();
$json->properties->source = array();
foreach ($maille['stations'] as $source => $nombreStations) {
$json->properties->source[] = $source;
}
$json->properties->source = $this->sourceDonnees;
$json->properties->typeSite = 'MAILLE';
$json->properties->stations = $maille['stations'];
$json->properties->observations = $maille['observations'];
$json->properties->nombrePoints = $maille['points'];
return $json;
}
public function formaterObservations($observations) {
//print_r($observations); exit;
public function formaterObservations($observations, $nomSite) {
$objetJSON = new StdClass();
$objetJSON->site = trim($observations[0]['nom_station']);
$objetJSON->site = trim($nomSite);
$objetJSON->total = count($observations);
$objetJSON->observations = array();
foreach ($observations as $observation) {
$this->concatenerLieuObservation($observation);
$observationJson = new stdClass();
foreach ($observation as $colonne => $valeur) {
if ($colonne == 'nom_referentiel') {
127,38 → 122,31
$observationJson->$colonne = is_string($valeur) ? trim($valeur) : $valeur;
}
}
$this->formaterDateObservation($observationJson);
$objetJSON->observations[] = $observationJson;
}
return $objetJSON;
}
private function formaterDateObservation(& $observation) {
if (isset($observation->date) && strlen($observation->date) > 4) {
$dateFormatee = preg_replace('/(\d{4})-(\d{2})-(\d{2})/', '$3/$2/$1', $observation->date);
$observation->date = $dateFormatee;
}
}
private function genererUrlFicheEflore(& $observation) {
private function genererUrlFicheEflore($observation) {
$url = null;
if (strstr($observation['nom_referentiel'], 'bdtfx') !== false) {
if (strstr('bdtfx', $observation['nom_referentiel']) !== false) {
$url = 'http://www.tela-botanica.org/bdtfx-nn-'.$observation['nn'];
}
return $url;
}
private function concatenerLieuObservation(& $observation) {
$lieux = [];
if (!is_null($observation['lieudit'])) {
$lieux[] = $observation['lieudit'];
public function formaterMaillesVides($mailles) {
$objetJSON = new StdClass();
$objetJSON->type = "FeatureCollection";
$objetJSON->stats = new StdClass();
$objetJSON->stats->source = '';
$objetJSON->stats->formeDonnees = 'maille';
$objetJSON->stats->sites = 0;
$objetJSON->features = array();
foreach ($mailles as $maille) {
$objetJSON->features[] = $this->formaterMaille($maille);
}
if (!is_null($observation['milieu'])) {
$lieux[] = $observation['milieu'];
}
unset($observation['lieudit']);
unset($observation['milieu']);
$observation['lieu'] = implode(', ', $lieux);
return $objetJSON;
}
}