X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/d0741f21b1b8225cd6339b846eb65e04b6a8dad4..cb76635da768d0ba63f12eb8e8d53b6d0d29c373:/lib/ReverseGeocode.php diff --git a/lib/ReverseGeocode.php b/lib/ReverseGeocode.php index a2416929..83f6c7e3 100644 --- a/lib/ReverseGeocode.php +++ b/lib/ReverseGeocode.php @@ -87,17 +87,18 @@ class ReverseGeocode if ($aPoly) { $iParentPlaceID = $aPoly['parent_place_id']; $iRankSearch = $aPoly['rank_search']; - $iGeometry = $aPoly['geometry']; + $iPlaceID = $aPoly['place_id']; - $sSQL = 'select place_id,parent_place_id,rank_search,country_code,'; + $sSQL = 'select place_id,parent_place_id,rank_search,country_code, linked_place_id,'; $sSQL .=' ST_distance('.$sPointSQL.', geometry) as distance'; $sSQL .= ' FROM placex'; $sSQL .= ' WHERE osm_type = \'N\''; $sSQL .= ' AND rank_search >= '.$iRankSearch; $sSQL .= ' AND rank_search <= LEAST(25, '.$iMaxRank.')'; - $sSQL .= ' AND ST_CONTAINS(\''.$iGeometry.'\'::geometry, geometry )'; + $sSQL .= ' AND ST_CONTAINS((SELECT geometry FROM placex WHERE place_id = '.$iPlaceID.'), geometry )'; $sSQL .= ' AND type != \'postcode\''; $sSQL .= ' AND name IS NOT NULL '; + $sSQL .= ' AND class not in ( \'waterway\')'; $sSQL .= ' ORDER BY distance ASC,'; $sSQL .= ' rank_search DESC'; $sSQL .= ' limit 1'; @@ -194,17 +195,26 @@ class ReverseGeocode }else{ $aPlace = $this->lookupPolygon($sPointSQL, $iMaxRank); if ($aPlace) { - $oResult = new Result($aPlace['place_id']); + // if place node is found adress goes over linked_place_id + if (!empty($aPlace['linked_place_id'])) { + $oResult = new Result($aPlace['linked_place_id']); + }else{ + $oResult = new Result($aPlace['place_id']); + } } } // lower than street level ($iMaxRank < 26 ) }else{ $aPlace = $this->lookupPolygon($sPointSQL, $iMaxRank); if ($aPlace) { - $oResult = new Result($aPlace['place_id']); + // if place node is found adress goes over linked_place_id + if (!empty($aPlace['linked_place_id'])) { + $oResult = new Result($aPlace['linked_place_id']); + }else{ + $oResult = new Result($aPlace['place_id']); + } + } } - - } return $oResult; }