Php 地理坐标周围的边界

Php 地理坐标周围的边界,php,google-maps,google-maps-api-3,geocoding,Php,Google Maps,Google Maps Api 3,Geocoding,我有一组地理坐标显示在谷歌地图上。如何确定最外面的点来构建包含所有点的多边形边界 我已经知道如何创建多边形了。但我需要确定所有的外部点 所有地理坐标都在mysql数据库中。我想使用PHP来分离创建多边形所需的坐标 我不想看如何做边界框。您可以使用delaunay三角剖分并连接凸包上的所有顶点,即查找不与相邻顶点的顶点。您可以下载我的php类凸面外壳@phpclasses.org。你也可以看看我的网站,作为一个delaunay三角剖分和基于lat lng对的凹面船体的例子。您可以使用我的示例5来查

我有一组地理坐标显示在谷歌地图上。如何确定最外面的点来构建包含所有点的多边形边界

我已经知道如何创建多边形了。但我需要确定所有的外部点

所有地理坐标都在mysql数据库中。我想使用PHP来分离创建多边形所需的坐标


我不想看如何做边界框。

您可以使用delaunay三角剖分并连接凸包上的所有顶点,即查找不与相邻顶点的顶点。您可以下载我的php类凸面外壳@phpclasses.org。你也可以看看我的网站,作为一个delaunay三角剖分和基于lat lng对的凹面船体的例子。您可以使用我的示例5来查找lat lng对的凸包:

require_once("convex-hull.php"); 
//example5 
$mapPadding  = 100; 
$mapWidth    = 500; 
$mapHeight   = 500; 
$mapLonLeft  =1000; 
$mapLatBottom=1000; 
$mapLonRight =   0; 
$mapLatTop   =   0; 
$set=array(); 
$geocoord = array ("8.6544487,50.1005233", 
                   "8.7839489,50.0907496", 
                   "8.1004734,50.2002273", 
                   "8.4117234,50.0951493", 
                   "8.3508367,49.4765982", 
                   "9.1828630,48.7827027", 
                   "9.1686483,48.7686426", 
                   "9.2118466,48.7829101", 
                   "8.9670738,48.9456327"); 

foreach ($geocoord as $key => $arr) 
{ 
    list($lon,$lat) = explode(",",$arr); 
    $mapLonLeft = min($mapLonLeft,$lon); 
    $mapLonRight = max($mapLonRight,$lon); 
    $mapLatBottom = min($mapLatBottom,$lat); 
    $mapLatTop = max($mapLatTop,$lat); 
    $set[]=array($lon,$lat); 
} 

$mapLonDelta = $mapLonRight-$mapLonLeft; 
$mapLatDelta = $mapLatTop-$mapLatBottom; 
$mapLatTopY=$mapLatTop*(M_PI/180); 
$worldMapWidth=(($mapWidth/$mapLonDelta)*360)/(2*M_PI); 
$LatBottomSin=min(max(sin($mapLatBottom*(M_PI/180)),-0.9999),0.9999); 
$mapOffsetY=$worldMapWidth/2 * log((1+$LatBottomSin)/(1-$LatBottomSin)); 
$LatTopSin=min(max(sin($mapLatTop*(M_PI/180)),-0.9999),0.9999); 
$mapOffsetTopY=$worldMapWidth/2 * log((1+$LatTopSin)/(1-$LatTopSin)); 
$mapHeightD=$mapOffsetTopY-$mapOffsetY; 
$mapRatioH=$mapHeight/$mapHeightD; 
$newWidth=$mapWidth*($mapHeightD/$mapHeight); 
$mapRatioW=$mapWidth/$newWidth; 

foreach ($set as $key => $arr) 
{ 
    list($lon,$lat) = $arr; 
    $tx = ($lon - $mapLonLeft) * ($newWidth/$mapLonDelta)*$mapRatioW; 
    $f = sin($lat*M_PI/180); 
    $ty = ($mapHeightD-(($worldMapWidth/2 * log((1+$f)/(1-$f)))-$mapOffsetY)); 
} 

$chull=new convexhull(); 
$chull->main($set,$mapWidth,$mapHeightD); 
foreach ($chull->convexhull as $key => $arr)
      {
     foreach ($arr as $ikey => $iarr)
     {
        list($x1,$y1,$x2,$y2) = $iarr;
        if (abs($x1) != SUPER_TRIANGLE && abs($y1) != SUPER_TRIANGLE && abs($x2) != SUPER_TRIANGLE && abs($y2) != SUPER_TRIANGLE)
        {
           $ok=0;
           foreach ($chull->pointset as $iikey => $iiarr)
           {
          if ($iiarr==array($x1,$y1))
          {
             $ok=1;
          }
           }
           if ($ok)
           {
          solution[]=set[$iikey];  
           }
        }
     }
      }
