]> git.openstreetmap.org Git - nominatim.git/blob - utils/imports.php
one US postcode has no name. Unable to find secondary source what it would have been
[nominatim.git] / utils / imports.php
1 #!/usr/bin/php -Cq
2 <?php
3
4         require_once(dirname(dirname(__FILE__)).'/settings/settings.php');
5         require_once(CONST_BasePath.'/lib/init-cmd.php');
6         ini_set('memory_limit', '800M');
7
8         $aCMDOptions = array(
9                 "Create and setup nominatim search system",
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'),
13
14                 array('parse-tiger', '', 0, 1, 1, 1, 'realpath', 'Convert tiger edge files to nominatim sql import - datafiles from 2011 or later (source: edges directory of tiger data)'),
15         );
16         getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true);
17
18
19         if (isset($aCMDResult['parse-tiger']))
20         {
21                 if (!file_exists(CONST_Tiger_Data_Path)) mkdir(CONST_Tiger_Data_Path);
22
23                 $sTempDir = tempnam('/tmp', 'tiger');
24                 unlink($sTempDir);
25                 mkdir($sTempDir);
26
27                 foreach(glob($aCMDResult['parse-tiger'].'/tl_20??_?????_edges.zip', 0) as $sImportFile)
28                 {
29                         set_time_limit(30);
30                         preg_match('#([0-9]{5})_(.*)#',basename($sImportFile), $aMatch);
31                         $sCountyID = $aMatch[1];
32                         echo "Processing ".$sCountyID."...\n";
33                         $sUnzipCmd = "unzip -d $sTempDir $sImportFile";
34                         exec($sUnzipCmd);
35                         $sShapeFile = $sTempDir.'/'.basename($sImportFile, '.zip').'.shp';
36                         if (!file_exists($sShapeFile))
37                         {
38                                 echo "Failed unzip ($sImportFile)\n";
39                         }
40                         else
41                         {
42                                 $sParseCmd = CONST_BasePath.'/utils/tigerAddressImport.py '.$sShapeFile;
43                                 exec($sParseCmd);
44                                 $sOsmFile = $sTempDir.'/'.basename($sImportFile, '.zip').'.osm1.osm';
45                                 if (!file_exists($sOsmFile))
46                                 {
47                                         echo "Failed parse ($sImportFile)\n";
48                                 }
49                                 else
50                                 {
51                                         copy($sOsmFile, CONST_Tiger_Data_Path.'/'.$sCountyID.'.sql');
52                                 }
53                         }
54                         // Cleanup
55                         foreach(glob($sTempDir.'/*') as $sTmpFile)
56                         {
57                                 unlink($sTmpFile);
58                         }
59
60                 }
61         }