my $service_radius=15; my $numpoints=8; my @complaints = ( { 'complaint_id' => 'a123', 'x' => '45.2', 'y' => '39.7' }, { 'complaint_id' => 'b456', 'x' => '46.5', 'y' => '41.2' }, { 'complaint_id' => 'c789', 'x' => '47.5', 'y' => '38.8' }, { 'complaint_id' => 'd863', 'x' => '95.3', 'y' => '17.2' }, { 'complaint_id' => 'e635', 'x' => '10.5', 'y' => '89.3' }, { 'complaint_id' => 'f635', 'x' => '12.5', 'y' => '1.3' }, { 'complaint_id' => 'g635', 'x' => '14.5', 'y' => '15.3' }, { 'complaint_id' => 'h635', 'x' => '4.5', 'y' => '20.3' }, ) ; while ($numpoints > 0) { my @highlight = (0.0,0.0); my $highvalue = 0.0; my @points; for ($i = 0.0; $i < 100.0; $i += 1.0) { for ($j = 0.0; $j < 100.0; $j+= 1.0) { $points[$i][$j] = 0 ; } } foreach $testpoint (@complaints) { next if not defined $testpoint; print "Plotting " . $testpoint->{'complaint_id'} . "\n"; for ($i = 0.0; $i < 100.0; $i += 1.0) { for ($j = 0.0; $j < 100.0; $j+= 1.0) { $dsqrd = ((($testpoint->{'x'} - $i)**2 + ($testpoint->{'y'} - $j)**2)); $points[$i][$j] += $dsqrd ? (1 / sqrt ($dsqrd)) : 0 ; if ($points[$i][$j] > $highvalue) { @highlight = ($i,$j); $highvalue = $points[$i][$j]; } } } } print "$highlight[0], $highlight[1] has value $highvalue\n"; foreach $testpoint (@complaints) { next if not defined $testpoint; if (sqrt (($testpoint->{'x'} - $highlight[0])**2 + ($testpoint->{'y'} - $highlight[1])**2) < $service_radius) { print "removing " . $testpoint->{'complaint_id'} . " coordinates $testpoint->{'x'} , $testpoint->{'y'}\n"; $testpoint = undef; $numpoints--; } } print "\n\n"; } #end while