我想在Drupal中使用GEOPHP检查多边形中是否存在一个点。我创建了多边形并从http://www.birdtheme.org/useful/v3tool.html得到了坐标。
$userLocation = geoPHP::load("POINT(77.600555 12.965416)","wkt");
$storeServingArea=geoPHP::load("POLYGON((77.569656 12.986159, 77.596779 12.993518, 77.622185 12.973780, 77.623215 12.954710, 77.608109 12.945676, 77.577896 12.945341, 77.565880 12.957386, 77.565193 12.976122, 77.568970 12.985824))","wkt");
var_dump($storeServingArea->contains($userLocation));
此代码将结果显示为NULL
。
然后我尝试交换纬度和经度的值,并测试如下:
$userLocation = geoPHP::load("POINT(12.965416 77.600555)","wkt");
$storeServingArea=geoPHP::load("POLYGON((12.986159 77.569656, 12.993518 77.596779, 12.973780 77.622185, 12.954710 77.623215, 12.945676 77.608109, 12.945341 77.577896, 12.957386 77.565880, 12.976122 77.565193, 12.985824 77.568970))","wkt");
var_dump($storeServingArea->contains($userLocation));
这也将结果显示为NULL
。
我在这里可能犯的错误是什么?我该如何解决?
SOLUTION:
有用的链接:Check if Google Map Point is in polygon from PHP
我通过以下链接解决了我的问题: http://assemblysys.com/php-point-in-polygon-algorithm/
答案 0 :(得分:2)
为了这个目的,我已经分叉了geoPHP并添加了Polygon-> pointInPolygon和MultiPolygon-> pointInPolygon方法。看看:https://github.com/sookoll/geoPHP
$point = \geoPHP::load('POINT (x y)','wkt');
$polygon = \geoPHP::load('POLYGON ((x y...))','wkt');
$point_is_in_polygon = $polygon->pointInPolygon($point);