]> git.openstreetmap.org Git - nominatim.git/commitdiff
use PlaceLookup::loadParamArray in search and lookup
authorSarah Hoffmann <lonvia@denofr.de>
Mon, 23 Oct 2017 21:28:00 +0000 (23:28 +0200)
committerSarah Hoffmann <lonvia@denofr.de>
Mon, 23 Oct 2017 21:30:53 +0000 (23:30 +0200)
lib/Geocode.php
lib/PlaceLookup.php
website/lookup.php
website/reverse.php
website/search.php

index bf359caf77a6c94b564573ebdc4e24473b61474b..ae518d5137623c9e240dd6a10b116aeb03aef6b1 100644 (file)
@@ -12,21 +12,13 @@ class Geocode
 {
     protected $oDB;
 
+    protected $oPlaceLookup;
+
     protected $aLangPrefOrder = array();
 
     protected $bIncludeAddressDetails = false;
-    protected $bIncludeExtraTags = false;
-    protected $bIncludeNameDetails = false;
-
-    protected $bIncludePolygonAsPoints = false;
-    protected $bIncludePolygonAsText = false;
-    protected $bIncludePolygonAsGeoJSON = false;
-    protected $bIncludePolygonAsKML = false;
-    protected $bIncludePolygonAsSVG = false;
-    protected $fPolygonSimplificationThreshold = 0.0;
 
     protected $aExcludePlaceIDs = array();
-    protected $bDeDupe = true;
     protected $bReverseInPlan = false;
 
     protected $iLimit = 20;
@@ -57,6 +49,7 @@ class Geocode
     public function __construct(&$oDB)
     {
         $this->oDB =& $oDB;
+        $this->oPlaceLookup = new PlaceLookup($this->oDB);
         $this->oNormalizer = \Transliterator::createFromRules(CONST_Term_Normalization_Rules);
     }
 
@@ -87,26 +80,14 @@ class Geocode
             $aParams = array('q' => $this->sQuery);
         }
 
+        $aParams = array_merge($aParams, $this->oPlaceLookup->getMoreUrlParams());
+
         if ($this->aExcludePlaceIDs) {
             $aParams['exclude_place_ids'] = implode(',', $this->aExcludePlaceIDs);
         }
 
         if ($this->bIncludeAddressDetails) $aParams['addressdetails'] = '1';
-        if ($this->bIncludeExtraTags) $aParams['extratags'] = '1';
-        if ($this->bIncludeNameDetails) $aParams['namedetails'] = '1';
-
-        if ($this->bIncludePolygonAsPoints) $aParams['polygon'] = '1';
-        if ($this->bIncludePolygonAsText) $aParams['polygon_text'] = '1';
-        if ($this->bIncludePolygonAsGeoJSON) $aParams['polygon_geojson'] = '1';
-        if ($this->bIncludePolygonAsKML) $aParams['polygon_kml'] = '1';
-        if ($this->bIncludePolygonAsSVG) $aParams['polygon_svg'] = '1';
-
-        if ($this->fPolygonSimplificationThreshold > 0.0) {
-            $aParams['polygon_threshold'] = $this->fPolygonSimplificationThreshold;
-        }
-
         if ($this->bBoundedSearch) $aParams['bounded'] = '1';
-        if (!$this->bDeDupe) $aParams['dedupe'] = '0';
 
         if ($this->aCountryCodes) {
             $aParams['countrycodes'] = implode(',', $this->aCountryCodes);
@@ -119,36 +100,6 @@ class Geocode
         return $aParams;
     }
 
-    public function setIncludePolygonAsPoints($b = true)
-    {
-        $this->bIncludePolygonAsPoints = $b;
-    }
-
-    public function setIncludePolygonAsText($b = true)
-    {
-        $this->bIncludePolygonAsText = $b;
-    }
-
-    public function setIncludePolygonAsGeoJSON($b = true)
-    {
-        $this->bIncludePolygonAsGeoJSON = $b;
-    }
-
-    public function setIncludePolygonAsKML($b = true)
-    {
-        $this->bIncludePolygonAsKML = $b;
-    }
-
-    public function setIncludePolygonAsSVG($b = true)
-    {
-        $this->bIncludePolygonAsSVG = $b;
-    }
-
-    public function setPolygonSimplificationThreshold($f)
-    {
-        $this->fPolygonSimplificationThreshold = $f;
-    }
-
     public function setLimit($iLimit = 10)
     {
         if ($iLimit > 50) $iLimit = 50;
@@ -229,17 +180,12 @@ class Geocode
     }
 
 
