X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/d42aa0870592b36ba9c64eae05a0ceafd2467f4c..3087ac1145f148adcfbb4abeb31bcc62d062b1bd:/lib/ReverseGeocode.php diff --git a/lib/ReverseGeocode.php b/lib/ReverseGeocode.php index 31ebe717..27f8c89c 100644 --- a/lib/ReverseGeocode.php +++ b/lib/ReverseGeocode.php @@ -65,7 +65,7 @@ class ReverseGeocode return chksql( $this->oDB->getRow($sSQL), - "Could not determine closest housenumber on an osm interpolation line." + 'Could not determine closest housenumber on an osm interpolation line.' ); } @@ -121,19 +121,28 @@ class ReverseGeocode $sSQL = 'select place_id,parent_place_id,rank_search,country_code,'; $sSQL .= ' ST_distance('.$sPointSQL.', geometry) as distance'; - $sSQL .= ' FROM placex'; - $sSQL .= ' WHERE ST_DWithin('.$sPointSQL.', geometry, '.$fSearchDiam.')'; - $sSQL .= ' and rank_search != 28 and rank_search >= '.$iMaxRank; - $sSQL .= ' and (name is not null or housenumber is not null)'; + $sSQL .= ' FROM '; + if ($fSearchDiam < 0.01) { + $sSQL .= ' placex'; + $sSQL .= ' WHERE ST_DWithin('.$sPointSQL.', geometry, '.$fSearchDiam.')'; + $sSQL .= ' AND'; + } else { + $sSQL .= ' (SELECT * FROM placex '; + $sSQL .= ' WHERE ST_DWithin('.$sPointSQL.', geometry, '.$fSearchDiam.')'; + $sSQL .= ' LIMIT 1000) as p WHERE'; + } + $sSQL .= ' rank_search != 28 and rank_search >= '.$iMaxRank; + $sSQL .= ' and (name is not null or housenumber is not null'; + $sSQL .= ' or rank_search between 26 and 27)'; $sSQL .= ' and class not in (\'waterway\',\'railway\',\'tunnel\',\'bridge\',\'man_made\')'; - $sSQL .= ' and indexed_status = 0 '; + $sSQL .= ' and indexed_status = 0 and linked_place_id is null'; $sSQL .= ' and (ST_GeometryType(geometry) not in (\'ST_Polygon\',\'ST_MultiPolygon\') '; $sSQL .= ' OR ST_DWithin('.$sPointSQL.', centroid, '.$fSearchDiam.'))'; $sSQL .= ' ORDER BY distance ASC limit 1'; if (CONST_Debug) var_dump($sSQL); $aPlace = chksql( $this->oDB->getRow($sSQL), - "Could not determine closest place." + 'Could not determine closest place.' ); if ($aPlace) { $oResult = new Result($aPlace['place_id']); @@ -178,7 +187,7 @@ class ReverseGeocode $aPlaceTiger = chksql( $this->oDB->getRow($sSQL), - "Could not determine closest Tiger place." + 'Could not determine closest Tiger place.' ); if ($aPlaceTiger) { if (CONST_Debug) var_dump('found Tiger housenumber', $aPlaceTiger); @@ -197,12 +206,13 @@ class ReverseGeocode } else { $iPlaceID = $oResult->iId; } - $sSQL = 'select address_place_id'; - $sSQL .= ' FROM place_addressline'; - $sSQL .= " WHERE place_id = $iPlaceID"; + $sSQL = 'select a.address_place_id'; + $sSQL .= ' FROM place_addressline a, placex p'; + $sSQL .= " WHERE a.place_id = $iPlaceID and a.address_place_id = p.place_id"; + $sSQL .= ' AND p.linked_place_id is null'; $sSQL .= " ORDER BY abs(cached_rank_address - $iMaxRank) asc,cached_rank_address desc,isaddress desc,distance desc"; $sSQL .= ' LIMIT 1'; - $iPlaceID = chksql($this->oDB->getOne($sSQL), "Could not get parent for place."); + $iPlaceID = chksql($this->oDB->getOne($sSQL), 'Could not get parent for place.'); if ($iPlaceID) { $oResult = new Result($iPlaceID); }