2
我需要檢查用戶經緯度和長駐留在多邊形。檢查緯度/長位置在一個多邊形
我的MySQL版本是73年5月1日
查詢我想有如下
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);
我沒有在生產DB ST_Intersect功能,但我想它在MariaDB的地方
我試過ST_CONTAINS以及問題是一樣的。
其產生NULL。它應該是1或0但是。多邊形覆蓋斯里蘭卡的國家。而長期和拉特的用戶也是斯里蘭卡的一個城市。
當我用PHP做的時候,下面是我的功能,它沒有任何問題。
/**
* 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;
}
函數調用
//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];
;
但我需要從數據庫方面做到這一點。
欣賞任何線索。
是的,我正在尋找一個解決方案,而無需升級mysql版本 –