]> git.openstreetmap.org Git - nominatim.git/commitdiff
refactor ReverseGeocode
authorSarah Hoffmann <lonvia@denofr.de>
Mon, 25 Jul 2016 20:44:01 +0000 (22:44 +0200)
committerSarah Hoffmann <lonvia@denofr.de>
Tue, 26 Jul 2016 18:54:14 +0000 (20:54 +0200)
- remove unused functions and members
- move coordinates from being members to being parameters of lookup()

lib/Geocode.php
lib/ReverseGeocode.php
utils/warm.php
website/reverse.php

index 2d246d98ae16b8209596de6ed470e88a95890c99..ce77862b8004086520b55f738d0756c252cd9c59 100644 (file)
                        {
                                // 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);
 
index 0c684a4eed1b0f0016e2623785b11e9ebb8651bf..6a531ebb965fccedbf58d8ca5fbb9119d0047090 100644 (file)
@@ -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
                        $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;
 
index 72eac27adf254d0597596a66813bff6539e9a71c..b034fa8c9ce997c2e02f3ce8529056405cff1129 100755 (executable)
        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";
                        $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";
index 0e0f2ff84965962998a9804c20e05e8e74d0fbfd..07ef2d745b1d9517def19a83068068d964983c31 100755 (executable)
        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')