Subversion Repositories eFlore/Applications.cel

Rev

Rev 766 | Rev 794 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 766 Rev 772
Line 7... Line 7...
7
 * @author Aurélien PERONNET <aurelien@tela-botanica.org>
7
 * @author Aurélien PERONNET <aurelien@tela-botanica.org>
8
 * @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
8
 * @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
9
 * @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
9
 * @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
10
 * @version $Id$
10
 * @version $Id$
11
 */
11
 */
12
class CoordSearch {
12
class CoordSearch extends Cel {
Line 13... Line 13...
13
	
13
	
14
	private $adresse_service_geonames = null;
14
	private $adresse_service_geonames = null;
Line 15... Line 15...
15
	private $adresse_service_local = null;
15
	private $adresse_service_local = null;
Line 19... Line 19...
19
	
19
	
Line 20... Line 20...
20
	function CoordSearch($config) {
20
	function CoordSearch($config) {
Line 21... Line 21...
21
		
21
		
22
		parent::__construct($config);
22
		parent::__construct($config);
Line 23... Line 23...
23
		
23
		
24
		$this->adresse_service_geonames = $config['cel_db']['url_service_geo_geonames'];
24
		$this->adresse_service_geonames = $this->config['cel_db']['url_service_geo_geonames'];
25
		$this->adresse_service_local = $config['cel_db']['url_service_geo_local'];
25
		$this->adresse_service_local = $this->config['cel_db']['url_service_geo_local'];
Line 26... Line 26...
26
		
26
		
27
		$this->nom_service_geocoding = $config['cel_db']['nom_service_geocoding_geonames'];
27
		$this->nom_service_geocoding = $this->config['cel_db']['nom_service_geocoding_geonames'];
28
		$this->nom_service_reverse_geocoding = $config['cel_db']['nom_service_reverse_geocoding_geonames'];
28
		$this->nom_service_reverse_geocoding = $this->config['cel_db']['nom_service_reverse_geocoding_geonames'];
Line 55... Line 55...
55
			$header = 'Content-Type: application/json; charset=UTF-8';
55
			$header = 'Content-Type: application/json; charset=UTF-8';
56
			$retour = json_encode($informations_communes) ;
56
			$retour = json_encode($informations_communes) ;
Line 57... Line 57...
57
 
57
 
Line 58... Line 58...
58
	    } elseif ($this->estUneRequeteGeocoding($params)) {
58
	    } elseif ($this->estUneRequeteGeocoding($params)) {
Line 59... Line 59...
59
	    	
59
	    	
60
	    	$informations_coord = $this->effectuerRequeteGeocodingGeonames($params['commune'],$params['code_postal'],$params['pays']);
60
	    	$informations_coord = $this->effectuerRequeteGeocodingGeonames($params['commune'],$params['code_postal'],$params['code_pays']);
Line 61... Line 61...
61
 
61
 
Line 121... Line 121...
121
		
121
		
122
		$infos_commune_json = @file_get_contents($this->adresse_service_geonames.
122
		$infos_commune_json = @file_get_contents($this->adresse_service_geonames.
123
												$this->nom_service_reverse_geocoding.
123
												$this->nom_service_reverse_geocoding.
124
												"?featureClass=ADM4&lat=".urlencode($lat)."&lng=".urlencode($lon).
124
												"?featureClass=ADM4&lat=".urlencode($lat)."&lng=".urlencode($lon).
-
 
125
												"&style=full") ;
125
												"&style=full") ;
126
											
Line 126... Line 127...
126
		$objet_retour = json_decode($infos_commune_json);
127
		$objet_retour = json_decode($infos_commune_json);
127
		
-
 
128
		$retour = false;
128
		
129
		
129
		$retour = false;
130
		if($this->estUnRetourGeonamesValide($retour)) { 
130
		if($this->estUnRetourReverseGeocodingGeonamesValide($objet_retour)) { 
Line 131... Line 131...
131
			$retour = array('nom' => $objet_retour->geonames[0]->name, 'code_insee' => $objet_retour->geonames[0]->AdminCode2);
131
			$retour = array('nom' => $objet_retour->geonames[0]->name, 'code_insee' => $objet_retour->geonames[0]->adminCode4);
132
		}
132
		}
Line 133... Line 133...
133
		
133
		
Line 134... Line 134...
134
		return $retour;
134
		return $retour;
Line 135... Line 135...
135
	}
135
	}
136
	
136
	
137
	private function estUnRetourGeonamesValide($retour) {
137
	private function estUnRetourReverseGeocodingGeonamesValide($retour) {
138
		
138
		
139
		$valide = false;
139
		$valide = false;
140
		
140
		
141
		if (is_a($retour,'stdClass') && property_exists($retour,'geonames') 
141
		if (is_a($retour,'stdClass') && property_exists($retour,'geonames') 
Line 142... Line 142...
142
			&& is_array($retour->geonames) && count($retour->geonames > 0)) {
142
			&& is_array($retour->geonames) && count($retour->geonames > 0)) {
Line 159... Line 159...
159
			$requete .= "&postalcode_startsWith=".urlencode($code_postal);
159
			$requete .= "&postalcode_startsWith=".urlencode($code_postal);
160
	    }
160
	    }
161
		$requete .= "&country=".urlencode($code_pays)."&maxRows=10" ;
161
		$requete .= "&country=".urlencode($code_pays)."&maxRows=10" ;
Line 162... Line 162...
162
 
162
 
-
 
163
		$coord_json = @file_get_contents($requete);
-
 
164
		$objet_retour = json_decode($coord_json);
-
 
165
		
-
 
166
		$retour = false;
-
 
167
		
-
 
168
		if($this->estUnRetourGeocodingGeonamesValide($objet_retour)) { 
-
 
169
			$retour = array('lat' => $objet_retour->postalCodes[0]->lat, 
-
 
170
							'lng' => $objet_retour->postalCodes[0]->lng,
-
 
171
							'nom' => $objet_retour->postalCodes[0]->placeName,
-
 
172
							'code_insee' => $objet_retour->postalCodes[0]->postalCode
-
 
173
							);
Line 163... Line 174...
163
		$coord_json = @file_get_contents($requete);
174
		}
-
 
175
 
-
 
176
		return $retour;
-
 
177
	}
-
 
178
	
-
 
179
	private function estUnRetourGeocodingGeonamesValide($retour) {
-
 
180
		$valide = false;
-
 
181
		
-
 
182
		if (is_a($retour,'stdClass') && property_exists($retour,'postalCodes') 
-
 
183
			&& is_array($retour->postalCodes) && count($retour->postalCodes > 0)) {
-
 
184
			$objet_resultats = $retour->postalCodes[0];
-
 
185
			if (property_exists($objet_resultats,'lat') && property_exists($objet_resultats,'lng')) {
-
 
186
				$valide = true;
-
 
187
			}
-
 
188
		} 
164
 
189
		
165
		return $coord_json;
190
		return $valide;
166
	}
191
	}