new query if no polygon is found

the new query searchs in the country_osm_grid table for a polygon
This commit is contained in:
gemo1011
2018-05-23 13:37:18 +02:00
parent 43ee4a8faf
commit ee54ebfe77

View File

@@ -68,7 +68,42 @@ class ReverseGeocode
'Could not determine closest housenumber on an osm interpolation line.'
);
}
protected function noPolygonFound($sPointSQL, $iMaxRank)
{
$sSQL = 'SELECT * FROM country_osm_grid';
$sSQL .= ' WHERE ST_CONTAINS (geometry, '.$sPointSQL.' )';
$aPoly = chksql(
$this->oDB->getRow($sSQL),
'Could not determine polygon containing the point.'
);
if ($aPoly) {
$sCountryCode = $aPoly['country_code'];
$sSQL = 'SELECT *, ST_distance('.$sPointSQL.', geometry) as distance';
$sSQL .= ' FROM placex';
$sSQL .= ' WHERE osm_type = \'N\'';
$sSQL .= ' AND country_code = \''.$sCountryCode.'\'';
$sSQL .= ' AND rank_address > 0';
$sSQL .= ' AND rank_address <= ' .Min(25, $iMaxRank);
$sSQL .= ' AND type != \'postcode\'';
$sSQL .= ' AND name IS NOT NULL ';
$sSQL .= ' and indexed_status = 0 and linked_place_id is null';
$sSQL .= ' ORDER BY distance ASC, rank_address DESC';
$sSQL .= ' LIMIT 1';
if (CONST_Debug) var_dump($sSQL);
$aPlacNode = chksql(
$this->oDB->getRow($sSQL),
'Could not determine place node.'
);
if ($aPlacNode) {
return $aPlacNode;
}
}
}
protected function lookupPolygon($sPointSQL, $iMaxRank)
{
@@ -152,7 +187,7 @@ class ReverseGeocode
$bIsTigerStreet = false;
// try with interpolations before continuing
if ($bDoInterpolation && $iMaxRank >= 30 ) {
if ($bDoInterpolation && $iMaxRank >= 30) {
$aHouse = $this->lookupInterpolation($sPointSQL, $fSearchDiam/3);
if ($aHouse) {
@@ -231,6 +266,11 @@ class ReverseGeocode
$aPlace = $this->lookupPolygon($sPointSQL, $iMaxRank);
if ($aPlace) {
$oResult = new Result($aPlace['place_id']);
} else {
$aPlace = $this->noPolygonFound($sPointSQL, $iMaxRank);
if ($aPlace) {
$oResult = new Result($aPlace['place_id']);
}
}
}
// lower than street level ($iMaxRank < 26 )
@@ -238,6 +278,11 @@ class ReverseGeocode
$aPlace = $this->lookupPolygon($sPointSQL, $iMaxRank);
if ($aPlace) {
$oResult = new Result($aPlace['place_id']);
} else {
$aPlace = $this->noPolygonFound($sPointSQL, $iMaxRank);
if ($aPlace) {
$oResult = new Result($aPlace['place_id']);
}
}
}
return $oResult;