4 require_once(dirname(dirname(__FILE__)).'/lib/init-cmd.php');
5 ini_set('memory_limit', '800M');
8 "Create and setup nominatim search system",
9 array('help', 'h', 0, 1, 0, 0, false, 'Show Help'),
10 array('quiet', 'q', 0, 1, 0, 0, 'bool', 'Quiet output'),
11 array('verbose', 'v', 0, 1, 0, 0, 'bool', 'Verbose output'),
13 array('create-db', '', 0, 1, 0, 0, 'bool', 'Build a blank nominatim db'),
14 array('load-data', '', 0, 1, 0, 0, 'realpath', 'Import a osm file'),
15 array('create-partitions', '', 0, 1, 0, 0, 'bool', 'Create required partition tables and triggers'),
17 getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true);
19 if ($aCMDResult['create-db'])
21 // TODO: path detection, detection memory, etc.
22 passthru('createdb nominatim');
23 passthru('createlang plpgsql nominatim');
24 passthru('psql -f /mqdata/mapquest/postgres-9.0.1-server/share/contrib/_int.sql nominatim');
25 passthru('psql -f /mqdata/mapquest/postgres-9.0.1-server/share/contrib/hstore.sql nominatim');
26 passthru('psql -f /mqdata/mapquest/postgres-9.0.1-server/share/contrib/postgis-1.5/postgis.sql nominatim');
27 passthru('psql -f /mqdata/mapquest/postgres-9.0.1-server/share/contrib/postgis-1.5/spatial_ref_sys.sql nominatim');
30 if ($aCMDResult['load-data'])
32 passthru(CONST_BasePath.'/osm2pgsql -lsc -O gazetteer -C 10000 --hstore -d nominatim '.$aCMDResult['load-data']);
35 if ($aCMDResult['create-partitions'])
37 $sSQL = 'select distinct country_code from country_name order by country_code';
38 $aPartitions = $oDB->getCol($sSQL);
39 if (PEAR::isError($aPartitions))
41 fail($aPartitions->getMessage());
43 $aPartitions[] = 'none';
45 $sTemplate = file_get_contents(CONST_BasePath.'/sql/partitions.src.sql');
46 preg_match_all('#^-- start(.*?)^-- end#ms', $sTemplate, $aMatches, PREG_SET_ORDER);
47 foreach($aMatches as $aMatch)
50 foreach($aPartitions as $sPartitionName)
52 $sResult .= str_replace('-partition-', $sPartitionName, $aMatch[1]);
54 $sTemplate = str_replace($aMatch[0], $sResult, $sTemplate);
60 showUsage($aCMDOptions, true);