4 require_once(dirname(dirname(__FILE__)).'/lib/init-cmd.php');
5 ini_set('memory_limit', '800M');
6 ini_set('display_errors', 'stderr');
9 "Import and export special phrases",
10 array('help', 'h', 0, 1, 0, 0, false, 'Show Help'),
11 array('quiet', 'q', 0, 1, 0, 0, 'bool', 'Quiet output'),
12 array('verbose', 'v', 0, 1, 0, 0, 'bool', 'Verbose output'),
14 array('wiki-import', '', 0, 1, 0, 0, 'bool', 'Create nominatim db'),
16 getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true);
52 if ($aCMDResult['wiki-import'])
56 foreach($aLanguageIn as $sLanguage)
58 $sURL = 'http://wiki.openstreetmap.org/wiki/Special:Export/Nominatim/Special_Phrases/'.strtoupper($sLanguage);
59 $sWikiPageXML = file_get_contents($sURL);
60 if (preg_match_all('#\\| ([^|]+) \\|\\| ([^|]+) \\|\\| ([^|]+) \\|\\| ([^|]+) \\|\\| ([\\-YN])#', $sWikiPageXML, $aMatches, PREG_SET_ORDER))
62 foreach($aMatches as $aMatch)
67 # hack around a bug where building=yes was imported with
68 # quotes into the wiki
69 $sType = preg_replace('/"/', '', $sType);
70 # sanity check, in case somebody added garbage in the wiki
71 if (preg_match('/^\\w+$/', $sClass) < 1 ||
72 preg_match('/^\\w+$/', $sType) < 1) {
73 trigger_error("Bad class/type for language $sLanguage: $sClass=$sType");
76 $aPairs[$sClass.'|'.$sType] = array($sClass, $sType);
78 switch(trim($aMatch[4]))
81 echo "select getorcreate_amenityoperator(make_standard_name('".pg_escape_string($sLabel)."'), '$sClass', '$sType', 'near');\n";
84 echo "select getorcreate_amenityoperator(make_standard_name('".pg_escape_string($sLabel)."'), '$sClass', '$sType', 'in');\n";
87 echo "select getorcreate_amenity(make_standard_name('".pg_escape_string($sLabel)."'), '$sClass', '$sType');\n";
94 echo "create index idx_placex_classtype on placex (class, type);\n";
96 foreach($aPairs as $aPair)
98 if ($aPair[1] == 'highway') continue;
100 echo "drop table if exists place_classtype_".pg_escape_string($aPair[0])."_".pg_escape_string($aPair[1]).";\n";
101 echo "create table place_classtype_".pg_escape_string($aPair[0])."_".pg_escape_string($aPair[1])." as ";
102 echo "select place_id as place_id,st_centroid(geometry) as centroid from placex where ";
103 echo "class = '".pg_escape_string($aPair[0])."' and type = '".pg_escape_string($aPair[1])."';\n";
105 echo "CREATE INDEX idx_place_classtype_".pg_escape_string($aPair[0])."_".pg_escape_string($aPair[1])."_centroid ";
106 echo "ON place_classtype_".pg_escape_string($aPair[0])."_".pg_escape_string($aPair[1])." USING GIST (centroid);\n";
108 echo "CREATE INDEX idx_place_classtype_".pg_escape_string($aPair[0])."_".pg_escape_string($aPair[1])."_place_id ";
109 echo "ON place_classtype_".pg_escape_string($aPair[0])."_".pg_escape_string($aPair[1])." USING btree(place_id);\n";
111 echo "GRANT SELECT ON place_classtype_".pg_escape_string($aPair[0])."_".pg_escape_string($aPair[1])." TO \"www-data\";\n";
115 echo "drop index idx_placex_classtype;\n";