directly do country search for reverse zoom < 5

Fixes #1145.
This commit is contained in:
Sarah Hoffmann
2018-08-20 22:07:37 +02:00
parent 3af8dc9580
commit de8888ec58
2 changed files with 48 additions and 27 deletions

View File

@@ -78,12 +78,15 @@ class ReverseGeocode
// starts the nopolygonFound function if no polygon is found with the lookupPolygon function // starts the nopolygonFound function if no polygon is found with the lookupPolygon function
$oResult = null; $oResult = null;
$aPlace = $this->lookupPolygon($sPointSQL, $iMaxRank); if ($iMaxRank > 4) {
if ($aPlace) { $aPlace = $this->lookupPolygon($sPointSQL, $iMaxRank);
$oResult = new Result($aPlace['place_id']); if ($aPlace) {
$oResult = new Result($aPlace['place_id']);
}
}
// if no polygon which contains the searchpoint is found, // if no polygon which contains the searchpoint is found,
// the noPolygonFound function searches in the country_osm_grid table for a polygon // the noPolygonFound function searches in the country_osm_grid table for a polygon
} elseif (!$aPlace && $iMaxRank > 4) { if (!$oResult) {
$aPlace = $this->noPolygonFound($sPointSQL, $iMaxRank); $aPlace = $this->noPolygonFound($sPointSQL, $iMaxRank);
if ($aPlace) { if ($aPlace) {
$oResult = new Result($aPlace['place_id']); $oResult = new Result($aPlace['place_id']);
@@ -101,34 +104,36 @@ class ReverseGeocode
$aPoly = chksql( $aPoly = chksql(
$this->oDB->getRow($sSQL), $this->oDB->getRow($sSQL),
'Could not determine polygon containing the point.' 'Could not determine country polygon containing the point.'
); );
if ($aPoly) { if ($aPoly) {
$sCountryCode = $aPoly['country_code']; $sCountryCode = $aPoly['country_code'];
// look for place nodes with the given country code if ($iMaxRank > 4) {
$sSQL = 'SELECT place_id FROM'; // look for place nodes with the given country code
$sSQL .= ' (SELECT place_id, rank_search,'; $sSQL = 'SELECT place_id FROM';
$sSQL .= ' ST_distance('.$sPointSQL.', geometry) as distance'; $sSQL .= ' (SELECT place_id, rank_search,';
$sSQL .= ' FROM placex'; $sSQL .= ' ST_distance('.$sPointSQL.', geometry) as distance';
$sSQL .= ' WHERE osm_type = \'N\''; $sSQL .= ' FROM placex';
$sSQL .= ' AND country_code = \''.$sCountryCode.'\''; $sSQL .= ' WHERE osm_type = \'N\'';
$sSQL .= ' AND rank_search between 5 and ' .min(25, $iMaxRank); $sSQL .= ' AND country_code = \''.$sCountryCode.'\'';
$sSQL .= ' AND class = \'place\' AND type != \'postcode\''; $sSQL .= ' AND rank_search between 5 and ' .min(25, $iMaxRank);
$sSQL .= ' AND name IS NOT NULL '; $sSQL .= ' AND class = \'place\' AND type != \'postcode\'';
$sSQL .= ' and indexed_status = 0 and linked_place_id is null'; $sSQL .= ' AND name IS NOT NULL ';
$sSQL .= ' AND ST_DWithin('.$sPointSQL.', geometry, 1.8)) p '; $sSQL .= ' and indexed_status = 0 and linked_place_id is null';
$sSQL .= 'WHERE distance <= reverse_place_diameter(rank_search)'; $sSQL .= ' AND ST_DWithin('.$sPointSQL.', geometry, 1.8)) p ';
$sSQL .= ' ORDER BY rank_search DESC, distance ASC'; $sSQL .= 'WHERE distance <= reverse_place_diameter(rank_search)';
$sSQL .= ' LIMIT 1'; $sSQL .= ' ORDER BY rank_search DESC, distance ASC';
$sSQL .= ' LIMIT 1';
if (CONST_Debug) var_dump($sSQL); if (CONST_Debug) var_dump($sSQL);
$aPlacNode = chksql( $aPlacNode = chksql(
$this->oDB->getRow($sSQL), $this->oDB->getRow($sSQL),
'Could not determine place node.' 'Could not determine place node.'
); );
if ($aPlacNode) { if ($aPlacNode) {
return $aPlacNode; return $aPlacNode;
}
} }
// still nothing, then return the country object // still nothing, then return the country object

View File

@@ -59,3 +59,19 @@ Feature: Reverse geocoding
Then results contain Then results contain
| display_name | | display_name |
| Tacuarembó, Uruguay | | 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 |