-    public function loadParamArray($oParams)
+    public function loadParamArray($oParams, $sForceGeometryType = null)
     {
         $this->bIncludeAddressDetails
          = $oParams->getBool('addressdetails', $this->bIncludeAddressDetails);
-        $this->bIncludeExtraTags
-         = $oParams->getBool('extratags', $this->bIncludeExtraTags);
-        $this->bIncludeNameDetails
-         = $oParams->getBool('namedetails', $this->bIncludeNameDetails);
 
         $this->bBoundedSearch = $oParams->getBool('bounded', $this->bBoundedSearch);
-        $this->bDeDupe = $oParams->getBool('dedupe', $this->bDeDupe);
 
         $this->setLimit($oParams->getInt('limit', $this->iFinalLimit));
         $this->iOffset = $oParams->getInt('offset', $this->iOffset);
@@ -298,6 +244,10 @@ class Geocode
                 }
             }
         }
+
+        $this->oPlaceLookup->loadParamArray($oParams, $sForceGeometryType);
+        $this->oPlaceLookup->setIncludeAddressDetails(false);
+        $this->oPlaceLookup->setIncludePolygonAsPoints($oParams->getBool('polygon'));
     }
 
     public function setQueryFromParams($oParams)
@@ -906,26 +856,16 @@ class Geocode
             return array();
         }
 
-        $oPlaceLookup = new PlaceLookup($this->oDB);
-        $oPlaceLookup->setIncludePolygonAsPoints($this->bIncludePolygonAsPoints);
-        $oPlaceLookup->setIncludePolygonAsText($this->bIncludePolygonAsText);
-        $oPlaceLookup->setIncludePolygonAsGeoJSON($this->bIncludePolygonAsGeoJSON);
-        $oPlaceLookup->setIncludePolygonAsKML($this->bIncludePolygonAsKML);
-        $oPlaceLookup->setIncludePolygonAsSVG($this->bIncludePolygonAsSVG);
-        $oPlaceLookup->setPolygonSimplificationThreshold($this->fPolygonSimplificationThreshold);
-        $oPlaceLookup->setDeDupe($this->bDeDupe);
         if ($this->aAddressRankList) {
-            $oPlaceLookup->setAddressRankList($this->aAddressRankList);
+            $this->oPlaceLookup->setAddressRankList($this->aAddressRankList);
         }
-        $oPlaceLookup->setAllowedTypesSQLList($this->sAllowedTypesSQLList);
-        $oPlaceLookup->setLanguagePreference($this->aLangPrefOrder);
-        $oPlaceLookup->setIncludeExtraTags($this->bIncludeExtraTags);
-        $oPlaceLookup->setIncludeNameDetails($this->bIncludeNameDetails);
+        $this->oPlaceLookup->setAllowedTypesSQLList($this->sAllowedTypesSQLList);
+        $this->oPlaceLookup->setLanguagePreference($this->aLangPrefOrder);
         if ($oCtx->hasNearPoint()) {
-            $oPlaceLookup->setAnchorSql($oCtx->sqlNear);
+            $this->oPlaceLookup->setAnchorSql($oCtx->sqlNear);
         }
 
-        $aSearchResults = $oPlaceLookup->lookup($aResults);
+        $aSearchResults = $this->oPlaceLookup->lookup($aResults);
 
         $aClassType = getClassTypesWithImportance();
         $aRecheckWords = preg_split('/\b[\s,\\-]*/u', $sQuery);
@@ -942,7 +882,7 @@ class Geocode
             // Default
             $fDiameter = getResultDiameter($aResult);
 
-            $aOutlineResult = $oPlaceLookup->getOutlines($aResult['place_id'], $aResult['lon'], $aResult['lat'], $fDiameter/2);
+            $aOutlineResult = $this->oPlaceLookup->getOutlines($aResult['place_id'], $aResult['lon'], $aResult['lat'], $fDiameter/2);
             if ($aOutlineResult) {
                 $aResult = array_merge($aResult, $aOutlineResult);
             }
@@ -1036,7 +976,7 @@ class Geocode
                 if (isset($aResult['zoom'])) $iZoom = $aResult['zoom'];
                 $bFirst = false;
             }
