]> git.openstreetmap.org Git - nominatim.git/blobdiff - lib/Geocode.php
Merge remote-tracking branch 'upstream/master'
[nominatim.git] / lib / Geocode.php
index ed618aec874cc05243dbd9bf98d1c86d19189a5d..5464c386b21631aee1a67f8fcd45990ea2be41a4 100644 (file)
@@ -12,6 +12,7 @@
                protected $bIncludePolygonAsGeoJSON = false;
                protected $bIncludePolygonAsKML = false;
                protected $bIncludePolygonAsSVG = false;
+               protected $fPolygonSimplificationThreshold = 0.0;
 
                protected $aExcludePlaceIDs = array();
                protected $bDeDupe = true;
                        $this->bIncludePolygonAsSVG = $b;
                }
 
+               function setPolygonSimplificationThreshold($f)
+               {
+                       $this->fPolygonSimplificationThreshold = $f;
+               }
+
                function setDeDupe($bDeDupe = true)
                {
                        $this->bDeDupe = (bool)$bDeDupe;
                                                                                        else $aSearch['sOperator'] = 'near'; // near = in for the moment
                                                                                        if (strlen($aSearchTerm['operator']) == 0) $aSearch['iSearchRank'] += 1;
 
-                                                                                       // Do we have a shortcut id?
-                                                                                       if ($aSearch['sOperator'] == 'name')
-                                                                                       {
-                                                                                               $sSQL = "select get_tagpair('".$aSearch['sClass']."', '".$aSearch['sType']."')";
-                                                                                               if ($iAmenityID = $this->oDB->getOne($sSQL))
-                                                                                               {
-                                                                                                       $aValidTokens[$aSearch['sClass'].':'.$aSearch['sType']] = array('word_id' => $iAmenityID);
-                                                                                                       $aSearch['aName'][$iAmenityID] = $iAmenityID;
-                                                                                                       $aSearch['sClass'] = '';
-                                                                                                       $aSearch['sType'] = '';
-                                                                                               }
-                                                                                       }
                                                                                        if ($aSearch['iSearchRank'] < $this->iMaxRank) $aNewWordsetSearches[] = $aSearch;
                                                                                }
                                                                        }
                        if (!$this->sQuery && !$this->aStructuredQuery) return false;
 
                        $sLanguagePrefArraySQL = "ARRAY[".join(',',array_map("getDBQuoted",$this->aLangPrefOrder))."]";
-
                        $sCountryCodesSQL = false;
                        if ($this->aCountryCodes && sizeof($this->aCountryCodes))
                        {
                                        if ($this->bIncludePolygonAsKML) $sSQL .= ",ST_AsKML(geometry) as askml";
                                        if ($this->bIncludePolygonAsSVG) $sSQL .= ",ST_AsSVG(geometry) as assvg";
                                        if ($this->bIncludePolygonAsText || $this->bIncludePolygonAsPoints) $sSQL .= ",ST_AsText(geometry) as astext";
-                                       $sSQL .= " from placex where place_id = ".$aResult['place_id'];
+                                       $sFrom = " from placex where place_id = ".$aResult['place_id'];
+                                       if ($this->fPolygonSimplificationThreshold > 0)
+                                       {
+                                               $sSQL .= " from (select place_id,centroid,ST_SimplifyPreserveTopology(geometry,".$this->fPolygonSimplificationThreshold.") as geometry".$sFrom.") as plx";
+                                       }
+                                       else
+                                       {
+                                               $sSQL .= $sFrom;
+                                       }
+
                                        $aPointPolygon = $this->oDB->getRow($sSQL);
                                        if (PEAR::IsError($aPointPolygon))
                                        {