mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-03-07 18:44:07 +00:00
refactor ReverseGeocode
- remove unused functions and members - move coordinates from being members to being parameters of lookup()
This commit is contained in:
@@ -1698,10 +1698,11 @@
|
|||||||
{
|
{
|
||||||
// Just interpret as a reverse geocode
|
// Just interpret as a reverse geocode
|
||||||
$oReverse = new ReverseGeocode($this->oDB);
|
$oReverse = new ReverseGeocode($this->oDB);
|
||||||
$oReverse->setLatLon((float)$this->aNearPoint[0], (float)$this->aNearPoint[1]);
|
|
||||||
$oReverse->setZoom(18);
|
$oReverse->setZoom(18);
|
||||||
|
|
||||||
$aLookup = $oReverse->lookup(false);
|
$aLookup = $oReverse->lookup((float)$this->aNearPoint[0],
|
||||||
|
(float)$this->aNearPoint[1],
|
||||||
|
false);
|
||||||
|
|
||||||
if (CONST_Debug) var_dump("Reverse search", $aLookup);
|
if (CONST_Debug) var_dump("Reverse search", $aLookup);
|
||||||
|
|
||||||
|
|||||||
@@ -2,42 +2,14 @@
|
|||||||
class ReverseGeocode
|
class ReverseGeocode
|
||||||
{
|
{
|
||||||
protected $oDB;
|
protected $oDB;
|
||||||
|
|
||||||
protected $fLat;
|
|
||||||
protected $fLon;
|
|
||||||
protected $iMaxRank = 28;
|
protected $iMaxRank = 28;
|
||||||
|
|
||||||
protected $aLangPrefOrder = array();
|
|
||||||
|
|
||||||
protected $bIncludePolygonAsPoints = false;
|
|
||||||
protected $bIncludePolygonAsText = false;
|
|
||||||
protected $bIncludePolygonAsGeoJSON = false;
|
|
||||||
protected $bIncludePolygonAsKML = false;
|
|
||||||
protected $bIncludePolygonAsSVG = false;
|
|
||||||
protected $fPolygonSimplificationThreshold = 0.0;
|
|
||||||
|
|
||||||
|
|
||||||
function ReverseGeocode(&$oDB)
|
function ReverseGeocode(&$oDB)
|
||||||
{
|
{
|
||||||
$this->oDB =& $oDB;
|
$this->oDB =& $oDB;
|
||||||
}
|
}
|
||||||
|
|
||||||
function setLanguagePreference($aLangPref)
|
|
||||||
{
|
|
||||||
$this->aLangPrefOrder = $aLangPref;
|
|
||||||
}
|
|
||||||
|
|
||||||
function setLatLon($fLat, $fLon)
|
|
||||||
{
|
|
||||||
$this->fLat = (float)$fLat;
|
|
||||||
$this->fLon = (float)$fLon;
|
|
||||||
}
|
|
||||||
|
|
||||||
function setRank($iRank)
|
|
||||||
{
|
|
||||||
$this->iMaxRank = $iRank;
|
|
||||||
}
|
|
||||||
|
|
||||||
function setZoom($iZoom)
|
function setZoom($iZoom)
|
||||||
{
|
{
|
||||||
// Zoom to rank, this could probably be calculated but a lookup gives fine control
|
// Zoom to rank, this could probably be calculated but a lookup gives fine control
|
||||||
@@ -66,51 +38,11 @@
|
|||||||
$this->iMaxRank = (isset($iZoom) && isset($aZoomRank[$iZoom]))?$aZoomRank[$iZoom]:28;
|
$this->iMaxRank = (isset($iZoom) && isset($aZoomRank[$iZoom]))?$aZoomRank[$iZoom]:28;
|
||||||
}
|
}
|
||||||
|
|
||||||
function setIncludePolygonAsPoints($b = true)
|
|
||||||
{
|
|
||||||
$this->bIncludePolygonAsPoints = $b;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getIncludePolygonAsPoints()
|
|
||||||
{
|
|
||||||
return $this->bIncludePolygonAsPoints;
|
|
||||||
}
|
|
||||||
|
|
||||||
function setIncludePolygonAsText($b = true)
|
|
||||||
{
|
|
||||||
$this->bIncludePolygonAsText = $b;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getIncludePolygonAsText()
|
|
||||||
{
|
|
||||||
return $this->bIncludePolygonAsText;
|
|
||||||
}
|
|
||||||
|
|
||||||
function setIncludePolygonAsGeoJSON($b = true)
|
|
||||||
{
|
|
||||||
$this->bIncludePolygonAsGeoJSON = $b;
|
|
||||||
}
|
|
||||||
|
|
||||||
function setIncludePolygonAsKML($b = true)
|
|
||||||
{
|
|
||||||
$this->bIncludePolygonAsKML = $b;
|
|
||||||
}
|
|
||||||
|
|
||||||
function setIncludePolygonAsSVG($b = true)
|
|
||||||
{
|
|
||||||
$this->bIncludePolygonAsSVG = $b;
|
|
||||||
}
|
|
||||||
|
|
||||||
function setPolygonSimplificationThreshold($f)
|
|
||||||
{
|
|
||||||
$this->fPolygonSimplificationThreshold = $f;
|
|
||||||
}
|
|
||||||
|
|
||||||
// returns { place_id =>, type => '(osm|tiger)' }
|
// returns { place_id =>, type => '(osm|tiger)' }
|
||||||
// fails if no place was found
|
// fails if no place was found
|
||||||
function lookup($bDoInterpolation = true)
|
function lookup($fLat, $fLon, $bDoInterpolation = true)
|
||||||
{
|
{
|
||||||
$sPointSQL = 'ST_SetSRID(ST_Point('.$this->fLon.','.$this->fLat.'),4326)';
|
$sPointSQL = 'ST_SetSRID(ST_Point('.$fLon.','.$fLat.'),4326)';
|
||||||
$iMaxRank = $this->iMaxRank;
|
$iMaxRank = $this->iMaxRank;
|
||||||
$iMaxRank_orig = $this->iMaxRank;
|
$iMaxRank_orig = $this->iMaxRank;
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,10 @@
|
|||||||
if (!$aResult['search-only']) {
|
if (!$aResult['search-only']) {
|
||||||
|
|
||||||
$oReverseGeocode = new ReverseGeocode($oDB);
|
$oReverseGeocode = new ReverseGeocode($oDB);
|
||||||
$oReverseGeocode->setIncludeAddressDetails(true);
|
$oReverseGeocode->setZoom(20);
|
||||||
|
$oPlaceLookup = new PlaceLookup($oDB);
|
||||||
|
$oPlaceLookup->setIncludeAddressDetails(true);
|
||||||
|
$oPlaceLookup->setLanguagePreference(array('en'));
|
||||||
|
|
||||||
echo "Warm reverse: ";
|
echo "Warm reverse: ";
|
||||||
if ($bVerbose) echo "\n";
|
if ($bVerbose) echo "\n";
|
||||||
@@ -35,11 +38,12 @@
|
|||||||
$fLat = rand(-9000, 9000) / 100;
|
$fLat = rand(-9000, 9000) / 100;
|
||||||
$fLon = rand(-18000, 18000) / 100;
|
$fLon = rand(-18000, 18000) / 100;
|
||||||
if ($bVerbose) echo "$fLat, $fLon = ";
|
if ($bVerbose) echo "$fLat, $fLon = ";
|
||||||
$oReverseGeocode->setLanguagePreference(array('en'));
|
$aLookup = $oReverseGeocode->lookup($fLat, $fLon);
|
||||||
$oReverseGeocode->setLatLon($fLat, $fLon);
|
if ($aLookup && $aLookup['place_id'])
|
||||||
$oReverseGeocode->setZoom(20);
|
{
|
||||||
$aDetails = $oReverseGeocode->lookup();
|
$aDetails = $oPlaceLookup->lookupPlace($aLookup);
|
||||||
if ($bVerbose) echo $aDetails['langaddress']."\n";
|
if ($bVerbose) echo $aDetails['langaddress']."\n";
|
||||||
|
}
|
||||||
else echo ".";
|
else echo ".";
|
||||||
}
|
}
|
||||||
echo "\n";
|
echo "\n";
|
||||||
|
|||||||
@@ -54,12 +54,9 @@
|
|||||||
else if ($fLat !== false && $fLon !==false)
|
else if ($fLat !== false && $fLon !==false)
|
||||||
{
|
{
|
||||||
$oReverseGeocode = new ReverseGeocode($oDB);
|
$oReverseGeocode = new ReverseGeocode($oDB);
|
||||||
$oReverseGeocode->setLanguagePreference($aLangPrefOrder);
|
|
||||||
|
|
||||||
$oReverseGeocode->setLatLon($fLat, $fLon);
|
|
||||||
$oReverseGeocode->setZoom(getParamInt('zoom', 18));
|
$oReverseGeocode->setZoom(getParamInt('zoom', 18));
|
||||||
|
|
||||||
$aLookup = $oReverseGeocode->lookup();
|
$aLookup = $oReverseGeocode->lookup($fLat, $fLon);
|
||||||
if (CONST_Debug) var_dump($aLookup);
|
if (CONST_Debug) var_dump($aLookup);
|
||||||
}
|
}
|
||||||
else if ($sOutputFormat != 'html')
|
else if ($sOutputFormat != 'html')
|
||||||
|
|||||||
Reference in New Issue
Block a user