【问题标题】:Get center and furthest point of polygon to extend area by radius in mysql获取多边形的中心和最远点以在mysql中按半径扩展区域
【发布时间】:2016-06-22 16:56:47
【问题描述】:

因为我的另一个问题没有成功 (How to extend polygon by a certain distance in PHP/Mysql?),我正在考虑找到一个更简单的解决方案。

我有一个位置表(由 lat 和 lng 定义)和一个位置表(存储为几何图形的多边形)。我需要的是在多边形+一定半径(例如1/4英里)内搜索mysql中的记录。

有ST_Centroid函数可以获取多边形的中心点,但是如何获取中心点和最远点之间的距离以获得圆的扩展半径?

【问题讨论】:

    标签: mysql geolocation polygon geo


    【解决方案1】:

    圆是扩展多边形最简单的解决方案,但总比没有好。

    这是获取多边形最远点的计算方法。 $polygon$centroid 取自数据库(在 mysql 中:ST_AsText(polygon), ST_AsText(ST_Centroid(polygon)))并转换为数组。

    function get_max_point ($polygon,$centroid) {
      foreach ($polygon AS $point) {
        $distance = (sin(deg2rad($centroid['lat'])) * sin(deg2rad($point['lat']))) + (cos(deg2rad($centroid['lat'])) * cos(deg2rad($point['lat'])) * cos(deg2rad($centroid['lng'] - $point['lng'])));
        $distance = acos($distance);
        $distance = rad2deg($distance);
        $distance = $distance * 60 * 1.152;
        if($distance>$distance_max) $distance_max=$distance;
      }
      return (round($distance_max,2));
    }
    

    【讨论】:

      猜你喜欢
      • 2016-10-11
      • 2020-01-11
      • 1970-01-01
      • 2015-10-16
      • 1970-01-01
      • 2021-10-01
      • 1970-01-01
      • 2011-07-03
      • 1970-01-01
      相关资源
      最近更新 更多