1652 |
raphael |
1 |
<?php
|
|
|
2 |
/*
|
|
|
3 |
cat >> /etc/php.d/php.ini <<EOF
|
|
|
4 |
pdo.dsn.dbcoel = "mysql:dbname=tb_coel;host=localhost"
|
|
|
5 |
mysql.default_user = root
|
|
|
6 |
mysql.default_password =
|
|
|
7 |
EOF
|
|
|
8 |
*/
|
|
|
9 |
|
|
|
10 |
date_default_timezone_set('Europe/Paris');
|
|
|
11 |
$DIR = dirname(__FILE__); // XXX: PHP-5.3
|
|
|
12 |
define("_GEO_STORE_CACHE", $DIR . "/nominatim-coords.cache.ser");
|
|
|
13 |
|
|
|
14 |
require_once($DIR . '/../../jrest/services/Coel.php');
|
|
|
15 |
|
|
|
16 |
|
|
|
17 |
$db = new PDO('dbcoel',
|
|
|
18 |
ini_get('mysql.default_user'),
|
|
|
19 |
ini_get('mysql.default_password'),
|
|
|
20 |
array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'"));
|
|
|
21 |
|
|
|
22 |
$cache = @unserialize(file_get_contents(_GEO_STORE_CACHE));
|
|
|
23 |
|
|
|
24 |
/* raw:
|
|
|
25 |
$q = "SELECT cs_id_structure AS id, cs_adresse_01 AS addr, cs_code_postal AS cp, cs_ville AS city".
|
|
|
26 |
" FROM coel_structure".
|
|
|
27 |
" WHERE cs_latitude IS NULL OR cs_latitude = '' OR cs_longitude IS NULL OR cs_longitude = ''";
|
|
|
28 |
$query = http_build_query(array('q' => implode(',',$q),'accept_language' => 'fr', 'format' => 'json', 'limit' => 1));
|
|
|
29 |
var_dump( json_decode(file_get_contents('http://nominatim.openstreetmap.org/search.php?' . $query)) );
|
|
|
30 |
*/
|
|
|
31 |
|
|
|
32 |
|
|
|
33 |
// smooth:
|
|
|
34 |
$q = "SELECT * FROM coel_structure".
|
|
|
35 |
" WHERE cs_latitude IS NULL OR cs_latitude = '' OR cs_longitude IS NULL OR cs_longitude = '' LIMIT 85";
|
|
|
36 |
|
|
|
37 |
foreach($db->query($q)->fetchAll(PDO::FETCH_ASSOC) AS $params) {
|
|
|
38 |
$id = $params['cs_id_structure'];
|
|
|
39 |
if(array_key_exists($id, $cache)) {
|
|
|
40 |
// TODO: UPDATE
|
|
|
41 |
continue;
|
|
|
42 |
}
|
|
|
43 |
if(array_key_exists($id, @$cache['failed'])) {
|
|
|
44 |
// TODO: UPDATE
|
|
|
45 |
continue;
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
|
|
|
49 |
$lonlat = array();
|
|
|
50 |
if(Coel::coordGuess(Coel::addrReStruct($params), $lonlat, array('countrycodes' => 'fr,de,ae'))) {
|
|
|
51 |
$lat = $lonlat['lat'];
|
|
|
52 |
$lon = $lonlat['lon'];
|
|
|
53 |
$cache[$id] = $lonlat;
|
|
|
54 |
}
|
|
|
55 |
else {
|
|
|
56 |
$cache['failed'][$id] = FALSE;
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
echo "sleep\n";
|
|
|
60 |
sleep(1.5);
|
|
|
61 |
}
|
|
|
62 |
if($cache) {
|
|
|
63 |
ksort($cache, SORT_NUMERIC);
|
|
|
64 |
file_put_contents(_GEO_STORE_CACHE, serialize($cache));
|
|
|
65 |
}
|