use PlaceLookup::loadParamArray in search and lookup

This commit is contained in:
Sarah Hoffmann
2017-10-23 23:28:00 +02:00
parent 9981d74ee1
commit 282c6777ee
5 changed files with 69 additions and 162 deletions

View File

@@ -12,21 +12,13 @@ class Geocode
{ {
protected $oDB; protected $oDB;
protected $oPlaceLookup;
protected $aLangPrefOrder = array(); protected $aLangPrefOrder = array();
protected $bIncludeAddressDetails = false; protected $bIncludeAddressDetails = false;
protected $bIncludeExtraTags = false;
protected $bIncludeNameDetails = false;
protected $bIncludePolygonAsPoints = false;
protected $bIncludePolygonAsText = false;
protected $bIncludePolygonAsGeoJSON = false;
protected $bIncludePolygonAsKML = false;
protected $bIncludePolygonAsSVG = false;
protected $fPolygonSimplificationThreshold = 0.0;
protected $aExcludePlaceIDs = array(); protected $aExcludePlaceIDs = array();
protected $bDeDupe = true;
protected $bReverseInPlan = false; protected $bReverseInPlan = false;
protected $iLimit = 20; protected $iLimit = 20;
@@ -57,6 +49,7 @@ class Geocode
public function __construct(&$oDB) public function __construct(&$oDB)
{ {
$this->oDB =& $oDB; $this->oDB =& $oDB;
$this->oPlaceLookup = new PlaceLookup($this->oDB);
$this->oNormalizer = \Transliterator::createFromRules(CONST_Term_Normalization_Rules); $this->oNormalizer = \Transliterator::createFromRules(CONST_Term_Normalization_Rules);
} }
@@ -87,26 +80,14 @@ class Geocode
$aParams = array('q' => $this->sQuery); $aParams = array('q' => $this->sQuery);
} }
$aParams = array_merge($aParams, $this->oPlaceLookup->getMoreUrlParams());
if ($this->aExcludePlaceIDs) { if ($this->aExcludePlaceIDs) {
$aParams['exclude_place_ids'] = implode(',', $this->aExcludePlaceIDs); $aParams['exclude_place_ids'] = implode(',', $this->aExcludePlaceIDs);
} }
if ($this->bIncludeAddressDetails) $aParams['addressdetails'] = '1'; if ($this->bIncludeAddressDetails) $aParams['addressdetails'] = '1';
if ($this->bIncludeExtraTags) $aParams['extratags'] = '1';
if ($this->bIncludeNameDetails) $aParams['namedetails'] = '1';
if ($this->bIncludePolygonAsPoints) $aParams['polygon'] = '1';
if ($this->bIncludePolygonAsText) $aParams['polygon_text'] = '1';
if ($this->bIncludePolygonAsGeoJSON) $aParams['polygon_geojson'] = '1';
if ($this->bIncludePolygonAsKML) $aParams['polygon_kml'] = '1';
if ($this->bIncludePolygonAsSVG) $aParams['polygon_svg'] = '1';
if ($this->fPolygonSimplificationThreshold > 0.0) {
$aParams['polygon_threshold'] = $this->fPolygonSimplificationThreshold;
}
if ($this->bBoundedSearch) $aParams['bounded'] = '1'; if ($this->bBoundedSearch) $aParams['bounded'] = '1';
if (!$this->bDeDupe) $aParams['dedupe'] = '0';
if ($this->aCountryCodes) { if ($this->aCountryCodes) {
$aParams['countrycodes'] = implode(',', $this->aCountryCodes); $aParams['countrycodes'] = implode(',', $this->aCountryCodes);
@@ -119,36 +100,6 @@ class Geocode
return $aParams; return $aParams;
} }
public function setIncludePolygonAsPoints($b = true)
{
$this->bIncludePolygonAsPoints = $b;
}
public function setIncludePolygonAsText($b = true)
{
$this->bIncludePolygonAsText = $b;
}
public function setIncludePolygonAsGeoJSON($b = true)
{
$this->bIncludePolygonAsGeoJSON = $b;
}
public function setIncludePolygonAsKML($b = true)
{
$this->bIncludePolygonAsKML = $b;
}
public function setIncludePolygonAsSVG($b = true)
{
$this->bIncludePolygonAsSVG = $b;
}
public function setPolygonSimplificationThreshold($f)
{
$this->fPolygonSimplificationThreshold = $f;
}
public function setLimit($iLimit = 10) public function setLimit($iLimit = 10)
{ {
if ($iLimit > 50) $iLimit = 50; if ($iLimit > 50) $iLimit = 50;
@@ -229,17 +180,12 @@ class Geocode
} }
public function loadParamArray($oParams) public function loadParamArray($oParams, $sForceGeometryType = null)
{ {
$this->bIncludeAddressDetails $this->bIncludeAddressDetails
= $oParams->getBool('addressdetails', $this->bIncludeAddressDetails); = $oParams->getBool('addressdetails', $this->bIncludeAddressDetails);
$this->bIncludeExtraTags
= $oParams->getBool('extratags', $this->bIncludeExtraTags);
$this->bIncludeNameDetails
= $oParams->getBool('namedetails', $this->bIncludeNameDetails);
$this->bBoundedSearch = $oParams->getBool('bounded', $this->bBoundedSearch); $this->bBoundedSearch = $oParams->getBool('bounded', $this->bBoundedSearch);
$this->bDeDupe = $oParams->getBool('dedupe', $this->bDeDupe);
$this->setLimit($oParams->getInt('limit', $this->iFinalLimit)); $this->setLimit($oParams->getInt('limit', $this->iFinalLimit));
$this->iOffset = $oParams->getInt('offset', $this->iOffset); $this->iOffset = $oParams->getInt('offset', $this->iOffset);
@@ -298,6 +244,10 @@ class Geocode
} }
} }
} }
$this->oPlaceLookup->loadParamArray($oParams, $sForceGeometryType);
$this->oPlaceLookup->setIncludeAddressDetails(false);
$this->oPlaceLookup->setIncludePolygonAsPoints($oParams->getBool('polygon'));
} }
public function setQueryFromParams($oParams) public function setQueryFromParams($oParams)
@@ -906,26 +856,16 @@ class Geocode
return array(); return array();
} }
$oPlaceLookup = new PlaceLookup($this->oDB);
$oPlaceLookup->setIncludePolygonAsPoints($this->bIncludePolygonAsPoints);
$oPlaceLookup->setIncludePolygonAsText($this->bIncludePolygonAsText);
$oPlaceLookup->setIncludePolygonAsGeoJSON($this->bIncludePolygonAsGeoJSON);
$oPlaceLookup->setIncludePolygonAsKML($this->bIncludePolygonAsKML);
$oPlaceLookup->setIncludePolygonAsSVG($this->bIncludePolygonAsSVG);
$oPlaceLookup->setPolygonSimplificationThreshold($this->fPolygonSimplificationThreshold);
$oPlaceLookup->setDeDupe($this->bDeDupe);
if ($this->aAddressRankList) { if ($this->aAddressRankList) {
$oPlaceLookup->setAddressRankList($this->aAddressRankList); $this->oPlaceLookup->setAddressRankList($this->aAddressRankList);
} }
$oPlaceLookup->setAllowedTypesSQLList($this->sAllowedTypesSQLList); $this->oPlaceLookup->setAllowedTypesSQLList($this->sAllowedTypesSQLList);
$oPlaceLookup->setLanguagePreference($this->aLangPrefOrder); $this->oPlaceLookup->setLanguagePreference($this->aLangPrefOrder);
$oPlaceLookup->setIncludeExtraTags($this->bIncludeExtraTags);
$oPlaceLookup->setIncludeNameDetails($this->bIncludeNameDetails);
if ($oCtx->hasNearPoint()) { if ($oCtx->hasNearPoint()) {
$oPlaceLookup->setAnchorSql($oCtx->sqlNear); $this->oPlaceLookup->setAnchorSql($oCtx->sqlNear);
} }
$aSearchResults = $oPlaceLookup->lookup($aResults); $aSearchResults = $this->oPlaceLookup->lookup($aResults);
$aClassType = getClassTypesWithImportance(); $aClassType = getClassTypesWithImportance();
$aRecheckWords = preg_split('/\b[\s,\\-]*/u', $sQuery); $aRecheckWords = preg_split('/\b[\s,\\-]*/u', $sQuery);
@@ -942,7 +882,7 @@ class Geocode
// Default // Default
$fDiameter = getResultDiameter($aResult); $fDiameter = getResultDiameter($aResult);
$aOutlineResult = $oPlaceLookup->getOutlines($aResult['place_id'], $aResult['lon'], $aResult['lat'], $fDiameter/2); $aOutlineResult = $this->oPlaceLookup->getOutlines($aResult['place_id'], $aResult['lon'], $aResult['lat'], $fDiameter/2);
if ($aOutlineResult) { if ($aOutlineResult) {
$aResult = array_merge($aResult, $aOutlineResult); $aResult = array_merge($aResult, $aOutlineResult);
} }
@@ -1036,7 +976,7 @@ class Geocode
if (isset($aResult['zoom'])) $iZoom = $aResult['zoom']; if (isset($aResult['zoom'])) $iZoom = $aResult['zoom'];
$bFirst = false; $bFirst = false;
} }
if (!$this->bDeDupe || (!isset($aOSMIDDone[$aResult['osm_type'].$aResult['osm_id']]) if (!$this->oPlaceLookup->doDeDupe() || (!isset($aOSMIDDone[$aResult['osm_type'].$aResult['osm_id']])
&& !isset($aClassTypeNameDone[$aResult['osm_type'].$aResult['class'].$aResult['type'].$aResult['name'].$aResult['admin_level']])) && !isset($aClassTypeNameDone[$aResult['osm_type'].$aResult['class'].$aResult['type'].$aResult['name'].$aResult['admin_level']]))
) { ) {
$aOSMIDDone[$aResult['osm_type'].$aResult['osm_id']] = true; $aOSMIDDone[$aResult['osm_type'].$aResult['osm_id']] = true;

View File

@@ -32,19 +32,40 @@ class PlaceLookup
$this->oDB =& $oDB; $this->oDB =& $oDB;
} }
public function loadParamArray($oParams) public function doDeDupe()
{
return $this->bDeDupe;
}
public function setIncludePolygonAsPoints($b = true)
{
$this->bIncludePolygonAsPoints = $b;
}
public function loadParamArray($oParams, $sGeomType = null)
{ {
$aLangs = $oParams->getPreferredLanguages(); $aLangs = $oParams->getPreferredLanguages();
$this->aLangPrefOrderSql = $this->aLangPrefOrderSql =
'ARRAY['.join(',', array_map('getDBQuoted', $aLangs)).']'; 'ARRAY['.join(',', array_map('getDBQuoted', $aLangs)).']';
$this->bAddressDetails = $oParams->getBool('addressdetails', true);
$this->bExtraTags = $oParams->getBool('extratags', false); $this->bExtraTags = $oParams->getBool('extratags', false);
$this->bNameDetails = $oParams->getBool('namedetails', false); $this->bNameDetails = $oParams->getBool('namedetails', false);
$this->bIncludePolygonAsText = $oParams->getBool('polygon_text'); $this->bDeDupe = $oParams->getBool('dedupe', $this->bDeDupe);
$this->bIncludePolygonAsGeoJSON = $oParams->getBool('polygon_geojson');
$this->bIncludePolygonAsKML = $oParams->getBool('polygon_kml'); if ($sGeomType === null || $sGeomType == 'text') {
$this->bIncludePolygonAsSVG = $oParams->getBool('polygon_svg'); $this->bIncludePolygonAsText = $oParams->getBool('polygon_text');
}
if ($sGeomType === null || $sGeomType == 'geojson') {
$this->bIncludePolygonAsGeoJSON = $oParams->getBool('polygon_geojson');
}
if ($sGeomType === null || $sGeomType == 'kml') {
$this->bIncludePolygonAsKML = $oParams->getBool('polygon_kml');
}
if ($sGeomType === null || $sGeomType == 'svg') {
$this->bIncludePolygonAsSVG = $oParams->getBool('polygon_svg');
}
$this->fPolygonSimplificationThreshold $this->fPolygonSimplificationThreshold
= $oParams->getFloat('polygon_threshold', 0.0); = $oParams->getFloat('polygon_threshold', 0.0);
@@ -62,16 +83,34 @@ class PlaceLookup
} }
} }
public function getMoreUrlParams()
{
$aParams = array();
if ($this->bAddressDetails) $aParams['addressdetails'] = '1';
if ($this->bExtraTags) $aParams['extratags'] = '1';
if ($this->bNameDetails) $aParams['namedetails'] = '1';
if ($this->bIncludePolygonAsPoints) $aParams['polygon'] = '1';
if ($this->bIncludePolygonAsText) $aParams['polygon_text'] = '1';
if ($this->bIncludePolygonAsGeoJSON) $aParams['polygon_geojson'] = '1';
if ($this->bIncludePolygonAsKML) $aParams['polygon_kml'] = '1';
if ($this->bIncludePolygonAsSVG) $aParams['polygon_svg'] = '1';
if ($this->fPolygonSimplificationThreshold > 0.0) {
$aParams['polygon_threshold'] = $this->fPolygonSimplificationThreshold;
}
if (!$this->bDeDupe) $aParams['dedupe'] = '0';
return $aParams;
}
public function setAnchorSql($sPoint) public function setAnchorSql($sPoint)
{ {
$this->sAnchorSql = $sPoint; $this->sAnchorSql = $sPoint;
} }
public function setDeDupe($bDeDupe)
{
$this->bDeDupe = $bDeDupe;
}
public function setAddressRankList($aList) public function setAddressRankList($aList)
{ {
$this->sAddressRankListSql = '('.join(',', $aList).')'; $this->sAddressRankListSql = '('.join(',', $aList).')';
@@ -93,46 +132,6 @@ class PlaceLookup
$this->bAddressDetails = $bAddressDetails; $this->bAddressDetails = $bAddressDetails;
} }
public function setIncludeExtraTags($bExtraTags = false)
{
$this->bExtraTags = $bExtraTags;
}
public function setIncludeNameDetails($bNameDetails = false)
{
$this->bNameDetails = $bNameDetails;
}
public function setIncludePolygonAsPoints($b = true)
{
$this->bIncludePolygonAsPoints = $b;
}
public function setIncludePolygonAsText($b = true)
{
$this->bIncludePolygonAsText = $b;
}
public function setIncludePolygonAsGeoJSON($b = true)
{
$this->bIncludePolygonAsGeoJSON = $b;
}
public function setIncludePolygonAsKML($b = true)
{
$this->bIncludePolygonAsKML = $b;
}
public function setIncludePolygonAsSVG($b = true)
{
$this->bIncludePolygonAsSVG = $b;
}
public function setPolygonSimplificationThreshold($f)
{
$this->fPolygonSimplificationThreshold = $f;
}
private function addressImportanceSql($sGeometry, $sPlaceId) private function addressImportanceSql($sGeometry, $sPlaceId)
{ {
if ($this->sAnchorSql) { if ($this->sAnchorSql) {

View File

@@ -24,10 +24,7 @@ $aSearchResults = array();
$aCleanedQueryParts = array(); $aCleanedQueryParts = array();
$oPlaceLookup = new Nominatim\PlaceLookup($oDB); $oPlaceLookup = new Nominatim\PlaceLookup($oDB);
$oPlaceLookup->setLanguagePreference($aLangPrefOrder); $oPlaceLookup->loadParamArray($oParams);
$oPlaceLookup->setIncludeAddressDetails($oParams->getBool('addressdetails', true));
$oPlaceLookup->setIncludeExtraTags($oParams->getBool('extratags', false));
$oPlaceLookup->setIncludeNameDetails($oParams->getBool('namedetails', false));
$aOsmIds = explode(',', $oParams->getString('osm_ids', '')); $aOsmIds = explode(',', $oParams->getString('osm_ids', ''));

View File

@@ -23,7 +23,6 @@ $hLog = logStart($oDB, 'reverse', $_SERVER['QUERY_STRING'], $aLangPrefOrder);
$oPlaceLookup = new Nominatim\PlaceLookup($oDB); $oPlaceLookup = new Nominatim\PlaceLookup($oDB);
$oPlaceLookup->loadParamArray($oParams); $oPlaceLookup->loadParamArray($oParams);
$oPlaceLookup->setIncludeAddressDetails($oParams->getBool('addressdetails', true));
$sOsmType = $oParams->getSet('osm_type', array('N', 'W', 'R')); $sOsmType = $oParams->getSet('osm_type', array('N', 'W', 'R'));
$iOsmId = $oParams->getInt('osm_id', -1); $iOsmId = $oParams->getInt('osm_id', -1);

View File

@@ -28,36 +28,8 @@ if (CONST_Search_ReversePlanForAll
// Format for output // Format for output
$sOutputFormat = $oParams->getSet('format', array('html', 'xml', 'json', 'jsonv2'), 'html'); $sOutputFormat = $oParams->getSet('format', array('html', 'xml', 'json', 'jsonv2'), 'html');
// Show / use polygons $sForcedGeometry = ($sOutputFormat == 'html') ? "geojson" : null;
if ($sOutputFormat == 'html') { $oGeocode->loadParamArray($oParams, $sForcedGeometry);
$oGeocode->setIncludePolygonAsGeoJSON($oParams->getBool('polygon_geojson'));
$bAsGeoJSON = false;
} else {
$bAsPoints = $oParams->getBool('polygon');
$bAsGeoJSON = $oParams->getBool('polygon_geojson');
$bAsKML = $oParams->getBool('polygon_kml');
$bAsSVG = $oParams->getBool('polygon_svg');
$bAsText = $oParams->getBool('polygon_text');
$iWantedTypes = ($bAsGeoJSON?1:0) + ($bAsKML?1:0) + ($bAsSVG?1:0) + ($bAsText?1:0) + ($bAsPoints?1:0);
if ($iWantedTypes > CONST_PolygonOutput_MaximumTypes) {
if (CONST_PolygonOutput_MaximumTypes) {
userError("Select only ".CONST_PolygonOutput_MaximumTypes." polgyon output option");
} else {
userError("Polygon output is disabled");
}
exit;
}
$oGeocode->setIncludePolygonAsPoints($bAsPoints);
$oGeocode->setIncludePolygonAsText($bAsText);
$oGeocode->setIncludePolygonAsGeoJSON($bAsGeoJSON);
$oGeocode->setIncludePolygonAsKML($bAsKML);
$oGeocode->setIncludePolygonAsSVG($bAsSVG);
}
// Polygon simplification threshold (optional)
$oGeocode->setPolygonSimplificationThreshold($oParams->getFloat('polygon_threshold', 0.0));
$oGeocode->loadParamArray($oParams);
if (CONST_Search_BatchMode && isset($_GET['batch'])) { if (CONST_Search_BatchMode && isset($_GET['batch'])) {
$aBatch = json_decode($_GET['batch'], true); $aBatch = json_decode($_GET['batch'], true);