Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获取多边形的中心和最远点,以在mysql中按半径扩展面积_Mysql_Geolocation_Polygon_Geo - Fatal编程技术网

获取多边形的中心和最远点,以在mysql中按半径扩展面积

获取多边形的中心和最远点,以在mysql中按半径扩展面积,mysql,geolocation,polygon,geo,Mysql,Geolocation,Polygon,Geo,因为我的另一个问题没有成功 (),我在想一个更简单的解决办法 我有一个位置表(由lat和lng定义)和一个位置表(存储为几何体的多边形)。我需要的是在mysql中搜索多边形+一定半径(例如1/4英里)内的记录 有函数ST_形心用于获取多边形的中心点,但如何获取中心点和最远点之间的距离以获得圆的扩展半径 圆是扩展多边形的最简单解决方案,但总比没有好 下面是获取多边形最远点的计算$多边形和$centroid取自数据库(在mysql中:ST_AsText(多边形)、ST_AsText(ST_centr

因为我的另一个问题没有成功 (),我在想一个更简单的解决办法

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

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


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

下面是获取多边形最远点的计算$多边形和$centroid取自数据库(在mysql中:ST_AsText(多边形)、ST_AsText(ST_centroid(多边形)),并转换为数组

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));
}