mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-02-26 11:08:13 +00:00
use NearPoint class in Search array
This commit is contained in:
@@ -693,10 +693,11 @@ class Geocode
|
|||||||
if ($aSearch['iSearchRank'] < $this->iMaxRank) $aNewWordsetSearches[] = $aSearch;
|
if ($aSearch['iSearchRank'] < $this->iMaxRank) $aNewWordsetSearches[] = $aSearch;
|
||||||
}
|
}
|
||||||
} elseif (isset($aSearchTerm['lat']) && $aSearchTerm['lat'] !== '' && $aSearchTerm['lat'] !== null) {
|
} elseif (isset($aSearchTerm['lat']) && $aSearchTerm['lat'] !== '' && $aSearchTerm['lat'] !== null) {
|
||||||
if ($aSearch['fLat'] === '') {
|
if ($aSearch['oNear'] === false) {
|
||||||
$aSearch['fLat'] = $aSearchTerm['lat'];
|
$aSearch['oNear'] = new NearPoint(
|
||||||
$aSearch['fLon'] = $aSearchTerm['lon'];
|
$aSearchTerm['lat'],
|
||||||
$aSearch['fRadius'] = $aSearchTerm['radius'];
|
$aSearchTerm['lon'],
|
||||||
|
$aSearchTerm['radius']);
|
||||||
if ($aSearch['iSearchRank'] < $this->iMaxRank) $aNewWordsetSearches[] = $aSearch;
|
if ($aSearch['iSearchRank'] < $this->iMaxRank) $aNewWordsetSearches[] = $aSearch;
|
||||||
}
|
}
|
||||||
} elseif ($sPhraseType == 'postalcode') {
|
} elseif ($sPhraseType == 'postalcode') {
|
||||||
@@ -961,19 +962,10 @@ class Geocode
|
|||||||
'sClass' => '',
|
'sClass' => '',
|
||||||
'sType' => '',
|
'sType' => '',
|
||||||
'sHouseNumber' => '',
|
'sHouseNumber' => '',
|
||||||
'fLat' => '',
|
'oNear' => $oNearPoint
|
||||||
'fLon' => '',
|
|
||||||
'fRadius' => ''
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Do we have a radius search?
|
|
||||||
if ($oNearPoint) {
|
|
||||||
$aSearches[0]['fLat'] = $oNearPoint->lat();
|
|
||||||
$aSearches[0]['fLon'] = $oNearPoint->lon();
|
|
||||||
$aSearches[0]['fRadius'] = $oNearPoint->radius();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Any 'special' terms in the search?
|
// Any 'special' terms in the search?
|
||||||
$bSpecialTerms = false;
|
$bSpecialTerms = false;
|
||||||
preg_match_all('/\\[(.*)=(.*)\\]/', $sQuery, $aSpecialTermsRaw, PREG_SET_ORDER);
|
preg_match_all('/\\[(.*)=(.*)\\]/', $sQuery, $aSpecialTermsRaw, PREG_SET_ORDER);
|
||||||
@@ -1233,7 +1225,7 @@ class Geocode
|
|||||||
if (CONST_Debug) _debugDumpGroupedSearches(array($iGroupedRank => array($aSearch)), $aValidTokens);
|
if (CONST_Debug) _debugDumpGroupedSearches(array($iGroupedRank => array($aSearch)), $aValidTokens);
|
||||||
|
|
||||||
// No location term?
|
// No location term?
|
||||||
if (!sizeof($aSearch['aName']) && !sizeof($aSearch['aAddress']) && !$aSearch['fLon']) {
|
if (!sizeof($aSearch['aName']) && !sizeof($aSearch['aAddress']) && !$aSearch['oNear']) {
|
||||||
if ($aSearch['sCountryCode'] && !$aSearch['sClass'] && !$aSearch['sHouseNumber']) {
|
if ($aSearch['sCountryCode'] && !$aSearch['sClass'] && !$aSearch['sHouseNumber']) {
|
||||||
// Just looking for a country by code - look it up
|
// Just looking for a country by code - look it up
|
||||||
if (4 >= $this->iMinAddressRank && 4 <= $this->iMaxAddressRank) {
|
if (4 >= $this->iMinAddressRank && 4 <= $this->iMaxAddressRank) {
|
||||||
@@ -1248,7 +1240,7 @@ class Geocode
|
|||||||
$aPlaceIDs = array();
|
$aPlaceIDs = array();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!$bBoundingBoxSearch && !$aSearch['fLon']) continue;
|
if (!$bBoundingBoxSearch && !$aSearch['oNear']) continue;
|
||||||
if (!$aSearch['sClass']) continue;
|
if (!$aSearch['sClass']) continue;
|
||||||
|
|
||||||
$sSQL = "SELECT COUNT(*) FROM pg_tables WHERE tablename = 'place_classtype_".$aSearch['sClass']."_".$aSearch['sType']."'";
|
$sSQL = "SELECT COUNT(*) FROM pg_tables WHERE tablename = 'place_classtype_".$aSearch['sClass']."_".$aSearch['sType']."'";
|
||||||
@@ -1293,7 +1285,7 @@ class Geocode
|
|||||||
$aPlaceIDs = chksql($this->oDB->getCol($sSQL));
|
$aPlaceIDs = chksql($this->oDB->getCol($sSQL));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} elseif ($aSearch['fLon'] && !sizeof($aSearch['aName']) && !sizeof($aSearch['aAddress']) && !$aSearch['sClass']) {
|
} elseif ($aSearch['oNear'] && !sizeof($aSearch['aName']) && !sizeof($aSearch['aAddress']) && !$aSearch['sClass']) {
|
||||||
// If a coordinate is given, the search must either
|
// If a coordinate is given, the search must either
|
||||||
// be for a name or a special search. Ignore everythin else.
|
// be for a name or a special search. Ignore everythin else.
|
||||||
$aPlaceIDs = array();
|
$aPlaceIDs = array();
|
||||||
@@ -1358,15 +1350,10 @@ class Geocode
|
|||||||
$aTerms[] = "address_rank <= ".$this->iMaxAddressRank;
|
$aTerms[] = "address_rank <= ".$this->iMaxAddressRank;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($aSearch['fLon'] && $aSearch['fLat']) {
|
if ($aSearch['oNear']) {
|
||||||
$aTerms[] = sprintf(
|
$aTerms[] = $aSearch['oNear']->withinSQL('centroid');
|
||||||
'ST_DWithin(centroid, ST_SetSRID(ST_Point(%F,%F),4326), %F)',
|
|
||||||
$aSearch['fLon'],
|
|
||||||
$aSearch['fLat'],
|
|
||||||
$aSearch['fRadius']
|
|
||||||
);
|
|
||||||
|
|
||||||
$aOrder[] = "ST_Distance(centroid, ST_SetSRID(ST_Point(".$aSearch['fLon'].",".$aSearch['fLat']."),4326)) ASC";
|
$aOrder[] = $aSearch['oNear']->distanceSQL('centroid');
|
||||||
}
|
}
|
||||||
if (sizeof($this->aExcludePlaceIDs)) {
|
if (sizeof($this->aExcludePlaceIDs)) {
|
||||||
$aTerms[] = "place_id not in (".join(',', $this->aExcludePlaceIDs).")";
|
$aTerms[] = "place_id not in (".join(',', $this->aExcludePlaceIDs).")";
|
||||||
@@ -1614,7 +1601,9 @@ class Geocode
|
|||||||
if (CONST_Debug) var_dump($sSQL);
|
if (CONST_Debug) var_dump($sSQL);
|
||||||
$aClassPlaceIDs = array_merge($aClassPlaceIDs, chksql($this->oDB->getCol($sSQL)));
|
$aClassPlaceIDs = array_merge($aClassPlaceIDs, chksql($this->oDB->getCol($sSQL)));
|
||||||
} else {
|
} else {
|
||||||
if (isset($aSearch['fRadius']) && $aSearch['fRadius']) $fRange = $aSearch['fRadius'];
|
if ($aSearch['oNear']) {
|
||||||
|
$fRange = $aSearch['oNear']->radius();
|
||||||
|
}
|
||||||
|
|
||||||
$sOrderBySQL = '';
|
$sOrderBySQL = '';
|
||||||
if ($oNearPoint) {
|
if ($oNearPoint) {
|
||||||
|
|||||||
@@ -32,6 +32,17 @@ class NearPoint
|
|||||||
return 'ST_Distance('.$this->sSQL.", $sObj)";
|
return 'ST_Distance('.$this->sSQL.", $sObj)";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function withinSQL($sObj)
|
||||||
|
{
|
||||||
|
return sprintf(
|
||||||
|
'ST_DWithin(%S, ST_SetSRID(ST_Point(%F,%F),4326), %F)',
|
||||||
|
$sObj,
|
||||||
|
$this->fLon,
|
||||||
|
$this->fLat,
|
||||||
|
$this->fRadius
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check that the coordinates are valid WSG84 coordinates.
|
* Check that the coordinates are valid WSG84 coordinates.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user