mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-03-11 05:14:07 +00:00
tiger import code
This commit is contained in:
@@ -18,6 +18,27 @@
|
|||||||
|
|
||||||
if (isset($aCMDResult['parse-tiger']))
|
if (isset($aCMDResult['parse-tiger']))
|
||||||
{
|
{
|
||||||
|
foreach(glob($aCMDResult['parse-tiger'].'/??_*', GLOB_ONLYDIR) as $sStateFolder)
|
||||||
|
{
|
||||||
|
preg_match('#([0-9]{2})_(.*)#',basename($sStateFolder), $aMatch);
|
||||||
|
var_dump($aMatch);
|
||||||
|
exit;
|
||||||
|
foreach(glob($sStateFolder.'/?????_*', GLOB_ONLYDIR) as $sCountyFolder)
|
||||||
|
{
|
||||||
|
set_time_limit(30);
|
||||||
|
preg_match('#([0-9]{5})_(.*)#',basename($sCountyFolder), $aMatch);
|
||||||
|
$sCountyID = $aMatch[1];
|
||||||
|
$sCountyName = str_replace('_', ' ', $aMatch[2]);
|
||||||
|
$sImportFile = $sCountyFolder.'/tl_2009_'.$sCountyID.'_edges.zip';
|
||||||
|
$sCountyName = str_replace("'", "''", $sCountyName);
|
||||||
|
$sCountyName = str_replace(" County", "", $sCountyName);
|
||||||
|
echo "'$sCountyID' : '$sCountyName' ,\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exit;
|
||||||
|
|
||||||
|
if (!file_exists(CONST_BasePath.'/data/tiger2009')) mkdir(CONST_BasePath.'/data/tiger2009');
|
||||||
|
|
||||||
$sTempDir = tempnam('/tmp', 'tiger');
|
$sTempDir = tempnam('/tmp', 'tiger');
|
||||||
unlink($sTempDir);
|
unlink($sTempDir);
|
||||||
mkdir($sTempDir);
|
mkdir($sTempDir);
|
||||||
@@ -26,18 +47,40 @@
|
|||||||
{
|
{
|
||||||
foreach(glob($sStateFolder.'/?????_*', GLOB_ONLYDIR) as $sCountyFolder)
|
foreach(glob($sStateFolder.'/?????_*', GLOB_ONLYDIR) as $sCountyFolder)
|
||||||
{
|
{
|
||||||
|
set_time_limit(30);
|
||||||
preg_match('#([0-9]{5})_(.*)#',basename($sCountyFolder), $aMatch);
|
preg_match('#([0-9]{5})_(.*)#',basename($sCountyFolder), $aMatch);
|
||||||
$sCountyID = $aMatch[1];
|
$sCountyID = $aMatch[1];
|
||||||
$sCountyName = str_replace('_', ' ', $aMatch[2]);
|
$sCountyName = str_replace('_', ' ', $aMatch[2]);
|
||||||
$sImportFile = $sCountyFolder.'/tl_2009_'.$sCountyID.'_edges.zip';
|
$sImportFile = $sCountyFolder.'/tl_2009_'.$sCountyID.'_edges.zip';
|
||||||
|
echo "$sCountyID, $sCountyName\n";
|
||||||
if (!file_exists($sImportFile))
|
if (!file_exists($sImportFile))
|
||||||
{
|
{
|
||||||
echo "Missing: $sImportFile\n";
|
echo "Missing: $sImportFile\n";
|
||||||
}
|
}
|
||||||
$sUnzipCmd = "unzip -d $sTempDir $sImportFile";
|
$sUnzipCmd = "unzip -d $sTempDir $sImportFile";
|
||||||
var_dump($sUnzipCmd);
|
exec($sUnzipCmd);
|
||||||
exit;
|
if (!file_exists($sTempDir.'/tl_2009_'.$sCountyID.'_edges.shp'))
|
||||||
// exec($sUnzipCmd);
|
{
|
||||||
|
echo "Failed unzip ($sCountyID)\n";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$sParseCmd = CONST_BasePath.'/utils/tigerAddressImport.py '.$sTempDir.'/tl_2009_'.$sCountyID.'_edges.shp';
|
||||||
|
exec($sParseCmd);
|
||||||
|
if (!file_exists($sTempDir.'/tl_2009_'.$sCountyID.'_edges.osm1.osm'))
|
||||||
|
{
|
||||||
|
echo "Failed parse ($sCountyID)\n";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
copy($sTempDir.'/tl_2009_'.$sCountyID.'_edges.osm1.osm', CONST_BasePath.'/data/tiger2009/'.$sCountyID.'.sql');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Cleanup
|
||||||
|
foreach(glob($sTempDir.'/*') as $sTmpFile)
|
||||||
|
{
|
||||||
|
unlink($sTmpFile);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -197,12 +197,14 @@ county_fips = {
|
|||||||
'02013' : 'Aleutians East, AK' ,
|
'02013' : 'Aleutians East, AK' ,
|
||||||
'02016' : 'Aleutians West, AK' ,
|
'02016' : 'Aleutians West, AK' ,
|
||||||
'02020' : 'Anchorage, AK' ,
|
'02020' : 'Anchorage, AK' ,
|
||||||
|
'02230' : 'Skagway Municipality' ,
|
||||||
'02050' : 'Bethel, AK' ,
|
'02050' : 'Bethel, AK' ,
|
||||||
'02060' : 'Bristol Bay, AK' ,
|
'02060' : 'Bristol Bay, AK' ,
|
||||||
'02068' : 'Denali, AK' ,
|
'02068' : 'Denali, AK' ,
|
||||||
'02070' : 'Dillingham, AK' ,
|
'02070' : 'Dillingham, AK' ,
|
||||||
'02090' : 'Fairbanks North Star, AK' ,
|
'02090' : 'Fairbanks North Star, AK' ,
|
||||||
'02100' : 'Haines, AK' ,
|
'02100' : 'Haines, AK' ,
|
||||||
|
'02105' : 'Hoonah-Angoon Census Area' ,
|
||||||
'02110' : 'Juneau, AK' ,
|
'02110' : 'Juneau, AK' ,
|
||||||
'02122' : 'Kenai Peninsula, AK' ,
|
'02122' : 'Kenai Peninsula, AK' ,
|
||||||
'02130' : 'Ketchikan Gateway, AK' ,
|
'02130' : 'Ketchikan Gateway, AK' ,
|
||||||
@@ -212,12 +214,15 @@ county_fips = {
|
|||||||
'02180' : 'Nome, AK' ,
|
'02180' : 'Nome, AK' ,
|
||||||
'02185' : 'North Slope, AK' ,
|
'02185' : 'North Slope, AK' ,
|
||||||
'02188' : 'Northwest Arctic, AK' ,
|
'02188' : 'Northwest Arctic, AK' ,
|
||||||
|
'02195' : 'Petersburg Census Area' ,
|
||||||
|
'02198' : 'Prince of Wales-Hyder Census Area' ,
|
||||||
'02201' : 'Prince of Wales-Outer Ketchikan, AK' ,
|
'02201' : 'Prince of Wales-Outer Ketchikan, AK' ,
|
||||||
'02220' : 'Sitka, AK' ,
|
'02220' : 'Sitka, AK' ,
|
||||||
'02232' : 'Skagway-Hoonah-Angoon, AK' ,
|
'02232' : 'Skagway-Hoonah-Angoon, AK' ,
|
||||||
'02240' : 'Southeast Fairbanks, AK' ,
|
'02240' : 'Southeast Fairbanks, AK' ,
|
||||||
'02261' : 'Valdez-Cordova, AK' ,
|
'02261' : 'Valdez-Cordova, AK' ,
|
||||||
'02270' : 'Wade Hampton, AK' ,
|
'02270' : 'Wade Hampton, AK' ,
|
||||||
|
'02275' : 'Wrangell City and Borough' ,
|
||||||
'02280' : 'Wrangell-Petersburg, AK' ,
|
'02280' : 'Wrangell-Petersburg, AK' ,
|
||||||
'02282' : 'Yakutat, AK' ,
|
'02282' : 'Yakutat, AK' ,
|
||||||
'02290' : 'Yukon-Koyukuk, AK' ,
|
'02290' : 'Yukon-Koyukuk, AK' ,
|
||||||
@@ -3690,6 +3695,10 @@ def addressways(waylist, nodelist, first_id):
|
|||||||
rtags = []
|
rtags = []
|
||||||
ltags = []
|
ltags = []
|
||||||
tags = []
|
tags = []
|
||||||
|
zipr = ''
|
||||||
|
zipl = ''
|
||||||
|
name = ''
|
||||||
|
county = ''
|
||||||
if "tiger:zip_right" in waykey:
|
if "tiger:zip_right" in waykey:
|
||||||
zipr = waykey["tiger:zip_right"]
|
zipr = waykey["tiger:zip_right"]
|
||||||
rtags.append( "<tag k=\"addr:postcode\" v=\"%s\" />" % zipr )
|
rtags.append( "<tag k=\"addr:postcode\" v=\"%s\" />" % zipr )
|
||||||
@@ -3719,11 +3728,11 @@ def addressways(waylist, nodelist, first_id):
|
|||||||
if right:
|
if right:
|
||||||
rlinestring = [];
|
rlinestring = [];
|
||||||
for i, point in rsegment:
|
for i, point in rsegment:
|
||||||
rlinestring.append( "%f %f" % (point[0], point[1]) )
|
rlinestring.append( "%f %f" % (point[1], point[0]) )
|
||||||
if left:
|
if left:
|
||||||
llinestring = [];
|
llinestring = [];
|
||||||
for i, point in lsegment:
|
for i, point in lsegment:
|
||||||
llinestring.append( "%f %f" % (point[0], point[1]) )
|
llinestring.append( "%f %f" % (point[1], point[0]) )
|
||||||
if right:
|
if right:
|
||||||
rsegments.append( rsegment )
|
rsegments.append( rsegment )
|
||||||
if left:
|
if left:
|
||||||
@@ -3786,7 +3795,7 @@ def addressways(waylist, nodelist, first_id):
|
|||||||
# ret.append( "</way>" )
|
# ret.append( "</way>" )
|
||||||
|
|
||||||
ret.append( "select tigger_create_interpolation(ST_GeomFromText('LINESTRING(%s)',4326), '%s', '%s', '%s', '%s', '%s', '%s');" %
|
ret.append( "select tigger_create_interpolation(ST_GeomFromText('LINESTRING(%s)',4326), '%s', '%s', '%s', '%s', '%s', '%s');" %
|
||||||
( ",".join(rlinestring), rfromadd, rtoadd, interpolationtype, name, county, zipr ) )
|
( ",".join(rlinestring), rfromadd.replace("'", "''"), rtoadd.replace("'", "''"), interpolationtype.replace("'", "''"), name.replace("'", "''"), county.replace("'", "''"), zipr.replace("'", "''") ) )
|
||||||
|
|
||||||
if left:
|
if left:
|
||||||
id += 1
|
id += 1
|
||||||
@@ -3811,7 +3820,7 @@ def addressways(waylist, nodelist, first_id):
|
|||||||
else:
|
else:
|
||||||
interpolationtype = "all";
|
interpolationtype = "all";
|
||||||
ret.append( "select tigger_create_interpolation(ST_GeomFromText('LINESTRING(%s)',4326), '%s', '%s', '%s', '%s', '%s', '%s');" %
|
ret.append( "select tigger_create_interpolation(ST_GeomFromText('LINESTRING(%s)',4326), '%s', '%s', '%s', '%s', '%s', '%s');" %
|
||||||
( ",".join(llinestring), lfromadd, ltoadd, interpolationtype, name, county, zipl ) )
|
( ",".join(llinestring), lfromadd.replace("'", "''"), ltoadd.replace("'", "''"), interpolationtype.replace("'", "''"), name.replace("'", "''"), county.replace("'", "''"), zipl.replace("'", "''") ) )
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user