forked from hans/Nominatim
Merge branch 'master' of github.com:twain47/Nominatim
This commit is contained in:
@@ -145,7 +145,7 @@ void nominatim_index(int rank_min, int rank_max, int num_threads, const char *co
|
|||||||
writer = nominatim_exportXMLStart(structuredoutputfile);
|
writer = nominatim_exportXMLStart(structuredoutputfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr, "Starting indexing rank (%i to %i) using %i treads\n", rank_min, rank_max, num_threads);
|
fprintf(stderr, "Starting indexing rank (%i to %i) using %i threads\n", rank_min, rank_max, num_threads);
|
||||||
|
|
||||||
for (rank = rank_min; rank <= rank_max; rank++)
|
for (rank = rank_min; rank <= rank_max; rank++)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -598,8 +598,8 @@ BEGIN
|
|||||||
isArea := true;
|
isArea := true;
|
||||||
centroid := ST_Centroid(geometry);
|
centroid := ST_Centroid(geometry);
|
||||||
|
|
||||||
FOR geometry IN select split_geometry(geometry) as geometry LOOP
|
FOR secgeo IN select split_geometry(geometry) AS geom LOOP
|
||||||
x := insertLocationAreaLarge(partition, place_id, country_code, keywords, rank_search, rank_address, false, centroid, geometry);
|
x := insertLocationAreaLarge(partition, place_id, country_code, keywords, rank_search, rank_address, false, centroid, secgeo);
|
||||||
END LOOP;
|
END LOOP;
|
||||||
|
|
||||||
ELSEIF rank_search < 26 THEN
|
ELSEIF rank_search < 26 THEN
|
||||||
@@ -2878,10 +2878,10 @@ BEGIN
|
|||||||
IF st_intersects(geometry, secbox) THEN
|
IF st_intersects(geometry, secbox) THEN
|
||||||
secgeo := st_intersection(geometry, secbox);
|
secgeo := st_intersection(geometry, secbox);
|
||||||
IF NOT ST_IsEmpty(secgeo) AND ST_GeometryType(secgeo) in ('ST_Polygon','ST_MultiPolygon') THEN
|
IF NOT ST_IsEmpty(secgeo) AND ST_GeometryType(secgeo) in ('ST_Polygon','ST_MultiPolygon') THEN
|
||||||
FOR geo IN select quad_split_geometry(secgeo, maxarea, remainingdepth) as geometry LOOP
|
FOR geo IN select quad_split_geometry(secgeo, maxarea, remainingdepth) as geom LOOP
|
||||||
IF NOT ST_IsEmpty(geo.geometry) AND ST_GeometryType(geo.geometry) in ('ST_Polygon','ST_MultiPolygon') THEN
|
IF NOT ST_IsEmpty(geo.geom) AND ST_GeometryType(geo.geom) in ('ST_Polygon','ST_MultiPolygon') THEN
|
||||||
added := added + 1;
|
added := added + 1;
|
||||||
RETURN NEXT geo.geometry;
|
RETURN NEXT geo.geom;
|
||||||
END IF;
|
END IF;
|
||||||
END LOOP;
|
END LOOP;
|
||||||
END IF;
|
END IF;
|
||||||
@@ -2900,8 +2900,8 @@ DECLARE
|
|||||||
geo RECORD;
|
geo RECORD;
|
||||||
BEGIN
|
BEGIN
|
||||||
-- 10000000000 is ~~ 1x1 degree
|
-- 10000000000 is ~~ 1x1 degree
|
||||||
FOR geo IN select quad_split_geometry(geometry, 0.25, 20) as geometry LOOP
|
FOR geo IN select quad_split_geometry(geometry, 0.25, 20) as geom LOOP
|
||||||
RETURN NEXT geo.geometry;
|
RETURN NEXT geo.geom;
|
||||||
END LOOP;
|
END LOOP;
|
||||||
RETURN;
|
RETURN;
|
||||||
END;
|
END;
|
||||||
|
|||||||
@@ -121,7 +121,11 @@
|
|||||||
$bDidSomething = true;
|
$bDidSomething = true;
|
||||||
|
|
||||||
$osm2pgsql = CONST_Osm2pgsql_Binary;
|
$osm2pgsql = CONST_Osm2pgsql_Binary;
|
||||||
if (!file_exists($osm2pgsql)) fail("please download and build 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'");
|
||||||
|
}
|
||||||
$osm2pgsql .= ' -lsc -O gazetteer --hstore';
|
$osm2pgsql .= ' -lsc -O gazetteer --hstore';
|
||||||
$osm2pgsql .= ' -C '.$iCacheMemory;
|
$osm2pgsql .= ' -C '.$iCacheMemory;
|
||||||
$osm2pgsql .= ' -d '.$aDSNInfo['database'].' '.$aCMDResult['osm-file'];
|
$osm2pgsql .= ' -d '.$aDSNInfo['database'].' '.$aCMDResult['osm-file'];
|
||||||
@@ -492,7 +496,12 @@
|
|||||||
{
|
{
|
||||||
$bDidSomething = true;
|
$bDidSomething = true;
|
||||||
$sTargetDir = $aCMDResult['create-website'];
|
$sTargetDir = $aCMDResult['create-website'];
|
||||||
if (!is_dir($sTargetDir)) fail('please specify a directory to setup');
|
if (!is_dir($sTargetDir))
|
||||||
|
{
|
||||||
|
echo "You must create the website directory before calling this function.\n";
|
||||||
|
fail("Target directory does not exist.");
|
||||||
|
}
|
||||||
|
|
||||||
@symlink(CONST_BasePath.'/website/details.php', $sTargetDir.'/details.php');
|
@symlink(CONST_BasePath.'/website/details.php', $sTargetDir.'/details.php');
|
||||||
@symlink(CONST_BasePath.'/website/reverse.php', $sTargetDir.'/reverse.php');
|
@symlink(CONST_BasePath.'/website/reverse.php', $sTargetDir.'/reverse.php');
|
||||||
@symlink(CONST_BasePath.'/website/search.php', $sTargetDir.'/search.php');
|
@symlink(CONST_BasePath.'/website/search.php', $sTargetDir.'/search.php');
|
||||||
|
|||||||
144
utils/update.php
144
utils/update.php
@@ -30,6 +30,7 @@
|
|||||||
array('import-node', '', 0, 1, 1, 1, 'int', 'Re-import node'),
|
array('import-node', '', 0, 1, 1, 1, 'int', 'Re-import node'),
|
||||||
array('import-way', '', 0, 1, 1, 1, 'int', 'Re-import way'),
|
array('import-way', '', 0, 1, 1, 1, 'int', 'Re-import way'),
|
||||||
array('import-relation', '', 0, 1, 1, 1, 'int', 'Re-import relation'),
|
array('import-relation', '', 0, 1, 1, 1, 'int', 'Re-import relation'),
|
||||||
|
array('import-from-main-api', '', 0, 1, 0, 0, 'bool', 'Use OSM API instead of Overpass to download objects'),
|
||||||
|
|
||||||
array('index', '', 0, 1, 0, 0, 'bool', 'Index'),
|
array('index', '', 0, 1, 0, 0, 'bool', 'Index'),
|
||||||
array('index-rank', '', 0, 1, 1, 1, 'int', 'Rank to start indexing from'),
|
array('index-rank', '', 0, 1, 1, 1, 'int', 'Rank to start indexing from'),
|
||||||
@@ -46,6 +47,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($aResult['index-instances'])) $aResult['index-instances'] = 1;
|
if (!isset($aResult['index-instances'])) $aResult['index-instances'] = 1;
|
||||||
|
if (!isset($aResult['index-rank'])) $aResult['index-rank'] = 0;
|
||||||
/*
|
/*
|
||||||
// Lock to prevent multiple copies running
|
// Lock to prevent multiple copies running
|
||||||
if (exec('/bin/ps uww | grep '.basename(__FILE__).' | grep -v /dev/null | grep -v grep -c', $aOutput2, $iResult) > 1)
|
if (exec('/bin/ps uww | grep '.basename(__FILE__).' | grep -v /dev/null | grep -v grep -c', $aOutput2, $iResult) > 1)
|
||||||
@@ -67,6 +69,8 @@
|
|||||||
|
|
||||||
$oDB =& getDB();
|
$oDB =& getDB();
|
||||||
|
|
||||||
|
$aDSNInfo = DB::parseDSN(CONST_Database_DSN);
|
||||||
|
|
||||||
$bFirst = true;
|
$bFirst = true;
|
||||||
$bContinue = $aResult['import-all'];
|
$bContinue = $aResult['import-all'];
|
||||||
while ($bContinue || $bFirst)
|
while ($bContinue || $bFirst)
|
||||||
@@ -95,7 +99,7 @@
|
|||||||
{
|
{
|
||||||
// import diff directly (e.g. from osmosis --rri)
|
// import diff directly (e.g. from osmosis --rri)
|
||||||
$sNextFile = $aResult['import-diff'];
|
$sNextFile = $aResult['import-diff'];
|
||||||
if (!file_exists($nextFile))
|
if (!file_exists($sNextFile))
|
||||||
{
|
{
|
||||||
echo "Cannot open $nextFile\n";
|
echo "Cannot open $nextFile\n";
|
||||||
exit;
|
exit;
|
||||||
@@ -105,10 +109,10 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Missing file is not an error - it might not be created yet
|
// Missing file is not an error - it might not be created yet
|
||||||
if (($aResult['import-hourly'] || $aResult['import-daily']) && file_exists($sNextFile))
|
if (($aResult['import-hourly'] || $aResult['import-daily'] || isset($aResult['import-diff'])) && file_exists($sNextFile))
|
||||||
{
|
{
|
||||||
// Import the file
|
// Import the file
|
||||||
$sCMD = CONST_Osm2pgsql_Binary.' -klas -C 2000 -O gazetteer -d '.$sDatabaseName.' '.$sNextFile;
|
$sCMD = CONST_Osm2pgsql_Binary.' -klas -C 2000 -O gazetteer -d '.$aDSNInfo['database'].' '.$sNextFile;
|
||||||
echo $sCMD."\n";
|
echo $sCMD."\n";
|
||||||
exec($sCMD, $sJunk, $iErrorLevel);
|
exec($sCMD, $sJunk, $iErrorLevel);
|
||||||
|
|
||||||
@@ -127,63 +131,104 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$sModifyXML = false;
|
$bModifyXML = false;
|
||||||
|
$sModifyXMLstr = '';
|
||||||
|
$bUseOSMApi = isset($aResult['import-from-main-api']) && $aResult['import-from-main-api'];
|
||||||
if (isset($aResult['import-file']) && $aResult['import-file'])
|
if (isset($aResult['import-file']) && $aResult['import-file'])
|
||||||
{
|
{
|
||||||
$sModifyXML = file_get_contents($aResult['import-file']);
|
$bModifyXML = true;
|
||||||
}
|
}
|
||||||
if (isset($aResult['import-node']) && $aResult['import-node'])
|
if (isset($aResult['import-node']) && $aResult['import-node'])
|
||||||
{
|
{
|
||||||
$sModifyXML = file_get_contents('http://www.openstreetmap.org/api/0.6/node/'.$aResult['import-node']);
|
$bModifyXML = true;
|
||||||
|
if ($bUseOSMApi)
|
||||||
|
{
|
||||||
|
$sModifyXMLstr = file_get_contents('http://www.openstreetmap.org/api/0.6/node/'.$aResult['import-node']);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$sModifyXMLstr = file_get_contents('http://overpass.osm.rambler.ru/cgi/interpreter?data=node('.$aResult['import-node'].');out%20meta;');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (isset($aResult['import-way']) && $aResult['import-way'])
|
if (isset($aResult['import-way']) && $aResult['import-way'])
|
||||||
{
|
{
|
||||||
$sModifyXML = file_get_contents('http://www.openstreetmap.org/api/0.6/way/'.$aResult['import-way'].'/full');
|
$bModifyXML = true;
|
||||||
|
if ($bUseOSMApi)
|
||||||
|
{
|
||||||
|
$sCmd = 'http://www.openstreetmap.org/api/0.6/way/'.$aResult['import-way'].'/full';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$sCmd = 'http://overpass.osm.rambler.ru/cgi/interpreter?data=(way('.$aResult['import-way'].');node(w););out%20meta;';
|
||||||
|
}
|
||||||
|
$sModifyXMLstr = file_get_contents($sCmd);
|
||||||
}
|
}
|
||||||
if (isset($aResult['import-relation']) && $aResult['import-relation'])
|
if (isset($aResult['import-relation']) && $aResult['import-relation'])
|
||||||
{
|
{
|
||||||
$sModifyXML = file_get_contents('http://www.openstreetmap.org/api/0.6/relation/'.$aResult['import-relation'].'/full');
|
$bModifyXML = true;
|
||||||
}
|
if ($bUseOSMApi)
|
||||||
if ($sModifyXML)
|
|
||||||
{
|
|
||||||
// Hack into a modify request
|
|
||||||
$sModifyXML = str_replace('<osm version="0.6" generator="OpenStreetMap server">',
|
|
||||||
'<osmChange version="0.6" generator="OpenStreetMap server"><modify>', $sModifyXML);
|
|
||||||
$sModifyXML = str_replace('<osm version=\'0.6\' upload=\'true\' generator=\'JOSM\'>',
|
|
||||||
'<osmChange version="0.6" generator="OpenStreetMap server"><modify>', $sModifyXML);
|
|
||||||
$sModifyXML = str_replace('</osm>', '</modify></osmChange>', $sModifyXML);
|
|
||||||
|
|
||||||
// Outputing this is too verbose
|
|
||||||
if ($aResult['verbose'] && false) var_dump($sModifyXML);
|
|
||||||
|
|
||||||
$sDatabaseName = 'nominatim';
|
|
||||||
$aSpec = array(
|
|
||||||
0 => array("pipe", "r"), // stdin
|
|
||||||
1 => array("pipe", "w"), // stdout
|
|
||||||
2 => array("pipe", "w") // stderr
|
|
||||||
);
|
|
||||||
$aPipes = array();
|
|
||||||
$sCMD = CONST_Osm2pgsql_Binary.' -klas -C 2000 -O gazetteer -d '.$sDatabaseName.' -';
|
|
||||||
echo $sCMD."\n";
|
|
||||||
$hProc = proc_open($sCMD, $aSpec, $aPipes);
|
|
||||||
if (!is_resource($hProc))
|
|
||||||
{
|
{
|
||||||
echo "$sBasePath/osm2pgsql failed\n";
|
$sModifyXMLstr = file_get_contents('http://www.openstreetmap.org/api/0.6/relation/'.$aResult['import-relation'].'/full');
|
||||||
exit;
|
|
||||||
}
|
}
|
||||||
fwrite($aPipes[0], $sModifyXML);
|
else
|
||||||
fclose($aPipes[0]);
|
|
||||||
$sOut = stream_get_contents($aPipes[1]);
|
|
||||||
if ($aResult['verbose']) echo $sOut;
|
|
||||||
fclose($aPipes[1]);
|
|
||||||
$sErrors = stream_get_contents($aPipes[2]);
|
|
||||||
if ($aResult['verbose']) echo $sErrors;
|
|
||||||
fclose($aPipes[2]);
|
|
||||||
if ($iError = proc_close($hProc))
|
|
||||||
{
|
{
|
||||||
echo "osm2pgsql existed with error level $iError\n";
|
$sModifyXMLstr = file_get_contents('http://overpass.osm.rambler.ru/cgi/interpreter?data=((rel('.$aResult['import-relation'].');way(r);node(w));node(r));out%20meta;');
|
||||||
echo $sOut;
|
}
|
||||||
echo $sErrors;
|
}
|
||||||
|
if ($bModifyXML)
|
||||||
|
{
|
||||||
|
// derive change from normal osm file with osmosis
|
||||||
|
$sTemporaryFile = CONST_BasePath.'/data/osmosischange.osc';
|
||||||
|
if (isset($aResult['import-file']) && $aResult['import-file'])
|
||||||
|
{
|
||||||
|
$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)
|
||||||
|
{
|
||||||
|
echo "Error converting osm to osc, osmosis returned: $iErrorLevel\n";
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$aSpec = array(
|
||||||
|
0 => array("pipe", "r"), // stdin
|
||||||
|
1 => array("pipe", "w"), // stdout
|
||||||
|
2 => array("pipe", "w") // stderr
|
||||||
|
);
|
||||||
|
$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))
|
||||||
|
{
|
||||||
|
echo "Error converting osm to osc, osmosis failed\n";
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
fwrite($aPipes[0], $sModifyXMLstr);
|
||||||
|
fclose($aPipes[0]);
|
||||||
|
$sOut = stream_get_contents($aPipes[1]);
|
||||||
|
if ($aResult['verbose']) echo $sOut;
|
||||||
|
fclose($aPipes[1]);
|
||||||
|
$sErrors = stream_get_contents($aPipes[2]);
|
||||||
|
if ($aResult['verbose']) echo $sErrors;
|
||||||
|
fclose($aPipes[2]);
|
||||||
|
if ($iError = proc_close($hProc))
|
||||||
|
{
|
||||||
|
echo "Error converting osm to osc, osmosis returned: $iError\n";
|
||||||
|
echo $sOut;
|
||||||
|
echo $sErrors;
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// import generated change file
|
||||||
|
$sCMD = CONST_Osm2pgsql_Binary.' -klas -C 2000 -O gazetteer -d '.$aDSNInfo['database'].' '.$sTemporaryFile;
|
||||||
|
echo $sCMD."\n";
|
||||||
|
exec($sCMD, $sJunk, $iErrorLevel);
|
||||||
|
if ($iErrorLevel)
|
||||||
|
{
|
||||||
|
echo "osm2pgsql exited with error level $iErrorLevel\n";
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -297,7 +342,7 @@
|
|||||||
|
|
||||||
if ($aResult['index'])
|
if ($aResult['index'])
|
||||||
{
|
{
|
||||||
index($aResult, $sDatabaseDSN);
|
passthru(CONST_BasePath.'/nominatim/nominatim -i -d '.$aDSNInfo['database'].' -t '.$aResult['index-instances'].' -r '.$aResult['index-rank']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($aResult['import-osmosis'] || $aResult['import-osmosis-all'])
|
if ($aResult['import-osmosis'] || $aResult['import-osmosis-all'])
|
||||||
@@ -305,10 +350,9 @@
|
|||||||
$sImportFile = CONST_BasePath.'/data/osmosischange.osc';
|
$sImportFile = CONST_BasePath.'/data/osmosischange.osc';
|
||||||
$sOsmosisCMD = CONST_Osmosis_Binary;
|
$sOsmosisCMD = CONST_Osmosis_Binary;
|
||||||
$sOsmosisConfigDirectory = CONST_BasePath.'/settings';
|
$sOsmosisConfigDirectory = CONST_BasePath.'/settings';
|
||||||
$sDatabaseName = 'nominatim';
|
|
||||||
$sCMDDownload = $sOsmosisCMD.' --read-replication-interval workingDirectory='.$sOsmosisConfigDirectory.' --simplify-change --write-xml-change '.$sImportFile;
|
$sCMDDownload = $sOsmosisCMD.' --read-replication-interval workingDirectory='.$sOsmosisConfigDirectory.' --simplify-change --write-xml-change '.$sImportFile;
|
||||||
$sCMDImport = CONST_Osm2pgsql_Binary.' -klas -C 2000 -O gazetteer -d '.$sDatabaseName.' '.$sImportFile;
|
$sCMDImport = CONST_Osm2pgsql_Binary.' -klas -C 2000 -O gazetteer -d '.$aDSNInfo['database'].' '.$sImportFile;
|
||||||
$sCMDIndex = $sBasePath.'/nominatim/nominatim -i -t '.$aResult['index-instances'];
|
$sCMDIndex = $sBasePath.'/nominatim/nominatim -i -d '.$aDSNInfo['database'].' -t '.$aResult['index-instances'];
|
||||||
if (!$aResult['no-npi']) {
|
if (!$aResult['no-npi']) {
|
||||||
$sCMDIndex .= '-F ';
|
$sCMDIndex .= '-F ';
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user