]> git.openstreetmap.org Git - nominatim.git/commitdiff
Merge branch 'feature/polygon-simplification' of https://github.com/a1exsh/Nominatim
authorSarah Hoffmann <lonvia@denofr.de>
Thu, 30 Apr 2015 19:26:11 +0000 (21:26 +0200)
committerSarah Hoffmann <lonvia@denofr.de>
Thu, 30 Apr 2015 19:26:11 +0000 (21:26 +0200)
1  2 
lib/Geocode.php

diff --combined lib/Geocode.php
index 5f4a01740a00490912c93626424f7b34b7ace640,6781ceecb9993bccdf89b746795ab9a7d8c68763..212eebb97cc2a3b04f8a5369755fe6cc79163cc9
@@@ -12,6 -12,7 +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))
                                        {