X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/14e708f36660c886c49060b00ce673e702190806..f5718ed909f1ff93d238f2c3fac2429a420efbfa:/lib/ReverseGeocode.php diff --git a/lib/ReverseGeocode.php b/lib/ReverseGeocode.php index 820ca385..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']); } @@ -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']; @@ -213,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; } @@ -255,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) { @@ -314,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']); @@ -344,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);