-            if (!$this->bDeDupe || (!isset($aOSMIDDone[$aResult['osm_type'].$aResult['osm_id']])
+            if (!$this->oPlaceLookup->doDeDupe() || (!isset($aOSMIDDone[$aResult['osm_type'].$aResult['osm_id']])
                 && !isset($aClassTypeNameDone[$aResult['osm_type'].$aResult['class'].$aResult['type'].$aResult['name'].$aResult['admin_level']]))
             ) {
                 $aOSMIDDone[$aResult['osm_type'].$aResult['osm_id']] = true;
index c6a799e549e9dcf0515604c37689e21cce4e96cc..a48f5597e66c2218cd1d79891e382b281a20756d 100644 (file)
@@ -32,19 +32,40 @@ class PlaceLookup
         $this->oDB =& $oDB;
     }
 
-    public function loadParamArray($oParams)
+    public function doDeDupe()
+    {
+        return $this->bDeDupe;
+    }
+
+    public function setIncludePolygonAsPoints($b = true)
+    {
+        $this->bIncludePolygonAsPoints = $b;
+    }
+
+    public function loadParamArray($oParams, $sGeomType = null)
     {
         $aLangs = $oParams->getPreferredLanguages();
         $this->aLangPrefOrderSql =
             'ARRAY['.join(',', array_map('getDBQuoted', $aLangs)).']';
 
+        $this->bAddressDetails = $oParams->getBool('addressdetails', true);
         $this->bExtraTags = $oParams->getBool('extratags', false);
         $this->bNameDetails = $oParams->getBool('namedetails', false);
 
-        $this->bIncludePolygonAsText = $oParams->getBool('polygon_text');
-        $this->bIncludePolygonAsGeoJSON = $oParams->getBool('polygon_geojson');
-        $this->bIncludePolygonAsKML = $oParams->getBool('polygon_kml');
-        $this->bIncludePolygonAsSVG = $oParams->getBool('polygon_svg');
+        $this->bDeDupe = $oParams->getBool('dedupe', $this->bDeDupe);
+
+        if ($sGeomType === null || $sGeomType == 'text') {
+            $this->bIncludePolygonAsText = $oParams->getBool('polygon_text');
+        }
+        if ($sGeomType === null || $sGeomType == 'geojson') {
+            $this->bIncludePolygonAsGeoJSON = $oParams->getBool('polygon_geojson');
+        }
+        if ($sGeomType === null || $sGeomType == 'kml') {
+            $this->bIncludePolygonAsKML = $oParams->getBool('polygon_kml');
+        }
+        if ($sGeomType === null || $sGeomType == 'svg') {
+            $this->bIncludePolygonAsSVG = $oParams->getBool('polygon_svg');
+        }
         $this->fPolygonSimplificationThreshold
             = $oParams->getFloat('polygon_threshold', 0.0);
 
@@ -62,14 +83,32 @@ class PlaceLookup
         }
     }
 
-    public function setAnchorSql($sPoint)
+    public function getMoreUrlParams()
     {
-        $this->sAnchorSql = $sPoint;
+        $aParams = array();
+
+        if ($this->bAddressDetails) $aParams['addressdetails'] = '1';
+        if ($this->bExtraTags) $aParams['extratags'] = '1';
+        if ($this->bNameDetails) $aParams['namedetails'] = '1';
+
+        if ($this->bIncludePolygonAsPoints) $aParams['polygon'] = '1';
+        if ($this->bIncludePolygonAsText) $aParams['polygon_text'] = '1';
+        if ($this->bIncludePolygonAsGeoJSON) $aParams['polygon_geojson'] = '1';
+        if ($this->bIncludePolygonAsKML) $aParams['polygon_kml'] = '1';
+        if ($this->bIncludePolygonAsSVG) $aParams['polygon_svg'] = '1';
+
+        if ($this->fPolygonSimplificationThreshold > 0.0) {
+            $aParams['polygon_threshold'] = $this->fPolygonSimplificationThreshold;
+        }
+
+        if (!$this->bDeDupe) $aParams['dedupe'] = '0';
+
+        return $aParams;
     }
 
-    public function setDeDupe($bDeDupe)
+    public function setAnchorSql($sPoint)
     {
-        $this->bDeDupe = $bDeDupe;
+        $this->sAnchorSql = $sPoint;
     }
 
     public function setAddressRankList($aList)
@@ -93,46 +132,6 @@ class PlaceLookup
         $this->bAddressDetails = $bAddressDetails;
     }
 
