#!/usr/bin/perl
# Copyright       : http://www.fsf.org/copyleft/gpl.html
# Author 作者     : 積丹尼 Dan Jacobson -- http://jidanni.org/
# Thanks 特別感謝 : millerliu@gmail.com
# Created On      : Tue Feb  2 11:44:51 2016
# Last Modified On: Thu Mar 10 22:06:23 2016
# Update Count    : 19

## try shifting multiple points around so they don't overlap
use strict;
use warnings FATAL => q(all);
my %h;
my $distance = ( $ENV{DISTANCE} or die "no \$ENV{DISTANCE} set" )    #meters
  * 360 / 40_000_000;    #degrees / meters
while (<>) {
s!(<coordinates>)((\d+\.\d+),(\d+.\d+))(.*</coordinates>)!$1 . shifty(undef,undef,$2,$3,$4) . $5!e;
    print;
}

sub shifty {
    for my $pair ( $_[2] ) {
        $h{$pair}++;
        return join ",", map { $_ + $distance * ( $h{$pair} - 1 ) } @_[ 3, 4 ];
    }
}
