Esempio n. 1
0
	{
		echo "Too many blocking processes for import\n";
		exit;
	}
*/
// Assume osm2pgsql is in the folder above
$sBasePath = dirname(dirname(__FILE__));
date_default_timezone_set('Etc/UTC');
$oDB =& getDB();
$aDSNInfo = DB::parseDSN(CONST_Database_DSN);
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()) {
    $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)) {
    $sOsm2pgsqlCmd .= ' --flat-nodes ' . CONST_Osm2pgsql_Flatnode_File;
}
$bFirst = true;
$bContinue = $aResult['import-all'];
while ($bContinue || $bFirst) {
    $bFirst = false;
    if ($aResult['import-hourly']) {
        // Mirror the hourly diffs
        exec('wget --quiet --mirror -l 1 -P ' . $sMirrorDir . ' http://planet.openstreetmap.org/hourly');
        $sNextFile = $oDB->getOne('select TO_CHAR(lastimportdate,\'YYYYMMDDHH24\')||\'-\'||TO_CHAR(lastimportdate+\'1 hour\'::interval,\'YYYYMMDDHH24\')||\'.osc.gz\' from import_status');
Esempio n. 2
0
        fail('osm-file "' . $aCMDResult['osm-file'] . '" not readable');
    }
}
// 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) {
    $iInstances = 1;
    echo "WARNING: resetting threads to {$iInstances}\n";
}
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)
$iCacheMemory = isset($aCMDResult['osm2pgsql-cache']) ? $aCMDResult['osm2pgsql-cache'] : getCacheMemoryMB();
if ($iCacheMemory > getTotalMemoryMB()) {
    $iCacheMemory = getCacheMemoryMB();
    echo "WARNING: resetting cache memory to {$iCacheMemory}\n";
}
$aDSNInfo = DB::parseDSN(CONST_Database_DSN);
if (!isset($aDSNInfo['port']) || !$aDSNInfo['port']) {
    $aDSNInfo['port'] = 5432;
}
$fPostgisVersion = (double) CONST_Postgis_Version;
if ($aCMDResult['create-db'] || $aCMDResult['all']) {
    echo "Create DB\n";
    $bDidSomething = true;
    $oDB =& DB::connect(CONST_Database_DSN, false);
    if (!PEAR::isError($oDB)) {
        fail('database already exists (' . CONST_Database_DSN . ')');
    }