mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-02-26 02:58:13 +00:00
moved bIncludePolygonAsPoints related logic into lib.php, added tests
This commit is contained in:
committed by
Markus Gail
parent
9fb413a126
commit
607fef2d8f
@@ -862,9 +862,23 @@
|
|||||||
{
|
{
|
||||||
// Start with a blank search
|
// Start with a blank search
|
||||||
$aSearches = array(
|
$aSearches = array(
|
||||||
array('iSearchRank' => 0, 'iNamePhrase' => -1, 'sCountryCode' => false, 'aName'=>array(), 'aAddress'=>array(), 'aFullNameAddress'=>array(),
|
array('iSearchRank' => 0,
|
||||||
'aNameNonSearch'=>array(), 'aAddressNonSearch'=>array(),
|
'iNamePhrase' => -1,
|
||||||
'sOperator'=>'', 'aFeatureName' => array(), 'sClass'=>'', 'sType'=>'', 'sHouseNumber'=>'', 'fLat'=>'', 'fLon'=>'', 'fRadius'=>'')
|
'sCountryCode' => false,
|
||||||
|
'aName' => array(),
|
||||||
|
'aAddress' => array(),
|
||||||
|
'aFullNameAddress' => array(),
|
||||||
|
'aNameNonSearch' => array(),
|
||||||
|
'aAddressNonSearch' => array(),
|
||||||
|
'sOperator' => '',
|
||||||
|
'aFeatureName' => array(),
|
||||||
|
'sClass' => '',
|
||||||
|
'sType' => '',
|
||||||
|
'sHouseNumber' => '',
|
||||||
|
'fLat' => '',
|
||||||
|
'fLon' => '',
|
||||||
|
'fRadius' => ''
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Do we have a radius search?
|
// Do we have a radius search?
|
||||||
@@ -1676,34 +1690,16 @@
|
|||||||
|
|
||||||
if ($this->bIncludePolygonAsPoints)
|
if ($this->bIncludePolygonAsPoints)
|
||||||
{
|
{
|
||||||
// Translate geometry string to point array
|
$aPolyPoints[] = geometryText2Points($aPointPolygon['astext'],$fRadius);
|
||||||
if (preg_match('#POLYGON\\(\\(([- 0-9.,]+)#',$aPointPolygon['astext'],$aMatch))
|
|
||||||
{
|
|
||||||
preg_match_all('/(-?[0-9.]+) (-?[0-9.]+)/',$aMatch[1],$aPolyPoints,PREG_SET_ORDER);
|
|
||||||
}
|
|
||||||
elseif (preg_match('#MULTIPOLYGON\\(\\(\\(([- 0-9.,]+)#',$aPointPolygon['astext'],$aMatch))
|
|
||||||
{
|
|
||||||
preg_match_all('/(-?[0-9.]+) (-?[0-9.]+)/',$aMatch[1],$aPolyPoints,PREG_SET_ORDER);
|
|
||||||
}
|
|
||||||
elseif (preg_match('#POINT\\((-?[0-9.]+) (-?[0-9.]+)\\)#',$aPointPolygon['astext'],$aMatch))
|
|
||||||
{
|
|
||||||
$iSteps = max(8, min(100, ($fRadius * 40000)^2));
|
|
||||||
$fStepSize = (2*pi())/$iSteps;
|
|
||||||
$aPolyPoints = array();
|
|
||||||
for($f = 0; $f < 2*pi(); $f += $fStepSize)
|
|
||||||
{
|
|
||||||
$aPolyPoints[] = array('',$aMatch[1]+($fRadius*sin($f)),$aMatch[2]+($fRadius*cos($f)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Output data suitable for display (points and a bounding box)
|
// Output data suitable for display (points and a bounding box)
|
||||||
if ($this->bIncludePolygonAsPoints && isset($aPolyPoints))
|
if (isset($aPolyPoints))
|
||||||
{
|
|
||||||
$aResult['aPolyPoints'] = array();
|
|
||||||
foreach($aPolyPoints as $aPoint)
|
|
||||||
{
|
{
|
||||||
$aResult['aPolyPoints'][] = array($aPoint[1], $aPoint[2]);
|
$aResult['aPolyPoints'] = array();
|
||||||
|
foreach($aPolyPoints as $aPoint)
|
||||||
|
{
|
||||||
|
$aResult['aPolyPoints'][] = array($aPoint[1], $aPoint[2]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
26
lib/lib.php
26
lib/lib.php
@@ -1022,3 +1022,29 @@
|
|||||||
|
|
||||||
return array('lat' => $fQueryLat, 'lon' => $fQueryLon, 'query' => $sQuery);
|
return array('lat' => $fQueryLat, 'lon' => $fQueryLon, 'query' => $sQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function geometryText2Points($geometry_as_text,$fRadius)
|
||||||
|
{
|
||||||
|
$aPolyPoints = NULL;
|
||||||
|
if (preg_match('#POLYGON\\(\\(([- 0-9.,]+)#',$geometry_as_text,$aMatch))
|
||||||
|
{
|
||||||
|
preg_match_all('/(-?[0-9.]+) (-?[0-9.]+)/',$aMatch[1],$aPolyPoints,PREG_SET_ORDER);
|
||||||
|
}
|
||||||
|
elseif (preg_match('#MULTIPOLYGON\\(\\(\\(([- 0-9.,]+)#',$geometry_as_text,$aMatch))
|
||||||
|
{
|
||||||
|
preg_match_all('/(-?[0-9.]+) (-?[0-9.]+)/',$aMatch[1],$aPolyPoints,PREG_SET_ORDER);
|
||||||
|
}
|
||||||
|
elseif (preg_match('#POINT\\((-?[0-9.]+) (-?[0-9.]+)\\)#',$geometry_as_text,$aMatch))
|
||||||
|
{
|
||||||
|
$iSteps = max(8, min(100, ($fRadius * 40000)^2));
|
||||||
|
$fStepSize = (2*pi())/$iSteps;
|
||||||
|
$aPolyPoints = array();
|
||||||
|
for($f = 0; $f < 2*pi(); $f += $fStepSize)
|
||||||
|
{
|
||||||
|
$aPolyPoints[] = array('',$aMatch[1]+($fRadius*sin($f)),$aMatch[2]+($fRadius*cos($f)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $aPolyPoints;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user