Skip Menu |

This queue is for tickets about the Math-Polygon CPAN distribution.

Report information
The Basics
Id: 35388
Status: resolved
Priority: 0/
Queue: Math-Polygon

People
Owner: Nobody in particular
Requestors: mark.bitcard [...] hunnibell.net
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: (no value)
Fixed in: (no value)



Hello I installed Math::Polygon and it is very nice but am having what I hope is a problem with my ignorant syntax/usage rather than a bug, but I hope someone will be able to tell me how to fix it. I have some polygons coordinates in one file and another data file with coordinates like 89.000,34.02334 in it and I want to check if the coordinate is inside the polygon. But when I try to use the "contains" function, here is what it says: ----------------- Can't use string ("-80.89629636533394,29.7967418838") as an ARRAY ref while "strict refs" in use at /Library/Perl/5.8.6/Math/Polygon/Calc.pm line 304. ----------------- I have pasted below a simplified version of my test program that produces a similar error as above. Can anyone tell me where the problem is? I am sure it has to do with 'escaping' something, but I just don't know what or how. Thank you Mark Hunnibell -- Dist Name: Math-Polygon-1.00 Perl Version: perl, v5.8.6 built for darwin-thread-multi-2level OS: Mac OS X 10.4 (Tiger) -- #!/usr/bin/perl use Math::Polygon; $coordinates = "-82.39824720054879,26.94012565034653,0 -82.22443797267536,26.41777663135604,0 -81.75327922278925,25.79351665334116,0 -82.39824720054879,26.94012565034653"; @coords = split(/,0 /, $coordinates); my $polygon = Math::Polygon->new(points => \@coords); $latlong = "-80.89629636533394,29.7967418838"; my @ll = split(/\,/, $latlong); my $countinside += $polygon->contains(\@ll); print $countinside;
Subject: Re: [rt.cpan.org #35388]
Date: Fri, 25 Apr 2008 09:19:41 +0200
To: Mark Hunnibell via RT <bug-Math-Polygon [...] rt.cpan.org>
From: Mark Overmeer <mark [...] overmeer.net>
* Mark Hunnibell via RT (bug-Math-Polygon@rt.cpan.org) [080424 23:29]: Show quoted text
> Thu Apr 24 19:29:45 2008: Request 35388 was acted upon. > Transaction: Ticket created by MarkHunnibell > Queue: Math-Polygon > Subject: (No subject given) > Broken in: (no value) > Severity: Important > Owner: Nobody > Requestors: mark.bitcard@hunnibell.net > Status: new > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=35388 > > > Can't use string ("-80.89629636533394,29.7967418838") as an ARRAY ref > while "strict refs" in use at /Library/Perl/5.8.6/Math/Polygon/Calc.pm > line 304.
Math::Polygon represents points as ARRAY-of-Two (or three), but you pass a string. In the "contains" call, you pass the point correctly. Show quoted text
> #!/usr/bin/perl > > use Math::Polygon; > > $coordinates = "-82.39824720054879,26.94012565034653,0 > -82.22443797267536,26.41777663135604,0 > -81.75327922278925,25.79351665334116,0 > -82.39824720054879,26.94012565034653"; > > @coords = split(/,0 /, $coordinates);
my @coords = map { [ split /\,/ ] } split " ", $coordinates; a little more verbose: my @coords; foreach my $point (split ' ', $coordinates) { my ($x, $y, $z) = split /\,/, $point; push @coords, [ $x, $y ]; } Show quoted text
> my $polygon = Math::Polygon->new(points => \@coords); > > $latlong = "-80.89629636533394,29.7967418838"; > my @ll = split(/\,/, $latlong); > my $countinside += $polygon->contains(\@ll);
??? my and += ? my $countinside = $polygon->contains(\@ll) ? "in" : "out"; -- Regards, Met vriendelijke groet, MarkOv ------------------------------------------------------------------------ Mark Overmeer MSc MARKOV Solutions drs Mark A.C.J. Overmeer MARKOV Solutions Mark@Overmeer.net solutions@overmeer.net http://Mark.Overmeer.net http://solutions.overmeer.net
From: mark.bitcard [...] hunnibell.net
On Fri Apr 25 03:21:37 2008, Mark@Overmeer.net wrote: Show quoted text
> > my $countinside += $polygon->contains(\@ll);
> > ??? my and += ? > > my $countinside = $polygon->contains(\@ll) ? "in" : "out";
Thanks. That all worked great. The reason for the += in there is that it is iterating over a list of lat/longs and adding up which ones are inside the polygons. But the "in" "out" was a nice way to see it work. Thanks again.
Subject: Re: [rt.cpan.org #35388]
Date: Fri, 25 Apr 2008 23:44:13 +0200
To: Mark Hunnibell via RT <bug-Math-Polygon [...] rt.cpan.org>
From: Mark Overmeer <mark [...] overmeer.net>
* Mark Hunnibell via RT (bug-Math-Polygon@rt.cpan.org) [080425 21:41]: Show quoted text
> > > my $countinside += $polygon->contains(\@ll);
> > ??? my and += ?
> > The reason for the += in there is that it is iterating over a list of > lat/longs and adding up which ones are inside the polygons. But the > "in" "out" was a nice way to see it work.
My problem is the combination with 'my', which should create a new variable each time. -- MarkOv ------------------------------------------------------------------------ Mark Overmeer MSc MARKOV Solutions Mark@Overmeer.net solutions@overmeer.net http://Mark.Overmeer.net http://solutions.overmeer.net
From: mark.bitcard [...] hunnibell.net
On Fri Apr 25 17:44:35 2008, Mark@Overmeer.net wrote: Show quoted text
> My problem is the combination with 'my', which should create a new > variable each time.
Yes, thanks. I saw how you did "my @coords;" with no value assignment and then put a "my $countinside;" declaration just after that line. Then I simply removed the "my" when I did the conditional incremental increase. I am an old Perl 4.x amateur programmer and all this "my" business is pretty much Greek to me, but I am slowly learning. Thanks again for a great module.