protected $aLangPrefOrder = array();
protected $bIncludeAddressDetails = false;
+ protected $bIncludeExtraTags = false;
+ protected $bIncludeNameDetails = false;
protected $bIncludePolygonAsPoints = false;
protected $bIncludePolygonAsText = false;
return $this->bIncludeAddressDetails;
}
+ function getIncludeExtraTags()
+ {
+ return $this->bIncludeExtraTags;
+ }
+
+ function getIncludeNameDetails()
+ {
+ return $this->bIncludeNameDetails;
+ }
+
function setIncludePolygonAsPoints($b = true)
{
$this->bIncludePolygonAsPoints = $b;
function loadParamArray($aParams)
{
if (isset($aParams['addressdetails'])) $this->bIncludeAddressDetails = (bool)$aParams['addressdetails'];
+ if ((float) CONST_Postgresql_Version > 9.2)
+ {
+ if (isset($aParams['extratags'])) $this->bIncludeExtraTags = (bool)$aParams['extratags'];
+ if (isset($aParams['namedetails'])) $this->bIncludeNameDetails = (bool)$aParams['namedetails'];
+ }
if (isset($aParams['bounded'])) $this->bBoundedSearch = (bool)$aParams['bounded'];
if (isset($aParams['dedupe'])) $this->bDeDupe = (bool)$aParams['dedupe'];
$sSQL .= "get_address_by_language(place_id, $sLanguagePrefArraySQL) as langaddress,";
$sSQL .= "get_name_by_language(name, $sLanguagePrefArraySQL) as placename,";
$sSQL .= "get_name_by_language(name, ARRAY['ref']) as ref,";
+ if ($this->bIncludeExtraTags) $sSQL .= "hstore_to_json(extratags)::text as extra,";
+ if ($this->bIncludeNameDetails) $sSQL .= "hstore_to_json(name)::text as names,";
$sSQL .= "avg(ST_X(centroid)) as lon,avg(ST_Y(centroid)) as lat, ";
$sSQL .= $sImportanceSQL."coalesce(importance,0.75-(rank_search::float/40)) as importance, ";
$sSQL .= "(select max(p.importance*(p.rank_address+2)) from place_addressline s, placex p where s.place_id = min(CASE WHEN placex.rank_search < 28 THEN placex.place_id ELSE placex.parent_place_id END) and p.place_id = s.address_place_id and s.isaddress and p.importance is not null) as addressimportance, ";
$sSQL .= ",langaddress ";
$sSQL .= ",placename ";
$sSQL .= ",ref ";
+ if ($this->bIncludeExtraTags) $sSQL .= ",extratags";
+ if ($this->bIncludeNameDetails) $sSQL .= ",name";
$sSQL .= ",extratags->'place' ";
if (30 >= $this->iMinAddressRank && 30 <= $this->iMaxAddressRank)
$sSQL .= "get_address_by_language(place_id, $sLanguagePrefArraySQL) as langaddress,";
$sSQL .= "null as placename,";
$sSQL .= "null as ref,";
+ if ($this->bIncludeExtraTags) $sSQL .= "null as extra,";
+ if ($this->bIncludeNameDetails) $sSQL .= "null as names,";
$sSQL .= "avg(ST_X(centroid)) as lon,avg(ST_Y(centroid)) as lat, ";
$sSQL .= $sImportanceSQL."-1.15 as importance, ";
$sSQL .= "(select max(p.importance*(p.rank_address+2)) from place_addressline s, placex p where s.place_id = min(location_property_tiger.parent_place_id) and p.place_id = s.address_place_id and s.isaddress and p.importance is not null) as addressimportance, ";
$sSQL .= "get_address_by_language(place_id, $sLanguagePrefArraySQL) as langaddress,";
$sSQL .= "null as placename,";
$sSQL .= "null as ref,";
+ if ($this->bIncludeExtraTags) $sSQL .= "null as extra,";
+ if ($this->bIncludeNameDetails) $sSQL .= "null as names,";
$sSQL .= "avg(ST_X(centroid)) as lon,avg(ST_Y(centroid)) as lat, ";
$sSQL .= $sImportanceSQL."-1.10 as importance, ";
$sSQL .= "(select max(p.importance*(p.rank_address+2)) from place_addressline s, placex p where s.place_id = min(location_property_aux.parent_place_id) and p.place_id = s.address_place_id and s.isaddress and p.importance is not null) as addressimportance, ";
if (isset($aClassType[$aResult['class'].':'.$aResult['type'].':'.$aResult['admin_level']]['defdiameter'])
&& $aClassType[$aResult['class'].':'.$aResult['type'].':'.$aResult['admin_level']]['defdiameter'])
{
- $fDiameter = $aClassType[$aResult['class'].':'.$aResult['type'].':'.$aResult['admin_level']]['defzoom'];
+ $fDiameter = $aClassType[$aResult['class'].':'.$aResult['type'].':'.$aResult['admin_level']]['defdiameter'];
}
elseif (isset($aClassType[$aResult['class'].':'.$aResult['type']]['defdiameter'])
&& $aClassType[$aResult['class'].':'.$aResult['type']]['defdiameter'])
}
elseif (preg_match('#POINT\\((-?[0-9.]+) (-?[0-9.]+)\\)#',$aPointPolygon['astext'],$aMatch))
{
- $iSteps = ($fRadius * 40000)^2;
+ $iSteps = max(8, min(100, ($fRadius * 40000)^2));
$fStepSize = (2*pi())/$iSteps;
$aPolyPoints = array();
for($f = 0; $f < 2*pi(); $f += $fStepSize)
$aPointPolygon['minlon'] = $aPointPolygon['minlon'] - $fRadius;
$aPointPolygon['maxlon'] = $aPointPolygon['maxlon'] + $fRadius;
}
- $aResult['aBoundingBox'] = array($aPointPolygon['minlat'],$aPointPolygon['maxlat'],$aPointPolygon['minlon'],$aPointPolygon['maxlon']);
+ $aResult['aBoundingBox'] = array((string)$aPointPolygon['minlat'],(string)$aPointPolygon['maxlat'],(string)$aPointPolygon['minlon'],(string)$aPointPolygon['maxlon']);
}
}
}
}
+ if ($this->bIncludeExtraTags)
+ {
+ if ($aResult['extra'])
+ {
+ $aResult['sExtraTags'] = json_decode($aResult['extra']);
+ }
+ else
+ {
+ $aResult['sExtraTags'] = (object) array();
+ }
+ }
+
+ if ($this->bIncludeNameDetails)
+ {
+ if ($aResult['names'])
+ {
+ $aResult['sNameDetails'] = json_decode($aResult['names']);
+ }
+ else
+ {
+ $aResult['sNameDetails'] = (object) array();
+ }
+ }
+
// Adjust importance for the number of exact string matches in the result
$aResult['importance'] = max(0.001,$aResult['importance']);
$iCountWords = 0;
{
$aResult['foundorder'] += 0.01;
}
+ if (CONST_Debug) { var_dump($aResult); }
$aSearchResults[$iResNum] = $aResult;
}
uasort($aSearchResults, 'byImportance');