然后凸包在数组中,您需要从超三角形中删除顶点,并检查顶点是否在lat lng对中:

require_once("convex-hull.php"); 
//example5 
$mapPadding  = 100; 
$mapWidth    = 500; 
$mapHeight   = 500; 
$mapLonLeft  =1000; 
$mapLatBottom=1000; 
$mapLonRight =   0; 
$mapLatTop   =   0; 
$set=array(); 
$geocoord = array ("8.6544487,50.1005233", 
                   "8.7839489,50.0907496", 
                   "8.1004734,50.2002273", 
                   "8.4117234,50.0951493", 
                   "8.3508367,49.4765982", 
                   "9.1828630,48.7827027", 
                   "9.1686483,48.7686426", 
                   "9.2118466,48.7829101", 
                   "8.9670738,48.9456327"); 

foreach ($geocoord as $key => $arr) 
{ 
    list($lon,$lat) = explode(",",$arr); 
    $mapLonLeft = min($mapLonLeft,$lon); 
    $mapLonRight = max($mapLonRight,$lon); 
    $mapLatBottom = min($mapLatBottom,$lat); 
    $mapLatTop = max($mapLatTop,$lat); 
    $set[]=array($lon,$lat); 
} 

$mapLonDelta = $mapLonRight-$mapLonLeft; 
$mapLatDelta = $mapLatTop-$mapLatBottom; 
$mapLatTopY=$mapLatTop*(M_PI/180); 
$worldMapWidth=(($mapWidth/$mapLonDelta)*360)/(2*M_PI); 
$LatBottomSin=min(max(sin($mapLatBottom*(M_PI/180)),-0.9999),0.9999); 
$mapOffsetY=$worldMapWidth/2 * log((1+$LatBottomSin)/(1-$LatBottomSin)); 
$LatTopSin=min(max(sin($mapLatTop*(M_PI/180)),-0.9999),0.9999); 
$mapOffsetTopY=$worldMapWidth/2 * log((1+$LatTopSin)/(1-$LatTopSin)); 
$mapHeightD=$mapOffsetTopY-$mapOffsetY; 
$mapRatioH=$mapHeight/$mapHeightD; 
$newWidth=$mapWidth*($mapHeightD/$mapHeight); 
$mapRatioW=$mapWidth/$newWidth; 

foreach ($set as $key => $arr) 
{ 
    list($lon,$lat) = $arr; 
    $tx = ($lon - $mapLonLeft) * ($newWidth/$mapLonDelta)*$mapRatioW; 
    $f = sin($lat*M_PI/180); 
    $ty = ($mapHeightD-(($worldMapWidth/2 * log((1+$f)/(1-$f)))-$mapOffsetY)); 
} 

$chull=new convexhull(); 
$chull->main($set,$mapWidth,$mapHeightD); 
foreach ($chull->convexhull as $key => $arr)
      {
     foreach ($arr as $ikey => $iarr)
     {
        list($x1,$y1,$x2,$y2) = $iarr;
        if (abs($x1) != SUPER_TRIANGLE && abs($y1) != SUPER_TRIANGLE && abs($x2) != SUPER_TRIANGLE && abs($y2) != SUPER_TRIANGLE)
        {
           $ok=0;
           foreach ($chull->pointset as $iikey => $iiarr)
           {
          if ($iiarr==array($x1,$y1))
          {
             $ok=1;
          }
           }
           if ($ok)
           {
          solution[]=set[$iikey];  
           }
        }
     }
      }

完美的这正是我需要知道的。5000或20000分的表现如何?如果我的答案是有用的,请考虑接受它。非常感谢你!?是的,我不确定接受它是否会阻止进一步的评论。谢谢你的帮助。我必须测试性能。高达2000-5000分,问题不大。但是,可以使用另一种算法将点提升到抛物面。但也可以尝试快速外壳算法:。Phpdna,快速外壳非常容易使用。不完美。谢谢你的建议。我想试试你的,但觉得有点难。它只返回图像吗?您能否分享一个传入地理坐标数组并仅返回边坐标作为数组的示例?非常感谢。