Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 970 Rev 1296
Line 54... Line 54...
54
			
54
			
55
			$header = 'Content-Type: application/json; charset=UTF-8';
55
			$header = 'Content-Type: application/json; charset=UTF-8';
Line 56... Line 56...
56
			$retour = json_encode($informations_communes) ;
56
			$retour = json_encode($informations_communes) ;
57
 
57
 
-
 
58
	    } elseif ($this->estUneRequeteGeocoding($params)) {
-
 
59
	    	
58
	    } elseif ($this->estUneRequeteGeocoding($params)) {
60
			$informations_coord = $this->chercherCentroideCommuneBdd($params['commune'],$params['code_postal']);
-
 
61
			if(!$informations_coord) {
Line 59... Line 62...
59
	    	    	
62
				$informations_coord = $this->effectuerRequeteGeocodingGeonames($params['commune'],$params['code_postal'],$params['code_pays']);
60
	    	$informations_coord = $this->effectuerRequeteGeocodingGeonames($params['commune'],$params['code_postal'],$params['code_pays']);
63
			}
Line 61... Line 64...
61
 
64
 
Line 77... Line 80...
77
		$lat = $this->affecterValeurParametreOuDefaut($params, 0, '*');
80
		$lat = $this->affecterValeurParametreOuDefaut($params, 0, '*');
78
		$lng = $this->affecterValeurParametreOuDefaut($params, 1, '*'); 
81
		$lng = $this->affecterValeurParametreOuDefaut($params, 1, '*'); 
Line 79... Line 82...
79
 
82
 
80
		$commune = $this->affecterValeurParametreOuDefaut($params, 2, '*'); 
83
		$commune = $this->affecterValeurParametreOuDefaut($params, 2, '*'); 
81
		$code_postal = $this->affecterValeurParametreOuDefaut($params, 3, '*');
-
 
82
		
-
 
83
		if(strlen($code_postal) > 2) {
-
 
84
			$code_postal = substr($code_postal,0,2);	
-
 
Line 85... Line 84...
85
		}
84
		$code_postal = $this->affecterValeurParametreOuDefaut($params, 3, '*');
Line 86... Line 85...
86
 
85
 
87
		$code_pays = $this->affecterValeurParametreOuDefaut($params, 4, 'FR');
86
		$code_pays = $this->affecterValeurParametreOuDefaut($params, 4, 'FR');
Line 103... Line 102...
103
		return ($params['commune'] != '*');
102
		return ($params['commune'] != '*');
104
	}
103
	}
Line 105... Line 104...
105
	
104
	
Line 106... Line 105...
106
	private function effectuerRequeteReverseGeocodingCartoOsm($lat, $lon) {
105
	private function effectuerRequeteReverseGeocodingCartoOsm($lat, $lon) {
107
		
106
		
Line 108... Line -...
108
		$infos_commune_json = @file_get_contents($this->url_service_geo_local."?lat=".$lat."&lon=".$lon);
-
 
109
		$infos_commune = json_decode($infos_commune_json);
-
 
110
		
107
		$infos_commune_json = @file_get_contents($this->adresse_service_local."?lat=".$lat."&lon=".$lon);
Line 111... Line 108...
111
		print_r($infos_commune);
108
		$infos_commune = json_decode($infos_commune_json);
112
		
109
		
113
		$retour = false;
110
		$retour = false;
Line 124... Line 121...
124
	}
121
	}
Line 125... Line 122...
125
	
122
	
