]> git.openstreetmap.org Git - nominatim.git/commitdiff
directly do country search for reverse zoom < 5
authorSarah Hoffmann <lonvia@denofr.de>
Mon, 20 Aug 2018 20:07:37 +0000 (22:07 +0200)
committerSarah Hoffmann <lonvia@denofr.de>
Mon, 20 Aug 2018 20:09:08 +0000 (22:09 +0200)
Fixes #1145.

lib/ReverseGeocode.php
test/bdd/api/reverse/queries.feature

index 681403a19eff902d389fb8feba18e61b5b489a8d..58baac796a30b32772f7967c32365e3c9980d468 100644 (file)
@@ -78,12 +78,15 @@ class ReverseGeocode
         // starts the nopolygonFound function if no polygon is found with the lookupPolygon function
         $oResult = null;
 
-        $aPlace = $this->lookupPolygon($sPointSQL, $iMaxRank);
-        if ($aPlace) {
-            $oResult = new Result($aPlace['place_id']);
+        if ($iMaxRank > 4) {
+            $aPlace = $this->lookupPolygon($sPointSQL, $iMaxRank);
+            if ($aPlace) {
+                $oResult = new Result($aPlace['place_id']);
+            }
+        }
         // if no polygon which contains the searchpoint is found,
         // the noPolygonFound function searches in the country_osm_grid table for a polygon
-        } elseif (!$aPlace && $iMaxRank > 4) {
+        if (!$oResult) {
             $aPlace = $this->noPolygonFound($sPointSQL, $iMaxRank);
             if ($aPlace) {
                 $oResult = new Result($aPlace['place_id']);
@@ -101,34 +104,36 @@ class ReverseGeocode
 
         $aPoly = chksql(
             $this->oDB->getRow($sSQL),
-            'Could not determine polygon containing the point.'
+            'Could not determine country polygon containing the point.'
         );
         if ($aPoly) {
             $sCountryCode = $aPoly['country_code'];
 
-            // look for place nodes with the given country code
-            $sSQL = 'SELECT place_id FROM';
-            $sSQL .= ' (SELECT place_id, rank_search,';
-            $sSQL .= '         ST_distance('.$sPointSQL.', geometry) as distance';
-            $sSQL .= ' FROM placex';
-            $sSQL .= ' WHERE osm_type = \'N\'';
-            $sSQL .= ' AND country_code = \''.$sCountryCode.'\'';
-            $sSQL .= ' AND rank_search between 5 and ' .min(25, $iMaxRank);
-            $sSQL .= ' AND class = \'place\' AND type != \'postcode\'';
-            $sSQL .= ' AND name IS NOT NULL ';
-            $sSQL .= ' and indexed_status = 0 and linked_place_id is null';
-            $sSQL .= ' AND ST_DWithin('.$sPointSQL.', geometry, 1.8)) p ';
-            $sSQL .= 'WHERE distance <= reverse_place_diameter(rank_search)';
-            $sSQL .= ' ORDER BY rank_search DESC, distance ASC';
-            $sSQL .= ' LIMIT 1';
+            if ($iMaxRank > 4) {
+                // look for place nodes with the given country code
+                $sSQL = 'SELECT place_id FROM';
+                $sSQL .= ' (SELECT place_id, rank_search,';
+                $sSQL .= '         ST_distance('.$sPointSQL.', geometry) as distance';
+                $sSQL .= ' FROM placex';
+                $sSQL .= ' WHERE osm_type = \'N\'';
+                $sSQL .= ' AND country_code = \''.$sCountryCode.'\'';
+                $sSQL .= ' AND rank_search between 5 and ' .min(25, $iMaxRank);
+                $sSQL .= ' AND class = \'place\' AND type != \'postcode\'';
+                $sSQL .= ' AND name IS NOT NULL ';
+                $sSQL .= ' and indexed_status = 0 and linked_place_id is null';
+                $sSQL .= ' AND ST_DWithin('.$sPointSQL.', geometry, 1.8)) p ';
+                $sSQL .= 'WHERE distance <= reverse_place_diameter(rank_search)';
+                $sSQL .= ' ORDER BY rank_search DESC, distance ASC';
+                $sSQL .= ' LIMIT 1';
 
-            if (CONST_Debug) var_dump($sSQL);
-            $aPlacNode = chksql(
-                $this->oDB->getRow($sSQL),
-                'Could not determine place node.'
-            );
-            if ($aPlacNode) {
-                return $aPlacNode;
+                if (CONST_Debug) var_dump($sSQL);
+                $aPlacNode = chksql(
+                    $this->oDB->getRow($sSQL),
+                    'Could not determine place node.'
+                );
+                if ($aPlacNode) {
+                    return $aPlacNode;
+                }
             }
 
             // still nothing, then return the country object
index e06b1775fa2d69306833f11630229d0073c9e0f0..67e4676ccf6f67af7d771a2f4d3891cbb70b9e16 100644 (file)
@@ -59,3 +59,19 @@ Feature: Reverse geocoding
         Then results contain
          | display_name |
          | Tacuarembó, Uruguay |
+
+    Scenario Outline: Zoom levels below 5 result in country
+        When sending jsonv2 reverse coordinates -33.28,-56.29
+         | zoom |
+         | <zoom> |
+        Then results contain
+         | display_name |
+         | Uruguay |
+
+    Examples:
+         | zoom |
+         | 0    |
+         | 1    |
+         | 2    |
+         | 3    |
+         | 4    |