]> git.openstreetmap.org Git - nominatim.git/blob - utils/specialphrases.php
39c4dc4fe59b8767f61ec795a57cd6e7df5678a2
[nominatim.git] / utils / specialphrases.php
1 #!/usr/bin/php -Cq
2 <?php
3
4         require_once(dirname(dirname(__FILE__)).'/lib/init-cmd.php');
5         ini_set('memory_limit', '800M');
6
7         $aCMDOptions = array(
8                 "Import and export special phrases",
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'),
12
13                 array('wiki-import', '', 0, 1, 0, 0, 'bool', 'Create nominatim db'),
14         );
15         getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true);
16
17         $aLanguageIn = array(
18                         'af',
19                         'ar',
20                         'br',
21                         'ca',
22                         'cs',
23                         'de',
24                         'en',
25                         'es',
26                         'et',
27                         'eu',
28                         'fa',
29                         'fi',
30                         'fr',
31                         'gl',
32                         'hr',
33                         'hu',
34                         'ia',
35                         'is',
36                         'it',
37                         'ja',
38                         'mk',
39                         'nl',
40                         'no',
41                         'pl',
42                         'ps',
43                         'pt',
44                         'ru',
45                         'sk',
46                         'sv',
47                         'uk',
48                         'vi',
49                 );
50
51         if ($aCMDResult['wiki-import'])
52         {
53                 $aPairs = array();
54
55                 foreach($aLanguageIn as $sLanguage)
56                 {
57                         $sURL = 'http://wiki.openstreetmap.org/wiki/Special:Export/Nominatim/Special_Phrases/'.strtoupper($sLanguage);
58                         $sWikiPageXML = file_get_contents($sURL);
59                         if (preg_match_all('#\\| ([^|]+) \\|\\| ([^|]+) \\|\\| ([^|]+) \\|\\| ([^|]+) \\|\\| ([\\-YN])#', $sWikiPageXML, $aMatches, PREG_SET_ORDER))
60                         {
61                                 foreach($aMatches as $aMatch)
62                                 {
63                                         $sLabel = $aMatch[1];
64                                         $sClass = $aMatch[2];
65                                         $sType = $aMatch[3];
66                                         $aPairs[$sClass.'|'.$sType] = array($sClass, $sType);
67
68                                         switch(trim($aMatch[4]))
69                                         {
70                                         case 'near':
71                                                 echo "select getorcreate_amenityoperator(make_standard_name('".pg_escape_string($sLabel)."'), '$sClass', '$sType', 'near');\n";
72                                                 break;
73                                         case 'in':
74                                                 echo "select getorcreate_amenityoperator(make_standard_name('".pg_escape_string($sLabel)."'), '$sClass', '$sType', 'in');\n";
75                                                 break;
76                                         default:
77                                                 echo "select getorcreate_amenity(make_standard_name('".pg_escape_string($sLabel)."'), '$sClass', '$sType');\n";
78                                                 break;
79                                         }
80                                 }
81                         }
82                 }
83
84                 foreach($aPairs as $aPair)
85                 {
86                         if ($aPair[1] == 'highway') continue;
87
88                         echo "create table place_classtype_".pg_escape_string($aPair[0])."_".pg_escape_string($aPair[1])." as ";
89                         echo "select place_id as place_id,st_centroid(geometry) as centroid from placex where ";
90                         echo "class = '".pg_escape_string($aPair[0])."' and type = '".pg_escape_string($aPair[1])."' limit 0;\n";
91
92                         echo "CREATE INDEX idx_place_classtype_".pg_escape_string($aPair[0])."_".pg_escape_string($aPair[1])."_centroid ";
93                         echo "ON place_classtype_".pg_escape_string($aPair[0])."_".pg_escape_string($aPair[1])." USING GIST (centroid);\n";
94
95                         echo "CREATE INDEX idx_place_classtype_".pg_escape_string($aPair[0])."_".pg_escape_string($aPair[1])."_place_id ";
96                         echo "ON place_classtype_".pg_escape_string($aPair[0])."_".pg_escape_string($aPair[1])." USING btree(place_id);\n";
97
98                         echo "truncate place_classtype_".pg_escape_string($aPair[0])."_".pg_escape_string($aPair[1]).";\n";
99                         echo "insert into place_classtype_".pg_escape_string($aPair[0])."_".pg_escape_string($aPair[1])." ";
100                         echo "select place_id as place_id,st_centroid(geometry) as centroid from placex where ";
101                         echo "class = '".pg_escape_string($aPair[0])."' and type = '".pg_escape_string($aPair[1])."';\n";
102
103                 }
104         }