From: Sarah Hoffmann Date: Mon, 15 Mar 2021 09:50:04 +0000 (+0100) Subject: reverse: do not prefer interpolations over closer housenumbers X-Git-Tag: v3.7.0~16^2 X-Git-Url: https://git.openstreetmap.org./nominatim.git/commitdiff_plain/4d7c5ec089c6789f24dd7ff60183549dba3f2c0a?hp=81a6b746b83cd3e1d516c321e7098a8dee1cac09 reverse: do not prefer interpolations over closer housenumbers Always look up the closest housenumber before looking up interpolations. This ensures that closer housenumbers are preferred over interpolations. Fixes #2214. --- diff --git a/lib-php/ReverseGeocode.php b/lib-php/ReverseGeocode.php index b420e5dd..cf396b7a 100644 --- a/lib-php/ReverseGeocode.php +++ b/lib-php/ReverseGeocode.php @@ -280,29 +280,6 @@ class ReverseGeocode $iPlaceID = $aPlace['place_id']; $oResult = new Result($iPlaceID); $iRankAddress = $aPlace['rank_address']; - $iParentPlaceID = $aPlace['parent_place_id']; - } - - if ($bDoInterpolation && $iMaxRank >= 30) { - $fDistance = $fSearchDiam; - if ($aPlace) { - // We can't reliably go from the closest street to an - // interpolation line because the closest interpolation - // may have a different street segments as a parent. - // Therefore allow an interpolation line to take precendence - // even when the street is closer. - $fDistance = $iRankAddress < 28 ? 0.001 : $aPlace['distance']; - } - - $aHouse = $this->lookupInterpolation($sPointSQL, $fDistance); - Debug::printVar('Interpolation result', $aPlace); - - if ($aHouse) { - $oResult = new Result($aHouse['place_id'], Result::TABLE_OSMLINE); - $oResult->iHouseNumber = closestHouseNumber($aHouse); - $aPlace = $aHouse; - $iRankAddress = 30; - } } if ($aPlace) { @@ -328,7 +305,9 @@ class ReverseGeocode Debug::printVar('Closest POI result', $aStreet); if ($aStreet) { + $aPlace = $aStreet; $oResult = new Result($aStreet['place_id']); + $iRankAddress = 30; } } @@ -351,11 +330,37 @@ class ReverseGeocode Debug::printVar('Tiger house number result', $aPlaceTiger); if ($aPlaceTiger) { + $aPlace = $aPlaceTiger; $oResult = new Result($aPlaceTiger['place_id'], Result::TABLE_TIGER); $oResult->iHouseNumber = closestHouseNumber($aPlaceTiger); + $iRankAddress = 30; } } - } else { + } + + if ($bDoInterpolation && $iMaxRank >= 30) { + $fDistance = $fSearchDiam; + if ($aPlace) { + // We can't reliably go from the closest street to an + // interpolation line because the closest interpolation + // may have a different street segments as a parent. + // Therefore allow an interpolation line to take precendence + // even when the street is closer. + $fDistance = $iRankAddress < 28 ? 0.001 : $aPlace['distance']; + } + + $aHouse = $this->lookupInterpolation($sPointSQL, $fDistance); + Debug::printVar('Interpolation result', $aPlace); + + if ($aHouse) { + $oResult = new Result($aHouse['place_id'], Result::TABLE_OSMLINE); + $oResult->iHouseNumber = closestHouseNumber($aHouse); + $aPlace = $aHouse; + $iRankAddress = 30; + } + } + + if (!$aPlace) { // if no POI or street is found ... $oResult = $this->lookupLargeArea($sPointSQL, 25); } diff --git a/test/bdd/api/reverse/queries.feature b/test/bdd/api/reverse/queries.feature index 204751a0..303af2c3 100644 --- a/test/bdd/api/reverse/queries.feature +++ b/test/bdd/api/reverse/queries.feature @@ -70,6 +70,23 @@ Feature: Reverse geocoding | display_name | | 1021, Grosssteg, Sücka, Triesenberg, Oberland, 9497, Liechtenstein | + # github 2214 + Scenario: Interpolations do not override house numbers when they are closer + When sending jsonv2 reverse coordinates 47.11778,9.57255 + | zoom | + | 18 | + Then results contain + | display_name | + | 5, Grosssteg, Steg, Triesenberg, Oberland, 9497, Liechtenstein | + + Scenario: Interpolations do not override house numbers when they are closer (2) + When sending jsonv2 reverse coordinates 47.11834,9.57167 + | zoom | + | 18 | + Then results contain + | display_name | + | 3, Grosssteg, Sücka, Triesenberg, Oberland, 9497, Liechtenstein | + Scenario: When on a street with zoom 18, the closest housenumber is returned When sending jsonv2 reverse coordinates 47.11755503977281,9.572722250405036 | zoom |