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 function print_results($aResults, $bVerbose)
 
  29         if ($aResults && count($aResults)) {
 
  30             echo $aResults[0]['langaddress']."\n";
 
  39 if (!$aResult['search-only']) {
 
  40     $oReverseGeocode = new Nominatim\ReverseGeocode($oDB);
 
  41     $oReverseGeocode->setZoom(20);
 
  42     $oPlaceLookup = new Nominatim\PlaceLookup($oDB);
 
  43     $oPlaceLookup->setIncludeAddressDetails(true);
 
  44     $oPlaceLookup->setLanguagePreference(array('en'));
 
  46     echo 'Warm reverse: ';
 
  47     if ($bVerbose) echo "\n";
 
  48     for ($i = 0; $i < 1000; $i++) {
 
  49         $fLat = rand(-9000, 9000) / 100;
 
  50         $fLon = rand(-18000, 18000) / 100;
 
  51         if ($bVerbose) echo "$fLat, $fLon = ";
 
  53         $oLookup = $oReverseGeocode->lookup($fLat, $fLon);
 
  54         $aSearchResults = $oLookup ? $oPlaceLookup->lookup(array($oLookup->iId => $oLookup)) : null;
 
  55         print_results($aSearchResults, $bVerbose);
 
  60 if (!$aResult['reverse-only']) {
 
  61     $oGeocode = new Nominatim\Geocode($oDB);
 
  64     if ($bVerbose) echo "\n";
 
  65     $sSQL = 'SELECT word FROM word WHERE word is not null ORDER BY search_name_count DESC LIMIT 1000';
 
  66     foreach ($oDB->getCol($sSQL) as $sWord) {
 
  67         if ($bVerbose) echo "$sWord = ";
 
  69         $oGeocode->setLanguagePreference(array('en'));
 
  70         $oGeocode->setQuery($sWord);
 
  71         $aSearchResults = $oGeocode->lookup();
 
  72         print_results($aSearchResults, $bVerbose);