使用geoPHP指向多边形 [英] Point in polygon using geoPHP
问题描述
我想检查一个点是否存在于多边形中,或者不在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->包含($ userLocation));
此代码给出的结果为 NULL
。
$ bcode> $ 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->包含($ userLocation));
这也给出了 NULL
的结果。
我在这里可能犯的错误是什么?如何修复它?
解决方案:
有用的链接:检查Google Map Point是否在多边形中来自PHP
我通过以下链接解决了我的问题:
http://assemblysys.com/php-point-in-polygon-algorithm/
我为此分叉了geoPHP并添加了Polygon-> pointInPolygon和MultiPolygon-> pointInPolygon方法。看一看: https://github.com/sookoll/geoPHP
$ point = \geoPHP :: load('POINT(xy)','wkt');
$ polygon = \geoPHP :: load('POLYGON((x y ...))','wkt');
$ point_is_in_polygon = $ polygon-> pointInPolygon($ point);
I want to check a point exists in a polygon or not using GEOPHP in Drupal. I have created the polygon and got the coordinates from 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));
This code gives the result as NULL
.
Then I tried to exchange the values of latitude and longitude and tested like this:
$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));
This also give the result as NULL
.
What could be the possible mistake I'm doing here? how can I fix it?
SOLUTION:
Helpful link: Check if Google Map Point is in polygon from PHP
I fixed my issue with the following link: http://assemblysys.com/php-point-in-polygon-algorithm/
I have forked geoPHP and added Polygon->pointInPolygon and MultiPolygon->pointInPolygon methods for that purpose. Take a look: 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);
这篇关于使用geoPHP指向多边形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!