]> git.openstreetmap.org Git - nominatim.git/blobdiff - lib/PlaceLookup.php
placex must not return a lookup housenumber
[nominatim.git] / lib / PlaceLookup.php
index 6af559004c9f00495a44858ae9c0f395d2b7ba71..6d190c2a8047c0f5230504dd013189f69437a2fd 100644 (file)
@@ -32,75 +32,104 @@ class PlaceLookup
         $this->oDB =& $oDB;
     }
 
-    public function setAnchorSql($sPoint)
+    public function doDeDupe()
     {
-        $this->sAnchorSql = $sPoint;
+        return $this->bDeDupe;
     }
 
-    public function setDeDupe($bDeDupe)
+    public function setIncludePolygonAsPoints($b = true)
     {
-        $this->bDeDupe = $bDeDupe;
+        $this->bIncludePolygonAsPoints = $b;
     }
 
-    public function setAddressRankList($aList)
+    public function loadParamArray($oParams, $sGeomType = null)
     {
-        $this->sAddressRankListSql = '('.join(',', $aList).')';
-    }
+        $aLangs = $oParams->getPreferredLanguages();
+        $this->aLangPrefOrderSql =
+            'ARRAY['.join(',', array_map('getDBQuoted', $aLangs)).']';
 
-    public function setAllowedTypesSQLList($sSql)
-    {
-        $this->sAllowedTypesSQLList = $sSql;
-    }
+        $this->bAddressDetails = $oParams->getBool('addressdetails', true);
+        $this->bExtraTags = $oParams->getBool('extratags', false);
+        $this->bNameDetails = $oParams->getBool('namedetails', false);
 
-    public function setLanguagePreference($aLangPrefOrder)
-    {
-        $this->aLangPrefOrderSql =
-            'ARRAY['.join(',', array_map('getDBQuoted', $aLangPrefOrder)).']';
-    }
+        $this->bDeDupe = $oParams->getBool('dedupe', $this->bDeDupe);
 
-    public function setIncludeAddressDetails($bAddressDetails = true)
-    {
-        $this->bAddressDetails = $bAddressDetails;
+        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);
+
+        $iWantedTypes =
+            ($this->bIncludePolygonAsText ? 1 : 0) +
+            ($this->bIncludePolygonAsGeoJSON ? 1 : 0) +
+            ($this->bIncludePolygonAsKML ? 1 : 0) +
+            ($this->bIncludePolygonAsSVG ? 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");
+            }
+        }
     }
 
-    public function setIncludeExtraTags($bExtraTags = false)
+    public function getMoreUrlParams()
     {
-        $this->bExtraTags = $bExtraTags;
-    }
+        $aParams = array();
 
-    public function setIncludeNameDetails($bNameDetails = false)
-    {
-        $this->bNameDetails = $bNameDetails;
-    }
+        if ($this->bAddressDetails) $aParams['addressdetails'] = '1';
+        if ($this->bExtraTags) $aParams['extratags'] = '1';
+        if ($this->bNameDetails) $aParams['namedetails'] = '1';
 
-    public function setIncludePolygonAsPoints($b = true)
-    {
-        $this->bIncludePolygonAsPoints = $b;
+        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 setIncludePolygonAsText($b = true)
+    public function setAnchorSql($sPoint)
     {
-        $this->bIncludePolygonAsText = $b;
+        $this->sAnchorSql = $sPoint;
     }
 
-    public function setIncludePolygonAsGeoJSON($b = true)
+    public function setAddressRankList($aList)
     {
-        $this->bIncludePolygonAsGeoJSON = $b;
+        $this->sAddressRankListSql = '('.join(',', $aList).')';
     }
 
-    public function setIncludePolygonAsKML($b = true)
+    public function setAllowedTypesSQLList($sSql)
     {
-        $this->bIncludePolygonAsKML = $b;
+        $this->sAllowedTypesSQLList = $sSql;
     }
 
-    public function setIncludePolygonAsSVG($b = true)
+    public function setLanguagePreference($aLangPrefOrder)
     {
-        $this->bIncludePolygonAsSVG = $b;
+        $this->aLangPrefOrderSql =
+            'ARRAY['.join(',', array_map('getDBQuoted', $aLangPrefOrder)).']';
     }
 
-    public function setPolygonSimplificationThreshold($f)
+    public function setIncludeAddressDetails($bAddressDetails = true)
     {
-        $this->fPolygonSimplificationThreshold = $f;
+        $this->bAddressDetails = $bAddressDetails;
     }
 
     private function addressImportanceSql($sGeometry, $sPlaceId)
@@ -158,7 +187,7 @@ class PlaceLookup
             $sSQL .= '    rank_address,';
             $sSQL .= '    min(place_id) AS place_id,';
             $sSQL .= '    min(parent_place_id) AS parent_place_id,';
-            $sSQL .= '    housenumber,';
+            $sSQL .= '    -1 as housenumber,';
             $sSQL .= '    country_code,';
             $sSQL .= $this->langAddressSql('-1');
             $sSQL .= '    get_name_by_language(name,'.$this->aLangPrefOrderSql.') AS placename,';
@@ -173,7 +202,7 @@ class PlaceLookup
             $sSQL .= '    avg(ST_Y(centroid)) AS lat, ';
             $sSQL .= '    COALESCE(importance,0.75-(rank_search::float/40)) AS importance, ';
             $sSQL .= $this->addressImportanceSql(
-                'centroid',
+                'ST_Collect(centroid)',
                 'min(CASE WHEN placex.rank_search < 28 THEN placex.place_id ELSE placex.parent_place_id END)'
             );
             $sSQL .= "    (extratags->'place') AS extra_place ";
@@ -388,6 +417,7 @@ class PlaceLookup
             "Could not lookup place"
         );
 
+        $aClassType = getClassTypes();
         foreach ($aPlaces as &$aPlace) {
             if ($this->bAddressDetails) {
                 // to get addressdetails for tiger data, the housenumber is needed
@@ -413,7 +443,6 @@ class PlaceLookup
                 }
             }
 
-            $aClassType = getClassTypes();
             $sAddressType = '';
             $sClassType = $aPlace['class'].':'.$aPlace['type'].':'.$aPlace['admin_level'];
             if (isset($aClassType[$sClassType]) && isset($aClassType[$sClassType]['simplelabel'])) {