From: Sarah Hoffmann Date: Thu, 30 Apr 2015 19:26:11 +0000 (+0200) Subject: Merge branch 'feature/polygon-simplification' of https://github.com/a1exsh/Nominatim X-Git-Tag: v.2.5.0~62 X-Git-Url: https://git.openstreetmap.org./nominatim.git/commitdiff_plain/a7e1b3b1eeec1cebc71ee7ae0282dfe3bb31456c?hp=27753fb8dbce6bb595f95bad637078ab2106d794 Merge branch 'feature/polygon-simplification' of https://github.com/a1exsh/Nominatim --- diff --git a/lib/Geocode.php b/lib/Geocode.php index 5f4a0174..212eebb9 100644 --- a/lib/Geocode.php +++ b/lib/Geocode.php @@ -12,6 +12,7 @@ protected $bIncludePolygonAsGeoJSON = false; protected $bIncludePolygonAsKML = false; protected $bIncludePolygonAsSVG = false; + protected $fPolygonSimplificationThreshold = 0.0; protected $aExcludePlaceIDs = array(); protected $bDeDupe = true; @@ -102,6 +103,11 @@ $this->bIncludePolygonAsSVG = $b; } + function setPolygonSimplificationThreshold($f) + { + $this->fPolygonSimplificationThreshold = $f; + } + function setDeDupe($bDeDupe = true) { $this->bDeDupe = (bool)$bDeDupe; @@ -1599,7 +1605,16 @@ 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)) { diff --git a/website/search.php b/website/search.php index a9e20d4e..bf27ef9a 100755 --- a/website/search.php +++ b/website/search.php @@ -68,6 +68,11 @@ $oGeocode->setIncludePolygonAsSVG($bAsSVG); } + // Polygon simplification threshold (optional) + $fThreshold = 0.0; + if (isset($_GET['polygon_threshold'])) $fThreshold = (float)$_GET['polygon_threshold']; + $oGeocode->setPolygonSimplificationThreshold($fThreshold); + $oGeocode->loadParamArray($_GET); if (CONST_Search_BatchMode && isset($_GET['batch']))