Line 126... Line 123...
126
	private function effectuerRequeteReverseGeocodingGeonames($lat, $lon) {
123
	private function effectuerRequeteReverseGeocodingGeonames($lat, $lon) {
127
		
124
		
128
		$infos_commune_json = @file_get_contents($this->adresse_service_geonames.
125
		$infos_commune_json = @file_get_contents($this->adresse_service_geonames.
129
												$this->nom_service_reverse_geocoding.
126
			$this->nom_service_reverse_geocoding.
Line 130... Line 127...
130
												"?featureClass=ADM4&lat=".urlencode($lat)."&lng=".urlencode($lon).
127
			"?featureClass=ADM4&lat=".urlencode($lat)."&lng=".urlencode($lon).
Line 131... Line 128...
131
												"&style=full") ;
128
			"&style=full") ;
132
											
129
											
Line 152... Line 149...
152
			}
149
			}
153
		} 
150
		} 
Line 154... Line 151...
154
		
151
		
155
		return $valide;
152
		return $valide;
-
 
153
	}
-
 
154
 
-
 
155
	private function chercherCentroideCommuneBdd($commune, $departement) {
-
 
156
 
-
 
157
		$commune = str_replace(' ','_',$commune);
-
 
158
		$commune = str_replace('-','_',$commune);
-
 
159
 
-
 
160
		if(strlen($departement) > 2) {
-
 
161
			$departement = substr($departement,0,2);
-
 
162
		}
-
 
163
		$requete_selection_commune = 'SELECT utm_x, utm_y, utm_secteur, code FROM cel_zones_geo '.
-
 
164
					      'WHERE nom LIKE '.$this->proteger($commune).' AND code LIKE '.$this->proteger($departement.'%');
-
 
165
 
-
 
166
		$commune_coordonnees = $this->executerRequete($requete_selection_commune);
-
 
167
 
-
 
168
		$retour = false;
-
 
169
 
-
 
170
		if($commune_coordonnees && is_array($commune_coordonnees) && count($commune_coordonnees) > 0) {
-
 
171
 
-
 
172
			  $lat_lon = $this->convertirUtmVersLatLong($commune_coordonnees[0]['utm_x'],$commune_coordonnees[0]['utm_y'],$commune_coordonnees[0]['utm_secteur']);
-
 
173
			  
-
 
174
			  $retour = array('lat' => (float)$lat_lon['lat'],
-
 
175
			  'lng' => (float)$lat_lon['lng'],
-
 
176
			  'nom' => $commune,
-
 
177
			  'code_insee' => $commune_coordonnees[0]['code']
-
 
178
			  );
-
 
179
 
-
 
180
		}
-
 
181
 
-
 
182
		return $retour;
-
 
183
	}
-
 
184
 
-
 
185
	private function convertirUtmVersLatLong($x, $y, $sector) {
-
 
186
    	
-
 
187
		$lat_long = array();
-
 
188
		
-
 
189
		$convertisseur = new gPoint();
-
 
190
		$convertisseur->setUTM($x, $y, $sector);
-
 
191
		$convertisseur->convertTMtoLL();
-
 
192
		$lat_long['lat'] = str_replace(',','.',$convertisseur->Lat());
-
 
193
		$lat_long['lng'] = str_replace(',','.',$convertisseur->Long());
-
 
194
			
-
 
195
		return $lat_long;
Line 156... Line 196...
156
	}
196
	}
Line 157... Line 197...
157
	
197
	
158
	private function effectuerRequeteGeocodingGeonames($commune, $code_postal, $code_pays) {
198
	private function effectuerRequeteGeocodingGeonames($commune, $code_postal, $code_pays) {
159
		
199
		
Line 160... Line 200...
160
		$requete = $this->adresse_service_geonames.
200
		$requete = $this->adresse_service_geonames.
161
				$this->nom_service_geocoding.
201
				$this->nom_service_geocoding.
162
				"?placename_startsWith=".urlencode($commune);
202
				"?placename_startsWith=".urlencode($commune);
163
 
203
 
Line 164... Line 204...
164
		if($code_postal != '*') {
204
		if($code_postal != '*') {
165
			$requete .= "&postalcode_startsWith=".urlencode($code_postal);
205
			$requete .= "&postalcode_startsWith=".urlencode($code_postal);