mirror of
https://github.com/osm-search/Nominatim.git
synced 2024-11-23 05:35:13 +03:00
refactor ReverseGeocode
- remove unused functions and members - move coordinates from being members to being parameters of lookup()
This commit is contained in:
parent
3f06d9d3ba
commit
1b33999f10
@ -1698,10 +1698,11 @@
|
||||
{
|
||||
// Just interpret as a reverse geocode
|
||||
$oReverse = new ReverseGeocode($this->oDB);
|
||||
$oReverse->setLatLon((float)$this->aNearPoint[0], (float)$this->aNearPoint[1]);
|
||||
$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);
|
||||
|
||||
|
@ -2,42 +2,14 @@
|
||||
class ReverseGeocode
|
||||
{
|
||||
protected $oDB;
|
||||
|
||||
protected $fLat;
|
||||
protected $fLon;
|
||||
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)
|
||||
{
|
||||
$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)
|
||||
{
|
||||
// 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;
|
||||
}
|
||||
|
||||
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)' }
|
||||
// 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_orig = $this->iMaxRank;
|
||||
|
||||
|
@ -27,7 +27,10 @@
|
||||
if (!$aResult['search-only']) {
|
||||
|
||||
$oReverseGeocode = new ReverseGeocode($oDB);
|
||||
$oReverseGeocode->setIncludeAddressDetails(true);
|
||||
$oReverseGeocode->setZoom(20);
|
||||
$oPlaceLookup = new PlaceLookup($oDB);
|
||||
$oPlaceLookup->setIncludeAddressDetails(true);
|
||||
$oPlaceLookup->setLanguagePreference(array('en'));
|
||||
|
||||
echo "Warm reverse: ";
|
||||
if ($bVerbose) echo "\n";
|
||||
@ -35,11 +38,12 @@
|
||||
$fLat = rand(-9000, 9000) / 100;
|
||||
$fLon = rand(-18000, 18000) / 100;
|
||||
if ($bVerbose) echo "$fLat, $fLon = ";
|
||||
$oReverseGeocode->setLanguagePreference(array('en'));
|
||||
$oReverseGeocode->setLatLon($fLat, $fLon);
|
||||
$oReverseGeocode->setZoom(20);
|
||||
$aDetails = $oReverseGeocode->lookup();
|
||||
if ($bVerbose) echo $aDetails['langaddress']."\n";
|
||||
$aLookup = $oReverseGeocode->lookup($fLat, $fLon);
|
||||
if ($aLookup && $aLookup['place_id'])
|
||||
{
|
||||
$aDetails = $oPlaceLookup->lookupPlace($aLookup);
|
||||
if ($bVerbose) echo $aDetails['langaddress']."\n";
|
||||
}
|
||||
else echo ".";
|
||||
}
|
||||
echo "\n";
|
||||
|
@ -54,12 +54,9 @@
|
||||
else if ($fLat !== false && $fLon !==false)
|
||||
{
|
||||
$oReverseGeocode = new ReverseGeocode($oDB);
|
||||
$oReverseGeocode->setLanguagePreference($aLangPrefOrder);
|
||||
|
||||
$oReverseGeocode->setLatLon($fLat, $fLon);
|
||||
$oReverseGeocode->setZoom(getParamInt('zoom', 18));
|
||||
|
||||
$aLookup = $oReverseGeocode->lookup();
|
||||
$aLookup = $oReverseGeocode->lookup($fLat, $fLon);
|
||||
if (CONST_Debug) var_dump($aLookup);
|
||||
}
|
||||
else if ($sOutputFormat != 'html')
|
||||
|
Loading…
Reference in New Issue
Block a user