gpt4 book ai didi

php - 如何在 PHP mysql 中检查点是否在多边形内

转载 作者:行者123 更新时间:2023-11-29 09:53:31 25 4
gpt4 key购买 nike

我正在尝试获取形状文件中的点。我已经尝试了空间函数,它显示了一个名为

的错误

3033 - Binary geometry function st_contains given two geometries of different srids: 4326 and 0, which should have been identical.

我的查询是

SELECT lightning.lightning_id,lightning.latitude,lightning.longitude,
lightning.flash_type, DATE_FORMAT(lightning.lightning_time, '%D %b %Y %T %p') as lightning_time FROM lightning, districts_s
WHERE ST_CONTAINS(districts_s.SHAPE, Point(lightning.longitude, lightning.latitude)) AND lightning.height > 50

为了纠正错误,我从 here 获得了解决方案还有这个link但没有结果。因为这也显示了一个名为

的错误

ST_Transform does not exist

我使用的是 PHP 5.6。任何解决方案都非常有帮助。

最佳答案

您可以尝试使用 PHP 代码。

$point = array(22.765863,75.887488);
$vs = array();
$polygonPoints = '[{"lat":22.765863133410004,"lng":75.88748805487819},{"lat":22.76631821037386,"lng":75.89153282607265},{"lat":22.76462650356429,"lng":75.89126460517116},{"lat":22.764082382883878,"lng":75.89017026389308},{"lat":22.76430992452311,"lng":75.88933341468044},{"lat":22.763815268301787,"lng":75.88875405753322},{"lat":22.764705648209898,"lng":75.8886253115005},{"lat":22.764438534847113,"lng":75.88744513953395},{"lat":22.765229980328275,"lng":75.88824980223842}]';


$boundries = json_decode($polygonPoints);

foreach ($boundries as $key => $val)
{
$polygon[$key] = array($val->lat,$val->lng);
}

// Check Point Inside Polygone

$check = pointInPolygon($point, $polygon);
if($check == true)
{
echo "This point inside in polygone";
}
function pointInPolygon($point, $vs)
{
$x = $point[0];
$y = $point[1];

$inside = false;
for ($i = 0, $j = count($vs) - 1; $i < count($vs); $j = $i++) {
$xi = $vs[$i][0];
$yi = $vs[$i][1];
$xj = $vs[$j][0];
$yj = $vs[$j][1];

$intersect = (($yi > $y) != ($yj > $y))
&& ($x < ($xj - $xi) * ($y - $yi) / ($yj - $yi) + $xi);
if ($intersect) $inside = !$inside;
}

return $inside;;
}

关于php - 如何在 PHP mysql 中检查点是否在多边形内,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54325845/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com