mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-02-16 15:47:58 +00:00
Use GB postcode table as definitive source. resort by pressence of search word in output address and other misc very minor changes not commited from MQ servers
This commit is contained in:
committed by
Brian Quinion
parent
ad125a9913
commit
b99a043c78
50
lib/lib.php
50
lib/lib.php
@@ -40,9 +40,9 @@
|
||||
|
||||
function byImportance($a, $b)
|
||||
{
|
||||
/*
|
||||
if ($a['importance'] != $b['importance'])
|
||||
return ($a['importance'] > $b['importance']?-1:1);
|
||||
/*
|
||||
if ($a['aPointPolygon']['numfeatures'] != $b['aPointPolygon']['numfeatures'])
|
||||
return ($a['aPointPolygon']['numfeatures'] > $b['aPointPolygon']['numfeatures']?-1:1);
|
||||
if ($a['aPointPolygon']['area'] != $b['aPointPolygon']['area'])
|
||||
@@ -173,60 +173,12 @@
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
if (sizeof($aNearPostcodes))
|
||||
{
|
||||
return array(array('lat' => $aNearPostcodes[0]['lat'], 'lon' => $aNearPostcodes[0]['lon'], 'radius' => 0.005));
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
/* partial search disabled because it sequentially scans placex
|
||||
|
||||
$sSQL = 'select substring(upper(postcode) from \'^[A-Z][A-Z]?[0-9][0-9A-Z]? [0-9]([A-Z][A-Z])$\'),ST_X(ST_Centroid(geometry)) as lon,ST_Y(ST_Centroid(geometry)) as lat from placex where country_code::text = \'gb\'::text AND substring(postcode from \'^([A-Z][A-Z]?[0-9][0-9A-Z]? [0-9])[A-Z][A-Z]$\') = \''.$sPostcodeSector.'\' and class=\'place\' and type=\'postcode\' ';
|
||||
$sSQL .= ' union ';
|
||||
$sSQL .= 'select substring(upper(postcode) from \'^[A-Z][A-Z]?[0-9][0-9A-Z]? [0-9]([A-Z][A-Z])$\'),ST_X(ST_Centroid(geometry)) as lon,ST_Y(ST_Centroid(geometry)) as lat from gb_postcode where substring(postcode from \'^([A-Z][A-Z]?[0-9][0-9A-Z]? [0-9])[A-Z][A-Z]$\') = \''.$sPostcodeSector.'\'';
|
||||
$aNearPostcodes = $oDB->getAll($sSQL);
|
||||
if (PEAR::IsError($aNearPostcodes))
|
||||
{
|
||||
var_dump($sSQL, $aNearPostcodes);
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!sizeof($aNearPostcodes))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$fTotalLat = 0;
|
||||
$fTotalLon = 0;
|
||||
$fTotalFac = 0;
|
||||
foreach($aNearPostcodes as $aPostcode)
|
||||
{
|
||||
$iDiff = gbPostcodeAlphaDifference($sPostcodeEnd, $aPostcode['substring'])*2 + 1;
|
||||
if ($iDiff == 0)
|
||||
$fFac = 1;
|
||||
else
|
||||
$fFac = 1/($iDiff*$iDiff);
|
||||
|
||||
$fTotalFac += $fFac;
|
||||
$fTotalLat += $aPostcode['lat'] * $fFac;
|
||||
$fTotalLon += $aPostcode['lon'] * $fFac;
|
||||
}
|
||||
if ($fTotalFac)
|
||||
{
|
||||
$fLat = $fTotalLat / $fTotalFac;
|
||||
$fLon = $fTotalLon / $fTotalFac;
|
||||
$fRadius = min(0.1 / $fTotalFac, 0.02);
|
||||
return array(array('lat' => $fLat, 'lon' => $fLon, 'radius' => $fRadius));
|
||||
}
|
||||
return false;
|
||||
*/
|
||||
/*
|
||||
$fTotalFac is a suprisingly good indicator of accuracy
|
||||
$iZoom = 18 + round(log($fTotalFac,32));
|
||||
$iZoom = max(13,min(18,$iZoom));
|
||||
*/
|
||||
}
|
||||
|
||||
function usPostcodeCalculate($sPostcode, &$oDB)
|
||||
|
||||
@@ -26,7 +26,8 @@
|
||||
$oDB->query($sSQL);
|
||||
}
|
||||
|
||||
if (CONST_Log_File && CONST_Log_File_ReverseLog != '') {
|
||||
if (CONST_Log_File && CONST_Log_File_ReverseLog != '')
|
||||
{
|
||||
if ($sType == 'reverse')
|
||||
{
|
||||
$aStartTime = explode('.',$hLog[0]);
|
||||
@@ -68,7 +69,8 @@
|
||||
$oDB->query($sSQL);
|
||||
}
|
||||
|
||||
if (CONST_Log_File && CONST_Log_File_SearchLog != '') {
|
||||
if (CONST_Log_File && CONST_Log_File_SearchLog != '')
|
||||
{
|
||||
$aStartTime = explode('.',$hLog[0]);
|
||||
file_put_contents(CONST_Log_File_SearchLog,
|
||||
$aStartTime[0].','.$aStartTime[1].','.
|
||||
|
||||
@@ -74,11 +74,12 @@ body {
|
||||
var proj_map = map.getProjectionObject();
|
||||
var latlon;
|
||||
<?php
|
||||
if (isset($aPolyPoints)) {
|
||||
foreach($aPolyPoints as $aPolyPoint)
|
||||
if (isset($aPolyPoints))
|
||||
{
|
||||
echo " pointList.push(new OpenLayers.Geometry.Point(".$aPolyPoint[1].",".$aPolyPoint[2]."));\n";
|
||||
}
|
||||
foreach($aPolyPoints as $aPolyPoint)
|
||||
{
|
||||
echo " pointList.push(new OpenLayers.Geometry.Point(".$aPolyPoint[1].",".$aPolyPoint[2]."));\n";
|
||||
}
|
||||
}
|
||||
?>
|
||||
var linearRing = new OpenLayers.Geometry.LinearRing(pointList).transform(proj_EPSG4326, proj_map);;
|
||||
|
||||
Reference in New Issue
Block a user