]> git.openstreetmap.org Git - nominatim.git/blob - utils/imports.php
308d82591406fc6399e49f4ba7c71d46e75e25fa
[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     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         set_time_limit(30);
28         preg_match('#([0-9]{5})_(.*)#',basename($sImportFile), $aMatch);
29         $sCountyID = $aMatch[1];
30         echo "Processing ".$sCountyID."...\n";
31         $sUnzipCmd = "unzip -d $sTempDir $sImportFile";
32         exec($sUnzipCmd);
33         $sShapeFile = $sTempDir.'/'.basename($sImportFile, '.zip').'.shp';
34         if (!file_exists($sShapeFile)) {
35             echo "Failed unzip ($sImportFile)\n";
36         } else {
37             $sParseCmd = CONST_BasePath.'/utils/tigerAddressImport.py '.$sShapeFile;
38             exec($sParseCmd);
39             $sOsmFile = $sTempDir.'/'.basename($sImportFile, '.zip').'.osm1.osm';
40             if (!file_exists($sOsmFile)) {
41                 echo "Failed parse ($sImportFile)\n";
42             } else {
43                 copy($sOsmFile, CONST_Tiger_Data_Path.'/'.$sCountyID.'.sql');
44             }
45         }
46         // Cleanup
47         foreach (glob($sTempDir.'/*') as $sTmpFile) {
48             unlink($sTmpFile);
49         }
50     }
51 }