From: gemo1011 Date: Wed, 23 May 2018 11:37:18 +0000 (+0200) Subject: new query if no polygon is found X-Git-Tag: v3.2.0~60^2~19 X-Git-Url: https://git.openstreetmap.org./nominatim.git/commitdiff_plain/ee54ebfe77ef4c52a51c5326952f6a98299a3a68?hp=43ee4a8faf984382d718bbab25a3752ce19a5b97 new query if no polygon is found the new query searchs in the country_osm_grid table for a polygon --- diff --git a/lib/ReverseGeocode.php b/lib/ReverseGeocode.php index 93da7caf..42215931 100644 --- a/lib/ReverseGeocode.php +++ b/lib/ReverseGeocode.php @@ -68,7 +68,42 @@ class ReverseGeocode 'Could not determine closest housenumber on an osm interpolation line.' ); } - + + protected function noPolygonFound($sPointSQL, $iMaxRank) + { + $sSQL = 'SELECT * FROM country_osm_grid'; + $sSQL .= ' WHERE ST_CONTAINS (geometry, '.$sPointSQL.' )'; + + $aPoly = chksql( + $this->oDB->getRow($sSQL), + 'Could not determine polygon containing the point.' + ); + if ($aPoly) { + $sCountryCode = $aPoly['country_code']; + + $sSQL = 'SELECT *, ST_distance('.$sPointSQL.', geometry) as distance'; + $sSQL .= ' FROM placex'; + $sSQL .= ' WHERE osm_type = \'N\''; + $sSQL .= ' AND country_code = \''.$sCountryCode.'\''; + $sSQL .= ' AND rank_address > 0'; + $sSQL .= ' AND rank_address <= ' .Min(25, $iMaxRank); + $sSQL .= ' AND type != \'postcode\''; + $sSQL .= ' AND name IS NOT NULL '; + $sSQL .= ' and indexed_status = 0 and linked_place_id is null'; + $sSQL .= ' ORDER BY distance ASC, rank_address DESC'; + $sSQL .= ' LIMIT 1'; + + if (CONST_Debug) var_dump($sSQL); + $aPlacNode = chksql( + $this->oDB->getRow($sSQL), + 'Could not determine place node.' + ); + if ($aPlacNode) { + return $aPlacNode; + } + } + } + protected function lookupPolygon($sPointSQL, $iMaxRank) { @@ -152,7 +187,7 @@ class ReverseGeocode $bIsTigerStreet = false; // try with interpolations before continuing - if ($bDoInterpolation && $iMaxRank >= 30 ) { + if ($bDoInterpolation && $iMaxRank >= 30) { $aHouse = $this->lookupInterpolation($sPointSQL, $fSearchDiam/3); if ($aHouse) { @@ -231,6 +266,11 @@ class ReverseGeocode $aPlace = $this->lookupPolygon($sPointSQL, $iMaxRank); if ($aPlace) { $oResult = new Result($aPlace['place_id']); + } else { + $aPlace = $this->noPolygonFound($sPointSQL, $iMaxRank); + if ($aPlace) { + $oResult = new Result($aPlace['place_id']); + } } } // lower than street level ($iMaxRank < 26 ) @@ -238,6 +278,11 @@ class ReverseGeocode $aPlace = $this->lookupPolygon($sPointSQL, $iMaxRank); if ($aPlace) { $oResult = new Result($aPlace['place_id']); + } else { + $aPlace = $this->noPolygonFound($sPointSQL, $iMaxRank); + if ($aPlace) { + $oResult = new Result($aPlace['place_id']); + } } } return $oResult;