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 $aLookup = $oReverseGeocode->lookup($fLat, $fLon);
39 if ($aLookup && $aLookup['place_id']) {
40 $aDetails = $oPlaceLookup->lookup(
41 (int)$aLookup['place_id'],
45 if ($bVerbose) echo $aDetails['langaddress']."\n";
53 if (!$aResult['reverse-only']) {
54 $oGeocode = new Nominatim\Geocode($oDB);
57 if ($bVerbose) echo "\n";
58 $sSQL = 'select word from word where word is not null order by search_name_count desc limit 1000';
59 foreach ($oDB->getCol($sSQL) as $sWord) {
60 if ($bVerbose) echo "$sWord = ";
61 $oGeocode->setLanguagePreference(array('en'));
62 $oGeocode->setQuery($sWord);
63 $aSearchResults = $oGeocode->lookup();
64 if ($bVerbose) echo $aSearchResults[0]['langaddress']."\n";