]> git.openstreetmap.org Git - nominatim.git/blob - utils/imports.php
70a24963fa57f2f5338174dfe890965f12fb0057
[nominatim.git] / utils / imports.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                 "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'),
12
13                 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)'),
14         );
15         getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true);
16
17
18         if (isset($aCMDResult['parse-tiger']))
19         {
20                 if (!file_exists(CONST_Tiger_Data_Path)) mkdir(CONST_Tiger_Data_Path);
21
22                 $sTempDir = tempnam('/tmp', 'tiger');
23                 unlink($sTempDir);
24                 mkdir($sTempDir);
25
26                 foreach(glob($aCMDResult['parse-tiger'].'/tl_20??_?????_edges.zip', 0) as $sImportFile)
27                 {
28                         set_time_limit(30);
29                         preg_match('#([0-9]{5})_(.*)#',basename($sImportFile), $aMatch);
30                         $sCountyID = $aMatch[1];
31                         echo "Processing ".$sCountyID."...\n";
32                         $sUnzipCmd = "unzip -d $sTempDir $sImportFile";
33                         exec($sUnzipCmd);
34                         $sShapeFile = $sTempDir.'/'.basename($sImportFile, '.zip').'.shp';
35                         if (!file_exists($sShapeFile))
36                         {
37                                 echo "Failed unzip ($sImportFile)\n";
38                         }
39                         else
40                         {
41                                 $sParseCmd = CONST_BasePath.'/utils/tigerAddressImport.py '.$sShapeFile;
42                                 exec($sParseCmd);
43                                 $sOsmFile = $sTempDir.'/'.basename($sImportFile, '.zip').'.osm1.osm';
44                                 if (!file_exists($sOsmFile))
45                                 {
46                                         echo "Failed parse ($sImportFile)\n";
47                                 }
48                                 else
49                                 {
50                                         copy($sOsmFile, CONST_Tiger_Data_Path.'/'.$sCountyID.'.sql');
51                                 }
52                         }
53                         // Cleanup
54                         foreach(glob($sTempDir.'/*') as $sTmpFile)
55                         {
56                                 unlink($sTmpFile);
57                         }
58
59                 }
60         }