Skip to content

Instantly share code, notes, and snippets.

@lolicsystem
Created August 23, 2010 15:14
Show Gist options
  • Save lolicsystem/545685 to your computer and use it in GitHub Desktop.
Save lolicsystem/545685 to your computer and use it in GitHub Desktop.
左上が北緯90°東経0°、右下が南緯90°西経0°なメルカトル図法の地図データから、「黒」の点(海岸線?)の緯度経度を計算し、2次元配列に納め、JSONで出力。出力した結果は、地球儀描画に用いる。
#!/usr/bin/perl
use strict;
use warnings;
use Math::Round;
use GD::Image;
use JSON;
use 5.010;
my $image = GD::Image->newFromPng("worldmap.png");
my ($width,$height) = $image->getBounds();
my @coast; # 海岸線を表す点のリスト
for my $x (0..$width-1) {
for my $y (0..$height-1) {
my $index = $image->getPixel($x, $y);
my ($r, $g, $b) = $image->rgb($index);
if ($r == 0 && $g == 0 && $b == 0) {
my $degx = nearest(0.01, $x / $width * 360);
my $degy = nearest(0.01, ($y - $height / 2) / $height * 180);
push @coast, [$degx, $degy];
}
}
}
print "var coast=";
print encode_json(\@coast);
say ";";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment