Subversion Repositories eFlore/Applications.cel

Compare Revisions

Ignore whitespace Rev 2535 → Rev 2538

/trunk/jrest/services/ImportXLS.php
92,6 → 92,7
'nt',
'famille',
'nom_referentiel',
'pays',
'zone_geo',
'ce_zone_geo',
'date_observation',
565,6 → 566,7
// $localisation est rempli à partir de plusieurs champs: C_ZONE_GEO et C_CE_ZONE_GEO
$localisation = Array(C_ZONE_GEO => NULL, C_CE_ZONE_GEO => NULL);
self::traiterLocalisation($ligne, $localisation);
//TODO: le jour où c'est efficace, traiter le pays à l'import
 
// $transmission est utilisé pour date_transmission
// XXX: @ contre "Undefined index"
585,6 → 587,7
 
"nom_referentiel" => $referentiel,
 
"pays" => $ligne[C_PAYS],
"zone_geo" => $localisation[C_ZONE_GEO],
"ce_zone_geo" => $localisation[C_CE_ZONE_GEO],
 
/trunk/jrest/services/CelWidgetExport.php
38,6 → 38,7
'id_utilisateur' => 'ce_utilisateur',
'utilisateur' => 'courriel_utilisateur',
'courriel_utilisateur' => 'courriel_utilisateur',
'pays' => 'pays',
'commune' => 'zone_geo',
'zone_geo' => 'zone_geo',
'dept' => 'departement',
/trunk/jrest/services/CoordSearch.php
17,20 → 17,14
*/
class CoordSearch extends Cel {
 
private $adresse_service_geonames = null;
private $adresse_service_mondial = null;
private $adresse_service_local = null;
 
private $nom_service_geocoding = null;
private $nom_service_reverse_geocoding = null;
 
public function __construct($config) {
parent::__construct($config);
 
$this->adresse_service_geonames = $this->config['cel']['url_service_geo_geonames'];
$this->adresse_service_mondial = $this->config['cel']['url_service_geo_mondial'];
$this->adresse_service_local = $this->config['cel']['url_service_geo_local'];
 
$this->nom_service_geocoding = $this->config['cel']['nom_service_geocoding_geonames'];
$this->nom_service_reverse_geocoding = $this->config['cel']['nom_service_reverse_geocoding_geonames'];
}
 
/**
52,7 → 46,7
$informations_communes = $this->effectuerRequeteReverseGeocodingCartoOsm($params['lat'], $params['lon']);
 
if (!$informations_communes) {
$informations_communes = $this->effectuerRequeteReverseGeocodingGeonames($params['lat'], $params['lon']);
$informations_communes = $this->effectuerRequeteReverseGeocodingMondiale($params['lat'], $params['lon']);
}
 
$header = 'Content-Type: application/json; charset=UTF-8';
60,7 → 54,7
} elseif ($this->estUneRequeteGeocoding($params)) {
$informations_coord = $this->chercherCentroideCommuneBdd($params['commune'],$params['code_postal']);
if (!$informations_coord) {
$informations_coord = $this->effectuerRequeteGeocodingGeonames($params['commune'],$params['code_postal'],$params['code_pays']);
$informations_coord = $this->effectuerRequeteGeocodingMondiale($params['commune'],$params['code_postal'],$params['code_pays']);
}
 
$header = 'Content-Type: application/json; charset=UTF-8';
113,35 → 107,6
return (is_a($retour, 'stdClass') && property_exists($retour, 'nom') && property_exists($retour, 'codeINSEE'));
}
 
private function effectuerRequeteReverseGeocodingGeonames($lat, $lon) {
$url = $this->adresse_service_geonames.
$this->nom_service_reverse_geocoding.
'?lat='.urlencode($lat).'&lng='.urlencode($lon).
'&style=full';
$infos_commune_json = @file_get_contents($url);
$objet_retour = json_decode($infos_commune_json);
 
$retour = false;
if ($this->estUnRetourReverseGeocodingGeonamesValide($objet_retour)) {
$retour = array(
'nom' => $objet_retour->geonames[0]->adminName4,
'code_insee' => $objet_retour->geonames[0]->adminCode4);
}
return $retour;
}
 
private function estUnRetourReverseGeocodingGeonamesValide($retour) {
$valide = false;
if (is_a($retour, 'stdClass') && property_exists($retour, 'geonames')
&& is_array($retour->geonames) && count($retour->geonames) > 0) {
$objet_resultats = $retour->geonames[0];
if (property_exists($objet_resultats, 'adminName4') && property_exists($objet_resultats, 'adminCode2')) {
$valide = true;
}
}
return $valide;
}
 
private function chercherCentroideCommuneBdd($commune, $departement) {
$commune_formatee = str_replace(array(' ', '-'), '_', $commune);
if (strlen($departement) > 2) {
177,37 → 142,28
$lat_long['lng'] = str_replace(',','.',$convertisseur->Long());
return $lat_long;
}
 
private function effectuerRequeteGeocodingGeonames($commune, $code_postal, $code_pays) {
$url = $this->adresse_service_geonames.
$this->nom_service_geocoding.
'?placename_startsWith='.urlencode($commune).
(($code_postal != '*') ? '&postalcode_startsWith='.urlencode($code_postal) : '').
'&country='.urlencode($code_pays).'&maxRows=10';
$coord_json = @file_get_contents($url);
$objet_retour = json_decode($coord_json);
 
$retour = false;
if ($this->estUnRetourGeocodingGeonamesValide($objet_retour)) {
$retour = array(
'lat' => $objet_retour->postalCodes[0]->lat,
'lng' => $objet_retour->postalCodes[0]->lng,
'nom' => $objet_retour->postalCodes[0]->placeName,
'code_insee' => $objet_retour->postalCodes[0]->postalCode
);
private function effectuerRequeteReverseGeocodingMondiale($lat, $lon) {
$url = $this->adresse_service_mondial.'?lat='.$lat.'&lon='.$lon;
// Pour limiter par niveau ajouter ce qui suit à la requête :
//.'&niveau=2,3,4';
$res = json_decode(file_get_contents($url), true);
$code = "";
$localite = "";
if(!empty($res)) {
$infos_pays = $res[min(array_keys($res))];
$infos_localite = $res[max(array_keys($res))];
$localite = $infos_localite['intitule'];
if(!empty($infos_pays['codeIso31661'])) {
$code = $infos_pays['codeIso31661'];
} elseif(!empty($infos_pays['codeIso31662'])) {
$code = substr($infos_pays['codeIso31662'], 0, 2);
}
}
return $retour;
}
 
private function estUnRetourGeocodingGeonamesValide($retour) {
$valide = false;
if (is_a($retour, 'stdClass') && property_exists($retour, 'postalCodes')
&& is_array($retour->postalCodes) && count($retour->postalCodes) > 0) {
$objet_resultats = $retour->postalCodes[0];
if (property_exists($objet_resultats, 'lat') && property_exists($objet_resultats, 'lng')) {
$valide = true;
}
}
return $valide;
return array('nom' => $localite, 'code_insee' => $code);
}
}
/trunk/jrest/services/InventoryObservationList.php
89,7 → 89,7
}
 
// cas de mise à jour de multiples observations:
$ret = GestionObservation::modifierMultiplesObservation($uid[0], $obs, $pairs);
$ret = $gestionnaire_observation->modifierMultiplesObservation($uid[0], $obs, $pairs);
if ($ret === false) {
return false; // JRest::badRequest();
}