]> git.openstreetmap.org Git - nominatim.git/blobdiff - lib/lib.php
remove unused/unmaintained options in import scripts
[nominatim.git] / lib / lib.php
index d390a482805768f53af3881fd99837232ef1d0b8..fccda314e52904458396953d8f00d858fb7d8516 100644 (file)
@@ -77,7 +77,7 @@
        function getProcessorCount()
        {
                $sCPU = file_get_contents('/proc/cpuinfo');
-               preg_match_all('#processor      : [0-9]+#', $sCPU, $aMatches);
+               preg_match_all('#processor\s+: [0-9]+#', $sCPU, $aMatches);
                return sizeof($aMatches[0]);
        }
 
                   return ($a['aPointPolygon']['numfeatures'] > $b['aPointPolygon']['numfeatures']?-1:1);
                   if ($a['aPointPolygon']['area'] != $b['aPointPolygon']['area'])
                   return ($a['aPointPolygon']['area'] > $b['aPointPolygon']['area']?-1:1);
-               //              if ($a['levenshtein'] != $b['levenshtein'])
-               //                      return ($a['levenshtein'] < $b['levenshtein']?-1:1);
+               //      if ($a['levenshtein'] != $b['levenshtein'])
+               //          return ($a['levenshtein'] < $b['levenshtein']?-1:1);
                if ($a['rank_search'] != $b['rank_search'])
                return ($a['rank_search'] < $b['rank_search']?-1:1);
                 */
                return $aOrders;
        }
 
+       function getResultDiameter($aResult)
+       {
+               $aClassType = getClassTypes();
+
+               $fDiameter = 0.0001;
+
+               if (isset($aResult['class'])
+                         && isset($aResult['type'])
+                         && isset($aResult['admin_level'])
+                         && 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']]['defdiameter'];
+               }
+               elseif (isset($aResult['class'])
+                         && isset($aResult['type'])
+                         && isset($aClassType[$aResult['class'].':'.$aResult['type']]['defdiameter'])
+                               && $aClassType[$aResult['class'].':'.$aResult['type']]['defdiameter'])
+               {
+                       $fDiameter = $aClassType[$aResult['class'].':'.$aResult['type']]['defdiameter'];
+               }
+
+               return $fDiameter;
+       }
+
 
        function javascript_renderData($xVal, $iOptions = 0)
        {
        }
 
 
-       function getAddressDetails(&$oDB, $sLanguagePrefArraySQL, $iPlaceID, $sCountryCode = false, $housenumber, $bRaw = false)
+       function getAddressDetails(&$oDB, $sLanguagePrefArraySQL, $iPlaceID, $sCountryCode = false, $housenumber = -1, $bRaw = false)
        {
                $sSQL = "select *,get_name_by_language(name,$sLanguagePrefArraySQL) as localname from get_addressdata($iPlaceID, $housenumber)";
                if (!$bRaw) $sSQL .= " WHERE isaddress OR type = 'country_code'";
        }
 
 
-
-       function geometryText2Points($geometry_as_text,$fRadius)
+       function geometryText2Points($geometry_as_text, $fRadius)
        {
                $aPolyPoints = NULL;
-               if (preg_match('#POLYGON\\(\\(([- 0-9.,]+)#',$geometry_as_text,$aMatch))
+               if (preg_match('#POLYGON\\(\\(([- 0-9.,]+)#', $geometry_as_text, $aMatch))
                {
-                       preg_match_all('/(-?[0-9.]+) (-?[0-9.]+)/',$aMatch[1],$aPolyPoints,PREG_SET_ORDER);
+                       preg_match_all('/(-?[0-9.]+) (-?[0-9.]+)/', $aMatch[1], $aPolyPoints, PREG_SET_ORDER);
                }
-               elseif (preg_match('#MULTIPOLYGON\\(\\(\\(([- 0-9.,]+)#',$geometry_as_text,$aMatch))
+               elseif (preg_match('#LINESTRING\\(([- 0-9.,]+)#', $geometry_as_text, $aMatch))
                {
-                       preg_match_all('/(-?[0-9.]+) (-?[0-9.]+)/',$aMatch[1],$aPolyPoints,PREG_SET_ORDER);
+                       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))
+               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))
+               {
+                       $aPolyPoints = createPointsAroundCenter($aMatch[1], $aMatch[2], $fRadius);
+               }
+
+               if (isset($aPolyPoints))
+               {
+                       $aResultPoints = array();
+                       foreach($aPolyPoints as $aPoint)
+                       {
+                               $aResultPoints[] = array($aPoint[1], $aPoint[2]);
+                       }
+                       return $aResultPoints;
+               }
+
+               return;
+       }
+
+       function createPointsAroundCenter($fLon, $fLat, $fRadius)
+       {
                        $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)));
+                               $aPolyPoints[] = array('', $fLon+($fRadius*sin($f)), $fLat+($fRadius*cos($f)) );
                        }
-               }
-               return $aPolyPoints;
+                       return $aPolyPoints;
        }