I want print out the intersection of two polygons. but when there is no intersection of two polygons, how can I get to know to avoid print it?
Because if no intersection, I can't call $pgons[0]->polygons, it gives me an error.
(no holes in all polygons)
Thanks!
for my $x(0..$#polygon){
for my $y(0..$#polygon){
if ($x != $y){
my $it = GpcClip('INTERSECTION', $polygon[0]->convert2gpc, $polygon[1]->convert2gpc);
print FO "$x == $y \n";
my @pgons = Gpc2Polygons($it);
#since here we don't have holes, only the first one is a valid polygon
if(@pgons){
print FO Dumper($pgons[0]->polygons->[0]);
print "\n";
}
}
}
}
It seems like
Gpc2Polygons
returns an empty array when no intersection was found. So to determine if the intersection is nonempty you could check if the length of the returned array is greater than zero. For example:The output is: