4 require_once(dirname(dirname(__FILE__)).'/lib/init-cmd.php');
5 ini_set('memory_limit', '800M');
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'),
13 array('parse-tiger', '', 0, 1, 1, 1, 'realpath', 'Convert tiger edge files to nominatim sql import'),
14 array('parse-tiger-2011', '', 0, 1, 1, 1, 'realpath', 'Convert tiger edge files to nominatim sql import - datafiles from 2011 or later (source: edges directory of tiger data)'),
16 getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true);
18 $bDidSomething = false;
20 if (isset($aCMDResult['parse-tiger']))
22 $bDidSomething = true;
23 foreach(glob($aCMDResult['parse-tiger'].'/??_*', GLOB_ONLYDIR) as $sStateFolder)
25 preg_match('#([0-9]{2})_(.*)#',basename($sStateFolder), $aMatch);
28 foreach(glob($sStateFolder.'/?????_*', GLOB_ONLYDIR) as $sCountyFolder)
31 preg_match('#([0-9]{5})_(.*)#',basename($sCountyFolder), $aMatch);
32 $sCountyID = $aMatch[1];
33 $sCountyName = str_replace('_', ' ', $aMatch[2]);
34 $sImportFile = $sCountyFolder.'/tl_2009_'.$sCountyID.'_edges.zip';
35 $sCountyName = str_replace("'", "''", $sCountyName);
36 $sCountyName = str_replace(" County", "", $sCountyName);
37 echo "'$sCountyID' : '$sCountyName' ,\n";
42 if (!file_exists(CONST_BasePath.'/data/tiger2009')) mkdir(CONST_BasePath.'/data/tiger2009');
44 $sTempDir = tempnam('/tmp', 'tiger');
48 foreach(glob($aCMDResult['parse-tiger'].'/??_*', GLOB_ONLYDIR) as $sStateFolder)
50 foreach(glob($sStateFolder.'/?????_*', GLOB_ONLYDIR) as $sCountyFolder)
53 preg_match('#([0-9]{5})_(.*)#',basename($sCountyFolder), $aMatch);
54 $sCountyID = $aMatch[1];
55 $sCountyName = str_replace('_', ' ', $aMatch[2]);
56 $sImportFile = $sCountyFolder.'/tl_2009_'.$sCountyID.'_edges.zip';
57 echo "$sCountyID, $sCountyName\n";
58 if (!file_exists($sImportFile))
60 echo "Missing: $sImportFile\n";
62 $sUnzipCmd = "unzip -d $sTempDir $sImportFile";
64 if (!file_exists($sTempDir.'/tl_2009_'.$sCountyID.'_edges.shp'))
66 echo "Failed unzip ($sCountyID)\n";
70 $sParseCmd = CONST_BasePath.'/utils/tigerAddressImport.py '.$sTempDir.'/tl_2009_'.$sCountyID.'_edges.shp';
72 if (!file_exists($sTempDir.'/tl_2009_'.$sCountyID.'_edges.osm1.osm'))
74 echo "Failed parse ($sCountyID)\n";
78 copy($sTempDir.'/tl_2009_'.$sCountyID.'_edges.osm1.osm', CONST_BasePath.'/data/tiger2009/'.$sCountyID.'.sql');
82 foreach(glob($sTempDir.'/*') as $sTmpFile)
91 if (isset($aCMDResult['parse-tiger-2011']))
93 if (!file_exists(CONST_BasePath.'/data/tiger2011')) mkdir(CONST_BasePath.'/data/tiger2011');
95 $sTempDir = tempnam('/tmp', 'tiger');
100 $bDidSomething = true;
101 foreach(glob($aCMDResult['parse-tiger-2011'].'/tl_20??_?????_edges.zip', 0) as $sImportFile)
104 preg_match('#([0-9]{5})_(.*)#',basename($sImportFile), $aMatch);
105 $sCountyID = $aMatch[1];
106 echo "Processing ".$sCountyID."...\n";
107 $sUnzipCmd = "unzip -d $sTempDir $sImportFile";
109 $sShapeFile = $sTempDir.'/'.basename($sImportFile, '.zip').'.shp';
110 if (!file_exists($sShapeFile))
112 echo "Failed unzip ($sImportFile)\n";
116 $sParseCmd = CONST_BasePath.'/utils/tigerAddressImport.py '.$sShapeFile;
118 $sOsmFile = $sTempDir.'/'.basename($sImportFile, '.zip').'.osm1.osm';
119 if (!file_exists($sOsmFile))
121 echo "Failed parse ($sImportFile)\n";
125 copy($sOsmFile, CONST_BasePath.'/data/tiger2011/'.$sCountyID.'.sql');
129 foreach(glob($sTempDir.'/*') as $sTmpFile)