X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/3fcfab97722bf073784e012899b5a51e3ad43914..3737712044b50ec1319afeebcd24d0ca2d0b181d:/lib/ReverseGeocode.php?ds=inline diff --git a/lib/ReverseGeocode.php b/lib/ReverseGeocode.php index fc5e04d6..5cecfd33 100644 --- a/lib/ReverseGeocode.php +++ b/lib/ReverseGeocode.php @@ -36,8 +36,8 @@ class ReverseGeocode 13 => 18, 14 => 22, // Suburb 15 => 22, - 16 => 26, // Street, TODO: major street? - 17 => 26, + 16 => 26, // major street + 17 => 27, // minor street 18 => 30, // or >, Building 19 => 30, // or >, Building ); @@ -63,8 +63,9 @@ class ReverseGeocode $sSQL .= ' and indexed_status = 0 and startnumber is not NULL '; $sSQL .= ' ORDER BY distance ASC limit 1'; - return chksql( - $this->oDB->getRow($sSQL), + return $this->oDB->getRow( + $sSQL, + null, 'Could not determine closest housenumber on an osm interpolation line.' ); } @@ -92,8 +93,9 @@ class ReverseGeocode $sSQL = 'SELECT country_code FROM country_osm_grid'; $sSQL .= ' WHERE ST_CONTAINS(geometry, '.$sPointSQL.') LIMIT 1'; - $sCountryCode = chksql( - $this->oDB->getOne($sSQL), + $sCountryCode = $this->oDB->getOne( + $sSQL, + null, 'Could not determine country polygon containing the point.' ); if ($sCountryCode) { @@ -115,10 +117,7 @@ class ReverseGeocode $sSQL .= ' LIMIT 1'; if (CONST_Debug) var_dump($sSQL); - $aPlace = chksql( - $this->oDB->getRow($sSQL), - 'Could not determine place node.' - ); + $aPlace = $this->oDB->getRow($sSQL, null, 'Could not determine place node.'); if ($aPlace) { return new Result($aPlace['place_id']); } @@ -130,13 +129,11 @@ class ReverseGeocode $sSQL .= ' WHERE country_code = \''.$sCountryCode.'\''; $sSQL .= ' AND rank_search = 4 AND rank_address = 4'; $sSQL .= ' AND class in (\'boundary\', \'place\')'; + $sSQL .= ' AND linked_place_id is null'; $sSQL .= ' ORDER BY distance ASC'; if (CONST_Debug) var_dump($sSQL); - $aPlace = chksql( - $this->oDB->getRow($sSQL), - 'Could not determine place node.' - ); + $aPlace = $this->oDB->getRow($sSQL, null, 'Could not determine place node.'); if ($aPlace) { return new Result($aPlace['place_id']); } @@ -177,10 +174,8 @@ class ReverseGeocode $sSQL .= ' WHERE ST_CONTAINS(geometry, '.$sPointSQL.' )'; $sSQL .= ' ORDER BY rank_address DESC LIMIT 1'; - $aPoly = chksql( - $this->oDB->getRow($sSQL), - 'Could not determine polygon containing the point.' - ); + $aPoly = $this->oDB->getRow($sSQL, null, 'Could not determine polygon containing the point.'); + if ($aPoly) { // if a polygon is found, search for placenodes begins ... $iParentPlaceID = $aPoly['parent_place_id']; @@ -212,10 +207,7 @@ class ReverseGeocode $sSQL .= ' LIMIT 1'; if (CONST_Debug) var_dump($sSQL); - $aPlacNode = chksql( - $this->oDB->getRow($sSQL), - 'Could not determine place node.' - ); + $aPlacNode = $this->oDB->getRow($sSQL, null, 'Could not determine place node.'); if ($aPlacNode) { return $aPlacNode; } @@ -254,24 +246,18 @@ class ReverseGeocode $sSQL .= ' placex'; $sSQL .= ' WHERE ST_DWithin('.$sPointSQL.', geometry, '.$fSearchDiam.')'; $sSQL .= ' AND'; - // only streets - if ($iMaxRank == 26) { - $sSQL .= ' rank_address = 26'; - } else { - $sSQL .= ' rank_address between 26 and '.$iMaxRank; - } + $sSQL .= ' rank_address between 26 and '.$iMaxRank; $sSQL .= ' and (name is not null or housenumber is not null'; $sSQL .= ' or rank_address between 26 and 27)'; - $sSQL .= ' and class not in (\'railway\',\'tunnel\',\'bridge\',\'man_made\')'; + $sSQL .= ' and (rank_address between 26 and 27'; + $sSQL .= ' or ST_GeometryType(geometry) != \'ST_LineString\')'; + $sSQL .= ' and class not in (\'boundary\')'; $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.' - ); + $aPlace = $this->oDB->getRow($sSQL, null, 'Could not determine closest place.'); if (CONST_Debug) var_dump($aPlace); if ($aPlace) { @@ -313,16 +299,14 @@ class ReverseGeocode // radius ? $sSQL .= ' WHERE ST_DWithin('.$sPointSQL.', geometry, 0.001)'; $sSQL .= ' AND parent_place_id = '.$iPlaceID; - $sSQL .= ' and rank_address != 28'; + $sSQL .= ' and rank_address > 28'; + $sSQL .= ' and ST_GeometryType(geometry) != \'ST_LineString\''; $sSQL .= ' and (name is not null or housenumber is not null)'; - $sSQL .= ' and class not in (\'railway\',\'tunnel\',\'bridge\',\'man_made\')'; + $sSQL .= ' and class not in (\'boundary\')'; $sSQL .= ' and indexed_status = 0 and linked_place_id is null'; $sSQL .= ' ORDER BY distance ASC limit 1'; if (CONST_Debug) var_dump($sSQL); - $aStreet = chksql( - $this->oDB->getRow($sSQL), - 'Could not determine closest place.' - ); + $aStreet = $this->oDB->getRow($sSQL, null, 'Could not determine closest place.'); if ($aStreet) { if (CONST_Debug) var_dump($aStreet); $oResult = new Result($aStreet['place_id']); @@ -343,10 +327,7 @@ class ReverseGeocode $sSQL .= ' AND ST_DWithin('.$sPointSQL.', linegeo, 0.001)'; $sSQL .= ' ORDER BY distance ASC limit 1'; if (CONST_Debug) var_dump($sSQL); - $aPlaceTiger = chksql( - $this->oDB->getRow($sSQL), - 'Could not determine closest Tiger place.' - ); + $aPlaceTiger = $this->oDB->getRow($sSQL, null, 'Could not determine closest Tiger place.'); if ($aPlaceTiger) { if (CONST_Debug) var_dump('found Tiger housenumber', $aPlaceTiger); $oResult = new Result($aPlaceTiger['place_id'], Result::TABLE_TIGER);