Subversion Repositories eFlore/Applications.coel

Rev

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

Rev 1658 Rev 1666
Line 1... Line 1...
1
<?php
1
<?php
2
/*
2
/*
3
  cat >> /etc/php.d/php.ini <<EOF
3
  cat >> /etc/php.d/php.ini <<EOF
4
pdo.dsn.dbcoel = "mysql:dbname=tb_coel;host=localhost"
4
pdo.dsn.testcoel = "mysql:dbname=tb_coel_test;host=localhost"
5
mysql.default_user = root
5
mysql.default_user = root
6
mysql.default_password =
6
mysql.default_password =
7
EOF
7
EOF
8
*/
8
*/
-
 
9
if(PHP_SAPI !== 'cli') exit(1);
-
 
10
 
-
 
11
define('DOUBLE_CHECK', FALSE);
Line 9... Line 12...
9
 
12
 
10
date_default_timezone_set('Europe/Paris');
13
date_default_timezone_set('Europe/Paris');
11
$DIR = dirname(__FILE__); // XXX: PHP-5.3
14
$DIR = dirname(__FILE__); // XXX: PHP-5.3
Line 12... Line 15...
12
define("_GEO_STORE_CACHE", $DIR . "/nominatim-coords.cache.ser");
15
define("_GEO_STORE_CACHE", $DIR . "/nominatim-coords.cache.ser");
13
 
16
 
14
require_once($DIR . '/../../jrest/services/Coel.php');
17
require_once($DIR . '/../../jrest/services/Coel.php');
15
$db = new PDO('dbcoel',
18
$db = new PDO('testcoel',
16
			  ini_get('mysql.default_user'),
19
			  @$argv[1] ? $argv[1] : ini_get('mysql.default_user'),
17
			  ini_get('mysql.default_password'),
20
			  @$argv[2] ? $argv[2] : ini_get('mysql.default_password'),
Line 18... Line 21...
18
			  array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'"));
21
			  array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'")) or die('no db');
19
$cache = @unserialize(file_get_contents(_GEO_STORE_CACHE));
22
$cache = @unserialize(file_get_contents(_GEO_STORE_CACHE));
20
 
23
 
Line 36... Line 39...
36
}
39
}
Line 37... Line 40...
37
 
40
 
38
printf("cache already contains %d entries, will start in 4 seconds:\n", count($cache));
41
printf("cache already contains %d entries, will start in 4 seconds:\n", count($cache));
Line -... Line 42...
-
 
42
sleep(4);
-
 
43
 
-
 
44
// correction
-
 
45
$db->query('UPDATE coel_structure SET cs_longitude = REPLACE(cs_longitude, ",", "."), cs_latitude = REPLACE(cs_latitude, ",", ".")');
-
 
46
$db->query('ALTER TABLE coel_structure MODIFY cs_longitude DOUBLE(12,9) NULL DEFAULT NULL');
39
sleep(4);
47
$db->query('ALTER TABLE coel_structure MODIFY cs_latitude DOUBLE(12,9) NULL DEFAULT NULL');
40
 
48
$db->query('UPDATE coel_structure SET cs_latitude = NULL, cs_longitude = NULL WHERE cs_latitude = "0" AND cs_longitude = "0"');
41
// smooth:
49
// smooth:
42
$q = "SELECT * FROM coel_structure".
50
$q = "SELECT * FROM coel_structure".
43
	" WHERE cs_latitude IS NULL OR cs_latitude = '' OR cs_longitude IS NULL".
51
	" WHERE cs_latitude IS NULL OR cs_latitude = '' OR cs_longitude IS NULL".
44
	" OR cs_longitude = ''";
52
	" OR cs_longitude = ''";
45
foreach($db->query($q)->fetchAll(PDO::FETCH_ASSOC) AS $params) {
53
foreach($db->query($q)->fetchAll(PDO::FETCH_ASSOC) AS $params) {
46
	$params_override = array('countrycodes' => 'fr,de,ae');
54
	$params_override = array('countrycodes' => 'fr,de,ae');
-
 
55
	$id = $params['cs_id_structure'];
47
	$id = $params['cs_id_structure'];
56
	if(array_key_exists($id, $cache)) {
48
	if(array_key_exists($id, $cache)) {
57
		$db->query(sprintf("UPDATE coel_structure SET cs_latitude = %.9f, cs_longitude = %.9f WHERE cs_id_structure = %d",
49
		// TODO: UPDATE
58
						   $cache[$id]['lat'], $cache[$id]['lon'], $id));
50
		continue;
59
		continue;
-
 
60
	}
-
 
61
	if(array_key_exists($id, @$cache['failed'])) {
51
	}
62
		if(!DOUBLE_CHECK) continue;
52
	if(array_key_exists($id, @$cache['failed'])) {
63
 
53
		// mode texte-libre (plus efficace pour les cas tordus)
64
		// mode texte-libre (plus efficace pour les cas tordus)
54
		$params_override['force-q'] = TRUE;
65
		$params_override['force-q'] = TRUE;
55
		// cf (très) mauvaise gestion des CP par Nominatim
66
		// cf (très) mauvaise gestion des CP par Nominatim
56
		if($params['cs_ville']) {
67
		if($params['cs_ville']) {
57
			unset($params['cs_code_postal']);
68
			unset($params['cs_code_postal']);
-
 
69
		}
58
		}
70
		if($params['cs_adresse_01']) {
59
		if($params['cs_adresse_01']) {
71
			$params['cs_adresse_01'] = preg_replace(
60
			$params['cs_adresse_01'] = preg_replace('/.*(impasse|chemin|route|rue|avenue|boulevard|place|ville)( du|des|de )?(la )?/i',
72
				'/.*(?:impasse|chemin|route|rue|avenue|boulevard|place|ville)(?:\s(?:du|des|de)\s)?(la\s)?/i',
61
												'',
-
 
62
												$params['cs_adresse_01']);
-
 
63
		}
-
 
64
		else {
73
				'',
65
			continue;
-
 
66
		}
-
 
67
		// TODO: UPDATE
74
				$params['cs_adresse_01']);
Line 68... Line 75...
68
		//continue;
75
		}
69
	}
76
	}
70
 
77