switch remaining settings to dotenv format

CONST_Search_AreaPolygons and CONST_Search_ReversePlanForAll have
been removed completely.
This commit is contained in:
Sarah Hoffmann
2020-12-15 15:37:31 +01:00
parent d43f30903c
commit 0947b61808
14 changed files with 400 additions and 272 deletions

View File

@@ -18,7 +18,7 @@ class Geocode
protected $aLangPrefOrder = array(); protected $aLangPrefOrder = array();
protected $aExcludePlaceIDs = array(); protected $aExcludePlaceIDs = array();
protected $bReverseInPlan = false; protected $bReverseInPlan = true;
protected $iLimit = 20; protected $iLimit = 20;
protected $iFinalLimit = 10; protected $iFinalLimit = 10;

View File

@@ -486,65 +486,63 @@ class PlaceLookup
$aOutlineResult = array(); $aOutlineResult = array();
if (!$iPlaceID) return $aOutlineResult; if (!$iPlaceID) return $aOutlineResult;
if (CONST_Search_AreaPolygons) { // Get the bounding box and outline polygon
// Get the bounding box and outline polygon $sSQL = 'select place_id,0 as numfeatures,st_area(geometry) as area,';
$sSQL = 'select place_id,0 as numfeatures,st_area(geometry) as area,'; if ($fLonReverse != null && $fLatReverse != null) {
if ($fLonReverse != null && $fLatReverse != null) { $sSQL .= ' ST_Y(closest_point) as centrelat,';
$sSQL .= ' ST_Y(closest_point) as centrelat,'; $sSQL .= ' ST_X(closest_point) as centrelon,';
$sSQL .= ' ST_X(closest_point) as centrelon,'; } else {
} else { $sSQL .= ' ST_Y(centroid) as centrelat, ST_X(centroid) as centrelon,';
$sSQL .= ' ST_Y(centroid) as centrelat, ST_X(centroid) as centrelon,'; }
} $sSQL .= ' ST_YMin(geometry) as minlat,ST_YMax(geometry) as maxlat,';
$sSQL .= ' ST_YMin(geometry) as minlat,ST_YMax(geometry) as maxlat,'; $sSQL .= ' ST_XMin(geometry) as minlon,ST_XMax(geometry) as maxlon';
$sSQL .= ' ST_XMin(geometry) as minlon,ST_XMax(geometry) as maxlon'; if ($this->bIncludePolygonAsGeoJSON) $sSQL .= ',ST_AsGeoJSON(geometry) as asgeojson';
if ($this->bIncludePolygonAsGeoJSON) $sSQL .= ',ST_AsGeoJSON(geometry) as asgeojson'; if ($this->bIncludePolygonAsKML) $sSQL .= ',ST_AsKML(geometry) as askml';
if ($this->bIncludePolygonAsKML) $sSQL .= ',ST_AsKML(geometry) as askml'; if ($this->bIncludePolygonAsSVG) $sSQL .= ',ST_AsSVG(geometry) as assvg';
if ($this->bIncludePolygonAsSVG) $sSQL .= ',ST_AsSVG(geometry) as assvg'; if ($this->bIncludePolygonAsText) $sSQL .= ',ST_AsText(geometry) as astext';
if ($this->bIncludePolygonAsText) $sSQL .= ',ST_AsText(geometry) as astext'; if ($fLonReverse != null && $fLatReverse != null) {
if ($fLonReverse != null && $fLatReverse != null) { $sFrom = ' from (SELECT * , CASE WHEN (class = \'highway\') AND (ST_GeometryType(geometry) = \'ST_LineString\') THEN ';
$sFrom = ' from (SELECT * , CASE WHEN (class = \'highway\') AND (ST_GeometryType(geometry) = \'ST_LineString\') THEN '; $sFrom .=' ST_ClosestPoint(geometry, ST_SetSRID(ST_Point('.$fLatReverse.','.$fLonReverse.'),4326))';
$sFrom .=' ST_ClosestPoint(geometry, ST_SetSRID(ST_Point('.$fLatReverse.','.$fLonReverse.'),4326))'; $sFrom .=' ELSE centroid END AS closest_point';
$sFrom .=' ELSE centroid END AS closest_point'; $sFrom .= ' from placex where place_id = '.$iPlaceID.') as plx';
$sFrom .= ' from placex where place_id = '.$iPlaceID.') as plx'; } else {
} else { $sFrom = ' from placex where place_id = '.$iPlaceID;
$sFrom = ' from placex where place_id = '.$iPlaceID; }
} if ($this->fPolygonSimplificationThreshold > 0) {
if ($this->fPolygonSimplificationThreshold > 0) { $sSQL .= ' from (select place_id,centroid,ST_SimplifyPreserveTopology(geometry,'.$this->fPolygonSimplificationThreshold.') as geometry'.$sFrom.') as plx';
$sSQL .= ' from (select place_id,centroid,ST_SimplifyPreserveTopology(geometry,'.$this->fPolygonSimplificationThreshold.') as geometry'.$sFrom.') as plx'; } else {
} else { $sSQL .= $sFrom;
$sSQL .= $sFrom; }
$aPointPolygon = $this->oDB->getRow($sSQL, null, 'Could not get outline');
if ($aPointPolygon && $aPointPolygon['place_id']) {
if ($aPointPolygon['centrelon'] !== null && $aPointPolygon['centrelat'] !== null) {
$aOutlineResult['lat'] = $aPointPolygon['centrelat'];
$aOutlineResult['lon'] = $aPointPolygon['centrelon'];
} }
$aPointPolygon = $this->oDB->getRow($sSQL, null, 'Could not get outline'); if ($this->bIncludePolygonAsGeoJSON) $aOutlineResult['asgeojson'] = $aPointPolygon['asgeojson'];
if ($this->bIncludePolygonAsKML) $aOutlineResult['askml'] = $aPointPolygon['askml'];
if ($this->bIncludePolygonAsSVG) $aOutlineResult['assvg'] = $aPointPolygon['assvg'];
if ($this->bIncludePolygonAsText) $aOutlineResult['astext'] = $aPointPolygon['astext'];
if ($aPointPolygon && $aPointPolygon['place_id']) { if (abs($aPointPolygon['minlat'] - $aPointPolygon['maxlat']) < 0.0000001) {
if ($aPointPolygon['centrelon'] !== null && $aPointPolygon['centrelat'] !== null) { $aPointPolygon['minlat'] = $aPointPolygon['minlat'] - $fRadius;
$aOutlineResult['lat'] = $aPointPolygon['centrelat']; $aPointPolygon['maxlat'] = $aPointPolygon['maxlat'] + $fRadius;
$aOutlineResult['lon'] = $aPointPolygon['centrelon'];
}
if ($this->bIncludePolygonAsGeoJSON) $aOutlineResult['asgeojson'] = $aPointPolygon['asgeojson'];
if ($this->bIncludePolygonAsKML) $aOutlineResult['askml'] = $aPointPolygon['askml'];
if ($this->bIncludePolygonAsSVG) $aOutlineResult['assvg'] = $aPointPolygon['assvg'];
if ($this->bIncludePolygonAsText) $aOutlineResult['astext'] = $aPointPolygon['astext'];
if (abs($aPointPolygon['minlat'] - $aPointPolygon['maxlat']) < 0.0000001) {
$aPointPolygon['minlat'] = $aPointPolygon['minlat'] - $fRadius;
$aPointPolygon['maxlat'] = $aPointPolygon['maxlat'] + $fRadius;
}
if (abs($aPointPolygon['minlon'] - $aPointPolygon['maxlon']) < 0.0000001) {
$aPointPolygon['minlon'] = $aPointPolygon['minlon'] - $fRadius;
$aPointPolygon['maxlon'] = $aPointPolygon['maxlon'] + $fRadius;
}
$aOutlineResult['aBoundingBox'] = array(
(string)$aPointPolygon['minlat'],
(string)$aPointPolygon['maxlat'],
(string)$aPointPolygon['minlon'],
(string)$aPointPolygon['maxlon']
);
} }
if (abs($aPointPolygon['minlon'] - $aPointPolygon['maxlon']) < 0.0000001) {
$aPointPolygon['minlon'] = $aPointPolygon['minlon'] - $fRadius;
$aPointPolygon['maxlon'] = $aPointPolygon['maxlon'] + $fRadius;
}
$aOutlineResult['aBoundingBox'] = array(
(string)$aPointPolygon['minlat'],
(string)$aPointPolygon['maxlat'],
(string)$aPointPolygon['minlon'],
(string)$aPointPolygon['maxlon']
);
} }
// as a fallback we generate a bounding box without knowing the size of the geometry // as a fallback we generate a bounding box without knowing the size of the geometry

