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, 1, 1, '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 $bDidSomething = false;
21 if ($aCMDResult['create-db'])
23 $bDidSomething = true;
24 // TODO: path detection, detection memory, etc.
25 // passthru('createdb nominatim');
26 passthru('createlang plpgsql nominatim');
27 passthru('psql -f '.CONST_Path_Postgresql_Contrib.'/_int.sql nominatim');
28 passthru('psql -f '.CONST_Path_Postgresql_Contrib.'/hstore.sql nominatim');
29 passthru('psql -f '.CONST_Path_Postgresql_Postgis.'/postgis.sql nominatim');
30 passthru('psql -f '.CONST_Path_Postgresql_Postgis.'/spatial_ref_sys.sql nominatim');
31 passthru('psql -f '.CONST_BasePath.'/data/country_name.sql nominatim');
32 passthru('psql -f '.CONST_BasePath.'/data/country_osm_grid.sql nominatim');
33 passthru('psql -f '.CONST_BasePath.'/data/gb_postcode.sql nominatim');
34 passthru('psql -f '.CONST_BasePath.'/data/us_statecounty.sql nominatim');
35 passthru('psql -f '.CONST_BasePath.'/data/us_state.sql nominatim');
36 passthru('psql -f '.CONST_BasePath.'/data/worldboundaries.sql nominatim');
39 if (isset($aCMDResult['load-data']) && $aCMDResult['load-data'])
41 $bDidSomething = true;
42 passthru(CONST_BasePath.'/osm2pgsql/osm2pgsql -lsc -O gazetteer -C 10000 --hstore -d nominatim '.$aCMDResult['load-data']);
43 passthru('psql -f '.CONST_BasePath.'/sql/functions.sql nominatim');
44 passthru('psql -f '.CONST_BasePath.'/sql/tables.sql nominatim');
47 if ($aCMDResult['create-partitions'])
49 $bDidSomething = true;
50 $sSQL = 'select distinct country_code from country_name order by country_code';
51 $aPartitions = $oDB->getCol($sSQL);
52 if (PEAR::isError($aPartitions))
54 fail($aPartitions->getMessage());
56 $aPartitions[] = 'none';
58 $sTemplate = file_get_contents(CONST_BasePath.'/sql/partitions.src.sql');
59 preg_match_all('#^-- start(.*?)^-- end#ms', $sTemplate, $aMatches, PREG_SET_ORDER);
60 foreach($aMatches as $aMatch)
63 foreach($aPartitions as $sPartitionName)
65 $sResult .= str_replace('-partition-', $sPartitionName, $aMatch[1]);
67 $sTemplate = str_replace($aMatch[0], $sResult, $sTemplate);
75 showUsage($aCMDOptions, true);