-    public function setIncludeExtraTags($bExtraTags = false)
-    {
-        $this->bExtraTags = $bExtraTags;
-    }
-
-    public function setIncludeNameDetails($bNameDetails = false)
-    {
-        $this->bNameDetails = $bNameDetails;
-    }
-
-    public function setIncludePolygonAsPoints($b = true)
-    {
-        $this->bIncludePolygonAsPoints = $b;
-    }
-
-    public function setIncludePolygonAsText($b = true)
-    {
-        $this->bIncludePolygonAsText = $b;
-    }
-
-    public function setIncludePolygonAsGeoJSON($b = true)
-    {
-        $this->bIncludePolygonAsGeoJSON = $b;
-    }
-
-    public function setIncludePolygonAsKML($b = true)
-    {
-        $this->bIncludePolygonAsKML = $b;
-    }
-
-    public function setIncludePolygonAsSVG($b = true)
-    {
-        $this->bIncludePolygonAsSVG = $b;
-    }
-
-    public function setPolygonSimplificationThreshold($f)
-    {
-        $this->fPolygonSimplificationThreshold = $f;
-    }
-
     private function addressImportanceSql($sGeometry, $sPlaceId)
     {
         if ($this->sAnchorSql) {
index 667686d145bad20b49fc8f409f6b05b4f2849f58..578d4c37306d0ecebb545ab3518ac8e8d5017212 100755 (executable)
@@ -24,10 +24,7 @@ $aSearchResults = array();
 $aCleanedQueryParts = array();
 
 $oPlaceLookup = new Nominatim\PlaceLookup($oDB);
-$oPlaceLookup->setLanguagePreference($aLangPrefOrder);
-$oPlaceLookup->setIncludeAddressDetails($oParams->getBool('addressdetails', true));
-$oPlaceLookup->setIncludeExtraTags($oParams->getBool('extratags', false));
-$oPlaceLookup->setIncludeNameDetails($oParams->getBool('namedetails', false));
+$oPlaceLookup->loadParamArray($oParams);
 
 $aOsmIds = explode(',', $oParams->getString('osm_ids', ''));
 
index 269229d36a71ea689723ee979a1d3a83ad0f705f..85ca19816b196662b7864374c1d8b5863e264fdf 100755 (executable)
@@ -23,7 +23,6 @@ $hLog = logStart($oDB, 'reverse', $_SERVER['QUERY_STRING'], $aLangPrefOrder);
 
 $oPlaceLookup = new Nominatim\PlaceLookup($oDB);
 $oPlaceLookup->loadParamArray($oParams);
-$oPlaceLookup->setIncludeAddressDetails($oParams->getBool('addressdetails', true));
 
 $sOsmType = $oParams->getSet('osm_type', array('N', 'W', 'R'));
 $iOsmId = $oParams->getInt('osm_id', -1);
index 4952465e68ce858789fde582f45c42f5b1341431..bf9695ab52a3a73673cb691332103ac0bf4c31ab 100755 (executable)
@@ -28,36 +28,8 @@ if (CONST_Search_ReversePlanForAll
 // Format for output
 $sOutputFormat = $oParams->getSet('format', array('html', 'xml', 'json', 'jsonv2'), 'html');
 
-// Show / use polygons
-if ($sOutputFormat == 'html') {
-    $oGeocode->setIncludePolygonAsGeoJSON($oParams->getBool('polygon_geojson'));
-    $bAsGeoJSON = false;
-} else {
-    $bAsPoints = $oParams->getBool('polygon');
-    $bAsGeoJSON = $oParams->getBool('polygon_geojson');
-    $bAsKML = $oParams->getBool('polygon_kml');
-    $bAsSVG = $oParams->getBool('polygon_svg');
-    $bAsText = $oParams->getBool('polygon_text');
-    $iWantedTypes = ($bAsGeoJSON?1:0) + ($bAsKML?1:0) + ($bAsSVG?1:0) + ($bAsText?1:0) + ($bAsPoints?1:0);
-    if ($iWantedTypes > CONST_PolygonOutput_MaximumTypes) {
-        if (CONST_PolygonOutput_MaximumTypes) {
-            userError("Select only ".CONST_PolygonOutput_MaximumTypes." polgyon output option");
-        } else {
-            userError("Polygon output is disabled");
-        }
-        exit;
-    }
-    $oGeocode->setIncludePolygonAsPoints($bAsPoints);
-    $oGeocode->setIncludePolygonAsText($bAsText);
-    $oGeocode->setIncludePolygonAsGeoJSON($bAsGeoJSON);
-    $oGeocode->setIncludePolygonAsKML($bAsKML);
-    $oGeocode->setIncludePolygonAsSVG($bAsSVG);
-}
-
-// Polygon simplification threshold (optional)
-$oGeocode->setPolygonSimplificationThreshold($oParams->getFloat('polygon_threshold', 0.0));
-
-$oGeocode->loadParamArray($oParams);
+$sForcedGeometry = ($sOutputFormat == 'html') ? "geojson" : null;
+$oGeocode->loadParamArray($oParams, $sForcedGeometry);
 
 if (CONST_Search_BatchMode && isset($_GET['batch'])) {
     $aBatch = json_decode($_GET['batch'], true);