View File

@@ -198,19 +198,18 @@ function runSQLScript($sScript, $bfatal = true, $bVerbose = false, $bIgnoreError
function setupHTTPProxy() function setupHTTPProxy()
{ {
if (!CONST_HTTP_Proxy) { if (!getSettingBool('HTTP_PROXY')) {
return; return;
} }
$sProxy = 'tcp://'.CONST_HTTP_Proxy_Host.':'.CONST_HTTP_Proxy_Port; $sProxy = 'tcp://'.getSetting('HTTP_PROXY_HOST').':'.getSetting('HTTP_PROXY_PROT');
$aHeaders = array(); $aHeaders = array();
if (CONST_HTTP_Proxy_Login != null $sLogin = getSetting('HTTP_PROXY_LOGIN');
&& CONST_HTTP_Proxy_Login != '' $sPassword = getSetting('HTTP_PROXY_PASSWORD');
&& CONST_HTTP_Proxy_Password != null
&& CONST_HTTP_Proxy_Password != '' if ($sLogin && $sPassword) {
) { $sAuth = base64_encode($sLogin.':'.$sPassword);
$sAuth = base64_encode(CONST_HTTP_Proxy_Login.':'.CONST_HTTP_Proxy_Password);
$aHeaders = array('Proxy-Authorization: Basic '.$sAuth); $aHeaders = array('Proxy-Authorization: Basic '.$sAuth);
} }

View File

@@ -18,9 +18,35 @@ function loadSettings($sProjectDir)
$dotenv->load(CONST_DataDir.'/settings/env.defaults'); $dotenv->load(CONST_DataDir.'/settings/env.defaults');
} }
function getSetting($sConfName) function getSetting($sConfName, $sDefault = null)
{ {
return $_ENV['NOMINATIM_'.$sConfName]; $sValue = $_ENV['NOMINATIM_'.$sConfName];
if ($sDefault !== null && !$sValue) {
return $sDefault;
}
return $sValue;
}
function getSettingBool($sConfName)
{
$sVal = strtolower(getSetting($sConfName));
return strcmp($sVal, 'yes') == 0
|| strcmp($sVal, 'true') == 0
|| strcmp($sVal, '1') == 0;
}
function getSettingConfig($sConfName, $sSystemConfig)
{
$sValue = $_ENV['NOMINATIM_'.$sConfName];
if (!$sValue) {
return CONST_DataDir.'/settings/'.$sSystemConfig;
}
return $sValue;
} }
function fail($sError, $sUserError = false) function fail($sError, $sUserError = false)

View File

@@ -34,7 +34,7 @@ class SetupFunctions
if (isset($aCMDResult['osm2pgsql-cache'])) { if (isset($aCMDResult['osm2pgsql-cache'])) {
$this->iCacheMemory = $aCMDResult['osm2pgsql-cache']; $this->iCacheMemory = $aCMDResult['osm2pgsql-cache'];
} elseif (!is_null(CONST_Osm2pgsql_Flatnode_File)) { } elseif (getSetting('FLATNODE_FILE')) {
// When flatnode files are enabled then disable cache per default. // When flatnode files are enabled then disable cache per default.
$this->iCacheMemory = 0; $this->iCacheMemory = 0;
} else { } else {
@@ -42,10 +42,7 @@ class SetupFunctions
$this->iCacheMemory = getCacheMemoryMB(); $this->iCacheMemory = getCacheMemoryMB();
} }
$this->sModulePath = getSetting('DATABASE_MODULE_PATH'); $this->sModulePath = getSetting('DATABASE_MODULE_PATH', CONST_InstallDir.'/module');
if (strlen($this->sModulePath) == 0 || $this->sModulePath[0] != '/') {
$this->sModulePath = CONST_InstallDir.'/'.$this->sModulePath;
}
info('module path: ' . $this->sModulePath); info('module path: ' . $this->sModulePath);
// parse database string // parse database string
@@ -177,29 +174,29 @@ class SetupFunctions
{ {
info('Import data'); info('Import data');
if (!file_exists(CONST_Osm2pgsql_Binary)) { if (!file_exists(getOsm2pgsqlBinary())) {
echo "Check CONST_Osm2pgsql_Binary in your local settings file.\n"; echo "Check NOMINATIM_OSM2PGSQL_BINARY in your local .env file.\n";
echo "Normally you should not need to set this manually.\n"; echo "Normally you should not need to set this manually.\n";
fail("osm2pgsql not found in '".CONST_Osm2pgsql_Binary."'"); fail("osm2pgsql not found in '".getOsm2pgsqlBinary()."'");
} }
$oCmd = new \Nominatim\Shell(CONST_Osm2pgsql_Binary); $oCmd = new \Nominatim\Shell(getOsm2pgsqlBinary());
$oCmd->addParams('--style', CONST_Import_Style); $oCmd->addParams('--style', getImportStyle());
if (!is_null(CONST_Osm2pgsql_Flatnode_File) && CONST_Osm2pgsql_Flatnode_File) { if (getSetting('FLATNODE_FILE')) {
$oCmd->addParams('--flat-nodes', CONST_Osm2pgsql_Flatnode_File); $oCmd->addParams('--flat-nodes', getSetting('FLATNODE_FILE'));
} }
if (CONST_Tablespace_Osm2pgsql_Data) { if (getSetting('TABLESPACE_OSM_DATA')) {
$oCmd->addParams('--tablespace-slim-data', CONST_Tablespace_Osm2pgsql_Data); $oCmd->addParams('--tablespace-slim-data', getSetting('TABLESPACE_OSM_DATA'));
} }
if (CONST_Tablespace_Osm2pgsql_Index) { if (getSetting('TABLESPACE_OSM_INDEX')) {
$oCmd->addParams('--tablespace-slim-index', CONST_Tablespace_Osm2pgsql_Index); $oCmd->addParams('--tablespace-slim-index', getSetting('TABLESPACE_OSM_INDEX'));
} }
if (CONST_Tablespace_Place_Data) { if (getSetting('TABLESPACE_PLACE_DATA')) {
$oCmd->addParams('--tablespace-main-data', CONST_Tablespace_Place_Data); $oCmd->addParams('--tablespace-main-data', getSetting('TABLESPACE_PLACE_DATA'));
} }
if (CONST_Tablespace_Place_Index) { if (getSetting('TABLESPACE_PLACE_INDEX')) {
$oCmd->addParams('--tablespace-main-index', CONST_Tablespace_Place_Index); $oCmd->addParams('--tablespace-main-index', getSetting('TABLESPACE_PLACE_INDEX'));
} }
$oCmd->addParams('--latlong', '--slim', '--create'); $oCmd->addParams('--latlong', '--slim', '--create');
$oCmd->addParams('--output', 'gazetteer'); $oCmd->addParams('--output', 'gazetteer');
@@ -256,7 +253,7 @@ class SetupFunctions
$this->dropTable('search_name'); $this->dropTable('search_name');
} }
$oAlParser = new AddressLevelParser(CONST_Address_Level_Config); $oAlParser = new AddressLevelParser(getSettingConfig('ADDRESS_LEVEL_CONFIG', 'address-levels.json'));
$oAlParser->createTable($this->db(), 'address_levels'); $oAlParser->createTable($this->db(), 'address_levels');
} }
@@ -290,7 +287,8 @@ class SetupFunctions
public function importWikipediaArticles() public function importWikipediaArticles()
{ {
$sWikiArticlesFile = CONST_Wikipedia_Data_Path.'/wikimedia-importance.sql.gz'; $sWikiArticlePath = getSettings('WIKIPEDIA_DATA_PATH', CONST_DataDir.'/data');
$sWikiArticlesFile = $sWikiArticlePath.'/wikimedia-importance.sql.gz';
if (file_exists($sWikiArticlesFile)) { if (file_exists($sWikiArticlesFile)) {
info('Importing wikipedia articles and redirects'); info('Importing wikipedia articles and redirects');
$this->dropTable('wikipedia_article'); $this->dropTable('wikipedia_article');
@@ -339,7 +337,7 @@ class SetupFunctions
// used by getorcreate_word_id to ignore frequent partial words // used by getorcreate_word_id to ignore frequent partial words
$sSQL = 'CREATE OR REPLACE FUNCTION get_maxwordfreq() RETURNS integer AS '; $sSQL = 'CREATE OR REPLACE FUNCTION get_maxwordfreq() RETURNS integer AS ';
$sSQL .= '$$ SELECT '.CONST_Max_Word_Frequency.' as maxwordfreq; $$ LANGUAGE SQL IMMUTABLE'; $sSQL .= '$$ SELECT '.getSetting('MAX_WORD_FREQUENCY').' as maxwordfreq; $$ LANGUAGE SQL IMMUTABLE';
$oDB->exec($sSQL); $oDB->exec($sSQL);
echo ".\n"; echo ".\n";
@@ -428,14 +426,14 @@ class SetupFunctions
} }
} }
public function importTigerData() public function importTigerData($sTigerPath)
{ {
info('Import Tiger data'); info('Import Tiger data');
$aFilenames = glob(CONST_Tiger_Data_Path.'/*.sql'); $aFilenames = glob($sTigerPath.'/*.sql');
info('Found '.count($aFilenames).' SQL files in path '.CONST_Tiger_Data_Path); info('Found '.count($aFilenames).' SQL files in path '.$sTigerPath);
if (empty($aFilenames)) { if (empty($aFilenames)) {
warn('Tiger data import selected but no files found in path '.CONST_Tiger_Data_Path); warn('Tiger data import selected but no files found in path '.$sTigerPath);
return; return;
} }
$sTemplate = file_get_contents(CONST_DataDir.'/sql/tiger_import_start.sql'); $sTemplate = file_get_contents(CONST_DataDir.'/sql/tiger_import_start.sql');
@@ -642,10 +640,11 @@ class SetupFunctions
$this->pgsqlRunScript("select count(*) from (select getorcreate_country(make_standard_name(name->'name'), country_code) from country_name where name ? 'name') as x"); $this->pgsqlRunScript("select count(*) from (select getorcreate_country(make_standard_name(name->'name'), country_code) from country_name where name ? 'name') as x");
$sSQL = 'select count(*) from (select getorcreate_country(make_standard_name(v),' $sSQL = 'select count(*) from (select getorcreate_country(make_standard_name(v),'
.'country_code) from (select country_code, skeys(name) as k, svals(name) as v from country_name) x where k '; .'country_code) from (select country_code, skeys(name) as k, svals(name) as v from country_name) x where k ';
if (CONST_Languages) { $sLanguages = getSetting('LANGUAGES');
if ($sLanguages) {
$sSQL .= 'in '; $sSQL .= 'in ';
$sDelim = '('; $sDelim = '(';
foreach (explode(',', CONST_Languages) as $sLang) { foreach (explode(',', $sLanguages) as $sLang) {
$sSQL .= $sDelim."'name:$sLang'"; $sSQL .= $sDelim."'name:$sLang'";
$sDelim = ','; $sDelim = ',';
} }
@@ -716,24 +715,20 @@ class SetupFunctions
$rOutputFile = fopen(CONST_InstallDir.'/settings/settings-frontend.php', 'w'); $rOutputFile = fopen(CONST_InstallDir.'/settings/settings-frontend.php', 'w');
fwrite($rOutputFile, "<?php fwrite($rOutputFile, "<?php
if (file_exists(getenv('NOMINATIM_SETTINGS'))) require_once(getenv('NOMINATIM_SETTINGS'));
@define('CONST_Database_DSN', '".getSetting('DATABASE_DSN')."'); @define('CONST_Database_DSN', '".getSetting('DATABASE_DSN')."');
@define('CONST_Default_Language', ".(CONST_Default_Language ? ("'".CONST_Default_Language."'") : 'false')."); @define('CONST_Default_Language', ".getSetting('DEFAULT_LANGUAGE', 'false').");
@define('CONST_Log_DB', ".(CONST_Log_DB ? 'true' : 'false')."); @define('CONST_Log_DB', ".(getSettingBool('LOG_DB') ? 'true' : 'false').");
@define('CONST_Log_File', ".(CONST_Log_File ? ("'".CONST_Log_File."'") : 'false')."); @define('CONST_Log_File', ".getSetting('LOG_FILE', 'false').");
@define('CONST_Max_Word_Frequency', '".CONST_Max_Word_Frequency."'); @define('CONST_Max_Word_Frequency', '".getSetting('MAX_WORD_FREQUENCY')."');
@define('CONST_NoAccessControl', ".CONST_NoAccessControl."); @define('CONST_NoAccessControl', ".(getSettingBool('CORS_NOACCESSCONTROL') ? 'true' : 'false').");
@define('CONST_Places_Max_ID_count', ".CONST_Places_Max_ID_count."); @define('CONST_Places_Max_ID_count', ".getSetting('LOOKUP_MAX_COUNT').");
@define('CONST_PolygonOutput_MaximumTypes', ".CONST_PolygonOutput_MaximumTypes."); @define('CONST_PolygonOutput_MaximumTypes', ".getSetting('POLYGON_OUTPUT_MAX_TYPES').");
@define('CONST_Search_AreaPolygons', ".CONST_Search_AreaPolygons."); @define('CONST_Search_BatchMode', ".(getSettingBool('SEARCH_BATCH_MODE' ? 'true' : 'false').");
@define('CONST_Search_BatchMode', ".(CONST_Search_BatchMode ? 'true' : 'false')."); @define('CONST_Search_NameOnlySearchFrequencyThreshold', ".getSetting('SEARCH_NAME_ONLY_THRESHOLD').");
@define('CONST_Search_NameOnlySearchFrequencyThreshold', ".CONST_Search_NameOnlySearchFrequencyThreshold."); @define('CONST_Term_Normalization_Rules', \"".getSetting('TERM_NORMALIZATION')."\");
@define('CONST_Search_ReversePlanForAll', ".CONST_Search_ReversePlanForAll."); @define('CONST_Use_Aux_Location_data', ".(getSettingBool('USE_AUX_LOCATION_DATA') ? 'true' : 'false').");
@define('CONST_Term_Normalization_Rules', \"".CONST_Term_Normalization_Rules."\"); @define('CONST_Use_US_Tiger_Data', ".(getSettingBool('USE_US_TIGER_DATA') ? 'true' : 'false').");
@define('CONST_Use_Aux_Location_data', ".(CONST_Use_Aux_Location_data ? 'true' : 'false')."); @define('CONST_MapIcon_URL', ".(getSetting('MAPICON_URL', 'false').');
@define('CONST_Use_US_Tiger_Data', ".(CONST_Use_US_Tiger_Data ? 'true' : 'false').");
@define('CONST_MapIcon_URL', ".(CONST_MapIcon_URL ? ("'".CONST_MapIcon_URL."'") : 'false').');
'); ');
info(CONST_InstallDir.'/settings/settings-frontend.php has been set up successfully'); info(CONST_InstallDir.'/settings/settings-frontend.php has been set up successfully');
} }
@@ -758,10 +753,10 @@ if (file_exists(getenv('NOMINATIM_SETTINGS'))) require_once(getenv('NOMINATIM_SE
private function removeFlatnodeFile() private function removeFlatnodeFile()
{ {
if (!is_null(CONST_Osm2pgsql_Flatnode_File) && CONST_Osm2pgsql_Flatnode_File) { $sFName = getSetting('FLATNODE_FILE');
if (file_exists(CONST_Osm2pgsql_Flatnode_File)) { if ($sFName && file_exists($sFName)) {
if ($this->bVerbose) echo 'Deleting '.CONST_Osm2pgsql_Flatnode_File."\n"; if ($this->bVerbose) echo 'Deleting '.$sFName."\n";
unlink(CONST_Osm2pgsql_Flatnode_File); unlink($sFName);
} }
} }
} }
@@ -801,13 +796,13 @@ if (file_exists(getenv('NOMINATIM_SETTINGS'))) require_once(getenv('NOMINATIM_SE
if ($this->bEnableDebugStatements) { if ($this->bEnableDebugStatements) {
$sTemplate = str_replace('--DEBUG:', '', $sTemplate); $sTemplate = str_replace('--DEBUG:', '', $sTemplate);
} }
if (CONST_Limit_Reindexing) { if (getSettingBool('LIMIT_REINDEXING')) {
$sTemplate = str_replace('--LIMIT INDEXING:', '', $sTemplate); $sTemplate = str_replace('--LIMIT INDEXING:', '', $sTemplate);
} }
if (!CONST_Use_US_Tiger_Data) { if (!getSettingBool('USE_US_TIGER_DATA')) {
$sTemplate = str_replace('-- %NOTIGERDATA% ', '', $sTemplate); $sTemplate = str_replace('-- %NOTIGERDATA% ', '', $sTemplate);
} }
if (!CONST_Use_Aux_Location_data) { if (!getSettingBool('USE_AUX_LOCATION_DATA')) {
$sTemplate = str_replace('-- %NOAUXDATA% ', '', $sTemplate); $sTemplate = str_replace('-- %NOAUXDATA% ', '', $sTemplate);
} }
@@ -901,12 +896,12 @@ if (file_exists(getenv('NOMINATIM_SETTINGS'))) require_once(getenv('NOMINATIM_SE
$sSql = str_replace('{www-user}', getSetting('DATABASE_WEBUSER'), $sSql); $sSql = str_replace('{www-user}', getSetting('DATABASE_WEBUSER'), $sSql);
$aPatterns = array( $aPatterns = array(
'{ts:address-data}' => CONST_Tablespace_Address_Data, '{ts:address-data}' => getSetting('TABLESPACE_ADDRESS_DATA'),
'{ts:address-index}' => CONST_Tablespace_Address_Index, '{ts:address-index}' => getSetting('TABLESPACE_ADDRESS_INDEX'),
'{ts:search-data}' => CONST_Tablespace_Search_Data, '{ts:search-data}' => getSetting('TABLESPACE_SEARCH_DATA'),
'{ts:search-index}' => CONST_Tablespace_Search_Index, '{ts:search-index}' => getSetting('TABLESPACE_SEARCH_INDEX'),
'{ts:aux-data}' => CONST_Tablespace_Aux_Data, '{ts:aux-data}' => getSetting('TABLESPACE_AUX_DATA'),
'{ts:aux-index}' => CONST_Tablespace_Aux_Index, '{ts:aux-index}' => getSetting('TABLESPACE_AUX_INDEX')
); );
foreach ($aPatterns as $sPattern => $sTablespace) { foreach ($aPatterns as $sPattern => $sTablespace) {

View File

@@ -14,3 +14,24 @@ function checkInFile($sOSMFile)
fail('osm-file "' . $aCMDResult['osm-file'] . '" not readable'); fail('osm-file "' . $aCMDResult['osm-file'] . '" not readable');
} }
} }
function getOsm2pgsqlBinary()
{
$sBinary = getSetting('OSM2PGSQL_BINARY');
if (!$sBinary) {
$sBinary = CONST_InstallDir.'/osm2pgsql/osm2pgsql';
}
return $sBinary;
}
function getImportStyle()
{
$sStyle = getSetting('IMPORT_STYLE');
if (in_array($sStyle, array('admin', 'street', 'address', 'full', 'extratags'))) {
return CONST_DataDir.'/settings/import-'.$sStyle.'.style';
}
return $sStyle;
}

View File

@@ -2,7 +2,6 @@
if (file_exists(getenv('NOMINATIM_SETTINGS'))) require_once(getenv('NOMINATIM_SETTINGS')); if (file_exists(getenv('NOMINATIM_SETTINGS'))) require_once(getenv('NOMINATIM_SETTINGS'));
if (file_exists(CONST_InstallDir.'/settings/local.php')) require_once(CONST_InstallDir.'/settings/local.php'); if (file_exists(CONST_InstallDir.'/settings/local.php')) require_once(CONST_InstallDir.'/settings/local.php');
@define('CONST_Max_Word_Frequency', '50000');
@define('CONST_Limit_Reindexing', true); @define('CONST_Limit_Reindexing', true);
// Restrict search languages. // Restrict search languages.
// Normally Nominatim will include all language variants of name:XX // Normally Nominatim will include all language variants of name:XX

View File

@@ -1,9 +1,11 @@
# .env # .env
# Default configuration settings for Nominatim # Default configuration settings for Nominatim.
# This file uses the dotenv format.
# Database connection string. # Database connection string.
# Add host, port, user etc through additional semicolon-separated attributes. # Add host, port, user etc through additional semicolon-separated attributes.
# e.g. ;host=...;port=...;user=...;password=... # e.g. ;host=...;port=...;user=...;password=...
# Changing this variable requires to run 'setup.php --setup-website'.
NOMINATIM_DATABASE_DSN="pgsql:dbname=nominatim" NOMINATIM_DATABASE_DSN="pgsql:dbname=nominatim"
# Database web user. # Database web user.
@@ -11,115 +13,201 @@ NOMINATIM_DATABASE_DSN="pgsql:dbname=nominatim"
NOMINATIM_DATABASE_WEBUSER="www-data" NOMINATIM_DATABASE_WEBUSER="www-data"
# Directory where to find the PostgreSQL server module. # Directory where to find the PostgreSQL server module.
# When a relative path is given, it will be searched relative to the project # When empty the module is expected to be located in the 'module' subdirectory
# directory. # in the project directory.
NOMINATIM_DATABASE_MODULE_PATH="module" # Changing this value requires to run ./utils/setup --create-functions.
NOMINATIM_DATABASE_MODULE_PATH=
#@define('CONST_Max_Word_Frequency', '50000'); # Number of occurances of a word before it is considered frequent.
#@define('CONST_Limit_Reindexing', true); # Similar to the concept of stop words. Frequent partial words get ignored
#// Restrict search languages. # or handled differently during search.
#// Normally Nominatim will include all language variants of name:XX # Changing this value requires a reimport.
#// in the search index. Set this to a comma separated list of language NOMINATIM_MAX_WORD_FREQUENCY=50000
#// codes, to restrict import to a subset of languages.
#// Currently only affects the import of country names and special phrases. # If true, admin level changes on places with many contained children are blocked.
#@define('CONST_Languages', false); NOMINATIM_LIMIT_REINDEXING=yes
#// Rules for normalizing terms for comparison before doing comparisons.
#// The default is to remove accents and punctuation and to lower-case the # Restrict search languages.
#// term. Spaces are kept but collapsed to one standard space. # Normally Nominatim will include all language variants of name:XX
#@define('CONST_Term_Normalization_Rules', ":: NFD (); [[:Nonspacing Mark:] [:Cf:]] >; :: lower (); [[:Punctuation:][:Space:]]+ > ' '; :: NFC ();"); # in the search index. Set this to a comma separated list of language
# codes, to restrict import to a subset of languages.
# Currently only affects the initial import of country names and special phrases.
NOMINATIM_LANGUAGES=
# Rules for normalizing terms for comparisons.
# The default is to remove accents and punctuation and to lower-case the
# term. Spaces are kept but collapsed to one standard space.
# Changing this value requires a reimport.
NOMINATIM_TERM_NORMALIZATION=":: NFD (); [[:Nonspacing Mark:] [:Cf:]] >; :: lower (); [[:Punctuation:][:Space:]]+ > ' '; :: NFC ();"
# Search in the Tiger house number data for the US.
# Note: The tables must already exist or queries will throw errors.
# Changing this value requires to run ./utils/setup --create-functions --setup-website.
NOMINATIM_USE_US_TIGER_DATA=no
# Search in the auxilary housenumber table.
# Changing this value requires to run ./utils/setup --create-functions --setup-website.
NOMINATIM_USE_AUX_LOCATION_DATA=no
# Proxy settings
# The following settings allow to set a proxy to use when remotely downloading
# data. Host and port are required. Login and password are optional.
NOMINATIM_HTTP_PROXY=no
NOMINATIM_HTTP_PROXY_HOST=proxy.mydomain.com
NOMINATIM_HTTP_PROXY_PORT=3128
NOMINATIM_HTTP_PROXY_LOGIN=
NOMINATIM_HTTP_PROXY_PASSWORD=
# Location of the osm2pgsql binary.
# When empty, osm2pgsql is expected to reside in the osm2pgsql directory in
# the project directory.
# EXPERT ONLY. You should usually use the supplied osm2pgsql.
NOMINATIM_OSM2PGSQL_BINARY=
# Location of pyosmium-get-changes.
# Only needed when running updates.
NOMINATIM_PYOSMIUM_BINARY=
# Directory where to find US Tiger data files to import.
# Used with setup.php --import-tiger-data. When unset, the data is expected
# to be located under 'data/tiger' in the source tree.
NOMINATIM_TIGER_DATA_PATH=
# Directory where to find pre-computed Wikipedia importance files.
# When unset, the data is expected to be located in the 'data' directory
# in the source tree.
NOMINATIM_WIKIPEDIA_DATA_PATH=
# Configuration file for special phrase import.
# When unset, the internal default settings from 'settings/phrase_settings.php'
# are used.
NOMINATIM_PHRASE_CONFIG=
# Configuration file for rank assignments.
# When unset, the internal default settings from 'settings/address-levels.json'
# are used.
NOMINATIM_ADDRESS_LEVEL_CONFIG=
# Configuration file for OSM data import.
# This may either be the name of one of an internal style or point
# to a file with a custom style.
# Internal styles are: admin, street, address, full, extratags
NOMNIATIM_IMPORT_STYLE=extratags
# Location of the flatnode file used by osm2pgsql to store node locations.
# When unset, osm2pgsql stores the location in the PostgreSQL database. This
# is especially useful for imports of larger areas, like continents or the
# full planet. The file needs at least 70GB storage.
NOMINATIM_FLATNODE_FILE=
### Tablespace settings
# #
#/* Set to true after importing Tiger house number data for the US. # The following settings allow to move parts of the database tables into
# Note: The tables must already exist or queries will throw errors. # different tablespaces. This is especially interesting if you have disks
# After changing this setting run ./utils/setup --create-functions # with different speeds. When unset, the default tablespace is used.
# again. */ # Only has an effect during import.
#@define('CONST_Use_US_Tiger_Data', false);
#/* Set to true after importing other external house number data. # Tablespace used for tables used when searching.
# Note: the aux tables must already exist or queries will throw errors. NOMINATIM_TABLESPACE_SEARCH_DATA=
# After changing this setting run ./utils/setup --create-functions # Tablespace used for indexes used when searching.
# again. */ NOMINATIM_TABLESPACE_SEARCH_INDEX=
#@define('CONST_Use_Aux_Location_data', false);
# Tablespace used for the OSM data cache tables. Used for import and update only.
NOMINATIM_TABLESPACE_OSM_DATA=
# Tablespace used for the OSM data cache indexes. Used for import and update only.
NOMINATIM_TABLESPACE_OSM_INDEX=
# Tablespace used for place import table. Used for import and update only.
NOMINATIM_TABLESPACE_PLACE_DATA=
# Tablespace used for place import indexes. Used for import and update only.
NOMINATIM_TABLESPACE_PLACE_INDEX=
# Tablespace for tables used during address computation. Used for import and update only.
NOMINATIM_TABLESPACE_ADDRESS_DATA=
# Tablespace for indexes used during address computation. Used for import and update only.
NOMINATIM_TABLESPACE_ADDRESS_INDEX=
# Tablespace for tables for auxilary data, e.g. TIGER data, postcodes.
NOMINATIM_TABLESPACE_AUX_DATA=
# Tablespace for indexes for auxilary data, e.g. TIGER data, postcodes.
NOMINATIM_TABLESPACE_AUX_INDEX=
### Replication settings
# #
#// Proxy settings # The following settings control where and how updates for the database are
#@define('CONST_HTTP_Proxy', false); # retrieved.
#@define('CONST_HTTP_Proxy_Host', 'proxy.mydomain.com');
#@define('CONST_HTTP_Proxy_Port', '3128');
#@define('CONST_HTTP_Proxy_Login', '');
#@define('CONST_HTTP_Proxy_Password', '');
# #
#// Paths
#@define('CONST_ExtraDataPath', CONST_BasePath.'/data');
#@define('CONST_Osm2pgsql_Binary', CONST_InstallPath.'/osm2pgsql/osm2pgsql');
#@define('CONST_Pyosmium_Binary', '@PYOSMIUM_PATH@');
#@define('CONST_Tiger_Data_Path', CONST_ExtraDataPath.'/tiger');
#@define('CONST_Wikipedia_Data_Path', CONST_ExtraDataPath);
#@define('CONST_Phrase_Config', CONST_BasePath.'/settings/phrase_settings.php');
#@define('CONST_Address_Level_Config', CONST_BasePath.'/settings/address-levels.json');
#@define('CONST_Import_Style', CONST_BasePath.'/settings/import-full.style');
# #
#// osm2pgsql settings # Base URL of replication service.
#@define('CONST_Osm2pgsql_Flatnode_File', null); # A replication service provides change files of OSM data at regular intervals.
# These are used to keep the database up to date. Per default it points to
# the minutely updates for the main OSM database. There are other services
# geared towards larger update intervals or data extracts.
# Changing this value requires to rerun 'update/php --init-updates'.
NOMINATIM_REPLICATION_URL="https://planet.openstreetmap.org/replication/minute"
# Maximum amount of data to download per batch.
# Size is in MB.
NOMINATIM_REPLICATION_MAX_DIFF=50
# Publication interval of the replication service.
# Determines when Nominatim will attempt again to download again a new
# update. The time is computed from the publication date of the last diff
# downloaded. Setting this to a slightly higher value than the actual
# publication interval avoids unnecessary rechecks.
NOMINATIM_REPLICATION_UPDATE_INTERVAL=75
# Wait time to recheck for a pending update.
# Time to wait after an expected update was not available on the server.
NOMINATIM_REPLICATION_RECHECK_INTERVAL=60
### API settings
# #
#// tablespace settings # The following settings configure the API responses. You must rerun
#// osm2pgsql caching tables (aka slim mode tables) - update only # setup.php --setup-website after changing any of them.
#@define('CONST_Tablespace_Osm2pgsql_Data', false);
#@define('CONST_Tablespace_Osm2pgsql_Index', false); # Send permissive CORS access headers.
#// osm2pgsql output tables (aka main table) - update only # When enabled, send CORS headers to allow access to everybody.
#@define('CONST_Tablespace_Place_Data', false); NOMINATIM_CORS_NOACCESSCONTROL=yes
#@define('CONST_Tablespace_Place_Index', false);
#// address computation tables - update only # URL for static icon images.
#@define('CONST_Tablespace_Address_Data', false); # Set this to the /mapicon directory of your nominatim-ui to enable returning
#@define('CONST_Tablespace_Address_Index', false); # icon URLs with the results.
#// search tables - needed for lookups NOMINATIM_MAPICON_URL=
#@define('CONST_Tablespace_Search_Data', false);
#@define('CONST_Tablespace_Search_Index', false); # Language to assume when no particular language is requested.
#// additional data, e.g. TIGER data, type searches - needed for lookups # When unset, the local language (i.e. the name tag without suffix) will be used.
#@define('CONST_Tablespace_Aux_Data', false); NOMINATIM_DEFAULT_LANGUAGE=
#@define('CONST_Tablespace_Aux_Index', false);
# Enable a special batch query mode.
# This features is currently undocumented and potentially broken.
NOMINATIM_SEARCH_BATCH_MODE=no
# Threshold for searches by name only.
# Threshold where the lookup strategy in the database is switched. If there
# are less occurences of a tem than given, the search does the lookup only
# against the name, otherwise it uses indexes for name and address.
NOMINATIM_SEARCH_NAME_ONLY_THRESHOLD=500
# Maximum number of OSM ids accepted by /lookup.
NOMINATIM_LOOKUP_MAX_COUNT=50
# Number of different geometry formats that may be queried in parallel.
# Set to zero to disable polygon output.
NOMINATIM_POLYGON_OUTPUT_MAX_TYPES=1
### Log settings
# #
#//// Replication settings # The following options allow to enable logging of API requests.
# You must rerun setup.php --setup-website after changing any of them.
# #
#// Base URL of replication service # Enable logging of requests into the DB.
#@define('CONST_Replication_Url', 'https://planet.openstreetmap.org/replication/minute'); # The request will be logged into the new_query_log table.
# # You should set up a cron job that regularly clears out this table.
#// Maximum size in MB of data to download per batch NOMINATIM_LOG_DB=no
#@define('CONST_Replication_Max_Diff_size', '30');
#// How long until the service publishes the next diff # Enable logging of requests into a file.
#// (relative to the age of data in the diff). # To enable logging set this setting to the file to log to.
#@define('CONST_Replication_Update_Interval', '75'); NOMINATIM_LOG_FILE=
#// How long to sleep when no update could be found
#@define('CONST_Replication_Recheck_Interval', '60');
#
#// If true, send CORS headers to allow access
#@define('CONST_NoAccessControl', true);
#
#// Set this to the /mapicon directory of your nominatim-ui to enable returning
#// icon URLs with the results.
#@define('CONST_MapIcon_URL', false);
#// Language to assume when none is supplied with the query.
#// When set to false, the local language (i.e. the name tag without suffix)
#// will be used.
#@define('CONST_Default_Language', false);
#
#@define('CONST_Search_AreaPolygons', true);
#
#@define('CONST_Search_BatchMode', false);
#
#@define('CONST_Search_NameOnlySearchFrequencyThreshold', 500);
#// If set to true, then reverse order of queries will be tried by default.
#// When set to false only selected languages allow reverse search.
#@define('CONST_Search_ReversePlanForAll', true);
#
#// Maximum number of OSM ids that may be queried at once
#// for the places endpoint.
#@define('CONST_Places_Max_ID_count', 50);
#
#// Number of different geometry formats that may be queried in parallel.
#// Set to zero to disable polygon output.
#@define('CONST_PolygonOutput_MaximumTypes', 1);
#
#// Log settings
#// Set to true to log into new_query_log table.
#// You should set up a cron job that regularly clears out this table.
#@define('CONST_Log_DB', false);
#// Set to a file name to enable logging to a file.
#@define('CONST_Log_File', false);

View File

@@ -2,6 +2,8 @@
require_once(CONST_LibDir.'/init-cmd.php'); require_once(CONST_LibDir.'/init-cmd.php');
loadSettings(false);
$term_colors = array( $term_colors = array(
'green' => "\033[92m", 'green' => "\033[92m",
'red' => "\x1B[31m", 'red' => "\x1B[31m",
@@ -166,7 +168,7 @@ END;
if (CONST_Use_US_Tiger_Data) { if (getSettingBool('USE_US_TIGER_DATA')) {
echo 'Checking TIGER table exists ... '; echo 'Checking TIGER table exists ... ';
if ($oDB->tableExists('location_property_tiger')) { if ($oDB->tableExists('location_property_tiger')) {
$print_success(); $print_success();

View File

@@ -16,8 +16,6 @@ getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true);
setupHTTPProxy(); setupHTTPProxy();
include(CONST_Phrase_Config);
if (true) { if (true) {
$sURL = 'https://wiki.openstreetmap.org/wiki/Special:Export/Nominatim/Country_Codes'; $sURL = 'https://wiki.openstreetmap.org/wiki/Special:Export/Nominatim/Country_Codes';
$sWikiPageXML = file_get_contents($sURL); $sWikiPageXML = file_get_contents($sURL);

View File

@@ -118,7 +118,11 @@ if ($aCMDResult['load-data'] || $aCMDResult['all']) {
if ($aCMDResult['import-tiger-data']) { if ($aCMDResult['import-tiger-data']) {
$bDidSomething = true; $bDidSomething = true;
$oSetup->importTigerData(); $sTigerPath = getSetting('TIGER_DATA_PATH');
if (!$sTigerPath) {
$sTigerPath = CONST_DataDir.'/data/tiger';
}
$oSetup->importTigerData($sTigerPath);
} }
if ($aCMDResult['calculate-postcodes'] || $aCMDResult['all']) { if ($aCMDResult['calculate-postcodes'] || $aCMDResult['all']) {

View File

@@ -16,15 +16,17 @@ getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true);
setupHTTPProxy(); setupHTTPProxy();
include(CONST_Phrase_Config); include(getSettingConfig('PHRASE_CONFIG', 'phrase_settings.php'));
if ($aCMDResult['wiki-import']) { if ($aCMDResult['wiki-import']) {
$oNormalizer = Transliterator::createFromRules(CONST_Term_Normalization_Rules); $oNormalizer = Transliterator::createFromRules(getSetting('TERM_NORMALIZATION'));
$aPairs = array(); $aPairs = array();
$sLanguageIn = CONST_Languages ? CONST_Languages : $sLanguageIn = getSetting(
('af,ar,br,ca,cs,de,en,es,et,eu,fa,fi,fr,gl,hr,hu,'. LANGUAGES,
'ia,is,it,ja,mk,nl,no,pl,ps,pt,ru,sk,sl,sv,uk,vi'); 'af,ar,br,ca,cs,de,en,es,et,eu,fa,fi,fr,gl,hr,hu,'.
'ia,is,it,ja,mk,nl,no,pl,ps,pt,ru,sk,sl,sv,uk,vi';
);
foreach (explode(',', $sLanguageIn) as $sLanguage) { foreach (explode(',', $sLanguageIn) as $sLanguage) {
$sURL = 'https://wiki.openstreetmap.org/wiki/Special:Export/Nominatim/Special_Phrases/'.strtoupper($sLanguage); $sURL = 'https://wiki.openstreetmap.org/wiki/Special:Export/Nominatim/Special_Phrases/'.strtoupper($sLanguage);

View File

@@ -67,7 +67,7 @@ if ($iCacheMemory + 500 > getTotalMemoryMB()) {
echo "WARNING: resetting cache memory to $iCacheMemory\n"; echo "WARNING: resetting cache memory to $iCacheMemory\n";
} }
$oOsm2pgsqlCmd = (new \Nominatim\Shell(CONST_Osm2pgsql_Binary)) $oOsm2pgsqlCmd = (new \Nominatim\Shell(getOsm2pgsqlBinary()))
->addParams('--hstore') ->addParams('--hstore')
->addParams('--latlong') ->addParams('--latlong')
->addParams('--append') ->addParams('--append')
@@ -77,7 +77,7 @@ $oOsm2pgsqlCmd = (new \Nominatim\Shell(CONST_Osm2pgsql_Binary))
->addParams('--number-processes', 1) ->addParams('--number-processes', 1)
->addParams('--cache', $iCacheMemory) ->addParams('--cache', $iCacheMemory)
->addParams('--output', 'gazetteer') ->addParams('--output', 'gazetteer')
->addParams('--style', CONST_Import_Style) ->addParams('--style', getImportStyle())
->addParams('--database', $aDSNInfo['database']) ->addParams('--database', $aDSNInfo['database'])
->addParams('--port', $aDSNInfo['port']); ->addParams('--port', $aDSNInfo['port']);
@@ -90,8 +90,8 @@ if (isset($aDSNInfo['username']) && $aDSNInfo['username']) {
if (isset($aDSNInfo['password']) && $aDSNInfo['password']) { if (isset($aDSNInfo['password']) && $aDSNInfo['password']) {
$oOsm2pgsqlCmd->addEnvPair('PGPASSWORD', $aDSNInfo['password']); $oOsm2pgsqlCmd->addEnvPair('PGPASSWORD', $aDSNInfo['password']);
} }
if (!is_null(CONST_Osm2pgsql_Flatnode_File) && CONST_Osm2pgsql_Flatnode_File) { if (getSetting('FLATNODE_FILE')) {
$oOsm2pgsqlCmd->addParams('--flat-nodes', CONST_Osm2pgsql_Flatnode_File); $oOsm2pgsqlCmd->addParams('--flat-nodes', getSetting('FLATNODE_FILE'));
} }
if ($fPostgresVersion >= 11.0) { if ($fPostgresVersion >= 11.0) {
$oOsm2pgsqlCmd->addEnvPair( $oOsm2pgsqlCmd->addEnvPair(
@@ -121,31 +121,34 @@ if (isset($aDSNInfo['password']) && $aDSNInfo['password']) {
$oIndexCmd->addEnvPair('PGPASSWORD', $aDSNInfo['password']); $oIndexCmd->addEnvPair('PGPASSWORD', $aDSNInfo['password']);
} }
$sPyosmiumBin = getSetting('PYOSMIUM_BINARY');
$sBaseURL = getSetting('REPLICATION_URL');
if ($aResult['init-updates']) { if ($aResult['init-updates']) {
// sanity check that the replication URL is correct // sanity check that the replication URL is correct
$sBaseState = file_get_contents(CONST_Replication_Url.'/state.txt'); $sBaseState = file_get_contents($sBaseURL.'/state.txt');
if ($sBaseState === false) { if ($sBaseState === false) {
echo "\nCannot find state.txt file at the configured replication URL.\n"; echo "\nCannot find state.txt file at the configured replication URL.\n";
echo "Does the URL point to a directory containing OSM update data?\n\n"; echo "Does the URL point to a directory containing OSM update data?\n\n";
fail('replication URL not reachable.'); fail('replication URL not reachable.');
} }
// sanity check for pyosmium-get-changes // sanity check for pyosmium-get-changes
if (!CONST_Pyosmium_Binary) { if (!$sPyosmiumBin) {
echo "\nCONST_Pyosmium_Binary not configured.\n"; echo "\nNOMINATIM_PYOSMIUM_BINARY not configured.\n";
echo "You need to install pyosmium and set up the path to pyosmium-get-changes\n"; echo "You need to install pyosmium and set up the path to pyosmium-get-changes\n";
echo "in your local settings file.\n\n"; echo "in your local .env file.\n\n";
fail('CONST_Pyosmium_Binary not configured'); fail('NOMINATIM_PYOSMIUM_BINARY not configured');
} }
$aOutput = 0; $aOutput = 0;
$oCMD = new \Nominatim\Shell(CONST_Pyosmium_Binary, '--help'); $oCMD = new \Nominatim\Shell($sPyosmiumBin, '--help');
exec($oCMD->escapedCmd(), $aOutput, $iRet); exec($oCMD->escapedCmd(), $aOutput, $iRet);
if ($iRet != 0) { if ($iRet != 0) {
echo "Cannot execute pyosmium-get-changes.\n"; echo "Cannot execute pyosmium-get-changes.\n";
echo "Make sure you have pyosmium installed correctly\n"; echo "Make sure you have pyosmium installed correctly\n";
echo "and have set up CONST_Pyosmium_Binary to point to pyosmium-get-changes.\n"; echo "and have set up NOMINATIM_PYOSMIUM_BINARY to point to pyosmium-get-changes.\n";
fail('pyosmium-get-changes not found or not usable'); fail('pyosmium-get-changes not found or not usable');
} }
@@ -166,9 +169,9 @@ if ($aResult['init-updates']) {
// get the appropriate state id // get the appropriate state id
$aOutput = 0; $aOutput = 0;
$oCMD = (new \Nominatim\Shell(CONST_Pyosmium_Binary)) $oCMD = (new \Nominatim\Shell($sPyosmiumBin))
->addParams('--start-date', $sWindBack) ->addParams('--start-date', $sWindBack)
->addParams('--server', CONST_Replication_Url); ->addParams('--server', $sBaseURL);
exec($oCMD->escapedCmd(), $aOutput, $iRet); exec($oCMD->escapedCmd(), $aOutput, $iRet);
if ($iRet != 0 || $aOutput[0] == 'None') { if ($iRet != 0 || $aOutput[0] == 'None') {
@@ -196,7 +199,7 @@ if ($aResult['check-for-updates']) {
} }
$oCmd = (new \Nominatim\Shell(CONST_BinDir.'/check_server_for_updates.py')) $oCmd = (new \Nominatim\Shell(CONST_BinDir.'/check_server_for_updates.py'))
->addParams(CONST_Replication_Url) ->addParams($sBaseURL)
->addParams($aLastState['sequence_id']); ->addParams($aLastState['sequence_id']);
$iRet = $oCmd->run(); $iRet = $oCmd->run();
@@ -293,8 +296,9 @@ if ($aResult['index']) {
} }
if ($aResult['update-address-levels']) { if ($aResult['update-address-levels']) {
echo 'Updating address levels from '.CONST_Address_Level_Config.".\n"; $sAddressLevelConfig = getSettingConfig('ADDRESS_LEVEL_CONFIG', 'address-levels.json');
$oAlParser = new \Nominatim\Setup\AddressLevelParser(CONST_Address_Level_Config); echo 'Updating address levels from '.$sAddressLevelConfig.".\n";
$oAlParser = new \Nominatim\Setup\AddressLevelParser($sAddressLevelConfig);
$oAlParser->createTable($oDB, 'address_levels'); $oAlParser->createTable($oDB, 'address_levels');
} }
@@ -317,17 +321,17 @@ if ($aResult['recompute-importance']) {
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) { if (strpos($sBaseURL, 'download.geofabrik.de') !== false && getSetting('REPLICATION_UPDATE_INTERVAL') < 86400) {
fail('Error: Update interval too low for download.geofabrik.de. ' . fail('Error: Update interval too low for download.geofabrik.de. ' .
"Please check install documentation (https://nominatim.org/release-docs/latest/admin/Import-and-Update#setting-up-the-update-process)\n"); "Please check install documentation (https://nominatim.org/release-docs/latest/admin/Import-and-Update#setting-up-the-update-process)\n");
} }
$sImportFile = CONST_InstallDir.'/osmosischange.osc'; $sImportFile = CONST_InstallDir.'/osmosischange.osc';
$oCMDDownload = (new \Nominatim\Shell(CONST_Pyosmium_Binary)) $oCMDDownload = (new \Nominatim\Shell($sPyosmiumBin))
->addParams('--server', CONST_Replication_Url) ->addParams('--server', $sBaseURL)
->addParams('--outfile', $sImportFile) ->addParams('--outfile', $sImportFile)
->addParams('--size', CONST_Replication_Max_Diff_size); ->addParams('--size', getSetting('REPLICATION_MAX_DIFF'));
$oCMDImport = (clone $oOsm2pgsqlCmd)->addParams($sImportFile); $oCMDImport = (clone $oOsm2pgsqlCmd)->addParams($sImportFile);
@@ -347,7 +351,7 @@ if ($aResult['import-osmosis'] || $aResult['import-osmosis-all']) {
if ($aLastState['indexed']) { if ($aLastState['indexed']) {
// Sleep if the update interval has not yet been reached. // Sleep if the update interval has not yet been reached.
$fNextUpdate = $aLastState['unix_ts'] + CONST_Replication_Update_Interval; $fNextUpdate = $aLastState['unix_ts'] + getSetting('REPLICATION_UPDATE_INTERVAL');
if ($fNextUpdate > $fStartTime) { if ($fNextUpdate > $fStartTime) {
$iSleepTime = $fNextUpdate - $fStartTime; $iSleepTime = $fNextUpdate - $fStartTime;
echo "Waiting for next update for $iSleepTime sec."; echo "Waiting for next update for $iSleepTime sec.";
@@ -368,8 +372,9 @@ if ($aResult['import-osmosis'] || $aResult['import-osmosis-all']) {
exec($oCMD->escapedCmd(), $aOutput, $iResult); exec($oCMD->escapedCmd(), $aOutput, $iResult);
if ($iResult == 3) { if ($iResult == 3) {
echo 'No new updates. Sleeping for '.CONST_Replication_Recheck_Interval." sec.\n"; $sSleep = getSetting('REPLICATION_RECHECK_INTERVAL');
sleep(CONST_Replication_Recheck_Interval); echo 'No new updates. Sleeping for '.$sSleep." sec.\n";
sleep($sSleep);
} elseif ($iResult != 0) { } elseif ($iResult != 0) {
echo 'ERROR: updates failed.'; echo 'ERROR: updates failed.';
exit($iResult); exit($iResult);

View File

@@ -15,15 +15,6 @@ $oGeocode = new Nominatim\Geocode($oDB);
$aLangPrefOrder = $oParams->getPreferredLanguages(); $aLangPrefOrder = $oParams->getPreferredLanguages();
$oGeocode->setLanguagePreference($aLangPrefOrder); $oGeocode->setLanguagePreference($aLangPrefOrder);
if (CONST_Search_ReversePlanForAll
|| isset($aLangPrefOrder['name:de'])
|| isset($aLangPrefOrder['name:ru'])
|| isset($aLangPrefOrder['name:ja'])
|| isset($aLangPrefOrder['name:pl'])
) {
$oGeocode->setReverseInPlan(true);
}
// Format for output // Format for output
$sOutputFormat = $oParams->getSet('format', array('xml', 'json', 'jsonv2', 'geojson', 'geocodejson'), 'jsonv2'); $sOutputFormat = $oParams->getSet('format', array('xml', 'json', 'jsonv2', 'geojson', 'geocodejson'), 'jsonv2');
set_exception_handler_by_format($sOutputFormat); set_exception_handler_by_format($sOutputFormat);