X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/78d5b63e38b1165a22f27a5255e0c0d63d6464cb..174fca9c7ae30ad4bab666f2bdcdb288ed188e3e:/lib/ReverseGeocode.php?ds=sidebyside diff --git a/lib/ReverseGeocode.php b/lib/ReverseGeocode.php index 6d3cc829..9b43a3e3 100644 --- a/lib/ReverseGeocode.php +++ b/lib/ReverseGeocode.php @@ -57,7 +57,7 @@ class ReverseGeocode $sSQL .= ' , ST_Distance(linegeo,'.$sPointSQL.') as distance'; $sSQL .= ' FROM location_property_osmline'; $sSQL .= ' WHERE ST_DWithin('.$sPointSQL.', linegeo, '.$fSearchDiam.')'; - $sSQL .= ' and indexed_status = 0 '; + $sSQL .= ' and indexed_status = 0 and startnumber is not NULL '; $sSQL .= ' ORDER BY ST_distance('.$sPointSQL.', linegeo) ASC limit 1'; return chksql( @@ -66,15 +66,22 @@ class ReverseGeocode ); } + public function lookup($fLat, $fLon, $bDoInterpolation = true) + { + return $this->lookupPoint( + 'ST_SetSRID(ST_Point('.$fLon.','.$fLat.'),4326)', + $bDoInterpolation + ); + } + /* lookup() * returns { place_id =>, type => '(osm|tiger)' } * fails if no place was found */ - public function lookup($fLat, $fLon, $bDoInterpolation = true) + public function lookupPoint($sPointSQL, $bDoInterpolation = true) { - $sPointSQL = 'ST_SetSRID(ST_Point('.$fLon.','.$fLat.'),4326)'; $iMaxRank = $this->iMaxRank; // Find the nearest point @@ -118,7 +125,7 @@ class ReverseGeocode $iMaxRank = 26; } - $sSQL = 'select place_id,parent_place_id,rank_search,calculated_country_code'; + $sSQL = 'select place_id,parent_place_id,rank_search,country_code'; $sSQL .= ' FROM placex'; $sSQL .= ' WHERE ST_DWithin('.$sPointSQL.', geometry, '.$fSearchDiam.')'; $sSQL .= ' and rank_search != 28 and rank_search >= '.$iMaxRank; @@ -135,7 +142,7 @@ class ReverseGeocode ); $iPlaceID = $aPlace['place_id']; $iParentPlaceID = $aPlace['parent_place_id']; - $bIsInUnitedStates = ($aPlace['calculated_country_code'] == 'us'); + $bIsInUnitedStates = ($aPlace['country_code'] == 'us'); } // If a house was found make sure there isn't an interpolation line @@ -153,7 +160,7 @@ class ReverseGeocode // look for an interpolation that is closer $aPlaceLine = $this->lookupInterpolation($sPointSQL, $fDistancePlacex); - if ($aPlaceLine) { + if ($aPlaceLine && (float) $aPlaceLine['distance'] < (float) $fDistancePlacex) { // interpolation is closer to point than placex house $bPlaceIsLine = true; $aPlace = $aPlaceLine; @@ -201,6 +208,8 @@ class ReverseGeocode if ($iPlaceID && $iMaxRank < 28) { if (($aPlace['rank_search'] > 28 || $bPlaceIsTiger || $bPlaceIsLine) && $iParentPlaceID) { $iPlaceID = $iParentPlaceID; + $bPlaceIsLine = false; + $bPlaceIsTiger = false; } $sSQL = 'select address_place_id'; $sSQL .= ' FROM place_addressline';