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');
21 $oDB = new Nominatim\DB();
24 $bVerbose = $aResult['verbose'];
26 if (!$aResult['search-only']) {
27 $oReverseGeocode = new Nominatim\ReverseGeocode($oDB);
28 $oReverseGeocode->setZoom(20);
29 $oPlaceLookup = new Nominatim\PlaceLookup($oDB);
30 $oPlaceLookup->setIncludeAddressDetails(true);
31 $oPlaceLookup->setLanguagePreference(array('en'));
33 echo 'Warm reverse: ';
34 if ($bVerbose) echo "\n";
35 for ($i = 0; $i < 1000; $i++) {
36 $fLat = rand(-9000, 9000) / 100;
37 $fLon = rand(-18000, 18000) / 100;
38 if ($bVerbose) echo "$fLat, $fLon = ";
39 $oLookup = $oReverseGeocode->lookup($fLat, $fLon);
41 $aDetails = $oPlaceLookup->lookup(array($oLookup->iId => $oLookup));
42 if ($bVerbose) echo $aDetails['langaddress']."\n";
50 if (!$aResult['reverse-only']) {
51 $oGeocode = new Nominatim\Geocode($oDB);
54 if ($bVerbose) echo "\n";
55 $sSQL = 'select word from word where word is not null order by search_name_count desc limit 1000';
56 foreach ($oDB->getCol($sSQL) as $sWord) {
57 if ($bVerbose) echo "$sWord = ";
58 $oGeocode->setLanguagePreference(array('en'));
59 $oGeocode->setQuery($sWord);
60 $aSearchResults = $oGeocode->lookup();
61 if ($bVerbose) echo $aSearchResults[0]['langaddress']."\n";