Php 检查横向/纵向位置是否位于多边形内
我需要检查用户lat和long是否驻留在多边形中 我的mysql版本是5.1.73 我尝试的查询如下Php 检查横向/纵向位置是否位于多边形内,php,mysql,geometry,Php,Mysql,Geometry,我需要检查用户lat和long是否驻留在多边形中 我的mysql版本是5.1.73 我尝试的查询如下 SET @g1 = ST_GEOMFROMTEXT('POLYGON((9.557417356841308 80.3155517578125, 7.993957436359008 79.7772216796875, 6.926426847059551 79.8101806640625, 6.206090498573886 80.1068115234375, 5.954826733929924 8
SET @g1 = ST_GEOMFROMTEXT('POLYGON((9.557417356841308 80.3155517578125, 7.993957436359008 79.7772216796875, 6.926426847059551 79.8101806640625, 6.206090498573886 80.1068115234375, 5.954826733929924 80.4254150390625, 6.446317749457659 81.7108154296875, 7.427836528738338 81.8426513671875, 8.309341443917633 81.3592529296875, 9.199715262283302 80.7879638671875, 9.438224391343347 80.4254150390625, 9.470735674130932 80.3155517578125))');
SET @g2 = ST_GEOMFROMTEXT('POINT(6.89249389 80.8487013)');
SELECT ST_Intersects(@g1,@g2);
- 我在生产数据库中没有ST_Intersect函数,但我在本地的mariadb中尝试了它
- 我也试过ST_,但问题还是一样
/**
* to check if the given latitude and longitude reside inside the polygon coordinates
* @param mixed $value The value to be checked
* @$pointsPolygon number vertices - zero-based array
* @$verticesX x-coordinates of the vertices of the polygon
* @$verticesY y-coordinates of the vertices of the polygon
* @$longitudeX longitude to check
* @$latitudeY latitude to check
* @return boolean
*/
function inPolygon($pointsPolygon,$verticesX,$verticesY,$longitudeX,$latitudeY)
{
$i = $j = $c = 0;
for($i = 0,$j = $pointsPolygon; $i < $pointsPolygon; $j = $i++){
if((($verticesY[$i] > $latitudeY != ($verticesY[$j] > $latitudeY)) && ($longitudeX < ($verticesX[$j] - $verticesX[$i]) * ($latitudeY - $verticesY[$i]) / ($verticesY[$j] - $verticesY[$i]) + $verticesX[$i])))
$c = !$c;
}
return $c;
}
)
但我需要从数据库的角度来做
感谢您提供的任何线索。我认为Mysql 5.6+版本完全支持ST_uuuu前缀功能。您可能需要切换到较新的版本或使用PostGIS。对于较新版本的MySQL,您可以进行此操作,这将满足您的需求。是的,我正在寻找一种不升级MySQL版本的解决方案
//sri lanka map zone
$turf = '[{"id":953,"color":"#32CD32","coordinates":[[9.557417356841308,80.3155517578125],
[7.993957436359008,79.7772216796875],[6.926426847059551,79.8101806640625],
[6.206090498573886,80.1068115234375],[5.954826733929924,80.4254150390625],
[6.446317749457659,81.7108154296875],[7.427836528738338,81.8426513671875],
[8.309341443917633,81.3592529296875],[9.199715262283302,80.7879638671875],
[9.438224391343347,80.4254150390625],[9.470735674130932,80.3155517578125]]}]'
$cordinates = $turfArr[0]['coordinates'];
$longLat = '-0.2710333,48.3490398';
$splitArr = explode(',' , $longLat);
$long = $splitArr[0];
$lat = $splitArr[1];