]> git.openstreetmap.org Git - nominatim.git/commitdiff
moved bIncludePolygonAsPoints related logic into lib.php, added tests
authorMarc Tobias Metten <mtmail@gmx.net>
Sun, 28 Feb 2016 16:06:52 +0000 (17:06 +0100)
committerMarkus Gail <markus.gail.94@gmail.com>
Mon, 21 Mar 2016 12:32:44 +0000 (13:32 +0100)
lib/Geocode.php
lib/lib.php

index ba1842c3c33a062acceff7ce966cd33960f8fafc..a6ff279ca973d17c0488eef7eb5b5c0ddd0451d9 100644 (file)
                        {
                                // Start with a blank search
                                $aSearches = array(
-                                       array('iSearchRank' => 0, 'iNamePhrase' => -1, 'sCountryCode' => false, 'aName'=>array(), 'aAddress'=>array(), 'aFullNameAddress'=>array(),
-                                                               'aNameNonSearch'=>array(), 'aAddressNonSearch'=>array(),
-                                                               'sOperator'=>'', 'aFeatureName' => array(), 'sClass'=>'', 'sType'=>'', 'sHouseNumber'=>'', 'fLat'=>'', 'fLon'=>'', 'fRadius'=>'')
+                                       array('iSearchRank' => 0, 
+                                                               'iNamePhrase' => -1, 
+                                                               '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?
 
                                                if ($this->bIncludePolygonAsPoints)
                                                {
-                                                       // Translate geometry string to point array
-                                                       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))
+                                                       $aPolyPoints[] = geometryText2Points($aPointPolygon['astext'],$fRadius);
+
+                                                       // Output data suitable for display (points and a bounding box)
+                                                       if (isset($aPolyPoints))
                                                        {
-                                                               $iSteps = max(8, min(100, ($fRadius * 40000)^2));
-                                                               $fStepSize = (2*pi())/$iSteps;
-                                                               $aPolyPoints = array();
-                                                               for($f = 0; $f < 2*pi(); $f += $fStepSize)
+                                                               $aResult['aPolyPoints'] = array();
+                                                               foreach($aPolyPoints as $aPoint)
                                                                {
-                                                                       $aPolyPoints[] = array('',$aMatch[1]+($fRadius*sin($f)),$aMatch[2]+($fRadius*cos($f)));
+                                                                       $aResult['aPolyPoints'][] = array($aPoint[1], $aPoint[2]);
                                                                }
                                                        }
                                                }
 
-                                               // Output data suitable for display (points and a bounding box)
-                                               if ($this->bIncludePolygonAsPoints && isset($aPolyPoints))
-                                               {
-                                                       $aResult['aPolyPoints'] = array();
-                                                       foreach($aPolyPoints as $aPoint)
-                                                       {
-                                                               $aResult['aPolyPoints'][] = array($aPoint[1], $aPoint[2]);
-                                                       }
-                                               }
-
                                                if (abs($aPointPolygon['minlat'] - $aPointPolygon['maxlat']) < 0.0000001)
                                                {
                                                        $aPointPolygon['minlat'] = $aPointPolygon['minlat'] - $fRadius;
index 2134e1a44d78aae77f6769a3cac28f35bae2effa..e81d85becc68ffe9aac16dcb73a56a030c0e9fe9 100644 (file)
 
                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;
+       }