bracket spacing for if/else/for/foreach/while/switch according to PSR2 standard

This commit is contained in:
marc tobias
2016-09-08 02:16:22 +01:00
parent effd8e12af
commit f05ea577f4
30 changed files with 986 additions and 1505 deletions

View File

@@ -17,14 +17,12 @@ $aCMDOptions = array(
getCmdOpt($_SERVER['argv'], $aCMDOptions, $aResult, true, true);
$m = getBucketMemcache();
if (!$m)
{
if (!$m) {
echo "ERROR: Bucket memcache is not configured\n";
exit;
}
if ($aResult['list'])
{
if ($aResult['list']) {
$iCurrentSleeping = $m->get('sleepCounter');
echo "\n Sleeping blocks count: $iCurrentSleeping\n";
@@ -32,8 +30,7 @@ if ($aResult['list'])
echo "\n";
printf(" %-40s | %12s | %7s | %13s | %31s | %8s\n", "Key", "Total Blocks", "Current", "Still Blocked", "Last Block Time", "Sleeping");
printf(" %'--40s-|-%'-12s-|-%'-7s-|-%'-13s-|-%'-31s-|-%'-8s\n", "", "", "", "", "", "");
foreach($aBlocks as $sKey => $aDetails)
{
foreach ($aBlocks as $sKey => $aDetails) {
printf(" %-40s | %12s | %7s | %13s | %31s | %8s\n", $sKey, $aDetails['totalBlocks'],
(int)$aDetails['currentBucketSize'], $aDetails['currentlyBlocked']?'Y':'N',
date("r", $aDetails['lastBlockTimestamp']), $aDetails['isSleeping']?'Y':'N');
@@ -41,13 +38,11 @@ if ($aResult['list'])
echo "\n";
}
if ($aResult['delete'])
{
if ($aResult['delete']) {
$m->set('sleepCounter', 0);
clearBucketBlocks();
}
if ($aResult['flush'])
{
if ($aResult['flush']) {
$m->flush();
}

View File

@@ -17,17 +17,13 @@ require_once(CONST_BasePath.'/lib/init-cmd.php');
include(CONST_InstallPath.'/settings/phrase_settings.php');
if (true)
{
if (true) {
$sURL = 'http://wiki.openstreetmap.org/wiki/Special:Export/Nominatim/Country_Codes';
$sWikiPageXML = file_get_contents($sURL);
if (preg_match_all('#\\| ([a-z]{2}) \\|\\| [^|]+\\|\\| ([a-z,]+)#', $sWikiPageXML, $aMatches, PREG_SET_ORDER))
{
foreach($aMatches as $aMatch)
{
if (preg_match_all('#\\| ([a-z]{2}) \\|\\| [^|]+\\|\\| ([a-z,]+)#', $sWikiPageXML, $aMatches, PREG_SET_ORDER)) {
foreach ($aMatches as $aMatch) {
$aLanguages = explode(',', $aMatch[2]);
foreach($aLanguages as $i => $s)
{
foreach ($aLanguages as $i => $s) {
$aLanguages[$i] = '"'.pg_escape_string($s).'"';
}
echo "UPDATE country_name set country_default_language_codes = '{".join(',',$aLanguages)."}' where country_code = '".pg_escape_string($aMatch[1])."';\n";

View File

@@ -58,8 +58,7 @@ exit;
}
*/
if ($aCMDResult['create-tables'])
{
if ($aCMDResult['create-tables']) {
$sSQL = <<<'EOD'
CREATE TABLE wikipedia_article (
language text NOT NULL,
@@ -111,22 +110,18 @@ function _parseWikipediaContent($sPageText)
$aTemplateStack = array();
$aState = array('body');
foreach($aPageText as $i => $sPart)
{
switch($sPart)
{
foreach ($aPageText as $i => $sPart) {
switch ($sPart) {
case '{{':
array_unshift($aTemplateStack, array('', array()));
array_unshift($aState, 'template');
break;
case '}}':
if ($aState[0] == 'template' || $aState[0] == 'templateparam')
{
if ($aState[0] == 'template' || $aState[0] == 'templateparam') {
$aTemplate = array_shift($aTemplateStack);
array_shift($aState);
$aTemplates[] = $aTemplate;
}
break;
case '[[':
@@ -135,16 +130,14 @@ function _parseWikipediaContent($sPageText)
array_unshift($aState, 'link');
break;
case ']]':
if ($aState[0] == 'link' || $aState[0] == 'linksynonim')
{
if ($aState[0] == 'link' || $aState[0] == 'linksynonim') {
if (!$sLinkSyn) $sLinkSyn = $sLinkPage;
if (substr($sLinkPage, 0, 6) == 'Image:') $sLinkSyn = substr($sLinkPage, 6);
$aLinks[] = array($sLinkPage, $sLinkSyn);
array_shift($aState);
switch($aState[0])
{
switch ($aState[0]) {
case 'template':
$aTemplateStack[0][0] .= trim($sPart);
break;
@@ -167,8 +160,7 @@ function _parseWikipediaContent($sPageText)
}
break;
case '|':
if ($aState[0] == 'template' || $aState[0] == 'templateparam')
{
if ($aState[0] == 'template' || $aState[0] == 'templateparam') {
// Create a new template paramater
$aState[0] = 'templateparam';
array_unshift($aTemplateStack[0][1], '');
@@ -176,8 +168,7 @@ function _parseWikipediaContent($sPageText)
if ($aState[0] == 'link') $aState[0] = 'linksynonim';
break;
default:
switch($aState[0])
{
switch ($aState[0]) {
case 'template':
$aTemplateStack[0][0] .= trim($sPart);
break;
@@ -206,181 +197,139 @@ function _parseWikipediaContent($sPageText)
function _templatesToProperties($aTemplates)
{
$aPageProperties = array();
foreach($aTemplates as $iTemplate => $aTemplate)
{
foreach ($aTemplates as $iTemplate => $aTemplate) {
$aParams = array();
foreach(array_reverse($aTemplate[1]) as $iParam => $sParam)
{
if (($iPos = strpos($sParam, '=')) === FALSE)
{
foreach (array_reverse($aTemplate[1]) as $iParam => $sParam) {
if (($iPos = strpos($sParam, '=')) === FALSE) {
$aParams[] = trim($sParam);
}
else
{
} else {
$aParams[trim(substr($sParam, 0, $iPos))] = trim(substr($sParam, $iPos+1));
}
}
$aTemplates[$iTemplate][1] = $aParams;
if (!isset($aPageProperties['sOfficialName']) && isset($aParams['official_name']) && $aParams['official_name']) $aPageProperties['sOfficialName'] = $aParams['official_name'];
if (!isset($aPageProperties['iPopulation']) && isset($aParams['population']) && $aParams['population'] && preg_match('#^[0-9.,]+#', $aParams['population']))
{
if (!isset($aPageProperties['iPopulation']) && isset($aParams['population']) && $aParams['population'] && preg_match('#^[0-9.,]+#', $aParams['population'])) {
$aPageProperties['iPopulation'] = (int)str_replace(array(',','.'), '', $aParams['population']);
}
if (!isset($aPageProperties['iPopulation']) && isset($aParams['population_total']) && $aParams['population_total'] && preg_match('#^[0-9.,]+#', $aParams['population_total']))
{
if (!isset($aPageProperties['iPopulation']) && isset($aParams['population_total']) && $aParams['population_total'] && preg_match('#^[0-9.,]+#', $aParams['population_total'])) {
$aPageProperties['iPopulation'] = (int)str_replace(array(',','.'), '', $aParams['population_total']);
}
if (!isset($aPageProperties['iPopulation']) && isset($aParams['population_urban']) && $aParams['population_urban'] && preg_match('#^[0-9.,]+#', $aParams['population_urban']))
{
if (!isset($aPageProperties['iPopulation']) && isset($aParams['population_urban']) && $aParams['population_urban'] && preg_match('#^[0-9.,]+#', $aParams['population_urban'])) {
$aPageProperties['iPopulation'] = (int)str_replace(array(',','.'), '', $aParams['population_urban']);
}
if (!isset($aPageProperties['iPopulation']) && isset($aParams['population_estimate']) && $aParams['population_estimate'] && preg_match('#^[0-9.,]+#', $aParams['population_estimate']))
{
if (!isset($aPageProperties['iPopulation']) && isset($aParams['population_estimate']) && $aParams['population_estimate'] && preg_match('#^[0-9.,]+#', $aParams['population_estimate'])) {
$aPageProperties['iPopulation'] = (int)str_replace(array(',','.'), '', $aParams['population_estimate']);
}
if (!isset($aPageProperties['sWebsite']) && isset($aParams['website']) && $aParams['website'])
{
if (preg_match('#^\\[?([^ \\]]+)[^\\]]*\\]?$#', $aParams['website'], $aMatch))
{
if (!isset($aPageProperties['sWebsite']) && isset($aParams['website']) && $aParams['website']) {
if (preg_match('#^\\[?([^ \\]]+)[^\\]]*\\]?$#', $aParams['website'], $aMatch)) {
$aPageProperties['sWebsite'] = $aMatch[1];
if (strpos($aPageProperties['sWebsite'],':/'.'/') === FALSE)
{
if (strpos($aPageProperties['sWebsite'],':/'.'/') === FALSE) {
$aPageProperties['sWebsite'] = 'http:/'.'/'.$aPageProperties['sWebsite'];
}
}
}
if (!isset($aPageProperties['sTopLevelDomain']) && isset($aParams['cctld']) && $aParams['cctld'])
{
if (!isset($aPageProperties['sTopLevelDomain']) && isset($aParams['cctld']) && $aParams['cctld']) {
$aPageProperties['sTopLevelDomain'] = str_replace(array('[',']','.'),'', $aParams['cctld']);
}
if (!isset($aPageProperties['sInfoboxType']) && strtolower(substr($aTemplate[0],0,7)) == 'infobox')
{
if (!isset($aPageProperties['sInfoboxType']) && strtolower(substr($aTemplate[0],0,7)) == 'infobox') {
$aPageProperties['sInfoboxType'] = trim(substr($aTemplate[0],8));
// $aPageProperties['aInfoboxParams'] = $aParams;
}
// Assume the first template with lots of params is the type (fallback for infobox)
if (!isset($aPageProperties['sPossibleInfoboxType']) && sizeof($aParams) > 10)
{
if (!isset($aPageProperties['sPossibleInfoboxType']) && sizeof($aParams) > 10) {
$aPageProperties['sPossibleInfoboxType'] = trim($aTemplate[0]);
// $aPageProperties['aInfoboxParams'] = $aParams;
}
// do we have a lat/lon
if (!isset($aPageProperties['fLat']))
{
if (isset($aParams['latd']) && isset($aParams['longd']))
{
if (!isset($aPageProperties['fLat'])) {
if (isset($aParams['latd']) && isset($aParams['longd'])) {
$aPageProperties['fLat'] = degreesAndMinutesToDecimal($aParams['latd'], @$aParams['latm'], @$aParams['lats'], @$aParams['latNS']);
$aPageProperties['fLon'] = degreesAndMinutesToDecimal($aParams['longd'], @$aParams['longm'], @$aParams['longs'], @$aParams['longEW']);
}
if (isset($aParams['lat_degrees']) && isset($aParams['lat_degrees']))
{
if (isset($aParams['lat_degrees']) && isset($aParams['lat_degrees'])) {
$aPageProperties['fLat'] = degreesAndMinutesToDecimal($aParams['lat_degrees'], @$aParams['lat_minutes'], @$aParams['lat_seconds'], @$aParams['lat_direction']);
$aPageProperties['fLon'] = degreesAndMinutesToDecimal($aParams['long_degrees'], @$aParams['long_minutes'], @$aParams['long_seconds'], @$aParams['long_direction']);
}
if (isset($aParams['latitude']) && isset($aParams['longitude']))
{
if (preg_match('#[0-9.]+#', $aParams['latitude']) && preg_match('#[0-9.]+#', $aParams['longitude']))
{
if (isset($aParams['latitude']) && isset($aParams['longitude'])) {
if (preg_match('#[0-9.]+#', $aParams['latitude']) && preg_match('#[0-9.]+#', $aParams['longitude'])) {
$aPageProperties['fLat'] = (float)$aParams['latitude'];
$aPageProperties['fLon'] = (float)$aParams['longitude'];
}
}
if (strtolower($aTemplate[0]) == 'coord')
{
if (isset($aParams[3]) && (strtoupper($aParams[3]) == 'N' || strtoupper($aParams[3]) == 'S'))
{
if (strtolower($aTemplate[0]) == 'coord') {
if (isset($aParams[3]) && (strtoupper($aParams[3]) == 'N' || strtoupper($aParams[3]) == 'S')) {
$aPageProperties['fLat'] = degreesAndMinutesToDecimal($aParams[0], $aParams[1], $aParams[2], $aParams[3]);
$aPageProperties['fLon'] = degreesAndMinutesToDecimal($aParams[4], $aParams[5], $aParams[6], $aParams[7]);
}
elseif (isset($aParams[0]) && isset($aParams[1]) && isset($aParams[2]) && (strtoupper($aParams[2]) == 'N' || strtoupper($aParams[2]) == 'S'))
{
} elseif (isset($aParams[0]) && isset($aParams[1]) && isset($aParams[2]) && (strtoupper($aParams[2]) == 'N' || strtoupper($aParams[2]) == 'S')) {
$aPageProperties['fLat'] = degreesAndMinutesToDecimal($aParams[0], $aParams[1], 0, $aParams[2]);
$aPageProperties['fLon'] = degreesAndMinutesToDecimal($aParams[3], $aParams[4], 0, $aParams[5]);
}
else if (isset($aParams[0]) && isset($aParams[1]) && (strtoupper($aParams[1]) == 'N' || strtoupper($aParams[1]) == 'S'))
{
} else if (isset($aParams[0]) && isset($aParams[1]) && (strtoupper($aParams[1]) == 'N' || strtoupper($aParams[1]) == 'S')) {
$aPageProperties['fLat'] = (strtoupper($aParams[1]) == 'N'?1:-1) * (float)$aParams[0];
$aPageProperties['fLon'] = (strtoupper($aParams[3]) == 'E'?1:-1) * (float)$aParams[2];
}
else if (isset($aParams[0]) && is_numeric($aParams[0]) && isset($aParams[1]) && is_numeric($aParams[1]))
{
} else if (isset($aParams[0]) && is_numeric($aParams[0]) && isset($aParams[1]) && is_numeric($aParams[1])) {
$aPageProperties['fLat'] = (float)$aParams[0];
$aPageProperties['fLon'] = (float)$aParams[1];
}
}
if (isset($aParams['Latitude']) && isset($aParams['Longitude']))
{
if (isset($aParams['Latitude']) && isset($aParams['Longitude'])) {
$aParams['Latitude'] = str_replace('&nbsp;',' ',$aParams['Latitude']);
$aParams['Longitude'] = str_replace('&nbsp;',' ',$aParams['Longitude']);
if (preg_match('#^([0-9]+)°(([0-9]+))? ([NS]) to ([0-9]+)°(([0-9]+))? ([NS])#', $aParams['Latitude'], $aMatch))
{
if (preg_match('#^([0-9]+)°(([0-9]+))? ([NS]) to ([0-9]+)°(([0-9]+))? ([NS])#', $aParams['Latitude'], $aMatch)) {
$aPageProperties['fLat'] =
(degreesAndMinutesToDecimal($aMatch[1], $aMatch[3], 0, $aMatch[4])
+degreesAndMinutesToDecimal($aMatch[5], $aMatch[7], 0, $aMatch[8])) / 2;
}
else if (preg_match('#^([0-9]+)°(([0-9]+))? ([NS])#', $aParams['Latitude'], $aMatch))
{
} else if (preg_match('#^([0-9]+)°(([0-9]+))? ([NS])#', $aParams['Latitude'], $aMatch)) {
$aPageProperties['fLat'] = degreesAndMinutesToDecimal($aMatch[1], $aMatch[3], 0, $aMatch[4]);
}
if (preg_match('#^([0-9]+)°(([0-9]+))? ([EW]) to ([0-9]+)°(([0-9]+))? ([EW])#', $aParams['Longitude'], $aMatch))
{
if (preg_match('#^([0-9]+)°(([0-9]+))? ([EW]) to ([0-9]+)°(([0-9]+))? ([EW])#', $aParams['Longitude'], $aMatch)) {
$aPageProperties['fLon'] =
(degreesAndMinutesToDecimal($aMatch[1], $aMatch[3], 0, $aMatch[4])
+degreesAndMinutesToDecimal($aMatch[5], $aMatch[7], 0, $aMatch[8])) / 2;
}
else if (preg_match('#^([0-9]+)°(([0-9]+))? ([EW])#', $aParams['Longitude'], $aMatch))
{
} else if (preg_match('#^([0-9]+)°(([0-9]+))? ([EW])#', $aParams['Longitude'], $aMatch)) {
$aPageProperties['fLon'] = degreesAndMinutesToDecimal($aMatch[1], $aMatch[3], 0, $aMatch[4]);
}
}
}
}
if (isset($aPageProperties['sPossibleInfoboxType']))
{
if (isset($aPageProperties['sPossibleInfoboxType'])) {
if (!isset($aPageProperties['sInfoboxType'])) $aPageProperties['sInfoboxType'] = '#'.$aPageProperties['sPossibleInfoboxType'];
unset($aPageProperties['sPossibleInfoboxType']);
}
return $aPageProperties;
}
if (isset($aCMDResult['parse-wikipedia']))
{
if (isset($aCMDResult['parse-wikipedia'])) {
$oDB =& getDB();
$aArticleNames = $oDB->getCol('select page_title from content where page_namespace = 0 and page_id %10 = '.$aCMDResult['parse-wikipedia'].' and (page_content ilike \'%{{Coord%\' or (page_content ilike \'%lat%\' and page_content ilike \'%lon%\'))');
// $aArticleNames = $oDB->getCol($sSQL = 'select page_title from content where page_namespace = 0 and (page_content ilike \'%{{Coord%\' or (page_content ilike \'%lat%\' and page_content ilike \'%lon%\')) and page_title in (\'Virginia\')');
foreach($aArticleNames as $sArticleName)
{
foreach ($aArticleNames as $sArticleName) {
$sPageText = $oDB->getOne('select page_content from content where page_namespace = 0 and page_title = \''.pg_escape_string($sArticleName).'\'');
$aP = _templatesToProperties(_parseWikipediaContent($sPageText));
if (isset($aP['sInfoboxType']))
{
if (isset($aP['sInfoboxType'])) {
$aP['sInfoboxType'] = preg_replace('#\\s+#',' ',$aP['sInfoboxType']);
$sSQL = 'update wikipedia_article set ';
$sSQL .= 'infobox_type = \''.pg_escape_string($aP['sInfoboxType']).'\'';
$sSQL .= ' where language = \'en\' and title = \''.pg_escape_string($sArticleName).'\';';
$oDB->query($sSQL);
}
if (isset($aP['iPopulation']))
{
if (isset($aP['iPopulation'])) {
$sSQL = 'update wikipedia_article set ';
$sSQL .= 'population = \''.pg_escape_string($aP['iPopulation']).'\'';
$sSQL .= ' where language = \'en\' and title = \''.pg_escape_string($sArticleName).'\';';
$oDB->query($sSQL);
}
if (isset($aP['sWebsite']))
{
if (isset($aP['sWebsite'])) {
$sSQL = 'update wikipedia_article set ';
$sSQL .= 'website = \''.pg_escape_string($aP['sWebsite']).'\'';
$sSQL .= ' where language = \'en\' and title = \''.pg_escape_string($sArticleName).'\';';
$oDB->query($sSQL);
}
if (isset($aP['fLat']) && ($aP['fLat']!='-0' || $aP['fLon']!='-0'))
{
if (isset($aP['fLat']) && ($aP['fLat']!='-0' || $aP['fLon']!='-0')) {
if (!isset($aP['sInfoboxType'])) $aP['sInfoboxType'] = '';
echo $sArticleName.'|'.$aP['sInfoboxType'].'|'.$aP['fLat'].'|'.$aP['fLon'] ."\n";
$sSQL = 'update wikipedia_article set ';
@@ -395,8 +344,7 @@ if (isset($aCMDResult['parse-wikipedia']))
function nominatimXMLStart($hParser, $sName, $aAttr)
{
global $aNominatRecords;
switch($sName)
{
switch ($sName) {
case 'PLACE':
$aNominatRecords[] = $aAttr;
break;
@@ -408,16 +356,14 @@ function nominatimXMLEnd($hParser, $sName)
}
if (isset($aCMDResult['link']))
{
if (isset($aCMDResult['link'])) {
$oDB =& getDB();
$aWikiArticles = $oDB->getAll("select * from wikipedia_article where language = 'en' and lat is not null and osm_type is null and totalcount < 31 order by importance desc limit 200000");
// If you point this script at production OSM you will be blocked
$sNominatimBaseURL = 'http://SEVERNAME/search.php';
foreach($aWikiArticles as $aRecord)
{
foreach ($aWikiArticles as $aRecord) {
$aRecord['name'] = str_replace('_',' ',$aRecord['title']);
$sURL = $sNominatimBaseURL.'?format=xml&accept-language=en';
@@ -425,8 +371,7 @@ if (isset($aCMDResult['link']))
echo "\n-- ".$aRecord['name'].", ".$aRecord['infobox_type']."\n";
$fMaxDist = 0.0000001;
$bUnknown = false;
switch(strtolower($aRecord['infobox_type']))
{
switch (strtolower($aRecord['infobox_type'])) {
case 'former country':
continue 2;
case 'sea':
@@ -535,11 +480,9 @@ if (isset($aCMDResult['link']))
xml_parse($hXMLParser, $sXML, true);
xml_parser_free($hXMLParser);
if (!isset($aNominatRecords[0]))
{
if (!isset($aNominatRecords[0])) {
$aNameParts = preg_split('#[(,]#',$aRecord['name']);
if (sizeof($aNameParts) > 1)
{
if (sizeof($aNameParts) > 1) {
$sNameURL = $sURL.'&q='.urlencode(trim($aNameParts[0]));
var_Dump($sNameURL);
$sXML = file_get_contents($sNameURL);
@@ -553,8 +496,7 @@ if (isset($aCMDResult['link']))
}
// assume first is best/right
for($i = 0; $i < sizeof($aNominatRecords); $i++)
{
for ($i = 0; $i < sizeof($aNominatRecords); $i++) {
$fDiff = ($aRecord['lat']-$aNominatRecords[$i]['LAT']) * ($aRecord['lat']-$aNominatRecords[$i]['LAT']);
$fDiff += ($aRecord['lon']-$aNominatRecords[$i]['LON']) * ($aRecord['lon']-$aNominatRecords[$i]['LON']);
$fDiff = sqrt($fDiff);
@@ -572,15 +514,11 @@ if (isset($aCMDResult['link']))
else $fMaxDist = 0.001;
}
echo "-- FOUND \"".substr($aNominatRecords[$i]['DISPLAY_NAME'],0,50)."\", ".$aNominatRecords[$i]['CLASS'].", ".$aNominatRecords[$i]['TYPE'].", ".$aNominatRecords[$i]['PLACE_RANK'].", ".$aNominatRecords[$i]['OSM_TYPE']." (dist:$fDiff, max:$fMaxDist)\n";
if ($fDiff > $fMaxDist)
{
if ($fDiff > $fMaxDist) {
echo "-- Diff too big $fDiff (max: $fMaxDist)".$aRecord['lat'].','.$aNominatRecords[$i]['LAT'].' & '.$aRecord['lon'].','.$aNominatRecords[$i]['LON']." \n";
}
else
{
} else {
$sSQL = "update wikipedia_article set osm_type=";
switch($aNominatRecords[$i]['OSM_TYPE'])
{
switch ($aNominatRecords[$i]['OSM_TYPE']) {
case 'relation': $sSQL .= "'R'"; break;
case 'way': $sSQL .= "'W'"; break;
case 'node': $sSQL .= "'N'"; break;

View File

@@ -16,16 +16,14 @@ $aCMDOptions = array(
getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true);
if (isset($aCMDResult['parse-tiger']))
{
if (isset($aCMDResult['parse-tiger'])) {
if (!file_exists(CONST_Tiger_Data_Path)) mkdir(CONST_Tiger_Data_Path);
$sTempDir = tempnam('/tmp', 'tiger');
unlink($sTempDir);
mkdir($sTempDir);
foreach(glob($aCMDResult['parse-tiger'].'/tl_20??_?????_edges.zip', 0) as $sImportFile)
{
foreach (glob($aCMDResult['parse-tiger'].'/tl_20??_?????_edges.zip', 0) as $sImportFile) {
set_time_limit(30);
preg_match('#([0-9]{5})_(.*)#',basename($sImportFile), $aMatch);
$sCountyID = $aMatch[1];
@@ -33,29 +31,21 @@ if (isset($aCMDResult['parse-tiger']))
$sUnzipCmd = "unzip -d $sTempDir $sImportFile";
exec($sUnzipCmd);
$sShapeFile = $sTempDir.'/'.basename($sImportFile, '.zip').'.shp';
if (!file_exists($sShapeFile))
{
if (!file_exists($sShapeFile)) {
echo "Failed unzip ($sImportFile)\n";
}
else
{
} else {
$sParseCmd = CONST_BasePath.'/utils/tigerAddressImport.py '.$sShapeFile;
exec($sParseCmd);
$sOsmFile = $sTempDir.'/'.basename($sImportFile, '.zip').'.osm1.osm';
if (!file_exists($sOsmFile))
{
if (!file_exists($sOsmFile)) {
echo "Failed parse ($sImportFile)\n";
}
else
{
} else {
copy($sOsmFile, CONST_Tiger_Data_Path.'/'.$sCountyID.'.sql');
}
}
// Cleanup
foreach(glob($sTempDir.'/*') as $sTmpFile)
{
foreach (glob($sTempDir.'/*') as $sTmpFile) {
unlink($sTmpFile);
}
}
}

View File

@@ -29,8 +29,7 @@ getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true);
$oDB =& getDB();
$oParams = new ParameterParser($aCMDResult);
if ($oParams->getBool('search'))
{
if ($oParams->getBool('search')) {
if (isset($aCMDResult['nodedupe'])) $aCMDResult['dedupe'] = 'false';
$oGeocode = new Geocode($oDB);
@@ -41,12 +40,11 @@ if ($oParams->getBool('search'))
$aSearchResults = $oGeocode->lookup();
if (version_compare(phpversion(), "5.4.0", '<'))
if (version_compare(phpversion(), "5.4.0", '<')) {
echo json_encode($aSearchResults);
else
} else {
echo json_encode($aSearchResults, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)."\n";
}
else
{
}
} else {
showUsage($aCMDOptions, true);
}

View File

@@ -13,27 +13,23 @@ $sHost2Escaped = str_replace('/', '\\/', $sHost2);
$aToDo = array(251, 293, 328, 399.1, 455.1, 479, 496, 499, 574, 609, 702, 790, 846, 865, 878, 894, 902, 961, 980);
$hFile = @fopen($sFile, "r");
if (!$hFile)
{
if (!$hFile) {
echo "Unable to open file: $sFile\n";
exit;
}
$i = 0;
while (($sLine = fgets($hFile, 10000)) !== false)
{
while (($sLine = fgets($hFile, 10000)) !== false) {
$i++;
if (!in_array($i, $aToDo)) continue;
if (preg_match('#"GET (.*) HTTP/1.[01]"#', $sLine, $aResult))
{
if (preg_match('#"GET (.*) HTTP/1.[01]"#', $sLine, $aResult)) {
$sURL1 = $sHost1.$aResult[1];
$sURL2 = $sHost2.$aResult[1];
$sRes1 = '';
$k = 0;
while(!$sRes1 && $k < 10)
{
while (!$sRes1 && $k < 10) {
$sRes1 = file_get_contents($sURL1);
$k++;
if (!$sRes1) sleep(10);
@@ -48,29 +44,24 @@ while (($sLine = fgets($hFile, 10000)) !== false)
$sRes2 = str_replace($sHost2, '', $sRes2);
$sRes2 = str_replace($sHost2Escaped, '', $sRes2);
if ($sRes1 != $sRes2)
{
if ($sRes1 != $sRes2) {
echo "$i:\n";
var_dump($sURL1, $sURL2);
$sRes = $sURL1.":\n";
for ($j = 0; $j < strlen($sRes1); $j+=40)
{
for ($j = 0; $j < strlen($sRes1); $j+=40) {
$sRes .= substr($sRes1, $j, 40)."\n";
}
file_put_contents('log/'.$i.'.1', $sRes);
$sRes = $sURL2.":\n";
for ($j = 0; $j < strlen($sRes2); $j+=40)
{
for ($j = 0; $j < strlen($sRes2); $j+=40) {
$sRes .= substr($sRes2, $j, 40)."\n";
}
file_put_contents('log/'.$i.'.2', $sRes);
}
echo ".\n";
}
else
{
} else {
var_dump($sLine);
}
}

View File

@@ -44,20 +44,16 @@ getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true);
$bDidSomething = false;
// Check if osm-file is set and points to a valid file if --all or --import-data is given
if ($aCMDResult['import-data'] || $aCMDResult['all'])
{
if (!isset($aCMDResult['osm-file']))
{
if ($aCMDResult['import-data'] || $aCMDResult['all']) {
if (!isset($aCMDResult['osm-file'])) {
fail('missing --osm-file for data import');
}
if (!file_exists($aCMDResult['osm-file']))
{
if (!file_exists($aCMDResult['osm-file'])) {
fail('the path supplied to --osm-file does not exist');
}
if (!is_readable($aCMDResult['osm-file']))
{
if (!is_readable($aCMDResult['osm-file'])) {
fail('osm-file "'.$aCMDResult['osm-file'].'" not readable');
}
}
@@ -65,44 +61,36 @@ if ($aCMDResult['import-data'] || $aCMDResult['all'])
// This is a pretty hard core default - the number of processors in the box - 1
$iInstances = isset($aCMDResult['threads'])?$aCMDResult['threads']:(getProcessorCount()-1);
if ($iInstances < 1)
{
if ($iInstances < 1) {
$iInstances = 1;
echo "WARNING: resetting threads to $iInstances\n";
}
if ($iInstances > getProcessorCount())
{
if ($iInstances > getProcessorCount()) {
$iInstances = getProcessorCount();
echo "WARNING: resetting threads to $iInstances\n";
}
// Assume we can steal all the cache memory in the box (unless told otherwise)
if (isset($aCMDResult['osm2pgsql-cache']))
{
if (isset($aCMDResult['osm2pgsql-cache'])) {
$iCacheMemory = $aCMDResult['osm2pgsql-cache'];
}
else
{
} else {
$iCacheMemory = getCacheMemoryMB();
}
$aDSNInfo = DB::parseDSN(CONST_Database_DSN);
if (!isset($aDSNInfo['port']) || !$aDSNInfo['port']) $aDSNInfo['port'] = 5432;
if ($aCMDResult['create-db'] || $aCMDResult['all'])
{
if ($aCMDResult['create-db'] || $aCMDResult['all']) {
echo "Create DB\n";
$bDidSomething = true;
$oDB = DB::connect(CONST_Database_DSN, false);
if (!PEAR::isError($oDB))
{
if (!PEAR::isError($oDB)) {
fail('database already exists ('.CONST_Database_DSN.')');
}
passthruCheckReturn('createdb -E UTF-8 -p '.$aDSNInfo['port'].' '.$aDSNInfo['database']);
}
if ($aCMDResult['setup-db'] || $aCMDResult['all'])
{
if ($aCMDResult['setup-db'] || $aCMDResult['all']) {
echo "Setup DB\n";
$bDidSomething = true;
// TODO: path detection, detection memory, etc.
@@ -112,8 +100,7 @@ if ($aCMDResult['setup-db'] || $aCMDResult['all'])
$fPostgresVersion = getPostgresVersion($oDB);
echo 'Postgres version found: '.$fPostgresVersion."\n";
if ($fPostgresVersion < 9.1)
{
if ($fPostgresVersion < 9.1) {
fail("Minimum supported version of Postgresql is 9.1.");
}
@@ -125,8 +112,7 @@ if ($aCMDResult['setup-db'] || $aCMDResult['all'])
// versions add a dummy function that returns nothing.
$iNumFunc = chksql($oDB->getOne("select count(*) from pg_proc where proname = 'hstore_to_json'"));
if ($iNumFunc == 0)
{
if ($iNumFunc == 0) {
pgsqlRunScript("create function hstore_to_json(dummy hstore) returns text AS 'select null::text' language sql immutable");
echo "WARNING: Postgresql is too old. extratags and namedetails API not available.";
}
@@ -134,8 +120,7 @@ if ($aCMDResult['setup-db'] || $aCMDResult['all'])
$fPostgisVersion = getPostgisVersion($oDB);
echo 'Postgis version found: '.$fPostgisVersion."\n";
if ($fPostgisVersion < 2.1)
{
if ($fPostgisVersion < 2.1) {
// Function was renamed in 2.1 and throws an annoying deprecation warning
pgsqlRunScript('ALTER FUNCTION st_line_interpolate_point(geometry, double precision) RENAME TO ST_LineInterpolatePoint');
}
@@ -144,21 +129,16 @@ if ($aCMDResult['setup-db'] || $aCMDResult['all'])
pgsqlRunScriptFile(CONST_BasePath.'/data/country_naturalearthdata.sql');
pgsqlRunScriptFile(CONST_BasePath.'/data/country_osm_grid.sql');
pgsqlRunScriptFile(CONST_BasePath.'/data/gb_postcode_table.sql');
if (file_exists(CONST_BasePath.'/data/gb_postcode_data.sql.gz'))
{
if (file_exists(CONST_BasePath.'/data/gb_postcode_data.sql.gz')) {
pgsqlRunScriptFile(CONST_BasePath.'/data/gb_postcode_data.sql.gz');
}
else
{
} else {
echo "WARNING: external UK postcode table not found.\n";
}
if (CONST_Use_Extra_US_Postcodes)
{
if (CONST_Use_Extra_US_Postcodes) {
pgsqlRunScriptFile(CONST_BasePath.'/data/us_postcode.sql');
}
if ($aCMDResult['no-partitions'])
{
if ($aCMDResult['no-partitions']) {
pgsqlRunScript('update country_name set partition = 0');
}
@@ -170,20 +150,17 @@ if ($aCMDResult['setup-db'] || $aCMDResult['all'])
pgsqlRunScript('create type wikipedia_article_match as ()');
}
if ($aCMDResult['import-data'] || $aCMDResult['all'])
{
if ($aCMDResult['import-data'] || $aCMDResult['all']) {
echo "Import\n";
$bDidSomething = true;
$osm2pgsql = CONST_Osm2pgsql_Binary;
if (!file_exists($osm2pgsql))
{
if (!file_exists($osm2pgsql)) {
echo "Please download and build osm2pgsql.\nIf it is already installed, check the path in your local settings (settings/local.php) file.\n";
fail("osm2pgsql not found in '$osm2pgsql'");
}
if (!is_null(CONST_Osm2pgsql_Flatnode_File))
{
if (!is_null(CONST_Osm2pgsql_Flatnode_File)) {
$osm2pgsql .= ' --flat-nodes '.CONST_Osm2pgsql_Flatnode_File;
}
if (CONST_Tablespace_Osm2pgsql_Data)
@@ -201,22 +178,19 @@ if ($aCMDResult['import-data'] || $aCMDResult['all'])
passthruCheckReturn($osm2pgsql);
$oDB =& getDB();
if (!chksql($oDB->getRow('select * from place limit 1')))
{
if (!chksql($oDB->getRow('select * from place limit 1'))) {
fail('No Data');
}
}
if ($aCMDResult['create-functions'] || $aCMDResult['all'])
{
if ($aCMDResult['create-functions'] || $aCMDResult['all']) {
echo "Functions\n";
$bDidSomething = true;
if (!file_exists(CONST_InstallPath.'/module/nominatim.so')) fail("nominatim module not built");
create_sql_functions($aCMDResult);
}
if ($aCMDResult['create-tables'] || $aCMDResult['all'])
{
if ($aCMDResult['create-tables'] || $aCMDResult['all']) {
$bDidSomething = true;
echo "Tables\n";
@@ -241,8 +215,7 @@ if ($aCMDResult['create-tables'] || $aCMDResult['all'])
create_sql_functions($aCMDResult);
}
if ($aCMDResult['create-partition-tables'] || $aCMDResult['all'])
{
if ($aCMDResult['create-partition-tables'] || $aCMDResult['all']) {
echo "Partition Tables\n";
$bDidSomething = true;
@@ -264,8 +237,7 @@ if ($aCMDResult['create-partition-tables'] || $aCMDResult['all'])
}
if ($aCMDResult['create-partition-functions'] || $aCMDResult['all'])
{
if ($aCMDResult['create-partition-functions'] || $aCMDResult['all']) {
echo "Partition Functions\n";
$bDidSomething = true;
@@ -274,36 +246,28 @@ if ($aCMDResult['create-partition-functions'] || $aCMDResult['all'])
pgsqlRunPartitionScript($sTemplate);
}
if ($aCMDResult['import-wikipedia-articles'] || $aCMDResult['all'])
{
if ($aCMDResult['import-wikipedia-articles'] || $aCMDResult['all']) {
$bDidSomething = true;
$sWikiArticlesFile = CONST_BasePath.'/data/wikipedia_article.sql.bin';
$sWikiRedirectsFile = CONST_BasePath.'/data/wikipedia_redirect.sql.bin';
if (file_exists($sWikiArticlesFile))
{
if (file_exists($sWikiArticlesFile)) {
echo "Importing wikipedia articles...";
pgsqlRunDropAndRestore($sWikiArticlesFile);
echo "...done\n";
}
else
{
} else {
echo "WARNING: wikipedia article dump file not found - places will have default importance\n";
}
if (file_exists($sWikiRedirectsFile))
{
if (file_exists($sWikiRedirectsFile)) {
echo "Importing wikipedia redirects...";
pgsqlRunDropAndRestore($sWikiRedirectsFile);
echo "...done\n";
}
else
{
} else {
echo "WARNING: wikipedia redirect dump file not found - some place importance values may be missing\n";
}
}
if ($aCMDResult['load-data'] || $aCMDResult['all'])
{
if ($aCMDResult['load-data'] || $aCMDResult['all']) {
echo "Drop old Data\n";
$bDidSomething = true;
@@ -332,8 +296,7 @@ if ($aCMDResult['load-data'] || $aCMDResult['all'])
$sSQL = 'select distinct partition from country_name';
$aPartitions = chksql($oDB->getCol($sSQL));
if (!$aCMDResult['no-partitions']) $aPartitions[] = 0;
foreach($aPartitions as $sPartition)
{
foreach ($aPartitions as $sPartition) {
if (!pg_query($oDB->connection, 'TRUNCATE location_road_'.$sPartition)) fail(pg_last_error($oDB->connection));
echo '.';
}
@@ -343,8 +306,7 @@ if ($aCMDResult['load-data'] || $aCMDResult['all'])
echo ".\n";
// pre-create the word list
if (!$aCMDResult['disable-token-precalc'])
{
if (!$aCMDResult['disable-token-precalc']) {
echo "Loading word list\n";
pgsqlRunScriptFile(CONST_BasePath.'/data/words.sql');
}
@@ -352,8 +314,7 @@ if ($aCMDResult['load-data'] || $aCMDResult['all'])
echo "Load Data\n";
$aDBInstances = array();
$iLoadThreads = max(1, $iInstances - 1);
for($i = 0; $i < $iLoadThreads; $i++)
{
for ($i = 0; $i < $iLoadThreads; $i++) {
$aDBInstances[$i] =& getDB(true);
$sSQL = 'insert into placex (osm_type, osm_id, class, type, name, admin_level, ';
$sSQL .= 'housenumber, street, addr_place, isin, postcode, country_code, extratags, ';
@@ -371,11 +332,9 @@ if ($aCMDResult['load-data'] || $aCMDResult['all'])
if (!pg_send_query($aDBInstances[$i]->connection, $sSQL)) fail(pg_last_error($oDB->connection));
$bAnyBusy = true;
while($bAnyBusy)
{
while ($bAnyBusy) {
$bAnyBusy = false;
for($i = 0; $i <= $iLoadThreads; $i++)
{
for ($i = 0; $i <= $iLoadThreads; $i++) {
if (pg_connection_busy($aDBInstances[$i]->connection)) $bAnyBusy = true;
}
sleep(1);
@@ -386,8 +345,7 @@ if ($aCMDResult['load-data'] || $aCMDResult['all'])
pgsqlRunScript('ANALYSE');
}
if ($aCMDResult['import-tiger-data'])
{
if ($aCMDResult['import-tiger-data']) {
$bDidSomething = true;
$sTemplate = file_get_contents(CONST_BasePath.'/sql/tiger_import_start.sql');
@@ -399,31 +357,25 @@ if ($aCMDResult['import-tiger-data'])
pgsqlRunScript($sTemplate, false);
$aDBInstances = array();
for($i = 0; $i < $iInstances; $i++)
{
for ($i = 0; $i < $iInstances; $i++) {
$aDBInstances[$i] =& getDB(true);
}
foreach(glob(CONST_Tiger_Data_Path.'/*.sql') as $sFile)
{
foreach (glob(CONST_Tiger_Data_Path.'/*.sql') as $sFile) {
echo $sFile.': ';
$hFile = fopen($sFile, "r");
$sSQL = fgets($hFile, 100000);
$iLines = 0;
while(true)
{
for($i = 0; $i < $iInstances; $i++)
{
if (!pg_connection_busy($aDBInstances[$i]->connection))
{
while(pg_get_result($aDBInstances[$i]->connection));
while (true) {
for ($i = 0; $i < $iInstances; $i++) {
if (!pg_connection_busy($aDBInstances[$i]->connection)) {
while (pg_get_result($aDBInstances[$i]->connection));
$sSQL = fgets($hFile, 100000);
if (!$sSQL) break 2;
if (!pg_send_query($aDBInstances[$i]->connection, $sSQL)) fail(pg_last_error($oDB->connection));
$iLines++;
if ($iLines == 1000)
{
if ($iLines == 1000) {
echo ".";
$iLines = 0;
}
@@ -435,11 +387,9 @@ if ($aCMDResult['import-tiger-data'])
fclose($hFile);
$bAnyBusy = true;
while($bAnyBusy)
{
while ($bAnyBusy) {
$bAnyBusy = false;
for($i = 0; $i < $iInstances; $i++)
{
for ($i = 0; $i < $iInstances; $i++) {
if (pg_connection_busy($aDBInstances[$i]->connection)) $bAnyBusy = true;
}
usleep(10);
@@ -457,8 +407,7 @@ if ($aCMDResult['import-tiger-data'])
pgsqlRunScript($sTemplate, false);
}
if ($aCMDResult['calculate-postcodes'] || $aCMDResult['all'])
{
if ($aCMDResult['calculate-postcodes'] || $aCMDResult['all']) {
$bDidSomething = true;
$oDB =& getDB();
if (!pg_query($oDB->connection, 'DELETE from placex where osm_type=\'P\'')) fail(pg_last_error($oDB->connection));
@@ -469,8 +418,7 @@ if ($aCMDResult['calculate-postcodes'] || $aCMDResult['all'])
$sSQL .= "from placex where postcode is not null group by calculated_country_code,postcode) as x";
if (!pg_query($oDB->connection, $sSQL)) fail(pg_last_error($oDB->connection));
if (CONST_Use_Extra_US_Postcodes)
{
if (CONST_Use_Extra_US_Postcodes) {
$sSQL = "insert into placex (osm_type,osm_id,class,type,postcode,calculated_country_code,geometry) ";
$sSQL .= "select 'P',nextval('seq_postcodes'),'place','postcode',postcode,'us',";
$sSQL .= "ST_SetSRID(ST_Point(x,y),4326) as geometry from us_postcode";
@@ -478,27 +426,19 @@ if ($aCMDResult['calculate-postcodes'] || $aCMDResult['all'])
}
}
if ($aCMDResult['osmosis-init'] || ($aCMDResult['all'] && !$aCMDResult['drop'])) // no use doing osmosis-init when dropping update tables
{
if ($aCMDResult['osmosis-init'] || ($aCMDResult['all'] && !$aCMDResult['drop'])) { // no use doing osmosis-init when dropping update tables
$bDidSomething = true;
$oDB =& getDB();
if (!file_exists(CONST_Osmosis_Binary))
{
if (!file_exists(CONST_Osmosis_Binary)) {
echo "Please download osmosis.\nIf it is already installed, check the path in your local settings (settings/local.php) file.\n";
if (!$aCMDResult['all'])
{
if (!$aCMDResult['all']) {
fail("osmosis not found in '".CONST_Osmosis_Binary."'");
}
}
else
{
if (file_exists(CONST_InstallPath.'/settings/configuration.txt'))
{
} else {
if (file_exists(CONST_InstallPath.'/settings/configuration.txt')) {
echo "settings/configuration.txt already exists\n";
}
else
{
} else {
passthru(CONST_Osmosis_Binary.' --read-replication-interval-init '.CONST_InstallPath.'/settings');
// update osmosis configuration.txt with our settings
passthru("sed -i 's!baseUrl=.*!baseUrl=".CONST_Replication_Url."!' ".CONST_InstallPath.'/settings/configuration.txt');
@@ -520,11 +460,9 @@ if ($aCMDResult['osmosis-init'] || ($aCMDResult['all'] && !$aCMDResult['drop']))
// download.geofabrik.de: <a href="000/">000/</a></td><td align="right">26-Feb-2013 11:53 </td>
// planet.openstreetmap.org: <a href="273/">273/</a> 2013-03-11 07:41 -
preg_match_all('#<a href="[0-9]{3}/">([0-9]{3}/)</a>\s*([-0-9a-zA-Z]+ [0-9]{2}:[0-9]{2})#', $sRep, $aRepMatches, PREG_SET_ORDER);
if ($aRepMatches)
{
if ($aRepMatches) {
$aPrevRepMatch = false;
foreach($aRepMatches as $aRepMatch)
{
foreach ($aRepMatches as $aRepMatch) {
if (strtotime($aRepMatch[2]) < $iLastNodeTimestamp) break;
$aPrevRepMatch = $aRepMatch;
}
@@ -534,8 +472,7 @@ if ($aCMDResult['osmosis-init'] || ($aCMDResult['all'] && !$aCMDResult['drop']))
$sRep = file_get_contents($sRepURL."?C=M;O=D;F=1");
preg_match_all('#<a href="[0-9]{3}/">([0-9]{3}/)</a>\s*([-0-9a-zA-Z]+ [0-9]{2}:[0-9]{2})#', $sRep, $aRepMatches, PREG_SET_ORDER);
$aPrevRepMatch = false;
foreach($aRepMatches as $aRepMatch)
{
foreach ($aRepMatches as $aRepMatch) {
if (strtotime($aRepMatch[2]) < $iLastNodeTimestamp) break;
$aPrevRepMatch = $aRepMatch;
}
@@ -545,8 +482,7 @@ if ($aCMDResult['osmosis-init'] || ($aCMDResult['all'] && !$aCMDResult['drop']))
$sRep = file_get_contents($sRepURL."?C=M;O=D;F=1");
preg_match_all('#<a href="[0-9]{3}.state.txt">([0-9]{3}).state.txt</a>\s*([-0-9a-zA-Z]+ [0-9]{2}:[0-9]{2})#', $sRep, $aRepMatches, PREG_SET_ORDER);
$aPrevRepMatch = false;
foreach($aRepMatches as $aRepMatch)
{
foreach ($aRepMatches as $aRepMatch) {
if (strtotime($aRepMatch[2]) < $iLastNodeTimestamp) break;
$aPrevRepMatch = $aRepMatch;
}
@@ -561,19 +497,15 @@ if ($aCMDResult['osmosis-init'] || ($aCMDResult['all'] && !$aCMDResult['drop']))
pg_query($oDB->connection, 'TRUNCATE import_status');
$sSQL = "INSERT INTO import_status VALUES('".$aRepMatch[2]."')";
pg_query($oDB->connection, $sSQL);
}
else
{
if (!$aCMDResult['all'])
{
} else {
if (!$aCMDResult['all']) {
fail("Cannot read state file directory.");
}
}
}
}
if ($aCMDResult['index'] || $aCMDResult['all'])
{
if ($aCMDResult['index'] || $aCMDResult['all']) {
$bDidSomething = true;
$sOutputFile = '';
$sBaseCmd = CONST_InstallPath.'/nominatim/nominatim -i -d '.$aDSNInfo['database'].' -P '.$aDSNInfo['port'].' -t '.$iInstances.$sOutputFile;
@@ -584,8 +516,7 @@ if ($aCMDResult['index'] || $aCMDResult['all'])
passthruCheckReturn($sBaseCmd.' -r 26');
}
if ($aCMDResult['create-search-indices'] || $aCMDResult['all'])
{
if ($aCMDResult['create-search-indices'] || $aCMDResult['all']) {
echo "Search indices\n";
$bDidSomething = true;
@@ -600,8 +531,7 @@ if ($aCMDResult['create-search-indices'] || $aCMDResult['all'])
pgsqlRunScript($sTemplate);
}
if ($aCMDResult['drop'])
{
if ($aCMDResult['drop']) {
// The implementation is potentially a bit dangerous because it uses
// a positive selection of tables to keep, and deletes everything else.
// Including any tables that the unsuspecting user might have manually
@@ -631,13 +561,10 @@ if ($aCMDResult['drop'])
$aDropTables = array();
$aHaveTables = chksql($oDB->getCol("SELECT tablename FROM pg_tables WHERE schemaname='public'"));
foreach($aHaveTables as $sTable)
{
foreach ($aHaveTables as $sTable) {
$bFound = false;
foreach ($aKeepTables as $sKeep)
{
if (fnmatch($sKeep, $sTable))
{
foreach ($aKeepTables as $sKeep) {
if (fnmatch($sKeep, $sTable)) {
$bFound = true;
break;
}
@@ -645,27 +572,22 @@ if ($aCMDResult['drop'])
if (!$bFound) array_push($aDropTables, $sTable);
}
foreach ($aDropTables as $sDrop)
{
foreach ($aDropTables as $sDrop) {
if ($aCMDResult['verbose']) echo "dropping table $sDrop\n";
@pg_query($oDB->connection, "DROP TABLE $sDrop CASCADE");
// ignore warnings/errors as they might be caused by a table having
// been deleted already by CASCADE
}
if (!is_null(CONST_Osm2pgsql_Flatnode_File))
{
if (!is_null(CONST_Osm2pgsql_Flatnode_File)) {
if ($aCMDResult['verbose']) echo "deleting ".CONST_Osm2pgsql_Flatnode_File."\n";
unlink(CONST_Osm2pgsql_Flatnode_File);
}
}
if (!$bDidSomething)
{
if (!$bDidSomething) {
showUsage($aCMDOptions, true);
}
else
{
} else {
echo "Setup finished.\n";
}
@@ -679,8 +601,7 @@ function pgsqlRunScriptFile($sFilename)
$sCMD = 'psql -p '.$aDSNInfo['port'].' -d '.$aDSNInfo['database'];
$ahGzipPipes = null;
if (preg_match('/\\.gz$/', $sFilename))
{
if (preg_match('/\\.gz$/', $sFilename)) {
$aDescriptors = array(
0 => array('pipe', 'r'),
1 => array('pipe', 'w'),
@@ -690,9 +611,7 @@ function pgsqlRunScriptFile($sFilename)
if (!is_resource($hGzipProcess)) fail('unable to start zcat');
$aReadPipe = $ahGzipPipes[1];
fclose($ahGzipPipes[0]);
}
else
{
} else {
$sCMD .= ' -f '.$sFilename;
$aReadPipe = array('pipe', 'r');
}
@@ -708,19 +627,16 @@ function pgsqlRunScriptFile($sFilename)
// TODO: error checking
while(!feof($ahPipes[1]))
{
while (!feof($ahPipes[1])) {
echo fread($ahPipes[1], 4096);
}
fclose($ahPipes[1]);
$iReturn = proc_close($hProcess);
if ($iReturn > 0)
{
if ($iReturn > 0) {
fail("pgsql returned with error code ($iReturn)");
}
if ($ahGzipPipes)
{
if ($ahGzipPipes) {
fclose($ahGzipPipes[1]);
proc_close($hGzipProcess);
}
@@ -745,16 +661,14 @@ function pgsqlRunScript($sScript, $bfatal = true)
$hProcess = @proc_open($sCMD, $aDescriptors, $ahPipes);
if (!is_resource($hProcess)) fail('unable to start pgsql');
while(strlen($sScript))
{
while (strlen($sScript)) {
$written = fwrite($ahPipes[0], $sScript);
if ($written <= 0) break;
$sScript = substr($sScript, $written);
}
fclose($ahPipes[0]);
$iReturn = proc_close($hProcess);
if ($bfatal && $iReturn > 0)
{
if ($bfatal && $iReturn > 0) {
fail("pgsql returned with error code ($iReturn)");
}
}
@@ -769,11 +683,9 @@ function pgsqlRunPartitionScript($sTemplate)
if (!$aCMDResult['no-partitions']) $aPartitions[] = 0;
preg_match_all('#^-- start(.*?)^-- end#ms', $sTemplate, $aMatches, PREG_SET_ORDER);
foreach($aMatches as $aMatch)
{
foreach ($aMatches as $aMatch) {
$sResult = '';
foreach($aPartitions as $sPartitionName)
{
foreach ($aPartitions as $sPartitionName) {
$sResult .= str_replace('-partition-', $sPartitionName, $aMatch[1]);
}
$sTemplate = str_replace($aMatch[0], $sResult, $sTemplate);
@@ -801,8 +713,7 @@ function pgsqlRunRestoreData($sDumpFile)
fclose($ahPipes[0]);
// TODO: error checking
while(!feof($ahPipes[1]))
{
while (!feof($ahPipes[1])) {
echo fread($ahPipes[1], 4096);
}
fclose($ahPipes[1]);
@@ -829,8 +740,7 @@ function pgsqlRunDropAndRestore($sDumpFile)
fclose($ahPipes[0]);
// TODO: error checking
while(!feof($ahPipes[1]))
{
while (!feof($ahPipes[1])) {
echo fread($ahPipes[1], 4096);
}
fclose($ahPipes[1]);
@@ -847,11 +757,12 @@ function passthruCheckReturn($cmd)
function replace_tablespace($sTemplate, $sTablespace, $sSql)
{
if ($sTablespace)
if ($sTablespace) {
$sSql = str_replace($sTemplate, 'TABLESPACE "'.$sTablespace.'"',
$sSql);
else
} else {
$sSql = str_replace($sTemplate, '', $sSql);
}
return $sSql;
}
@@ -860,24 +771,19 @@ function create_sql_functions($aCMDResult)
{
$sTemplate = file_get_contents(CONST_BasePath.'/sql/functions.sql');
$sTemplate = str_replace('{modulepath}', CONST_InstallPath.'/module', $sTemplate);
if ($aCMDResult['enable-diff-updates'])
{
if ($aCMDResult['enable-diff-updates']) {
$sTemplate = str_replace('RETURN NEW; -- %DIFFUPDATES%', '--', $sTemplate);
}
if ($aCMDResult['enable-debug-statements'])
{
if ($aCMDResult['enable-debug-statements']) {
$sTemplate = str_replace('--DEBUG:', '', $sTemplate);
}
if (CONST_Limit_Reindexing)
{
if (CONST_Limit_Reindexing) {
$sTemplate = str_replace('--LIMIT INDEXING:', '', $sTemplate);
}
if (!CONST_Use_US_Tiger_Data)
{
if (!CONST_Use_US_Tiger_Data) {
$sTemplate = str_replace('-- %NOTIGERDATA% ', '', $sTemplate);
}
if (!CONST_Use_Aux_Location_data)
{
if (!CONST_Use_Aux_Location_data) {
$sTemplate = str_replace('-- %NOAUXDATA% ', '', $sTemplate);
}
pgsqlRunScript($sTemplate);

View File

@@ -6,17 +6,17 @@ require_once(CONST_BasePath.'/lib/init-cmd.php');
ini_set('memory_limit', '800M');
ini_set('display_errors', 'stderr');
$aCMDOptions = array(
"Import and export special phrases",
array('help', 'h', 0, 1, 0, 0, false, 'Show Help'),
array('quiet', 'q', 0, 1, 0, 0, 'bool', 'Quiet output'),
array('verbose', 'v', 0, 1, 0, 0, 'bool', 'Verbose output'),
array('countries', '', 0, 1, 0, 0, 'bool', 'Create import script for country codes and names'),
array('wiki-import', '', 0, 1, 0, 0, 'bool', 'Create import script for search phrases '),
);
getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true);
$aCMDOptions = array(
"Import and export special phrases",
array('help', 'h', 0, 1, 0, 0, false, 'Show Help'),
array('quiet', 'q', 0, 1, 0, 0, 'bool', 'Quiet output'),
array('verbose', 'v', 0, 1, 0, 0, 'bool', 'Verbose output'),
array('countries', '', 0, 1, 0, 0, 'bool', 'Create import script for country codes and names'),
array('wiki-import', '', 0, 1, 0, 0, 'bool', 'Create import script for search phrases '),
);
getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true);
include(CONST_InstallPath.'/settings/phrase_settings.php');
include(CONST_InstallPath.'/settings/phrase_settings.php');
if ($aCMDResult['countries']) {
@@ -25,24 +25,19 @@ if ($aCMDResult['countries']) {
echo "select count(*) from (select getorcreate_country(make_standard_name(country_code), country_code) from country_name where country_code is not null) as x;\n";
echo "select count(*) from (select getorcreate_country(make_standard_name(get_name_by_language(country_name.name,ARRAY['name'])), country_code) from country_name where get_name_by_language(country_name.name, ARRAY['name']) is not null) as x;\n";
foreach($aLanguageIn as $sLanguage)
{
foreach ($aLanguageIn as $sLanguage) {
echo "select count(*) from (select getorcreate_country(make_standard_name(get_name_by_language(country_name.name,ARRAY['name:".$sLanguage."'])), country_code) from country_name where get_name_by_language(country_name.name, ARRAY['name:".$sLanguage."']) is not null) as x;\n";
}
}
if ($aCMDResult['wiki-import'])
{
if ($aCMDResult['wiki-import']) {
$aPairs = array();
foreach($aLanguageIn as $sLanguage)
{
foreach ($aLanguageIn as $sLanguage) {
$sURL = 'http://wiki.openstreetmap.org/wiki/Special:Export/Nominatim/Special_Phrases/'.strtoupper($sLanguage);
$sWikiPageXML = file_get_contents($sURL);
if (preg_match_all('#\\| ([^|]+) \\|\\| ([^|]+) \\|\\| ([^|]+) \\|\\| ([^|]+) \\|\\| ([\\-YN])#', $sWikiPageXML, $aMatches, PREG_SET_ORDER))
{
foreach($aMatches as $aMatch)
{
if (preg_match_all('#\\| ([^|]+) \\|\\| ([^|]+) \\|\\| ([^|]+) \\|\\| ([^|]+) \\|\\| ([\\-YN])#', $sWikiPageXML, $aMatches, PREG_SET_ORDER)) {
foreach ($aMatches as $aMatch) {
$sLabel = trim($aMatch[1]);
$sClass = trim($aMatch[2]);
$sType = trim($aMatch[3]);
@@ -67,17 +62,16 @@ if ($aCMDResult['wiki-import'])
}
$aPairs[$sClass.'|'.$sType] = array($sClass, $sType);
switch(trim($aMatch[4]))
{
case 'near':
echo "select getorcreate_amenityoperator(make_standard_name('".pg_escape_string($sLabel)."'), '$sClass', '$sType', 'near');\n";
break;
case 'in':
echo "select getorcreate_amenityoperator(make_standard_name('".pg_escape_string($sLabel)."'), '$sClass', '$sType', 'in');\n";
break;
default:
echo "select getorcreate_amenity(make_standard_name('".pg_escape_string($sLabel)."'), '$sClass', '$sType');\n";
break;
switch (trim($aMatch[4])) {
case 'near':
echo "select getorcreate_amenityoperator(make_standard_name('".pg_escape_string($sLabel)."'), '$sClass', '$sType', 'near');\n";
break;
case 'in':
echo "select getorcreate_amenityoperator(make_standard_name('".pg_escape_string($sLabel)."'), '$sClass', '$sType', 'in');\n";
break;
default:
echo "select getorcreate_amenity(make_standard_name('".pg_escape_string($sLabel)."'), '$sClass', '$sType');\n";
break;
}
}
}
@@ -85,8 +79,7 @@ if ($aCMDResult['wiki-import'])
echo "create index idx_placex_classtype on placex (class, type);";
foreach($aPairs as $aPair)
{
foreach ($aPairs as $aPair) {
echo "create table place_classtype_".pg_escape_string($aPair[0])."_".pg_escape_string($aPair[1]);
if (CONST_Tablespace_Aux_Data)
echo " tablespace ".CONST_Tablespace_Aux_Data;
@@ -107,7 +100,6 @@ if ($aCMDResult['wiki-import'])
echo ";\n";
echo "GRANT SELECT ON place_classtype_".pg_escape_string($aPair[0])."_".pg_escape_string($aPair[1]).' TO "'.CONST_Database_Web_User."\";\n";
}
echo "drop index idx_placex_classtype;";

View File

@@ -47,24 +47,20 @@ if (!isset($aDSNInfo['port']) || !$aDSNInfo['port']) $aDSNInfo['port'] = 5432;
// cache memory to be used by osm2pgsql, should not be more than the available memory
$iCacheMemory = (isset($aResult['osm2pgsql-cache'])?$aResult['osm2pgsql-cache']:2000);
if ($iCacheMemory + 500 > getTotalMemoryMB())
{
if ($iCacheMemory + 500 > getTotalMemoryMB()) {
$iCacheMemory = getCacheMemoryMB();
echo "WARNING: resetting cache memory to $iCacheMemory\n";
}
$sOsm2pgsqlCmd = CONST_Osm2pgsql_Binary.' -klas --number-processes 1 -C '.$iCacheMemory.' -O gazetteer -d '.$aDSNInfo['database'].' -P '.$aDSNInfo['port'];
if (!is_null(CONST_Osm2pgsql_Flatnode_File))
{
if (!is_null(CONST_Osm2pgsql_Flatnode_File)) {
$sOsm2pgsqlCmd .= ' --flat-nodes '.CONST_Osm2pgsql_Flatnode_File;
}
if (isset($aResult['import-diff']))
{
if (isset($aResult['import-diff'])) {
// import diff directly (e.g. from osmosis --rri)
$sNextFile = $aResult['import-diff'];
if (!file_exists($sNextFile))
{
if (!file_exists($sNextFile)) {
fail("Cannot open $sNextFile\n");
}
@@ -73,8 +69,7 @@ if (isset($aResult['import-diff']))
echo $sCMD."\n";
exec($sCMD, $sJunk, $iErrorLevel);
if ($iErrorLevel)
{
if ($iErrorLevel) {
fail("Error from osm2pgsql, $iErrorLevel\n");
}
@@ -83,55 +78,43 @@ if (isset($aResult['import-diff']))
$sTemporaryFile = CONST_BasePath.'/data/osmosischange.osc';
$bHaveDiff = false;
if (isset($aResult['import-file']) && $aResult['import-file'])
{
if (isset($aResult['import-file']) && $aResult['import-file']) {
$bHaveDiff = true;
$sCMD = CONST_Osmosis_Binary.' --read-xml \''.$aResult['import-file'].'\' --read-empty --derive-change --write-xml-change '.$sTemporaryFile;
echo $sCMD."\n";
exec($sCMD, $sJunk, $iErrorLevel);
if ($iErrorLevel)
{
if ($iErrorLevel) {
fail("Error converting osm to osc, osmosis returned: $iErrorLevel\n");
}
}
$bUseOSMApi = isset($aResult['import-from-main-api']) && $aResult['import-from-main-api'];
$sContentURL = '';
if (isset($aResult['import-node']) && $aResult['import-node'])
{
if ($bUseOSMApi)
{
if (isset($aResult['import-node']) && $aResult['import-node']) {
if ($bUseOSMApi) {
$sContentURL = 'http://www.openstreetmap.org/api/0.6/node/'.$aResult['import-node'];
}
else
{
} else {
$sContentURL = 'http://overpass-api.de/api/interpreter?data=node('.$aResult['import-node'].');out%20meta;';
}
}
if (isset($aResult['import-way']) && $aResult['import-way'])
{
if ($bUseOSMApi)
{
if (isset($aResult['import-way']) && $aResult['import-way']) {
if ($bUseOSMApi) {
$sContentURL = 'http://www.openstreetmap.org/api/0.6/way/'.$aResult['import-way'].'/full';
}
else
{
} else {
$sContentURL = 'http://overpass-api.de/api/interpreter?data=(way('.$aResult['import-way'].');node(w););out%20meta;';
}
}
if (isset($aResult['import-relation']) && $aResult['import-relation'])
{
if ($bUseOSMApi)
{
if (isset($aResult['import-relation']) && $aResult['import-relation']) {
if ($bUseOSMApi) {
$sContentURLsModifyXMLstr = 'http://www.openstreetmap.org/api/0.6/relation/'.$aResult['import-relation'].'/full';
}
else
{
} else {
$sContentURL = 'http://overpass-api.de/api/interpreter?data=((rel('.$aResult['import-relation'].');way(r);node(w));node(r));out%20meta;';
}
}
if ($sContentURL)
{
if ($sContentURL) {
$sModifyXMLstr = file_get_contents($sContentURL);
$bHaveDiff = true;
@@ -143,8 +126,7 @@ if ($sContentURL)
$sCMD = CONST_Osmosis_Binary.' --read-xml - --read-empty --derive-change --write-xml-change '.$sTemporaryFile;
echo $sCMD."\n";
$hProc = proc_open($sCMD, $aSpec, $aPipes);
if (!is_resource($hProc))
{
if (!is_resource($hProc)) {
fail("Error converting osm to osc, osmosis failed\n");
}
fwrite($aPipes[0], $sModifyXMLstr);
@@ -155,31 +137,26 @@ if ($sContentURL)
$sErrors = stream_get_contents($aPipes[2]);
if ($aResult['verbose']) echo $sErrors;
fclose($aPipes[2]);
if ($iError = proc_close($hProc))
{
if ($iError = proc_close($hProc)) {
echo $sOut;
echo $sErrors;
fail("Error converting osm to osc, osmosis returned: $iError\n");
}
}
if ($bHaveDiff)
{
if ($bHaveDiff) {
// import generated change file
$sCMD = $sOsm2pgsqlCmd.' '.$sTemporaryFile;
echo $sCMD."\n";
exec($sCMD, $sJunk, $iErrorLevel);
if ($iErrorLevel)
{
if ($iErrorLevel) {
fail("osm2pgsql exited with error level $iErrorLevel\n");
}
}
if ($aResult['deduplicate'])
{
if (getPostgresVersion() < 9.3)
{
if ($aResult['deduplicate']) {
//
if (getPostgresVersion() < 9.3) {
fail("ERROR: deduplicate is only currently supported in postgresql 9.3");
}
@@ -190,8 +167,7 @@ if ($aResult['deduplicate'])
$sSQL = "select word_token,count(*) from word where substr(word_token, 1, 1) = ' ' and class is null and type is null and country_code is null group by word_token having count(*) > 1 order by word_token";
$aDuplicateTokens = chksql($oDB->getAll($sSQL));
foreach($aDuplicateTokens as $aToken)
{
foreach ($aDuplicateTokens as $aToken) {
if (trim($aToken['word_token']) == '' || trim($aToken['word_token']) == '-') continue;
echo "Deduping ".$aToken['word_token']."\n";
$sSQL = "select word_id,(select count(*) from search_name where nameaddress_vector @> ARRAY[word_id]) as num from word where word_token = '".$aToken['word_token']."' and class is null and type is null and country_code is null order by num desc";
@@ -200,8 +176,7 @@ if ($aResult['deduplicate'])
$aKeep = array_shift($aTokenSet);
$iKeepID = $aKeep['word_id'];
foreach($aTokenSet as $aRemove)
{
foreach ($aTokenSet as $aRemove) {
$sSQL = "update search_name set";
$sSQL .= " name_vector = array_replace(name_vector,".$aRemove['word_id'].",".$iKeepID."),";
$sSQL .= " nameaddress_vector = array_replace(nameaddress_vector,".$aRemove['word_id'].",".$iKeepID.")";
@@ -218,8 +193,7 @@ if ($aResult['deduplicate'])
$sSQL .= " where keywords @> ARRAY[".$aRemove['word_id']."]";
chksql($oDB->query($sSQL));
foreach ($aPartitions as $sPartition)
{
foreach ($aPartitions as $sPartition) {
$sSQL = "update search_name_".$sPartition." set";
$sSQL .= " name_vector = array_replace(name_vector,".$aRemove['word_id'].",".$iKeepID.")";
$sSQL .= " where name_vector @> ARRAY[".$aRemove['word_id']."]";
@@ -237,14 +211,12 @@ if ($aResult['deduplicate'])
}
}
if ($aResult['index'])
{
if ($aResult['index']) {
passthru(CONST_InstallPath.'/nominatim/nominatim -i -d '.$aDSNInfo['database'].' -P '.$aDSNInfo['port'].' -t '.$aResult['index-instances'].' -r '.$aResult['index-rank']);
}
if ($aResult['import-osmosis'] || $aResult['import-osmosis-all'])
{
if ($aResult['import-osmosis'] || $aResult['import-osmosis-all']) {
//
if (strpos(CONST_Replication_Url, 'download.geofabrik.de') !== false && CONST_Replication_Update_Interval < 86400) {
fail("Error: Update interval too low for download.geofabrik.de. Please check install documentation (http://wiki.openstreetmap.org/wiki/Nominatim/Installation#Updates)\n");
}
@@ -256,28 +228,20 @@ if ($aResult['import-osmosis'] || $aResult['import-osmosis-all'])
$sCMDImport = $sOsm2pgsqlCmd.' '.$sImportFile;
$sCMDIndex = CONST_InstallPath.'/nominatim/nominatim -i -d '.$aDSNInfo['database'].' -P '.$aDSNInfo['port'].' -t '.$aResult['index-instances'];
while(true)
{
while (true) {
$fStartTime = time();
$iFileSize = 1001;
if (!file_exists($sImportFile))
{
if (!file_exists($sImportFile)) {
// First check if there are new updates published (except for minutelies - there's always new diffs to process)
if ( CONST_Replication_Update_Interval > 60 )
{
if (CONST_Replication_Update_Interval > 60) {
unset($aReplicationLag);
exec($sCMDCheckReplicationLag, $aReplicationLag, $iErrorLevel);
while ($iErrorLevel > 0 || $aReplicationLag[0] < 1)
{
if ($iErrorLevel)
{
while ($iErrorLevel > 0 || $aReplicationLag[0] < 1) {
if ($iErrorLevel) {
echo "Error: $iErrorLevel. ";
echo "Re-trying: ".$sCMDCheckReplicationLag." in ".CONST_Replication_Recheck_Interval." secs\n";
}
else
{
} else {
echo ".";
}
sleep(CONST_Replication_Recheck_Interval);
@@ -291,8 +255,7 @@ if ($aResult['import-osmosis'] || $aResult['import-osmosis-all'])
$fCMDStartTime = time();
echo $sCMDDownload."\n";
exec($sCMDDownload, $sJunk, $iErrorLevel);
while ($iErrorLevel > 0)
{
while ($iErrorLevel > 0) {
echo "Error: $iErrorLevel\n";
sleep(60);
echo 'Re-trying: '.$sCMDDownload."\n";
@@ -313,8 +276,7 @@ if ($aResult['import-osmosis'] || $aResult['import-osmosis-all'])
$fCMDStartTime = time();
echo $sCMDImport."\n";
exec($sCMDImport, $sJunk, $iErrorLevel);
if ($iErrorLevel)
{
if ($iErrorLevel) {
echo "Error: $iErrorLevel\n";
exit($iErrorLevel);
}
@@ -332,12 +294,10 @@ if ($aResult['import-osmosis'] || $aResult['import-osmosis-all'])
$sThisIndexCmd = $sCMDIndex;
$fCMDStartTime = time();
if (!$aResult['no-index'])
{
if (!$aResult['no-index']) {
echo "$sThisIndexCmd\n";
exec($sThisIndexCmd, $sJunk, $iErrorLevel);
if ($iErrorLevel)
{
if ($iErrorLevel) {
echo "Error: $iErrorLevel\n";
exit($iErrorLevel);
}
@@ -355,12 +315,9 @@ if ($aResult['import-osmosis'] || $aResult['import-osmosis-all'])
echo date('Y-m-d H:i:s')." Completed all for $sBatchEnd in ".round($fDuration/60,2)." minutes\n";
if (!$aResult['import-osmosis-all']) exit(0);
if ( CONST_Replication_Update_Interval > 60 )
{
if (CONST_Replication_Update_Interval > 60) {
$iSleep = max(0,(strtotime($sBatchEnd)+CONST_Replication_Update_Interval-time()));
}
else
{
} else {
$iSleep = max(0,CONST_Replication_Update_Interval-$fDuration);
}
echo date('Y-m-d H:i:s')." Sleeping $iSleep seconds\n";

View File

@@ -25,7 +25,6 @@ $oDB =& getDB();
$bVerbose = $aResult['verbose'];
if (!$aResult['search-only']) {
$oReverseGeocode = new ReverseGeocode($oDB);
$oReverseGeocode->setZoom(20);
$oPlaceLookup = new PlaceLookup($oDB);
@@ -34,30 +33,29 @@ if (!$aResult['search-only']) {
echo "Warm reverse: ";
if ($bVerbose) echo "\n";
for($i = 0; $i < 1000; $i++) {
for ($i = 0; $i < 1000; $i++) {
$fLat = rand(-9000, 9000) / 100;
$fLon = rand(-18000, 18000) / 100;
if ($bVerbose) echo "$fLat, $fLon = ";
$aLookup = $oReverseGeocode->lookup($fLat, $fLon);
if ($aLookup && $aLookup['place_id'])
{
if ($aLookup && $aLookup['place_id']) {
$aDetails = $oPlaceLookup->lookup((int)$aLookup['place_id'],
$aLookup['type'], $aLookup['fraction']);
if ($bVerbose) echo $aDetails['langaddress']."\n";
} else {
echo ".";
}
else echo ".";
}
echo "\n";
}
if (!$aResult['reverse-only']) {
$oGeocode =& new Geocode($oDB);
echo "Warm search: ";
if ($bVerbose) echo "\n";
$sSQL = 'select word from word where word is not null order by search_name_count desc limit 1000';
foreach($oDB->getCol($sSQL) as $sWord) {
foreach ($oDB->getCol($sSQL) as $sWord) {
if ($bVerbose) echo "$sWord = ";
$oGeocode->setLanguagePreference(array('en'));
$oGeocode->setQuery($sWord);