I am trying to determine if a certain point is inside of a polygon. Trying to use Math::Polygon. I have the boundary of the polygon in a mySQL table as one record per point for the polygon:
example:
1,38.33208,-75.51919
2,38.33286,-75.52265
etc.
38,38.33208,-75.51919
No matter what I do, the routine will not show the point inside the polygon despite the fact that the point would be truly inside the polygon.
Here's the relevant code
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.
}
No matter what, I can't get the ->contains() routine to ever return true.
Any thoughts would be appreciated. Thanks.
use strict; use warnings;? If not, you should. - melpomene