【发布时间】:2019-11-10 18:51:06
【问题描述】:
我正在尝试确定某个点是否在多边形内。尝试使用 Math::Polygon。我在 mySQL 表中将多边形的边界作为多边形的每个点的一条记录:
示例:
1,38.33208,-75.51919
2,38.33286,-75.52265
等等
38,38.33208,-75.51919
无论我做什么,例程都不会显示多边形内的点,尽管该点确实在多边形内。
这是相关代码
use Math::Polygon;
my @poly = ();
$sqlc = "SELECT segment,lat,lon FROM boundary WHERE xxxxxxx ";
my $stcc = $dbh->prepare(qq{$sqlc});
$stcc->execute();
while(($seg,$slat,$slon) = $stcc->fetchrow_array())
{
$poly[$seg] = ([$slat,$slon]);
}
my $bound = Math::Polygon->new(points => @poly);
my @this_loc = ([$lat2,$lon2]);
if($bound->contains( $this_loc ))
{
# never reaches this point.
}
无论如何,我无法让 ->contains() 例程返回 true。
任何想法将不胜感激。谢谢。
【问题讨论】:
-
你在使用
use strict; use warnings;吗?如果没有,您应该这样做。