X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/57bf76a0e1d766bc90afcb8a748c5e25e7aa6f08..bda330a87d7e6de044d4a47e61ded8c4a49fe61e:/lib/ReverseGeocode.php?ds=sidebyside diff --git a/lib/ReverseGeocode.php b/lib/ReverseGeocode.php index 820ca385..56596b03 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']); } @@ -134,10 +133,7 @@ class ReverseGeocode $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']); } @@ -178,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']; @@ -199,6 +193,7 @@ class ReverseGeocode // for place nodes at rank_address 16 $sSQL .= ' AND rank_search > '.$iRankSearch; $sSQL .= ' AND rank_search <= '.$iMaxRank; + $sSQL .= ' AND rank_address > 0'; $sSQL .= ' AND class = \'place\''; $sSQL .= ' AND type != \'postcode\''; $sSQL .= ' AND name IS NOT NULL '; @@ -213,10 +208,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; } @@ -255,24 +247,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) { @@ -314,16 +300,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']); @@ -344,10 +328,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);