3 require_once(CONST_BasePath.'/lib/init-cmd.php');
4 ini_set('memory_limit', '800M');
7 'Tools to warm nominatim db',
8 array('help', 'h', 0, 1, 0, 0, false, 'Show Help'),
9 array('quiet', 'q', 0, 1, 0, 0, 'bool', 'Quiet output'),
10 array('verbose', 'v', 0, 1, 0, 0, 'bool', 'Verbose output'),
11 array('reverse-only', '', 0, 1, 0, 0, 'bool', 'Warm reverse only'),
12 array('search-only', '', 0, 1, 0, 0, 'bool', 'Warm search only'),
14 getCmdOpt($_SERVER['argv'], $aCMDOptions, $aResult, true, true);
16 require_once(CONST_BasePath.'/lib/log.php');
17 require_once(CONST_BasePath.'/lib/Geocode.php');
18 require_once(CONST_BasePath.'/lib/PlaceLookup.php');
19 require_once(CONST_BasePath.'/lib/ReverseGeocode.php');
23 $bVerbose = $aResult['verbose'];
25 if (!$aResult['search-only']) {
26 $oReverseGeocode = new Nominatim\ReverseGeocode($oDB);
27 $oReverseGeocode->setZoom(20);
28 $oPlaceLookup = new Nominatim\PlaceLookup($oDB);
29 $oPlaceLookup->setIncludeAddressDetails(true);
30 $oPlaceLookup->setLanguagePreference(array('en'));
32 echo 'Warm reverse: ';
33 if ($bVerbose) echo "\n";
34 for ($i = 0; $i < 1000; $i++) {
35 $fLat = rand(-9000, 9000) / 100;
36 $fLon = rand(-18000, 18000) / 100;
37 if ($bVerbose) echo "$fLat, $fLon = ";
38 $oLookup = $oReverseGeocode->lookup($fLat, $fLon);
40 $aDetails = $oPlaceLookup->lookup(array($oLookup->iId => $oLookup));
41 if ($bVerbose) echo $aDetails['langaddress']."\n";
49 if (!$aResult['reverse-only']) {
50 $oGeocode = new Nominatim\Geocode($oDB);
53 if ($bVerbose) echo "\n";
54 $sSQL = 'select word from word where word is not null order by search_name_count desc limit 1000';
55 foreach ($oDB->getCol($sSQL) as $sWord) {
56 if ($bVerbose) echo "$sWord = ";
57 $oGeocode->setLanguagePreference(array('en'));
58 $oGeocode->setQuery($sWord);
59 $aSearchResults = $oGeocode->lookup();
60 if ($bVerbose) echo $aSearchResults[0]['langaddress']."\n";