Subversion Repositories eFlore/Applications.cel

Compare Revisions

Ignore whitespace Rev 1295 → Rev 1296

/trunk/jrest/services/CoordSearch.php
56,8 → 56,11
$retour = json_encode($informations_communes) ;
 
} elseif ($this->estUneRequeteGeocoding($params)) {
$informations_coord = $this->effectuerRequeteGeocodingGeonames($params['commune'],$params['code_postal'],$params['code_pays']);
$informations_coord = $this->chercherCentroideCommuneBdd($params['commune'],$params['code_postal']);
if(!$informations_coord) {
$informations_coord = $this->effectuerRequeteGeocodingGeonames($params['commune'],$params['code_postal'],$params['code_pays']);
}
 
$header = 'Content-Type: application/json; charset=UTF-8';
$retour = json_encode($informations_coord);
79,10 → 82,6
 
$commune = $this->affecterValeurParametreOuDefaut($params, 2, '*');
$code_postal = $this->affecterValeurParametreOuDefaut($params, 3, '*');
if(strlen($code_postal) > 2) {
$code_postal = substr($code_postal,0,2);
}
 
$code_pays = $this->affecterValeurParametreOuDefaut($params, 4, 'FR');
105,11 → 104,9
private function effectuerRequeteReverseGeocodingCartoOsm($lat, $lon) {
$infos_commune_json = @file_get_contents($this->url_service_geo_local."?lat=".$lat."&lon=".$lon);
$infos_commune_json = @file_get_contents($this->adresse_service_local."?lat=".$lat."&lon=".$lon);
$infos_commune = json_decode($infos_commune_json);
print_r($infos_commune);
$retour = false;
if ($this->estUnRetourOsmValide($infos_commune)) {
126,9 → 123,9
private function effectuerRequeteReverseGeocodingGeonames($lat, $lon) {
$infos_commune_json = @file_get_contents($this->adresse_service_geonames.
$this->nom_service_reverse_geocoding.
"?featureClass=ADM4&lat=".urlencode($lat)."&lng=".urlencode($lon).
"&style=full") ;
$this->nom_service_reverse_geocoding.
"?featureClass=ADM4&lat=".urlencode($lat)."&lng=".urlencode($lon).
"&style=full") ;
$objet_retour = json_decode($infos_commune_json);
154,6 → 151,49
return $valide;
}
 
private function chercherCentroideCommuneBdd($commune, $departement) {
 
$commune = str_replace(' ','_',$commune);
$commune = str_replace('-','_',$commune);
 
if(strlen($departement) > 2) {
$departement = substr($departement,0,2);
}
$requete_selection_commune = 'SELECT utm_x, utm_y, utm_secteur, code FROM cel_zones_geo '.
'WHERE nom LIKE '.$this->proteger($commune).' AND code LIKE '.$this->proteger($departement.'%');
 
$commune_coordonnees = $this->executerRequete($requete_selection_commune);
 
$retour = false;
 
if($commune_coordonnees && is_array($commune_coordonnees) && count($commune_coordonnees) > 0) {
 
$lat_lon = $this->convertirUtmVersLatLong($commune_coordonnees[0]['utm_x'],$commune_coordonnees[0]['utm_y'],$commune_coordonnees[0]['utm_secteur']);
$retour = array('lat' => (float)$lat_lon['lat'],
'lng' => (float)$lat_lon['lng'],
'nom' => $commune,
'code_insee' => $commune_coordonnees[0]['code']
);
 
}
 
return $retour;
}
 
private function convertirUtmVersLatLong($x, $y, $sector) {
$lat_long = array();
$convertisseur = new gPoint();
$convertisseur->setUTM($x, $y, $sector);
$convertisseur->convertTMtoLL();
$lat_long['lat'] = str_replace(',','.',$convertisseur->Lat());
$lat_long['lng'] = str_replace(',','.',$convertisseur->Long());
return $lat_long;
}
private function effectuerRequeteGeocodingGeonames($commune, $code_postal, $code_pays) {
163,7 → 203,7
 
if($code_postal != '*') {
$requete .= "&postalcode_startsWith=".urlencode($code_postal);
}
}
$requete .= "&country=".urlencode($code_pays)."&maxRows=10" ;
 
$coord_json = @file_get_contents($requete);