Outils pour utilisateurs

Outils du site


geo_data:check_adresses

Ceci est une ancienne révision du document !


<php>

class GeoCodage { public static $DEBUG = false ; public $agentEmail = 'cgiquello@openstreetmap.fr' ; public function &geoCode($address, array $countrycodes = null) {

if( self::$DEBUG )
 echo 'geoCode: address: '.$address.'<br/>';
$data = array();
$data['google'] = self::geoCode_Google($address);
$data['nominatim'] = $this->geoCode_Nominatim($address, $countrycodes);
return $data ;

} public function &geoCode_Nominatim( $address, array $countrycodes = null){

if( self::$DEBUG )
 echo 'Nominatim: address: '.$address.'<br/>';
$url = 'http://nominatim.openstreetmap.org/search/?q='
  .urlencode($address)
  .'&format=json'.'&email='.urlencode($this->agentEmail);
if( $countrycodes != null )
 $url .= '&countrycodes='.implode(',',$countrycodes);
$get = file_get_contents($url);
if( self::$DEBUG )
 echo 'Nominatim: result: '.print_r($get,true).'<br/>';
$results = json_decode($get);
if( is_array($results) && count($results)>0 ){
 $data = array(
  'lat' => $results[0]->lat,
  'lon' => $results[0]->lon
 );
}
else {
 $data = array(
  'lat' =>0,
  'lon' => 0
 );
}
return $data;

} public function &geoCode_Google($address) {

 if( self::$DEBUG )
  echo 'Google: address: '.$address.'<br/>';
  $url = 'http://maps.google.com/maps/geo?q=' . urlencode($address) . '&output=csv&sensor=false';
  $get = file_get_contents($url);
  if( self::$DEBUG )
   echo 'Google: result: '.print_r($get,true).'<br/>';
   $records = explode(',', $get);
   $data = array(
    'lat' => $records['2'],
    'lon' => $records['3']
   );
return $data;

} }

$dataPluginFile = DOKU_PLUGIN.'data/syntax/table.php'; if(!file_exists($dataPluginFile)){ msg('Cannot find Data plugin.', -1); } require_once $dataPluginFile; $pdt = new syntax_plugin_data_table();

$data = array( 'classes' ⇒ 'association', 'limit' ⇒ 0, 'dynfilters' ⇒ false, 'summarize' ⇒ false, 'rownumbers' ⇒ false, 'sepbyheaders' ⇒ false, 'headers' ⇒ array(), 'widths' ⇒ array(), 'filter' ⇒ array() ); $dthlp = $pdt→dthlp ; $column = $dthlp→_column('%pageid%');$data['cols'][$column['key']] = $column; $column = $dthlp→_column('nom');$data['cols'][$column['key']] = $column; $column = $dthlp→_column('lat');$data['cols'][$column['key']] = $column; $column = $dthlp→_column('lon');$data['cols'][$column['key']] = $column; $column = $dthlp→_column('adresse1');$data['cols'][$column['key']] = $column; $column = $dthlp→_column('adresse2');$data['cols'][$column['key']] = $column; $column = $dthlp→_column('adresse3');$data['cols'][$column['key']] = $column; $column = $dthlp→_column('codepostal');$data['cols'][$column['key']] = $column; $column = $dthlp→_column('ville');$data['cols'][$column['key']] = $column; $column = $dthlp→_column('web');$data['cols'][$column['key']] = $column;

$sql = $pdt→_buildSQL($data); $sqlite = $dthlp→_getDB(); $res = $sqlite→query($sql); $rows = $sqlite→res2arr($res); $rowsCount = count($rows);

$geocodepage = ''; if( isset($_REQUEST['geocodepage']) && strlen(trim($_REQUEST['geocodepage']))>0 ) { $geocodepage = trim($_REQUEST['geocodepage']); } echo '<br/>geocodepage: ' .$geocodepage ;

foreach( $rows as $n ⇒ $row ){ list($pageid, $nom, $lat, $lon, $adr1, $adr2, $adr3, $cp, $ville, $web) = array_values($row); $addr = $adr1.', '.$adr2.', '.$adr3.','.$cp.','.$ville ;

echo '<p>', '<a href=“',$pageid,'”>',$nom,'</a> ', $addr; echo '<br/>',$lon,' ',$lat ,' <a href=“?geocodepage='.$pageid.'”>geocodage</a>' ;

if( $geocodepage == trim($pageid) ){

//GeoCodage::$DEBUG = true ;
$geoCod = new GeoCodage();
$geodata = $geoCod->geoCode( $addr, array('FR') );
$geo = $geodata['nominatim'];
if( $geo['lon']==0 || $geo['lat'] == 0 ) $color='red';
else if( $geo['lon']!=$lon || $geo['lat']!=$lat ) $color='orange';
else $color='green';
echo '<br/><span style="color: '.$color.'">'.$geo['lat'].';'.$geo['lon']."</class>\n";
//if( $geo['lon']==0 || $geo['lat'] == 0 ){
// $geo = $geodata['google'];
// echo '<br/><span style="color: '.$color.'">'.$geo['lat'].';'.$geo['lon']."</class>\n";
//}

} echo '</p>'; }

</php>

geo_data/check_adresses.1390315170.txt.gz · Dernière modification : 21/08/2020 13:26 (modification externe)